nsxiv2e758f7
Check if window manager supports fullscreen; related to issue #128
+44 −0
2 files changed
| @@ -54,6 +54,9 @@ static int barheight; | |||
| 54 | 54 | ||
| 55 | 55 | Atom atoms[ATOM_COUNT]; | |
| 56 | 56 | ||
| 57 | + | static Bool fs_support; | |
| 58 | + | static Bool fs_warned; | |
| 59 | + | ||
| 57 | 60 | void win_init_font(Display *dpy, const char *fontstr) | |
| 58 | 61 | { | |
| 59 | 62 | int n; | |
| @@ -102,6 +105,36 @@ unsigned long win_alloc_color(win_t *win, const char *name) | |||
| 102 | 105 | return col.pixel; | |
| 103 | 106 | } | |
| 104 | 107 | ||
| 108 | + | void win_check_wm_support(Display *dpy, Window root) | |
| 109 | + | { | |
| 110 | + | int format; | |
| 111 | + | long offset = 0, length = 16; | |
| 112 | + | Atom *data, type; | |
| 113 | + | unsigned long i, nitems, bytes_left; | |
| 114 | + | Bool found = False; | |
| 115 | + | ||
| 116 | + | while (!found && length > 0) { | |
| 117 | + | if (XGetWindowProperty(dpy, root, atoms[ATOM__NET_SUPPORTED], | |
| 118 | + | offset, length, False, XA_ATOM, &type, &format, | |
| 119 | + | &nitems, &bytes_left, (unsigned char**) &data)) | |
| 120 | + | { | |
| 121 | + | break; | |
| 122 | + | } | |
| 123 | + | if (type == XA_ATOM && format == 32) { | |
| 124 | + | for (i = 0; i < nitems; i++) { | |
| 125 | + | if (data[i] == atoms[ATOM__NET_WM_STATE_FULLSCREEN]) { | |
| 126 | + | found = True; | |
| 127 | + | fs_support = True; | |
| 128 | + | break; | |
| 129 | + | } | |
| 130 | + | } | |
| 131 | + | } | |
| 132 | + | XFree(data); | |
| 133 | + | offset += nitems; | |
| 134 | + | length = MIN(length, bytes_left / 4); | |
| 135 | + | } | |
| 136 | + | } | |
| 137 | + | ||
| 105 | 138 | #define INIT_ATOM_(atom) \ | |
| 106 | 139 | atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False); | |
| 107 | 140 | ||
| @@ -150,6 +183,9 @@ void win_init(win_t *win) | |||
| 150 | 183 | INIT_ATOM_(_NET_WM_ICON); | |
| 151 | 184 | INIT_ATOM_(_NET_WM_STATE); | |
| 152 | 185 | INIT_ATOM_(_NET_WM_STATE_FULLSCREEN); | |
| 186 | + | INIT_ATOM_(_NET_SUPPORTED); | |
| 187 | + | ||
| 188 | + | win_check_wm_support(e->dpy, RootWindow(e->dpy, e->scr)); | |
| 153 | 189 | } | |
| 154 | 190 | ||
| 155 | 191 | void win_update_sizehints(win_t *win) | |
| @@ -379,6 +415,13 @@ void win_toggle_fullscreen(win_t *win) | |||
| 379 | 415 | if (win == NULL || win->xwin == None) | |
| 380 | 416 | return; | |
| 381 | 417 | ||
| 418 | + | if (!fs_support) { | |
| 419 | + | if (!fs_warned) { | |
| 420 | + | warn("window manager does not support fullscreen"); | |
| 421 | + | fs_warned = True; | |
| 422 | + | } | |
| 423 | + | return; | |
| 424 | + | } | |
| 382 | 425 | win->fullscreen = !win->fullscreen; | |
| 383 | 426 | ||
| 384 | 427 | memset(&ev, 0, sizeof(ev)); | |
| @@ -36,6 +36,7 @@ enum { | |||
| 36 | 36 | ATOM__NET_WM_ICON, | |
| 37 | 37 | ATOM__NET_WM_STATE, | |
| 38 | 38 | ATOM__NET_WM_STATE_FULLSCREEN, | |
| 39 | + | ATOM__NET_SUPPORTED, | |
| 39 | 40 | ATOM_COUNT | |
| 40 | 41 | }; | |
| 41 | 42 | ||