initial import
[bbkeys.git] / wminterface.cc
blob8e91fbb182ca5e0e34d30aa45098f4d85d0b1e1c
1 // wminterface.cc for bbtools.
2 //
3 // Copyright (c) 1998-1999 by John Kennis, jkennis@chello.nl
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 // (See the included file COPYING / GPL-2.0)
22 #include "wminterface.hh"
23 #include "resource.hh"
24 #include "BaseDisplay.hh"
26 WMInterface::WMInterface(ToolWindow *toolwindow) : NETInterface(toolwindow) {
27 bbtool=toolwindow;
30 WMInterface::~WMInterface() {
33 void WMInterface::sendClientMessage(Atom atom, XID data) {
34 XEvent e;
35 unsigned long mask;
37 e.xclient.type = ClientMessage;
38 e.xclient.window = bbtool->getCurrentScreenInfo()->getRootWindow();
39 e.xclient.message_type = atom;
40 e.xclient.format = 32;
41 e.xclient.data.l[0] = (unsigned long) data;
42 e.xclient.data.l[1] = 0;
44 mask = SubstructureRedirectMask;
45 XSendEvent(bbtool->getXDisplay(),
46 bbtool->getCurrentScreenInfo()->getRootWindow(),
47 False, mask, &e);
50 void WMInterface::changeDesktop(int desk_number) {
51 sendClientMessage(bbtool->getBlackboxChangeWorkspaceAtom(),
52 static_cast<unsigned long int>(desk_number));
55 void WMInterface::sendWindowToDesktop(Window win, int desk_number) {
56 XEvent e;
57 unsigned long mask;
59 e.xclient.type = ClientMessage;
60 e.xclient.window = win;
61 e.xclient.message_type = bbtool->getBlackboxChangeAttributesAtom();
62 e.xclient.format = 32;
63 e.xclient.data.l[0] = AttribWorkspace;
64 e.xclient.data.l[2] = desk_number;
65 e.xclient.data.l[1] = e.xclient.data.l[3] = 0;
66 e.xclient.data.l[4] = e.xclient.data.l[5] = 0;
68 mask = SubstructureRedirectMask;
69 XSendEvent(bbtool->getXDisplay(),
70 bbtool->getCurrentScreenInfo()->getRootWindow(),
71 False, mask, &e);
72 bbtool->moveWinToDesktop(win, desk_number);
75 void WMInterface::decorateToggleWindow(Window win)
77 XEvent e;
78 e.xclient.type = ClientMessage;
79 e.xclient.message_type = bbtool->getBlackboxHintsAtom();
80 e.xclient.window = win;
81 e.xclient.format = 32;
82 e.xclient.data.l[0] = e.xclient.data.l[1] =
83 e.xclient.data.l[2] = e.xclient.data.l[3] =
84 e.xclient.data.l[4] = e.xclient.data.l[5] = 0l;
85 e.xclient.data.l[0] |= AttribDecoration;
87 int format;
88 Atom atom_return;
89 unsigned long num, len;
90 BlackboxHints *net_attributes;
92 if (XGetWindowProperty(bbtool->getXDisplay(), win,
93 bbtool->getBlackboxHintsAtom(), 0,
94 PropBlackboxHintsElements, False,
95 bbtool->getBlackboxHintsAtom(), &atom_return,
96 &format, &num, &len, (unsigned char **) &net_attributes)
98 Success && net_attributes) {
99 if(num == PropBlackboxHintsElements) {
100 if (net_attributes->decoration == DecorNone)
101 e.xclient.data.l[4] = DecorNormal;
102 else
103 e.xclient.data.l[4] = DecorNone;
105 XFree((void *) net_attributes);
106 } else
107 e.xclient.data.l[4] = DecorNone;
109 XSendEvent(bbtool->getXDisplay(), bbtool->getScreenInfo(0)->getRootWindow(), False,
110 SubstructureRedirectMask, &e);
113 void WMInterface::setWindowFocus(Window win) {
114 XEvent e;
115 unsigned long mask;
117 e.xclient.type = ClientMessage;
118 e.xclient.window = win;
120 e.xclient.message_type = bbtool->getBlackboxChangeWindowFocusAtom();
121 e.xclient.format = 32;
122 e.xclient.data.l[0] = 0;
123 e.xclient.data.l[1] = 0;
125 mask = SubstructureRedirectMask;
126 XSendEvent(bbtool->getXDisplay(),
127 bbtool->getCurrentScreenInfo()->getRootWindow(),
128 False, mask, &e);
131 void WMInterface::shadeWindow(Window win) {
132 XEvent e;
133 e.xclient.type = ClientMessage;
134 e.xclient.message_type = bbtool->getBlackboxChangeAttributesAtom();
135 e.xclient.window = win;
136 e.xclient.format = 32;
137 e.xclient.data.l[0] = AttribShaded;
138 e.xclient.data.l[2] = e.xclient.data.l[3] = e.xclient.data.l[4] = 0l;
140 Atom atom_return;
141 int foo;
142 unsigned long ulfoo, nitems;
143 BlackboxAttributes *net;
144 if (XGetWindowProperty(bbtool->getXDisplay(), win,
145 bbtool->getBlackboxAttributesAtom(),
147 PropBlackboxAttributesElements,
148 False,
149 bbtool->getBlackboxAttributesAtom(),
150 &atom_return, &foo, &nitems, &ulfoo, (unsigned char **) &net)
152 Success && net && nitems
154 PropBlackboxAttributesElements)
156 e.xclient.data.l[1] = net->attrib ^ AttribShaded;
157 XFree((void *) net);
158 } else
159 e.xclient.data.l[1] = AttribShaded;
161 XSendEvent(bbtool->getXDisplay(), bbtool->getScreenInfo(0)->getRootWindow(), False,
162 SubstructureRedirectMask, &e);
165 void WMInterface::maximizeWindow(Window win, bool maxhorz, bool maxvert) {
166 XEvent e;
167 e.xclient.type = ClientMessage;
168 e.xclient.message_type = bbtool->getBlackboxChangeAttributesAtom();
169 e.xclient.window = win;
170 e.xclient.format = 32;
171 e.xclient.data.l[0] = (maxhorz?AttribMaxHoriz:0) | (maxvert?AttribMaxVert:0);
172 e.xclient.data.l[2] = e.xclient.data.l[3] = e.xclient.data.l[4] = 0l;
174 Atom atom_return;
175 int foo;
176 unsigned long ulfoo, nitems;
177 BlackboxAttributes *net;
178 if (XGetWindowProperty(bbtool->getXDisplay(),
179 win,
180 bbtool->getBlackboxAttributesAtom(),
182 PropBlackboxAttributesElements,
183 False,
184 bbtool->getBlackboxAttributesAtom(),
185 &atom_return, &foo, &nitems, &ulfoo, (unsigned char **) &net)
187 Success && net && nitems
189 PropBlackboxAttributesElements) {
190 e.xclient.data.l[1] =
191 net->attrib ^ ((maxhorz?AttribMaxHoriz:0) | (maxvert?AttribMaxVert:0));
192 XFree((void *) net);
193 } else
194 e.xclient.data.l[1] = (maxhorz?AttribMaxHoriz:0) | (maxvert?AttribMaxVert:0);
196 XSendEvent(bbtool->getXDisplay(), bbtool->getScreenInfo(0)->getRootWindow(),
197 False, SubstructureRedirectMask, &e);
200 void WMInterface::stickWindow(Window win)
202 XEvent e;
203 e.xclient.type = ClientMessage;
204 e.xclient.message_type = bbtool->getBlackboxChangeAttributesAtom();
205 e.xclient.window = win;
206 e.xclient.format = 32;
207 e.xclient.data.l[0] = AttribOmnipresent;
208 e.xclient.data.l[2] = e.xclient.data.l[3] = e.xclient.data.l[4] = 0l;
210 Atom atom_return;
211 int foo;
212 unsigned long ulfoo, nitems;
213 BlackboxAttributes *net;
214 if (XGetWindowProperty(bbtool->getXDisplay(),
215 win,
216 bbtool->getBlackboxAttributesAtom(),
218 PropBlackboxAttributesElements,
219 False,
220 bbtool->getBlackboxAttributesAtom(),
221 &atom_return, &foo, &nitems, &ulfoo, (unsigned char **) &net)
223 Success && net && nitems
225 PropBlackboxAttributesElements) {
226 e.xclient.data.l[1] = net->attrib ^ AttribOmnipresent;
227 XFree((void *) net);
228 } else
229 e.xclient.data.l[1] = AttribOmnipresent;
231 XSendEvent(bbtool->getXDisplay(), bbtool->getScreenInfo(0)->getRootWindow(), False,
232 SubstructureRedirectMask, &e);
235 int WMInterface::isIconicState(Window win) {
236 Atom real_type;
237 int format;
238 unsigned long n, extra;
239 int status;
240 long *p=0;
241 int y=0;
243 status = XGetWindowProperty(bbtool->getXDisplay(), win,
244 bbtool->getWMStateAtom(), 0L, 1L,
245 False, bbtool->getWMStateAtom(), &real_type,
246 &format, &n, &extra, (unsigned char**)&p);
247 if (!status) {
248 if (p) {
249 y=(int)p[0];
250 XFree(p);
251 return (y==IconicState) ? 1 : 0;
252 } else {
253 return 0;
257 return -1;
260 int WMInterface::getAttributes(Window win) {
261 Atom real_type;
262 int format;
263 unsigned long n, extra;
264 int status;
265 long *p=0;
266 int y=0;
269 status = XGetWindowProperty(bbtool->getXDisplay(), win,
270 bbtool->getBlackboxAttributesAtom(), 0L, 1L,
271 False, bbtool->getBlackboxAttributesAtom(),
272 &real_type, &format,&n, &extra,
273 (unsigned char**)&p);
274 if (!status) {
275 if (p) {
276 y=(int)p[0];
277 XFree(p);
278 return y;
279 } else {
280 return 0;
284 return -1;
287 void WMInterface::NETNotifyStartup() {
288 // bbtool->setNETInit();
291 void WMInterface::NETNotifyWindowAdd(Window win,int desktop_nr) {
292 bbtool->addWindow(win, desktop_nr);
295 void WMInterface::NETNotifyDel(Window win) {
296 bbtool->removeWindow(win);
299 void WMInterface::NETNotifyAttributes(Window win) {
300 bbtool->windowAttributeChange(win);
303 void WMInterface::NETNotifyFocus(Window win) {
304 bbtool->focusWindow(win);
307 void WMInterface::NETNotifyCurrentWorkspace(int desktop_nr) {
308 bbtool->focusDesktop(desktop_nr);
311 void WMInterface::NETNotifyWorkspaceCount(int count) {
312 bbtool->setDesktopCount(count);