Skip to content

Instantly share code, notes, and snippets.

@aanatoly
Created February 28, 2014 01:37
Show Gist options
  • Select an option

  • Save aanatoly/9263530 to your computer and use it in GitHub Desktop.

Select an option

Save aanatoly/9263530 to your computer and use it in GitHub Desktop.
x11 app to monitor if there is a window in fullscreen mode
/* Compile: gcc xx.c -o xx -lX11 */
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#define err(fmt, args...) \
do { fprintf(stderr, fmt, ## args); } while(0)
static Window fs_win = None;
static int fs_win_state = 0;
static int in_fs = 0;
enum { STATE_NONE, STATE_CREATED, STATE_MAPPED };
static void
fullscreen(Window window, int win_state, char *msg)
{
int old_in_fs = in_fs;
in_fs = (window != None && win_state == STATE_MAPPED);
fs_win = window;
fs_win_state = win_state;
if (old_in_fs != in_fs)
err("fs %s, win %x, src %s\n",
in_fs ? "yes" : "no", (unsigned int) window, msg);
}
int main()
{
Display *display;
Window root;
int screen;
XEvent ev;
int w, h;
display = XOpenDisplay(0);
if (display == NULL) {
err("cannot open display\n");
exit(1);
}
screen = DefaultScreen(display);
root = DefaultRootWindow(display);
w = DisplayWidth(display, screen);
h = DisplayHeight(display, screen);
XSelectInput(display, root, SubstructureNotifyMask);
for (;;) {
XNextEvent(display, &ev);
if (ev.type == ConfigureNotify) {
if (ev.xconfigure.x == 0 && ev.xconfigure.y == 0
&& ev.xconfigure.width == w && ev.xconfigure.height == h)
fullscreen(ev.xconfigure.window, STATE_MAPPED, "configure");
else if (ev.xconfigure.window == fs_win)
fullscreen(None, STATE_NONE, "configure");
} else if (ev.type == CreateNotify) {
if (ev.xcreatewindow.x == 0 && ev.xcreatewindow.y == 0
&& ev.xcreatewindow.width == w && ev.xcreatewindow.height == h
&& ev.xcreatewindow.override_redirect)
fullscreen(ev.xcreatewindow.window, STATE_CREATED, "create");
} else if (ev.type == MapNotify) {
if (ev.xmap.window == fs_win)
fullscreen(ev.xmap.window, STATE_MAPPED, "map");
} else if (ev.type == DestroyNotify) {
if (ev.xdestroywindow.window == fs_win)
fullscreen(None, STATE_NONE, "destroy");
}
}
}
@philopaterwaheed
Copy link
Copy Markdown

Thanks that will help me in my window manager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment