From d49a63d063e24621e296c07a65f62665637d908d Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Mon, 15 Jul 2019 23:57:54 +0100 Subject: x11: Add fullscreen support --- src/x11_window.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/x11_window.c b/src/x11_window.c index 59c6119..0f488e2 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -3,18 +3,20 @@ #include #include #include +#include #include #include #include #include struct imv_window { - Display *x_display; - Window x_window; + Display *x_display; + Window x_window; GLXContext x_glc; + Atom x_state; + Atom x_fullscreen; int width; int height; - bool fullscreen; }; struct imv_window *imv_window_create(int w, int h, const char *title) @@ -47,6 +49,9 @@ struct imv_window *imv_window_create(int w, int h, const char *title) window->x_window = XCreateWindow(window->x_display, root, 0, 0, w, h, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &wa); + window->x_state = XInternAtom(window->x_display, "_NET_WM_STATE", true); + window->x_fullscreen = XInternAtom(window->x_display, "_NET_WM_STATE_FULLSCREEN", true); + XMapWindow(window->x_display, window->x_window); XStoreName(window->x_display, window->x_window, title); @@ -99,13 +104,46 @@ void imv_window_set_title(struct imv_window *window, const char *title) bool imv_window_is_fullscreen(struct imv_window *window) { - return window->fullscreen; + size_t count = 0; + Atom type; + int format; + size_t after; + Atom *props = NULL; + XGetWindowProperty(window->x_display, window->x_window, window->x_state, + 0, 1024, False, XA_ATOM, &type, &format, &count, &after, (unsigned char**)&props); + + bool fullscreen = false; + for (size_t i = 0; i < count; ++i) { + if (props[i] == window->x_fullscreen) { + fullscreen = true; + break; + } + } + XFree(props); + return fullscreen; } void imv_window_set_fullscreen(struct imv_window *window, bool fullscreen) { - (void)window; - (void)fullscreen; + Window root = DefaultRootWindow(window->x_display); + XEvent event = { + .xclient = { + .type = ClientMessage, + .window = window->x_window, + .format = 32, + .message_type = window->x_state, + .data = { + .l = { + (fullscreen ? 1 : 0), + window->x_fullscreen, + 0, + 1 + } + } + } + }; + XSendEvent(window->x_display, root, False, + SubstructureNotifyMask | SubstructureRedirectMask, &event ); } bool imv_window_get_mouse_button(struct imv_window *window, int button) -- cgit v1.2.3