aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-07-15 23:57:54 +0100
committerHarry Jeffery <harry@exec64.co.uk>2019-07-15 23:57:54 +0100
commitd49a63d063e24621e296c07a65f62665637d908d (patch)
treed9e53f690af59f59f63b1b73fd2e059f6758a4ab
parent37eb38340851a28b647aca47e167cf20fc7d4ae7 (diff)
downloadimv-d49a63d063e24621e296c07a65f62665637d908d.tar.gz
x11: Add fullscreen support
-rw-r--r--src/x11_window.c50
1 files changed, 44 insertions, 6 deletions
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 <GL/gl.h>
#include <GL/glx.h>
#include <X11/Xlib.h>
+#include <X11/Xatom.h>
#include <assert.h>
#include <poll.h>
#include <stdlib.h>
#include <string.h>
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)