Repository navigation
Expand file tree
/
Copy pathfocus_models.c
More file actions
117 lines (100 loc) · 3.25 KB
/
Copy pathfocus_models.c
File metadata and controls
117 lines (100 loc) · 3.25 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* This example experiments with the 4 ICCCM focus modes. */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
char *window_name[] = { "No Input", "Passive", "Locally Active",
"Globally Active", "Satellite" };
int input_hint[] = { False, True, True, False, False };
int take_focus[] = { False, False, True, True, False };
Window
input_window (Display *d, int screen, int i)
{
Window win;
XWMHints wm_hints;
win = XCreateSimpleWindow (d, RootWindow (d, screen),
10, 10, 150, 10, 0,
WhitePixel (d, screen), WhitePixel (d, screen));
XSelectInput (d, win, ButtonPressMask|FocusChangeMask|KeyPressMask);
XStoreName (d, win, window_name[i]);
wm_hints.flags = InputHint;
wm_hints.input = input_hint[i];
XSetWMHints (d, win, &wm_hints);
if (take_focus[i])
{
Atom protocols[1];
protocols[0] = XInternAtom (d, "WM_TAKE_FOCUS", False);
XSetWMProtocols (d, win, protocols, 1);
}
return win;
}
int main (int argc, char *argv[])
{
Display *d;
int screen, i;
Window window, win[5];
XWindowAttributes xatt;
Atom atom;
XEvent ev;
d = XOpenDisplay (NULL);
screen = DefaultScreen (d);
for (i = 0; i < 5; i++)
{
win[i] = input_window (d, screen, i);
XMapWindow (d, win[i]);
}
while (1)
{
XNextEvent (d, &ev);
for (i = 0; i < 5; i++)
{
window = ev.xany.window;
if (win[i] == window)
{
printf("event on window \"%s\": ", window_name[i]);
switch (ev.xany.type)
{
case FocusIn:
printf ("FocusIn\n");
break;
case FocusOut:
printf ("FocusOut\n");
break;
case ButtonPress:
printf ("ButtonPress\n");
case KeyPress:
printf ("KeyPress %s\n",
XKeysymToString (XLookupKeysym (&ev.xkey, 0)));
break;
case ClientMessage:
atom = ev.xclient.data.l[0];
printf ("ClientMessage %s\n", XGetAtomName (d, atom));
if (atom == XInternAtom (d, "WM_TAKE_FOCUS", False))
{
if (i == 2)
{
printf ("\t...do nothing\n");
}
else if (i == 3)
{
if (XGetWindowAttributes (d, win[4], &xatt)
&& (xatt.map_state == IsViewable))
{
printf ("\t...setting focus on our own\n");
XSetInputFocus (d, win[4], RevertToParent,
ev.xclient.data.l[1]);
}
else
{
printf ("\t...but we are not viewable\n");
}
}
}
break;
default:
printf ("event %d\n", ev.xany.type);
}
}
}
}
return 0;
}