]> icculus.org git repositories - dana/openbox.git/blob - tests/extentsrequest.c
make skiptaskbar test actually skip the taskbar
[dana/openbox.git] / tests / extentsrequest.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    extentsrequest.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/Xatom.h>
23
24 int main () {
25   Display   *display;
26   Window     win;
27   XEvent     report;
28   Atom       _request, _extents, _type, _normal, _desktop;
29   XEvent     msg;
30   int        x=10,y=10,h=100,w=400;
31
32   display = XOpenDisplay(NULL);
33
34   if (display == NULL) {
35     fprintf(stderr, "couldn't connect to X server :0\n");
36     return 0;
37   }
38
39   _type = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
40   _normal = XInternAtom(display, "_NET_WM_WINDOW_TYPE_NORMAL", False);
41   _desktop = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
42   _request = XInternAtom(display, "_NET_REQUEST_FRAME_EXTENTS", False);
43   _extents = XInternAtom(display, "_NET_FRAME_EXTENTS", False);
44
45   win = XCreateWindow(display, RootWindow(display, 0),
46                       x, y, w, h, 10, CopyFromParent, CopyFromParent,
47                       CopyFromParent, 0, NULL);
48   XSelectInput(display, win, PropertyChangeMask);
49
50   printf("requesting for type normal\n");
51   XChangeProperty(display, win, _type, XA_ATOM, 32,
52                   PropModeReplace, (unsigned char*)&_normal, 1);
53   msg.xclient.type = ClientMessage;
54   msg.xclient.message_type = _request;
55   msg.xclient.display = display;
56   msg.xclient.window = win;
57   msg.xclient.format = 32;
58   msg.xclient.data.l[0] = 0l;
59   msg.xclient.data.l[1] = 0l;
60   msg.xclient.data.l[2] = 0l;
61   msg.xclient.data.l[3] = 0l;
62   msg.xclient.data.l[4] = 0l;
63   XSendEvent(display, RootWindow(display, 0), False,
64              SubstructureNotifyMask | SubstructureRedirectMask, &msg);
65   XFlush(display);
66
67   printf("waiting for extents\n");
68   while (1) {
69     XNextEvent(display, &report);
70
71     if (report.type == PropertyNotify &&
72         report.xproperty.atom == _extents)
73     {
74         Atom ret_type;
75         int ret_format;
76         unsigned long ret_items, ret_bytesleft;
77         unsigned long *prop_return;
78         XGetWindowProperty(display, win, _extents, 0, 4,
79                            False, XA_CARDINAL, &ret_type, &ret_format,
80                            &ret_items, &ret_bytesleft,
81                            (unsigned char**) &prop_return);
82         if (ret_type == XA_CARDINAL && ret_format == 32 && ret_items == 4)
83             printf("got new extents %d, %d, %d, %d\n",
84                    prop_return[0], prop_return[1], prop_return[2],
85                    prop_return[3]);
86         break;
87     }
88   }
89
90   printf("requesting for type desktop\n");
91   XChangeProperty(display, win, _type, XA_ATOM, 32,
92                   PropModeReplace, (unsigned char*)&_desktop, 1);
93   msg.xclient.type = ClientMessage;
94   msg.xclient.message_type = _request;
95   msg.xclient.display = display;
96   msg.xclient.window = win;
97   msg.xclient.format = 32;
98   msg.xclient.data.l[0] = 0l;
99   msg.xclient.data.l[1] = 0l;
100   msg.xclient.data.l[2] = 0l;
101   msg.xclient.data.l[3] = 0l;
102   msg.xclient.data.l[4] = 0l;
103   XSendEvent(display, RootWindow(display, 0), False,
104              SubstructureNotifyMask | SubstructureRedirectMask, &msg);
105   XFlush(display);
106
107   printf("waiting for extents\n");
108   while (1) {
109     XNextEvent(display, &report);
110
111     if (report.type == PropertyNotify &&
112         report.xproperty.atom == _extents)
113     {
114         Atom ret_type;
115         int ret_format;
116         unsigned long ret_items, ret_bytesleft;
117         unsigned long *prop_return;
118         XGetWindowProperty(display, win, _extents, 0, 4,
119                            False, XA_CARDINAL, &ret_type, &ret_format,
120                            &ret_items, &ret_bytesleft,
121                            (unsigned char**) &prop_return);
122         if (ret_type == XA_CARDINAL && ret_format == 32 && ret_items == 4)
123             printf("got new extents %d, %d, %d, %d\n",
124                    prop_return[0], prop_return[1], prop_return[2],
125                    prop_return[3]);
126         break;
127     }
128   }
129
130   return 1;
131 }