comparison src/video/x11/SDL_x11window.c @ 3685:64ce267332c6

Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 21 Jan 2010 06:21:52 +0000
parents 08c5964f2a34
children f7b03b6838cb
comparison
equal deleted inserted replaced
3684:cc564f08884f 3685:64ce267332c6
43 static void 43 static void
44 X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h) 44 X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h)
45 { 45 {
46 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 46 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
47 SDL_DisplayData *displaydata = 47 SDL_DisplayData *displaydata =
48 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; 48 (SDL_DisplayData *) window->display->driverdata;
49 XWindowAttributes attr; 49 XWindowAttributes attr;
50 50
51 XGetWindowAttributes(data->display, RootWindow(data->display, 51 XGetWindowAttributes(data->display, RootWindow(data->display,
52 displaydata->screen), 52 displaydata->screen),
53 &attr); 53 &attr);
73 data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); 73 data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
74 if (!data) { 74 if (!data) {
75 SDL_OutOfMemory(); 75 SDL_OutOfMemory();
76 return -1; 76 return -1;
77 } 77 }
78 data->windowID = window->id; 78 data->window = window;
79 data->window = w; 79 data->xwindow = w;
80 #ifdef X_HAVE_UTF8_STRING 80 #ifdef X_HAVE_UTF8_STRING
81 if (SDL_X11_HAVE_UTF8) { 81 if (SDL_X11_HAVE_UTF8) {
82 data->ic = 82 data->ic =
83 pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w, 83 pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
84 XNInputStyle, XIMPreeditNothing | XIMStatusNothing, 84 XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
191 } 191 }
192 } 192 }
193 if (GetFocus() == hwnd) { 193 if (GetFocus() == hwnd) {
194 int index = data->videodata->keyboard; 194 int index = data->videodata->keyboard;
195 window->flags |= SDL_WINDOW_INPUT_FOCUS; 195 window->flags |= SDL_WINDOW_INPUT_FOCUS;
196 SDL_SetKeyboardFocus(index, data->windowID); 196 SDL_SetKeyboardFocus(index, data->window);
197 197
198 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { 198 if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
199 RECT rect; 199 RECT rect;
200 GetClientRect(hwnd, &rect); 200 GetClientRect(hwnd, &rect);
201 ClientToScreen(hwnd, (LPPOINT) & rect); 201 ClientToScreen(hwnd, (LPPOINT) & rect);
213 int 213 int
214 X11_CreateWindow(_THIS, SDL_Window * window) 214 X11_CreateWindow(_THIS, SDL_Window * window)
215 { 215 {
216 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 216 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
217 SDL_DisplayData *displaydata = 217 SDL_DisplayData *displaydata =
218 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; 218 (SDL_DisplayData *) window->display->driverdata;
219 Visual *visual; 219 Visual *visual;
220 int depth; 220 int depth;
221 XSetWindowAttributes xattr; 221 XSetWindowAttributes xattr;
222 int x, y; 222 int x, y;
223 Window w; 223 Window w;
780 return; 780 return;
781 } 781 }
782 status = XStringListToTextProperty(&title_locale, 1, &titleprop); 782 status = XStringListToTextProperty(&title_locale, 1, &titleprop);
783 SDL_free(title_locale); 783 SDL_free(title_locale);
784 if (status) { 784 if (status) {
785 XSetTextProperty(display, data->window, &titleprop, XA_WM_NAME); 785 XSetTextProperty(display, data->xwindow, &titleprop, XA_WM_NAME);
786 XFree(titleprop.value); 786 XFree(titleprop.value);
787 } 787 }
788 #ifdef X_HAVE_UTF8_STRING 788 #ifdef X_HAVE_UTF8_STRING
789 if (SDL_X11_HAVE_UTF8) { 789 if (SDL_X11_HAVE_UTF8) {
790 status = 790 status =
791 Xutf8TextListToTextProperty(display, (char **) &title, 1, 791 Xutf8TextListToTextProperty(display, (char **) &title, 1,
792 XUTF8StringStyle, &titleprop); 792 XUTF8StringStyle, &titleprop);
793 if (status == Success) { 793 if (status == Success) {
794 XSetTextProperty(display, data->window, &titleprop, 794 XSetTextProperty(display, data->xwindow, &titleprop,
795 _NET_WM_NAME); 795 _NET_WM_NAME);
796 XFree(titleprop.value); 796 XFree(titleprop.value);
797 } 797 }
798 } 798 }
799 #endif 799 #endif
805 return; 805 return;
806 } 806 }
807 status = XStringListToTextProperty(&icon_locale, 1, &iconprop); 807 status = XStringListToTextProperty(&icon_locale, 1, &iconprop);
808 SDL_free(icon_locale); 808 SDL_free(icon_locale);
809 if (status) { 809 if (status) {
810 XSetTextProperty(display, data->window, &iconprop, 810 XSetTextProperty(display, data->xwindow, &iconprop,
811 XA_WM_ICON_NAME); 811 XA_WM_ICON_NAME);
812 XFree(iconprop.value); 812 XFree(iconprop.value);
813 } 813 }
814 #ifdef X_HAVE_UTF8_STRING 814 #ifdef X_HAVE_UTF8_STRING
815 if (SDL_X11_HAVE_UTF8) { 815 if (SDL_X11_HAVE_UTF8) {
816 status = 816 status =
817 Xutf8TextListToTextProperty(display, (char **) &icon, 1, 817 Xutf8TextListToTextProperty(display, (char **) &icon, 1,
818 XUTF8StringStyle, &iconprop); 818 XUTF8StringStyle, &iconprop);
819 if (status == Success) { 819 if (status == Success) {
820 XSetTextProperty(display, data->window, &iconprop, 820 XSetTextProperty(display, data->xwindow, &iconprop,
821 _NET_WM_ICON_NAME); 821 _NET_WM_ICON_NAME);
822 XFree(iconprop.value); 822 XFree(iconprop.value);
823 } 823 }
824 } 824 }
825 #endif 825 #endif
853 if (propdata) { 853 if (propdata) {
854 propdata[0] = icon->w; 854 propdata[0] = icon->w;
855 propdata[1] = icon->h; 855 propdata[1] = icon->h;
856 SDL_memcpy(&propdata[2], surface->pixels, 856 SDL_memcpy(&propdata[2], surface->pixels,
857 surface->h * surface->pitch); 857 surface->h * surface->pitch);
858 XChangeProperty(display, data->window, _NET_WM_ICON, XA_CARDINAL, 858 XChangeProperty(display, data->xwindow, _NET_WM_ICON, XA_CARDINAL,
859 32, PropModeReplace, (unsigned char *) propdata, 859 32, PropModeReplace, (unsigned char *) propdata,
860 propsize); 860 propsize);
861 } 861 }
862 SDL_FreeSurface(surface); 862 SDL_FreeSurface(surface);
863 } else { 863 } else {
864 XDeleteProperty(display, data->window, _NET_WM_ICON); 864 XDeleteProperty(display, data->xwindow, _NET_WM_ICON);
865 } 865 }
866 } 866 }
867 867
868 void 868 void
869 X11_SetWindowPosition(_THIS, SDL_Window * window) 869 X11_SetWindowPosition(_THIS, SDL_Window * window)
870 { 870 {
871 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 871 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
872 SDL_DisplayData *displaydata = 872 SDL_DisplayData *displaydata =
873 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; 873 (SDL_DisplayData *) window->display->driverdata;
874 Display *display = data->videodata->display; 874 Display *display = data->videodata->display;
875 int x, y; 875 int x, y;
876 876
877 if ((window->flags & SDL_WINDOW_FULLSCREEN) 877 if ((window->flags & SDL_WINDOW_FULLSCREEN)
878 || window->x == SDL_WINDOWPOS_CENTERED) { 878 || window->x == SDL_WINDOWPOS_CENTERED) {
886 X11_GetDisplaySize(_this, window, NULL, &y); 886 X11_GetDisplaySize(_this, window, NULL, &y);
887 y = (y - window->h) / 2; 887 y = (y - window->h) / 2;
888 } else { 888 } else {
889 y = window->y; 889 y = window->y;
890 } 890 }
891 XMoveWindow(display, data->window, x, y); 891 XMoveWindow(display, data->xwindow, x, y);
892 } 892 }
893 893
894 void 894 void
895 X11_SetWindowSize(_THIS, SDL_Window * window) 895 X11_SetWindowSize(_THIS, SDL_Window * window)
896 { 896 {
897 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 897 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
898 Display *display = data->videodata->display; 898 Display *display = data->videodata->display;
899 899
900 XResizeWindow(display, data->window, window->w, window->h); 900 XResizeWindow(display, data->xwindow, window->w, window->h);
901 } 901 }
902 902
903 void 903 void
904 X11_ShowWindow(_THIS, SDL_Window * window) 904 X11_ShowWindow(_THIS, SDL_Window * window)
905 { 905 {
906 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 906 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
907 Display *display = data->videodata->display; 907 Display *display = data->videodata->display;
908 908
909 XMapRaised(display, data->window); 909 XMapRaised(display, data->xwindow);
910 } 910 }
911 911
912 void 912 void
913 X11_HideWindow(_THIS, SDL_Window * window) 913 X11_HideWindow(_THIS, SDL_Window * window)
914 { 914 {
915 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 915 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
916 Display *display = data->videodata->display; 916 Display *display = data->videodata->display;
917 917
918 XUnmapWindow(display, data->window); 918 XUnmapWindow(display, data->xwindow);
919 } 919 }
920 920
921 void 921 void
922 X11_RaiseWindow(_THIS, SDL_Window * window) 922 X11_RaiseWindow(_THIS, SDL_Window * window)
923 { 923 {
924 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 924 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
925 Display *display = data->videodata->display; 925 Display *display = data->videodata->display;
926 926
927 XRaiseWindow(display, data->window); 927 XRaiseWindow(display, data->xwindow);
928 } 928 }
929 929
930 static void 930 static void
931 X11_SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized) 931 X11_SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
932 { 932 {
933 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 933 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
934 SDL_DisplayData *displaydata = 934 SDL_DisplayData *displaydata =
935 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; 935 (SDL_DisplayData *) window->display->driverdata;
936 Display *display = data->videodata->display; 936 Display *display = data->videodata->display;
937 Atom _NET_WM_STATE = XInternAtom(display, "_NET_WM_STATE", False); 937 Atom _NET_WM_STATE = XInternAtom(display, "_NET_WM_STATE", False);
938 Atom _NET_WM_STATE_MAXIMIZED_VERT = 938 Atom _NET_WM_STATE_MAXIMIZED_VERT =
939 XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False); 939 XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
940 Atom _NET_WM_STATE_MAXIMIZED_HORZ = 940 Atom _NET_WM_STATE_MAXIMIZED_HORZ =
941 XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); 941 XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
942 XEvent e; 942 XEvent e;
943 943
944 e.xany.type = ClientMessage; 944 e.xany.type = ClientMessage;
945 e.xany.window = data->window; 945 e.xany.window = data->xwindow;
946 e.xclient.message_type = _NET_WM_STATE; 946 e.xclient.message_type = _NET_WM_STATE;
947 e.xclient.format = 32; 947 e.xclient.format = 32;
948 e.xclient.data.l[0] = 948 e.xclient.data.l[0] =
949 maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; 949 maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
950 e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT; 950 e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT;
984 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN)) 984 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
985 && (window->flags & SDL_WINDOW_INPUT_FOCUS)) { 985 && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
986 /* Try to grab the mouse */ 986 /* Try to grab the mouse */
987 for (;;) { 987 for (;;) {
988 int result = 988 int result =
989 XGrabPointer(display, data->window, True, 0, GrabModeAsync, 989 XGrabPointer(display, data->xwindow, True, 0, GrabModeAsync,
990 GrabModeAsync, data->window, None, CurrentTime); 990 GrabModeAsync, data->xwindow, None, CurrentTime);
991 if (result == GrabSuccess) { 991 if (result == GrabSuccess) {
992 break; 992 break;
993 } 993 }
994 SDL_Delay(100); 994 SDL_Delay(100);
995 } 995 }
996 996
997 /* Raise the window if we grab the mouse */ 997 /* Raise the window if we grab the mouse */
998 XRaiseWindow(display, data->window); 998 XRaiseWindow(display, data->xwindow);
999 999
1000 /* Now grab the keyboard */ 1000 /* Now grab the keyboard */
1001 XGrabKeyboard(display, data->window, True, GrabModeAsync, 1001 XGrabKeyboard(display, data->xwindow, True, GrabModeAsync,
1002 GrabModeAsync, CurrentTime); 1002 GrabModeAsync, CurrentTime);
1003 } else { 1003 } else {
1004 XUngrabPointer(display, CurrentTime); 1004 XUngrabPointer(display, CurrentTime);
1005 XUngrabKeyboard(display, CurrentTime); 1005 XUngrabKeyboard(display, CurrentTime);
1006 } 1006 }
1019 SDL_WindowData **windowlist = videodata->windowlist; 1019 SDL_WindowData **windowlist = videodata->windowlist;
1020 int i; 1020 int i;
1021 1021
1022 if (windowlist) { 1022 if (windowlist) {
1023 for (i = 0; i < numwindows; ++i) { 1023 for (i = 0; i < numwindows; ++i) {
1024 if (windowlist[i] && (windowlist[i]->windowID == window->id)) { 1024 if (windowlist[i] && (windowlist[i]->window == window)) {
1025 windowlist[i] = windowlist[numwindows - 1]; 1025 windowlist[i] = windowlist[numwindows - 1];
1026 windowlist[numwindows - 1] = NULL; 1026 windowlist[numwindows - 1] = NULL;
1027 videodata->numwindows--; 1027 videodata->numwindows--;
1028 break; 1028 break;
1029 } 1029 }
1033 if (data->ic) { 1033 if (data->ic) {
1034 XDestroyIC(data->ic); 1034 XDestroyIC(data->ic);
1035 } 1035 }
1036 #endif 1036 #endif
1037 if (data->created) { 1037 if (data->created) {
1038 XDestroyWindow(display, data->window); 1038 XDestroyWindow(display, data->xwindow);
1039 } 1039 }
1040 SDL_free(data); 1040 SDL_free(data);
1041 } 1041 }
1042 } 1042 }
1043 1043