|
24 | 24 | #ifdef GPUCA_BUILD_EVENT_DISPLAY_X11 |
25 | 25 | #include <GL/glx.h> |
26 | 26 | #include <GL/glxext.h> |
| 27 | +#include <X11/Xatom.h> |
27 | 28 | #endif |
28 | 29 |
|
29 | 30 | #include <pthread.h> |
@@ -187,6 +188,24 @@ void GPUDisplayFrontendGlut::ResizeSceneWrapper(int32_t width, int32_t height) |
187 | 188 | me->mHeight = height; |
188 | 189 | } |
189 | 190 | me->ResizeScene(width, height); |
| 191 | +#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11 |
| 192 | + Display* display = glXGetCurrentDisplay(); // Maximizing / unmaximizing by the window manager changes the size, read the state as freeglut does not report it (fullscreen stays as requested, freeglut tracks it itself) |
| 193 | + Atom type; |
| 194 | + int32_t format; |
| 195 | + unsigned long nItems, bytesAfter; |
| 196 | + unsigned char* data = nullptr; |
| 197 | + if (!display || XGetWindowProperty(display, glXGetCurrentDrawable(), XInternAtom(display, "_NET_WM_STATE", False), 0, 1024, False, XA_ATOM, &type, &format, &nItems, &bytesAfter, &data) != Success || data == nullptr) { |
| 198 | + return; |
| 199 | + } |
| 200 | + const Atom maxHorz = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False), maxVert = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False); |
| 201 | + bool isMaxHorz = false, isMaxVert = false; |
| 202 | + for (unsigned long i = 0; i < nItems; i++) { |
| 203 | + isMaxHorz |= ((Atom*)data)[i] == maxHorz; |
| 204 | + isMaxVert |= ((Atom*)data)[i] == maxVert; |
| 205 | + } |
| 206 | + XFree(data); |
| 207 | + me->setWindowState(me->mFullScreen, isMaxHorz && isMaxVert); |
| 208 | +#endif |
190 | 209 | } |
191 | 210 |
|
192 | 211 | void GPUDisplayFrontendGlut::mouseFunc(int32_t button, int32_t state, int32_t x, int32_t y) |
@@ -313,7 +332,27 @@ void GPUDisplayFrontendGlut::SwitchFullscreen(bool set) |
313 | 332 | } |
314 | 333 | } |
315 | 334 |
|
316 | | -void GPUDisplayFrontendGlut::ToggleMaximized(bool set) {} |
| 335 | +void GPUDisplayFrontendGlut::ToggleMaximized(bool set) // GLUT has no API for maximizing, request it from the window manager via GLX / X11 directly (no-op if freeglut does not use GLX) |
| 336 | +{ |
| 337 | +#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11 |
| 338 | + Display* display = glXGetCurrentDisplay(); |
| 339 | + if (!display) { |
| 340 | + return; |
| 341 | + } |
| 342 | + XEvent xev; |
| 343 | + memset(&xev, 0, sizeof(xev)); |
| 344 | + xev.type = ClientMessage; |
| 345 | + xev.xclient.window = glXGetCurrentDrawable(); // freeglut renders directly to the X window |
| 346 | + xev.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", False); |
| 347 | + xev.xclient.format = 32; |
| 348 | + xev.xclient.data.l[0] = set ? 1 : 0; // _NET_WM_STATE_ADD / _NET_WM_STATE_REMOVE |
| 349 | + xev.xclient.data.l[1] = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); |
| 350 | + xev.xclient.data.l[2] = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False); |
| 351 | + XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev); |
| 352 | + XFlush(display); |
| 353 | +#endif |
| 354 | +} |
| 355 | + |
317 | 356 | void GPUDisplayFrontendGlut::SetVSync(bool enable) // GLUT has no swap interval API, set it via GLX directly (no-op if freeglut does not use GLX) |
318 | 357 | { |
319 | 358 | #ifdef GPUCA_BUILD_EVENT_DISPLAY_X11 |
|
0 commit comments