changes to build..
[mikachu/openbox.git] / 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, FocusChangeMask);
51     XMapWindow(display, win);
52     XMapWindow(display, child);
53
54     while (1) {
55         const char *mode, *detail;
56
57         XNextEvent(display, &report);
58
59         switch (report.type) {
60         case ButtonPress:
61             printf("button press\n");
62             printf("type        : %d\n", report.xbutton.type);
63             printf("serial      : %d\n", report.xbutton.serial);
64             printf("send_event  : %d\n", report.xbutton.send_event);
65             printf("display     : 0x%x\n", report.xbutton.display);
66             printf("window      : 0x%x\n", report.xbutton.window);
67             printf("root        : 0x%x\n", report.xbutton.root);
68             printf("subwindow   : 0x%x\n", report.xbutton.subwindow);
69             printf("time        : %d\n", report.xbutton.time);
70             printf("x, y        : %d, %d\n", report.xbutton.x,
71                    report.xbutton.y);
72             printf("rootx, rooty: %d, %d\n", report.xbutton.x_root,
73                    report.xbutton.y_root);
74             printf("state       : 0x%x\n", report.xbutton.state);
75             printf("button      : %d\n", report.xbutton.button);
76             printf("same_screen : %d\n", report.xbutton.same_screen);
77             printf("---\n");
78             break;
79         case MotionNotify:
80             printf("motion\n");
81             printf("type        : %d\n", report.xmotion.type);
82             printf("serial      : %d\n", report.xmotion.serial);
83             printf("send_event  : %d\n", report.xmotion.send_event);
84             printf("display     : 0x%x\n", report.xmotion.display);
85             printf("window      : 0x%x\n", report.xmotion.window);
86             printf("root        : 0x%x\n", report.xmotion.root);
87             printf("subwindow   : 0x%x\n", report.xmotion.subwindow);
88             printf("time        : %d\n", report.xmotion.time);
89             printf("x, y        : %d, %d\n", report.xmotion.x,
90                    report.xmotion.y);
91             printf("rootx, rooty: %d, %d\n", report.xmotion.x_root,
92                    report.xmotion.y_root);
93             printf("state       : 0x%x\n", report.xmotion.state);
94             printf("is_hint     : %d\n", report.xmotion.is_hint);
95             printf("same_screen : %d\n", report.xmotion.same_screen);
96             printf("---\n");
97             if (XGrabPointer(display, win, False, ButtonReleaseMask,
98                              GrabModeAsync, GrabModeAsync, None, None,
99                              report.xmotion.time) == GrabSuccess)
100                 printf("GrabSuccess\n");
101             else
102                 printf("GrabFail\n");
103             break;
104         case ButtonRelease:
105             XUngrabPointer(display, report.xbutton.time);
106             break;
107         case FocusIn:
108             switch (report.xfocus.mode) {
109             case NotifyNormal: mode = "NotifyNormal"; break;
110             case NotifyGrab: mode = "NotifyGrab"; break;
111             case NotifyUngrab: mode = "NotifyUngrab"; break;
112             }
113
114             switch (report.xfocus.detail) {
115             case NotifyAncestor: detail = "NotifyAncestor"; break;
116             case NotifyVirtual: detail = "NotifyVirtual"; break;
117             case NotifyInferior: detail = "NotifyInferior"; break;
118             case NotifyNonlinear: detail = "NotifyNonlinear"; break;
119             case NotifyNonlinearVirtual: detail = "NotifyNonlinearVirtual"; break;
120             case NotifyPointer: detail = "NotifyPointer"; break;
121             case NotifyPointerRoot: detail = "NotifyPointerRoot"; break;
122             case NotifyDetailNone: detail = "NotifyDetailNone"; break;
123             }
124             printf("focusin\n");
125             printf("type      : %d\n", report.xfocus.type);
126             printf("serial    : %d\n", report.xfocus.serial);
127             printf("send_event: %d\n", report.xfocus.send_event);
128             printf("display   : 0x%x\n", report.xfocus.display);
129             printf("window    : 0x%x\n", report.xfocus.window);
130             printf("mode      : %s\n", mode);
131             printf("detail    : %s\n", detail);
132             printf("---\n");
133             break;
134         case FocusOut:
135             switch (report.xfocus.mode) {
136             case NotifyNormal: mode = "NotifyNormal"; break;
137             case NotifyGrab: mode = "NotifyGrab"; break;
138             case NotifyUngrab: mode = "NotifyUngrab"; break;
139             }
140
141             switch (report.xfocus.detail) {
142             case NotifyAncestor: detail = "NotifyAncestor"; break;
143             case NotifyVirtual: detail = "NotifyVirtual"; break;
144             case NotifyInferior: detail = "NotifyInferior"; break;
145             case NotifyNonlinear: detail = "NotifyNonlinear"; break;
146             case NotifyNonlinearVirtual: detail = "NotifyNonlinearVirtual"; break;
147             case NotifyPointer: detail = "NotifyPointer"; break;
148             case NotifyPointerRoot: detail = "NotifyPointerRoot"; break;
149             case NotifyDetailNone: detail = "NotifyDetailNone"; break;
150             }
151             printf("focusout\n");
152             printf("type      : %d\n", report.xfocus.type);
153             printf("serial    : %d\n", report.xfocus.serial);
154             printf("send_event: %d\n", report.xfocus.send_event);
155             printf("display   : 0x%x\n", report.xfocus.display);
156             printf("window    : 0x%x\n", report.xfocus.window);
157             printf("mode      : %s\n", mode);
158             printf("detail    : %s\n", detail);
159             printf("---\n");
160         }
161
162     }
163
164     return 1;
165 }