Well, now, you should have mentioned SDL. That makes it trickier indeed. The only true solution is moving over to SDL2, you will need to do that for Wayland support anyway. But if that is not an option, make sure you do these on SDL1:
And now the SDL variant, the most complicated of all:
SDL2 version for comparison:
- create the window as resizable (this is also true for SDL2, even the SDL_WINDOW_MAXIMIZED flag will not work without SDL_WINDOW_RESIZABLE)
- use info.x11.gfxdisplay and info.x11.wmwindow values from the SDL_SysWMinfo, not the regular display and window
- call XFlush after XSendEvent (SDL should take care of this but apparently it doesn't)
And now the SDL variant, the most complicated of all:
Code:
#include <SDL/SDL.h> #include <SDL/SDL_syswm.h> int main() { SDL_Init(SDL_INIT_VIDEO); const SDL_VideoInfo *video_info = SDL_GetVideoInfo(); SDL_SetVideoMode(100, 200, video_info->vfmt->BitsPerPixel, SDL_OPENGL | SDL_RESIZABLE); SDL_SysWMinfo wm_info; SDL_VERSION(&wm_info.version); SDL_GetWMInfo(&wm_info); Display *dpy = wm_info.info.x11.gfxdisplay; Window w = wm_info.info.x11.wmwindow; XEvent xev = {0}; xev.type = ClientMessage; xev.xclient.window = w; xev.xclient.message_type = XInternAtom(dpy, "_NET_WM_STATE", False);; xev.xclient.format = 32; xev.xclient.data.l[0] = 2; xev.xclient.data.l[1] = XInternAtom(dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);; xev.xclient.data.l[2] = XInternAtom(dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False); XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureNotifyMask, &xev); XFlush(dpy); for(;;) { SDL_Event event; SDL_PollEvent(&event); switch( event.type ) { case SDL_VIDEORESIZE: SDL_SetVideoMode(event.resize.w, event.resize.h, video_info->vfmt->BitsPerPixel, SDL_OPENGL | SDL_RESIZABLE); break; case SDL_QUIT: SDL_Quit(); exit(0); } } return 0; }
Code:
#include <SDL2/SDL.h> int main() { SDL_Init(SDL_INIT_VIDEO); SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, 200, 200, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN); SDL_MaximizeWindow(win); for(;;) { SDL_Event event; SDL_PollEvent(&event); switch(event.type) { case SDL_QUIT: SDL_DestroyWindow(win); SDL_Quit(); exit(0); } } return 0; }
Comment