fixing parse error in execcommand
[bbkeys.git] / src / wminterface.cc
blob0669fc387e19ba065d05d74db845e04d47022887
1 // wminterface.cc for bbtools.
2 //
3 // Copyright (c) 1998-1999 by John Kennis, jkennis@chello.nl
4 // Copyright (c) 2001 by Ben Jansens <xor@orodu.net>
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.
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.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 // (See the included file COPYING / GPL-2.0)
22 // $Id$
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif // HAVE_CONFIG_H
28 #include "wminterface.hh"
29 #include "bbkeys.hh"
31 WMInterface::WMInterface(ToolWindow *toolwindow) : NETInterface(toolwindow) {
32 bbtool=toolwindow;
35 WMInterface::~WMInterface() {
38 void WMInterface::sendClientMessage(Atom atom, XID data) {
39 XEvent e;
40 unsigned long mask;
42 e.xclient.type = ClientMessage;
43 e.xclient.window = bbtool->getCurrentScreenInfo()->getRootWindow();
44 e.xclient.message_type = atom;
45 e.xclient.format = 32;
46 e.xclient.data.l[0] = (unsigned long) data;
47 e.xclient.data.l[1] = 0;
49 mask = SubstructureRedirectMask;
50 XSendEvent(bbtool->getXDisplay(),
51 bbtool->getCurrentScreenInfo()->getRootWindow(),
52 False, mask, &e);
55 void WMInterface::changeDesktop(int desk_number, bool) {
56 sendClientMessage(bbtool->getBlackboxChangeWorkspaceAtom(),
57 static_cast<unsigned long int>(desk_number));
60 void WMInterface::sendWindowToDesktop(Window win, int desk_number) {
61 XEvent e;
62 unsigned long mask;
64 e.xclient.type = ClientMessage;
65 e.xclient.window = win;
66 e.xclient.message_type = bbtool->getBlackboxChangeAttributesAtom();
67 e.xclient.format = 32;
68 e.xclient.data.l[0] = AttribWorkspace;
69 e.xclient.data.l[2] = desk_number;
70 e.xclient.data.l[1] = e.xclient.data.l[3] = 0;
71 e.xclient.data.l[4] = e.xclient.data.l[5] = 0;
73 mask = SubstructureRedirectMask;
74 XSendEvent(bbtool->getXDisplay(),
75 bbtool->getCurrentScreenInfo()->getRootWindow(),
76 False, mask, &e);
77 bbtool->moveWinToDesktop(win, desk_number);
80 void WMInterface::decorateToggleWindow(Window win)
82 XEvent e;
83 e.xclient.type = ClientMessage;
84 e.xclient.message_type = bbtool->getBlackboxChangeAttributesAtom();
85 e.xclient.window = win;
86 e.xclient.format = 32;
87 e.xclient.data.l[0] = e.xclient.data.l[1] =
88 e.xclient.data.l[2] = e.xclient.data.l[3] =
89 e.xclient.data.l[4] = e.xclient.data.l[5] = 0l;
90 e.xclient.data.l[0] |= AttribDecoration;
92 int format;
93 Atom atom_return;
94 unsigned long num, len;
95 BlackboxAttributes *net_attributes;
97 if (XGetWindowProperty(bbtool->getXDisplay(), win,
98 bbtool->getBlackboxAttributesAtom(), 0,
99 PropBlackboxAttributesElements, False,
100 bbtool->getBlackboxAttributesAtom(), &atom_return,
101 &format, &num, &len, (unsigned char **) &net_attributes)
103 Success && net_attributes) {
104 if(num == PropBlackboxAttributesElements) {
105 if (net_attributes->decoration == DecorNone)
106 e.xclient.data.l[4] = DecorNormal;
107 else
108 e.xclient.data.l[4] = DecorNone;
110 XFree((void *) net_attributes);
111 } else
112 e.xclient.data.l[4] = DecorNone;
114 XSendEvent(bbtool->getXDisplay(), bbtool->getScreenInfo(0)->getRootWindow(), False,
115 SubstructureRedirectMask, &e);
118 void WMInterface::setWindowFocus(Window win) {
119 XEvent e;
120 unsigned long mask;
122 e.xclient.type = ClientMessage;
123 e.xclient.window = win;
125 e.xclient.message_type = bbtool->getBlackboxChangeWindowFocusAtom();
126 e.xclient.format = 32;
127 e.xclient.data.l[0] = 0;
128 e.xclient.data.l[1] = 0;
130 mask = SubstructureRedirectMask;
131 XSendEvent(bbtool->getXDisplay(),
132 bbtool->getCurrentScreenInfo()->getRootWindow(),
133 False, mask, &e);
136 void WMInterface::shadeWindow(Window win) {
137 XEvent e;
138 e.xclient.type = ClientMessage;
139 e.xclient.message_type = bbtool->getBlackboxChangeAttributesAtom();
140 e.xclient.window = win;
141 e.xclient.format = 32;
142 e.xclient.data.l[0] = AttribShaded;
143 e.xclient.data.l[2] = e.xclient.data.l[3] = e.xclient.data.l[4] = 0l;
145 Atom atom_return;
146 int foo;
147 unsigned long ulfoo, nitems;
148 BlackboxAttributes *net;
149 if (XGetWindowProperty(bbtool->getXDisplay(), win,
150 bbtool->getBlackboxAttributesAtom(),
152 PropBlackboxAttributesElements,
153 False,
154 bbtool->getBlackboxAttributesAtom(),
155 &atom_return, &foo, &nitems, &ulfoo, (unsigned char **) &net)
157 Success && net && nitems
159 PropBlackboxAttributesElements)
161 e.xclient.data.l[1] = net->attrib ^ AttribShaded;
162 XFree((void *) net);
163 } else
164 e.xclient.data.l[1] = AttribShaded;
166 XSendEvent(bbtool->getXDisplay(), bbtool->getScreenInfo(0)->getRootWindow(), False,
167 SubstructureRedirectMask, &e);
170 void WMInterface::maximizeWindow(Window win, bool maxhorz, bool maxvert) {
171 XEvent e;
172 e.xclient.type = ClientMessage;
173 e.xclient.message_type = bbtool->getBlackboxChangeAttributesAtom();
174 e.xclient.window = win;
175 e.xclient.format = 32;
176 e.xclient.data.l[0] = (maxhorz?AttribMaxHoriz:0) | (maxvert?AttribMaxVert:0);
177 e.xclient.data.l[2] = e.xclient.data.l[3] = e.xclient.data.l[4] = 0l;
179 Atom atom_return;
180 int foo;
181 unsigned long ulfoo, nitems;
182 BlackboxAttributes *net;
183 if (XGetWindowProperty(bbtool->getXDisplay(),
184 win,
185 bbtool->getBlackboxAttributesAtom(),
187 PropBlackboxAttributesElements,
188 False,
189 bbtool->getBlackboxAttributesAtom(),
190 &atom_return, &foo, &nitems, &ulfoo, (unsigned char **) &net)
192 Success && net && nitems
194 PropBlackboxAttributesElements) {
195 e.xclient.data.l[1] =
196 net->attrib ^ ((maxhorz?AttribMaxHoriz:0) | (maxvert?AttribMaxVert:0));
197 XFree((void *) net);
198 } else
199 e.xclient.data.l[1] = (maxhorz?AttribMaxHoriz:0) | (maxvert?AttribMaxVert:0);
201 XSendEvent(bbtool->getXDisplay(), bbtool->getScreenInfo(0)->getRootWindow(),
202 False, SubstructureRedirectMask, &e);
205 void WMInterface::stickWindow(Window win)
207 XEvent e;
208 e.xclient.type = ClientMessage;
209 e.xclient.message_type = bbtool->getBlackboxChangeAttributesAtom();
210 e.xclient.window = win;
211 e.xclient.format = 32;
212 e.xclient.data.l[0] = AttribOmnipresent;
213 e.xclient.data.l[2] = e.xclient.data.l[3] = e.xclient.data.l[4] = 0l;
215 Atom atom_return;
216 int foo;
217 unsigned long ulfoo, nitems;
218 BlackboxAttributes *net;
219 if (XGetWindowProperty(bbtool->getXDisplay(),
220 win,
221 bbtool->getBlackboxAttributesAtom(),
223 PropBlackboxAttributesElements,
224 False,
225 bbtool->getBlackboxAttributesAtom(),
226 &atom_return, &foo, &nitems, &ulfoo, (unsigned char **) &net)
228 Success && net && nitems
230 PropBlackboxAttributesElements) {
231 e.xclient.data.l[1] = net->attrib ^ AttribOmnipresent;
232 XFree((void *) net);
233 } else
234 e.xclient.data.l[1] = AttribOmnipresent;
236 XSendEvent(bbtool->getXDisplay(), bbtool->getScreenInfo(0)->getRootWindow(), False,
237 SubstructureRedirectMask, &e);
240 int WMInterface::isIconicState(Window win) {
241 Atom real_type;
242 int format;
243 unsigned long n, extra;
244 int status;
245 long *p=0;
246 int y=0;
248 status = XGetWindowProperty(bbtool->getXDisplay(), win,
249 bbtool->getWMStateAtom(), 0L, 1L,
250 False, bbtool->getWMStateAtom(), &real_type,
251 &format, &n, &extra, (unsigned char**)&p);
252 if (!status) {
253 if (p) {
254 y=(int)p[0];
255 XFree(p);
256 return (y==IconicState) ? 1 : 0;
257 } else {
258 return 0;
262 return -1;
265 int WMInterface::getAttributes(Window win) {
266 Atom real_type;
267 int format;
268 unsigned long n, extra;
269 int status;
270 long *p=0;
271 int y=0;
274 status = XGetWindowProperty(bbtool->getXDisplay(), win,
275 bbtool->getBlackboxAttributesAtom(), 0L, 1L,
276 False, bbtool->getBlackboxAttributesAtom(),
277 &real_type, &format,&n, &extra,
278 (unsigned char**)&p);
279 if (!status) {
280 if (p) {
281 y=(int)p[0];
282 XFree(p);
283 return y;
284 } else {
285 return 0;
289 return -1;
292 void WMInterface::NETNotifyStartup() {
293 // bbtool->setNETInit();
296 * We clear all windows from our internal window lists when we get this
297 * message because its quite possible that blackbox is restarting and deleted
298 * us before deleting other windows, leaving rogue windows behind in our
299 * window lists.
301 bbtool->clearWindows();
304 void WMInterface::NETNotifyWindowAdd(Window win,int desktop_nr) {
305 bbtool->addWindow(win, desktop_nr);
308 void WMInterface::NETNotifyDel(Window win) {
309 bbtool->removeWindow(win);
312 void WMInterface::NETNotifyAttributes(Window win)
314 bbtool->windowAttributeChange(win);
317 void WMInterface::NETNotifyFocus(Window win) {
318 bbtool->focusWindow(win);
321 void WMInterface::NETNotifyCurrentWorkspace(int desktop_nr) {
322 bbtool->focusDesktop(desktop_nr);
325 void WMInterface::NETNotifyWorkspaceCount(int count) {
326 bbtool->setDesktopCount(count);