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