Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11window.c @ 3077:9b58f26ede81
Implemented X11 maximized state control
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 19 Feb 2009 06:48:25 +0000 |
parents | 089a77aebb7d |
children | 81d15ace9129 |
comparison
equal
deleted
inserted
replaced
3076:085e46423377 | 3077:9b58f26ede81 |
---|---|
28 | 28 |
29 #include "SDL_x11video.h" | 29 #include "SDL_x11video.h" |
30 #include "SDL_x11mouse.h" | 30 #include "SDL_x11mouse.h" |
31 #include "SDL_x11gamma.h" | 31 #include "SDL_x11gamma.h" |
32 #include "../Xext/extensions/StdCmap.h" | 32 #include "../Xext/extensions/StdCmap.h" |
33 | |
34 #define _NET_WM_STATE_REMOVE 0l | |
35 #define _NET_WM_STATE_ADD 1l | |
36 #define _NET_WM_STATE_TOGGLE 2l | |
33 | 37 |
34 static void | 38 static void |
35 X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h) | 39 X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h) |
36 { | 40 { |
37 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 41 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
114 window->flags |= SDL_WINDOW_SHOWN; | 118 window->flags |= SDL_WINDOW_SHOWN; |
115 } else { | 119 } else { |
116 window->flags &= ~SDL_WINDOW_SHOWN; | 120 window->flags &= ~SDL_WINDOW_SHOWN; |
117 } | 121 } |
118 } | 122 } |
123 | |
124 { | |
125 Atom _NET_WM_STATE = XInternAtom(data->videodata->display, "_NET_WM_STATE", False); | |
126 Atom _NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(data->videodata->display, "_NET_WM_STATE_MAXIMIZED_VERT", False); | |
127 Atom _NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(data->videodata->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); | |
128 Atom actualType; | |
129 int actualFormat; | |
130 unsigned long i, numItems, bytesAfter; | |
131 unsigned char *propertyValue = NULL; | |
132 long maxLength = 1024; | |
133 | |
134 if (XGetWindowProperty(data->videodata->display, w, _NET_WM_STATE, | |
135 0l, maxLength, False, XA_ATOM, &actualType, &actualFormat, | |
136 &numItems, &bytesAfter, &propertyValue) == Success) { | |
137 Atom *atoms = (Atom *)propertyValue; | |
138 int maximized = 0; | |
139 | |
140 for (i = 0; i < numItems; ++i) { | |
141 if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT) { | |
142 maximized |= 1; | |
143 } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) { | |
144 maximized |= 2; | |
145 } | |
146 /* Might also want to check the following properties: | |
147 _NET_WM_STATE_ABOVE, _NET_WM_STATE_FULLSCREEN | |
148 */ | |
149 } | |
150 if (maximized == 3) { | |
151 window->flags |= SDL_WINDOW_MAXIMIZED; | |
152 } | |
153 XFree(propertyValue); | |
154 } | |
155 } | |
156 | |
119 /* FIXME: How can I tell? | 157 /* FIXME: How can I tell? |
120 { | 158 { |
121 DWORD style = GetWindowLong(hwnd, GWL_STYLE); | 159 DWORD style = GetWindowLong(hwnd, GWL_STYLE); |
122 if (style & WS_VISIBLE) { | 160 if (style & WS_VISIBLE) { |
123 if (style & (WS_BORDER | WS_THICKFRAME)) { | 161 if (style & (WS_BORDER | WS_THICKFRAME)) { |
855 Display *display = data->videodata->display; | 893 Display *display = data->videodata->display; |
856 | 894 |
857 XRaiseWindow(display, data->window); | 895 XRaiseWindow(display, data->window); |
858 } | 896 } |
859 | 897 |
898 static void | |
899 X11_SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized) | |
900 { | |
901 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; | |
902 SDL_DisplayData *displaydata = | |
903 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; | |
904 Display *display = data->videodata->display; | |
905 Atom _NET_WM_STATE = XInternAtom(display, "_NET_WM_STATE", False); | |
906 Atom _NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False); | |
907 Atom _NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); | |
908 XEvent e; | |
909 | |
910 e.xany.type = ClientMessage; | |
911 e.xany.window = data->window; | |
912 e.xclient.message_type = _NET_WM_STATE; | |
913 e.xclient.format = 32; | |
914 e.xclient.data.l[0] = maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; | |
915 e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT; | |
916 e.xclient.data.l[2] = _NET_WM_STATE_MAXIMIZED_HORZ; | |
917 e.xclient.data.l[3] = 0l; | |
918 e.xclient.data.l[4] = 0l; | |
919 | |
920 XSendEvent(display, RootWindow(display, displaydata->screen), 0, | |
921 SubstructureNotifyMask|SubstructureRedirectMask, &e); | |
922 } | |
923 | |
860 void | 924 void |
861 X11_MaximizeWindow(_THIS, SDL_Window * window) | 925 X11_MaximizeWindow(_THIS, SDL_Window * window) |
862 { | 926 { |
863 /* FIXME: is this even possible? */ | 927 X11_SetWindowMaximized(_this, window, SDL_TRUE); |
864 } | 928 } |
865 | 929 |
866 void | 930 void |
867 X11_MinimizeWindow(_THIS, SDL_Window * window) | 931 X11_MinimizeWindow(_THIS, SDL_Window * window) |
868 { | 932 { |
870 } | 934 } |
871 | 935 |
872 void | 936 void |
873 X11_RestoreWindow(_THIS, SDL_Window * window) | 937 X11_RestoreWindow(_THIS, SDL_Window * window) |
874 { | 938 { |
939 X11_SetWindowMaximized(_this, window, SDL_FALSE); | |
875 X11_ShowWindow(_this, window); | 940 X11_ShowWindow(_this, window); |
876 } | 941 } |
877 | 942 |
878 void | 943 void |
879 X11_SetWindowGrab(_THIS, SDL_Window * window) | 944 X11_SetWindowGrab(_THIS, SDL_Window * window) |