]> Dogcows Code - chaz/openbox/blob - tests/focusout.c
Merge branch 'master' into chaz
[chaz/openbox] / tests / focusout.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 focusout.c for the Openbox window manager
4 Copyright (c) 2003-2007 Dana Jansens
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include <stdio.h>
20 #include <unistd.h>
21 #include <X11/Xlib.h>
22 #include <X11/Xutil.h>
23
24 int main () {
25 Display *display;
26 Window win, child;
27 XEvent report;
28 Atom _net_fs, _net_state;
29 XEvent msg;
30 int x=50,y=50,h=100,w=400;
31 XWMHints hint;
32
33 display = XOpenDisplay(NULL);
34
35 if (display == NULL) {
36 fprintf(stderr, "couldn't connect to X server :0\n");
37 return 0;
38 }
39
40 win = XCreateWindow(display, RootWindow(display, 0),
41 x, y, w, h, 10, CopyFromParent, CopyFromParent,
42 CopyFromParent, 0, NULL);
43 child = XCreateWindow(display, win,
44 10, 10, w-20, h-20, 0, CopyFromParent, CopyFromParent,
45 CopyFromParent, 0, NULL);
46
47 XSetWindowBackground(display,win,WhitePixel(display,0));
48 XSetWindowBackground(display,child,BlackPixel(display,0));
49
50 XSelectInput(display, win,
51 FocusChangeMask|EnterWindowMask|LeaveWindowMask);
52 XMapWindow(display, win);
53 XMapWindow(display, child);
54
55 while (1) {
56 const char *mode, *detail;
57
58 XNextEvent(display, &report);
59
60 switch (report.type) {
61 case ButtonPress:
62 printf("button press\n");
63 printf("type : %d\n", report.xbutton.type);
64 printf("serial : %d\n", report.xbutton.serial);
65 printf("send_event : %d\n", report.xbutton.send_event);
66 printf("display : 0x%x\n", report.xbutton.display);
67 printf("window : 0x%x\n", report.xbutton.window);
68 printf("root : 0x%x\n", report.xbutton.root);
69 printf("subwindow : 0x%x\n", report.xbutton.subwindow);
70 printf("time : %d\n", report.xbutton.time);
71 printf("x, y : %d, %d\n", report.xbutton.x,
72 report.xbutton.y);
73 printf("rootx, rooty: %d, %d\n", report.xbutton.x_root,
74 report.xbutton.y_root);
75 printf("state : 0x%x\n", report.xbutton.state);
76 printf("button : %d\n", report.xbutton.button);
77 printf("same_screen : %d\n", report.xbutton.same_screen);
78 printf("---\n");
79 break;
80 case MotionNotify:
81 printf("motion\n");
82 printf("type : %d\n", report.xmotion.type);
83 printf("serial : %d\n", report.xmotion.serial);
84 printf("send_event : %d\n", report.xmotion.send_event);
85 printf("display : 0x%x\n", report.xmotion.display);
86 printf("window : 0x%x\n", report.xmotion.window);
87 printf("root : 0x%x\n", report.xmotion.root);
88 printf("subwindow : 0x%x\n", report.xmotion.subwindow);
89 printf("time : %d\n", report.xmotion.time);
90 printf("x, y : %d, %d\n", report.xmotion.x,
91 report.xmotion.y);
92 printf("rootx, rooty: %d, %d\n", report.xmotion.x_root,
93 report.xmotion.y_root);
94 printf("state : 0x%x\n", report.xmotion.state);
95 printf("is_hint : %d\n", report.xmotion.is_hint);
96 printf("same_screen : %d\n", report.xmotion.same_screen);
97 printf("---\n");
98 if (XGrabPointer(display, win, False, ButtonReleaseMask,
99 GrabModeAsync, GrabModeAsync, None, None,
100 report.xmotion.time) == GrabSuccess)
101 printf("GrabSuccess\n");
102 else
103 printf("GrabFail\n");
104 break;
105 case ButtonRelease:
106 XUngrabPointer(display, report.xbutton.time);
107 break;
108 case FocusIn:
109 switch (report.xfocus.mode) {
110 case NotifyNormal: mode = "NotifyNormal"; break;
111 case NotifyGrab: mode = "NotifyGrab"; break;
112 case NotifyUngrab: mode = "NotifyUngrab"; break;
113 }
114
115 switch (report.xfocus.detail) {
116 case NotifyAncestor: detail = "NotifyAncestor"; break;
117 case NotifyVirtual: detail = "NotifyVirtual"; break;
118 case NotifyInferior: detail = "NotifyInferior"; break;
119 case NotifyNonlinear: detail = "NotifyNonlinear"; break;
120 case NotifyNonlinearVirtual:
121 detail = "NotifyNonlinearVirtual"; break;
122 case NotifyPointer: detail = "NotifyPointer"; break;
123 case NotifyPointerRoot: detail = "NotifyPointerRoot"; break;
124 case NotifyDetailNone: detail = "NotifyDetailNone"; break;
125 }
126 printf("focusin\n");
127 printf("type : %d\n", report.xfocus.type);
128 printf("serial : %d\n", report.xfocus.serial);
129 printf("send_event: %d\n", report.xfocus.send_event);
130 printf("display : 0x%x\n", report.xfocus.display);
131 printf("window : 0x%x\n", report.xfocus.window);
132 printf("mode : %s\n", mode);
133 printf("detail : %s\n", detail);
134 printf("---\n");
135 break;
136 case FocusOut:
137 switch (report.xfocus.mode) {
138 case NotifyNormal: mode = "NotifyNormal"; break;
139 case NotifyGrab: mode = "NotifyGrab"; break;
140 case NotifyUngrab: mode = "NotifyUngrab"; break;
141 }
142
143 switch (report.xfocus.detail) {
144 case NotifyAncestor: detail = "NotifyAncestor"; break;
145 case NotifyVirtual: detail = "NotifyVirtual"; break;
146 case NotifyInferior: detail = "NotifyInferior"; break;
147 case NotifyNonlinear: detail = "NotifyNonlinear"; break;
148 case NotifyNonlinearVirtual:
149 detail = "NotifyNonlinearVirtual"; break;
150 case NotifyPointer: detail = "NotifyPointer"; break;
151 case NotifyPointerRoot: detail = "NotifyPointerRoot"; break;
152 case NotifyDetailNone: detail = "NotifyDetailNone"; break;
153 }
154 printf("focusout\n");
155 printf("type : %d\n", report.xfocus.type);
156 printf("serial : %d\n", report.xfocus.serial);
157 printf("send_event: %d\n", report.xfocus.send_event);
158 printf("display : 0x%x\n", report.xfocus.display);
159 printf("window : 0x%x\n", report.xfocus.window);
160 printf("mode : %s\n", mode);
161 printf("detail : %s\n", detail);
162 printf("---\n");
163 break;
164 case EnterNotify:
165 switch (report.xcrossing.mode) {
166 case NotifyNormal: mode = "NotifyNormal"; break;
167 case NotifyGrab: mode = "NotifyGrab"; break;
168 case NotifyUngrab: mode = "NotifyUngrab"; break;
169 }
170
171 switch (report.xcrossing.detail) {
172 case NotifyAncestor: detail = "NotifyAncestor"; break;
173 case NotifyVirtual: detail = "NotifyVirtual"; break;
174 case NotifyInferior: detail = "NotifyInferior"; break;
175 case NotifyNonlinear: detail = "NotifyNonlinear"; break;
176 case NotifyNonlinearVirtual:
177 detail = "NotifyNonlinearVirtual"; break;
178 case NotifyPointer: detail = "NotifyPointer"; break;
179 case NotifyPointerRoot: detail = "NotifyPointerRoot"; break;
180 case NotifyDetailNone: detail = "NotifyDetailNone"; break;
181 }
182 printf("enternotify\n");
183 printf("type : %d\n", report.xcrossing.type);
184 printf("serial : %d\n", report.xcrossing.serial);
185 printf("send_event: %d\n", report.xcrossing.send_event);
186 printf("display : 0x%x\n", report.xcrossing.display);
187 printf("window : 0x%x\n", report.xcrossing.window);
188 printf("mode : %s\n", mode);
189 printf("detail : %s\n", detail);
190 printf("---\n");
191 break;
192 case LeaveNotify:
193 switch (report.xcrossing.mode) {
194 case NotifyNormal: mode = "NotifyNormal"; break;
195 case NotifyGrab: mode = "NotifyGrab"; break;
196 case NotifyUngrab: mode = "NotifyUngrab"; break;
197 }
198
199 switch (report.xcrossing.detail) {
200 case NotifyAncestor: detail = "NotifyAncestor"; break;
201 case NotifyVirtual: detail = "NotifyVirtual"; break;
202 case NotifyInferior: detail = "NotifyInferior"; break;
203 case NotifyNonlinear: detail = "NotifyNonlinear"; break;
204 case NotifyNonlinearVirtual:
205 detail = "NotifyNonlinearVirtual"; break;
206 case NotifyPointer: detail = "NotifyPointer"; break;
207 case NotifyPointerRoot: detail = "NotifyPointerRoot"; break;
208 case NotifyDetailNone: detail = "NotifyDetailNone"; break;
209 }
210 printf("leavenotify\n");
211 printf("type : %d\n", report.xcrossing.type);
212 printf("serial : %d\n", report.xcrossing.serial);
213 printf("send_event: %d\n", report.xcrossing.send_event);
214 printf("display : 0x%x\n", report.xcrossing.display);
215 printf("window : 0x%x\n", report.xcrossing.window);
216 printf("mode : %s\n", mode);
217 printf("detail : %s\n", detail);
218 printf("---\n");
219 break;
220 }
221 }
222
223 return 1;
224 }
This page took 0.044066 seconds and 4 git commands to generate.