forked from patrickhaller/no-wm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
x-focus-manager.c
72 lines (58 loc) · 2.17 KB
/
x-focus-manager.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
x-focus-manager - for misbehaving apps running under no-wm
Written in 2010 by Patrick Haller
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty. You should have
received a copy of the CC0 Public Domain Dedication along with this software.
If not, see http://creativecommons.org/publicdomain/zero/1.0/ */
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
/* some clients fail to reset focus on exit
* we watch for that, and fix it
*
* instead of this, we also could use Elliott Hughes' clock
* to launch x-alt-tab
*/
void reset_focus(Display *d, XEvent *e);
static void (*handler[LASTEvent]) (Display *d, XEvent *) = {
[UnmapNotify] = reset_focus,
[DestroyNotify] = reset_focus
};
/// fun on down
void
reset_focus(Display *d, XEvent *e) {
XSetInputFocus(d, PointerRoot , RevertToPointerRoot, CurrentTime);
}
void set_atoms(Display *dpy) { // from scrotwm via euclid-wm
int root = DefaultRootWindow(dpy);
Atom wm_change_state = XInternAtom(dpy,"_NET_WM_STATE",False);
Atom wm_supported = XInternAtom(dpy,"_NET_SUPPORTED",False);
Atom wm_check = XInternAtom(dpy,"_NET_SUPPORTING_WM_CHECK",False);
Atom wm_name = XInternAtom(dpy,"_NET_WM_NAME",False);
Atom utf8 = XInternAtom(dpy,"UTF8_STRING",False);
Atom supported[] = {wm_supported, wm_name, wm_change_state};
XChangeProperty(dpy,root,wm_check,XA_WINDOW,32,PropModeReplace,(unsigned char *)&root,1);
XChangeProperty(dpy,root,wm_name,utf8,8,PropModeReplace,(unsigned char *) "LG3D",5);
XChangeProperty(dpy,root,wm_supported,XA_ATOM,32,PropModeReplace,(unsigned char *) supported,4);
XSync(dpy,False);
}
int
main(int argc, char **argv) {
Display *dpy;
XEvent e;
XSetWindowAttributes wa;
if(!(dpy = XOpenDisplay(NULL)))
return 1;
wa.cursor = XCreateFontCursor(dpy, XC_left_ptr);
wa.event_mask = SubstructureNotifyMask|StructureNotifyMask;
XChangeWindowAttributes(dpy, DefaultRootWindow(dpy) , CWEventMask|CWCursor, &wa);
set_atoms(dpy);
for(;;) {
XNextEvent(dpy, &e);
if(handler[e.type])
handler[e.type](dpy, &e);
}
}