From 9e824a79eeae03dc4cdd43d2e2ecf2f252d37093 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Fri, 4 Aug 2017 11:05:38 +0200 Subject: [PATCH] Add functions to check fullscreen windows --- src/x11/screen.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ src/x11/screen.h | 20 ++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/x11/screen.c b/src/x11/screen.c index 070c1f1..6ce1580 100644 --- a/src/x11/screen.c +++ b/src/x11/screen.c @@ -186,6 +186,61 @@ void screen_update_fallback(void) screens[0].dim.h = DisplayHeight(xctx.dpy, screen); } +/* see screen.h */ +bool have_fullscreen_window(void) +{ + return window_is_fullscreen(get_focused_window()); +} + +/* see screen.h */ +bool window_is_fullscreen(Window window) +{ + bool fs = false; + + Atom has_wm_state = XInternAtom(xctx.dpy, "_NET_WM_STATE", True); + if (has_wm_state == None){ + return false; + } + + Atom actual_type_return; + int actual_format_return; + unsigned long bytes_after_return; + unsigned char *prop_to_return; + unsigned long n_items; + int result = XGetWindowProperty( + xctx.dpy, + window, + has_wm_state, + 0, /* long_offset */ + sizeof(window), /* long_length */ + false, /* delete */ + AnyPropertyType, /* req_type */ + &actual_type_return, + &actual_format_return, + &n_items, + &bytes_after_return, + &prop_to_return); + + if (result == Success) { + for(int i = 0; i < n_items; i++) { + char *atom = XGetAtomName(xctx.dpy, ((Atom*)prop_to_return)[i]); + + if (atom) { + if(0 == strcmp("_NET_WM_STATE_FULLSCREEN", atom)) + fs = true; + XFree(atom); + if(fs) + break; + } + } + } + + if (prop_to_return) + XFree(prop_to_return); + + return fs; +} + /* * Select the screen on which the Window * should be displayed. diff --git a/src/x11/screen.h b/src/x11/screen.h index ed71081..fcd020d 100644 --- a/src/x11/screen.h +++ b/src/x11/screen.h @@ -3,6 +3,7 @@ #define DUNST_SCREEN_H #include +#include #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh)) @@ -27,5 +28,24 @@ void screen_check_event(XEvent event); screen_info *get_active_screen(void); double get_dpi_for_screen(screen_info *scr); +/** + * Find the currently focused window and check if it's in + * fullscreen mode + * + * @see window_is_fullscreen() + * @see get_focused_window() + * + * @return `true` if the focused window is in fullscreen mode + */ +bool have_fullscreen_window(void); + +/** + * Check if window is in fullscreen mode + * + * @param window the x11 window object + * @return `true` if `window` is in fullscreen mode + */ +bool window_is_fullscreen(Window window); + #endif /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */