1 // wminterface.cc for bbtools.
3 // Copyright (c) 1998-1999 by John Kennis, jkennis@chello.nl
4 // Copyright (c) 2001 by Ben Jansens <xor@orodu.net>
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)
24 #include "wminterface.hh"
25 #include "resource.hh"
26 #include "BaseDisplay.hh"
29 # include "../config.h"
30 #endif // HAVE_CONFIG_H
32 WMInterface::WMInterface(ToolWindow
*toolwindow
) : NETInterface(toolwindow
) {
37 WMInterface::~WMInterface() {
40 void WMInterface::sendClientMessage(Atom atom
, XID data
) {
44 e
.xclient
.type
= ClientMessage
;
45 e
.xclient
.window
= bbtool
->getCurrentScreenInfo()->getRootWindow();
46 e
.xclient
.message_type
= atom
;
47 e
.xclient
.format
= 32;
48 e
.xclient
.data
.l
[0] = (unsigned long) data
;
49 e
.xclient
.data
.l
[1] = 0;
51 mask
= SubstructureRedirectMask
;
52 XSendEvent(bbtool
->getXDisplay(),
53 bbtool
->getCurrentScreenInfo()->getRootWindow(),
57 void WMInterface::changeDesktop(int desk_number
, bool focusWin
) {
58 sendClientMessage(bbtool
->getBlackboxChangeWorkspaceAtom(),
59 static_cast<unsigned long int>(desk_number
));
60 focusWindow
= focusWin
;
63 void WMInterface::sendWindowToDesktop(Window win
, int desk_number
) {
67 e
.xclient
.type
= ClientMessage
;
68 e
.xclient
.window
= win
;
69 e
.xclient
.message_type
= bbtool
->getBlackboxChangeAttributesAtom();
70 e
.xclient
.format
= 32;
71 e
.xclient
.data
.l
[0] = AttribWorkspace
;
72 e
.xclient
.data
.l
[2] = desk_number
;
73 e
.xclient
.data
.l
[1] = e
.xclient
.data
.l
[3] = 0;
74 e
.xclient
.data
.l
[4] = e
.xclient
.data
.l
[5] = 0;
76 mask
= SubstructureRedirectMask
;
77 XSendEvent(bbtool
->getXDisplay(),
78 bbtool
->getCurrentScreenInfo()->getRootWindow(),
80 bbtool
->moveWinToDesktop(win
, desk_number
);
83 void WMInterface::decorateToggleWindow(Window win
)
86 e
.xclient
.type
= ClientMessage
;
87 e
.xclient
.message_type
= bbtool
->getBlackboxChangeAttributesAtom();
88 e
.xclient
.window
= win
;
89 e
.xclient
.format
= 32;
90 e
.xclient
.data
.l
[0] = e
.xclient
.data
.l
[1] =
91 e
.xclient
.data
.l
[2] = e
.xclient
.data
.l
[3] =
92 e
.xclient
.data
.l
[4] = e
.xclient
.data
.l
[5] = 0l;
93 e
.xclient
.data
.l
[0] |= AttribDecoration
;
97 unsigned long num
, len
;
98 BlackboxAttributes
*net_attributes
;
100 if (XGetWindowProperty(bbtool
->getXDisplay(), win
,
101 bbtool
->getBlackboxAttributesAtom(), 0,
102 PropBlackboxAttributesElements
, False
,
103 bbtool
->getBlackboxAttributesAtom(), &atom_return
,
104 &format
, &num
, &len
, (unsigned char **) &net_attributes
)
106 Success
&& net_attributes
) {
107 if(num
== PropBlackboxAttributesElements
) {
108 if (net_attributes
->decoration
== DecorNone
)
109 e
.xclient
.data
.l
[4] = DecorNormal
;
111 e
.xclient
.data
.l
[4] = DecorNone
;
113 XFree((void *) net_attributes
);
115 e
.xclient
.data
.l
[4] = DecorNone
;
117 XSendEvent(bbtool
->getXDisplay(), bbtool
->getScreenInfo(0)->getRootWindow(), False
,
118 SubstructureRedirectMask
, &e
);
121 void WMInterface::setWindowFocus(Window win
) {
125 e
.xclient
.type
= ClientMessage
;
126 e
.xclient
.window
= win
;
128 e
.xclient
.message_type
= bbtool
->getBlackboxChangeWindowFocusAtom();
129 e
.xclient
.format
= 32;
130 e
.xclient
.data
.l
[0] = 0;
131 e
.xclient
.data
.l
[1] = 0;
133 mask
= SubstructureRedirectMask
;
134 XSendEvent(bbtool
->getXDisplay(),
135 bbtool
->getCurrentScreenInfo()->getRootWindow(),
139 void WMInterface::shadeWindow(Window win
) {
141 e
.xclient
.type
= ClientMessage
;
142 e
.xclient
.message_type
= bbtool
->getBlackboxChangeAttributesAtom();
143 e
.xclient
.window
= win
;
144 e
.xclient
.format
= 32;
145 e
.xclient
.data
.l
[0] = AttribShaded
;
146 e
.xclient
.data
.l
[2] = e
.xclient
.data
.l
[3] = e
.xclient
.data
.l
[4] = 0l;
150 unsigned long ulfoo
, nitems
;
151 BlackboxAttributes
*net
;
152 if (XGetWindowProperty(bbtool
->getXDisplay(), win
,
153 bbtool
->getBlackboxAttributesAtom(),
155 PropBlackboxAttributesElements
,
157 bbtool
->getBlackboxAttributesAtom(),
158 &atom_return
, &foo
, &nitems
, &ulfoo
, (unsigned char **) &net
)
160 Success
&& net
&& nitems
162 PropBlackboxAttributesElements
)
164 e
.xclient
.data
.l
[1] = net
->attrib
^ AttribShaded
;
167 e
.xclient
.data
.l
[1] = AttribShaded
;
169 XSendEvent(bbtool
->getXDisplay(), bbtool
->getScreenInfo(0)->getRootWindow(), False
,
170 SubstructureRedirectMask
, &e
);
173 void WMInterface::maximizeWindow(Window win
, bool maxhorz
, bool maxvert
) {
175 e
.xclient
.type
= ClientMessage
;
176 e
.xclient
.message_type
= bbtool
->getBlackboxChangeAttributesAtom();
177 e
.xclient
.window
= win
;
178 e
.xclient
.format
= 32;
179 e
.xclient
.data
.l
[0] = (maxhorz
?AttribMaxHoriz
:0) | (maxvert
?AttribMaxVert
:0);
180 e
.xclient
.data
.l
[2] = e
.xclient
.data
.l
[3] = e
.xclient
.data
.l
[4] = 0l;
184 unsigned long ulfoo
, nitems
;
185 BlackboxAttributes
*net
;
186 if (XGetWindowProperty(bbtool
->getXDisplay(),
188 bbtool
->getBlackboxAttributesAtom(),
190 PropBlackboxAttributesElements
,
192 bbtool
->getBlackboxAttributesAtom(),
193 &atom_return
, &foo
, &nitems
, &ulfoo
, (unsigned char **) &net
)
195 Success
&& net
&& nitems
197 PropBlackboxAttributesElements
) {
198 e
.xclient
.data
.l
[1] =
199 net
->attrib
^ ((maxhorz
?AttribMaxHoriz
:0) | (maxvert
?AttribMaxVert
:0));
202 e
.xclient
.data
.l
[1] = (maxhorz
?AttribMaxHoriz
:0) | (maxvert
?AttribMaxVert
:0);
204 XSendEvent(bbtool
->getXDisplay(), bbtool
->getScreenInfo(0)->getRootWindow(),
205 False
, SubstructureRedirectMask
, &e
);
208 void WMInterface::stickWindow(Window win
)
211 e
.xclient
.type
= ClientMessage
;
212 e
.xclient
.message_type
= bbtool
->getBlackboxChangeAttributesAtom();
213 e
.xclient
.window
= win
;
214 e
.xclient
.format
= 32;
215 e
.xclient
.data
.l
[0] = AttribOmnipresent
;
216 e
.xclient
.data
.l
[2] = e
.xclient
.data
.l
[3] = e
.xclient
.data
.l
[4] = 0l;
220 unsigned long ulfoo
, nitems
;
221 BlackboxAttributes
*net
;
222 if (XGetWindowProperty(bbtool
->getXDisplay(),
224 bbtool
->getBlackboxAttributesAtom(),
226 PropBlackboxAttributesElements
,
228 bbtool
->getBlackboxAttributesAtom(),
229 &atom_return
, &foo
, &nitems
, &ulfoo
, (unsigned char **) &net
)
231 Success
&& net
&& nitems
233 PropBlackboxAttributesElements
) {
234 e
.xclient
.data
.l
[1] = net
->attrib
^ AttribOmnipresent
;
237 e
.xclient
.data
.l
[1] = AttribOmnipresent
;
239 XSendEvent(bbtool
->getXDisplay(), bbtool
->getScreenInfo(0)->getRootWindow(), False
,
240 SubstructureRedirectMask
, &e
);
243 int WMInterface::isIconicState(Window win
) {
246 unsigned long n
, extra
;
251 status
= XGetWindowProperty(bbtool
->getXDisplay(), win
,
252 bbtool
->getWMStateAtom(), 0L, 1L,
253 False
, bbtool
->getWMStateAtom(), &real_type
,
254 &format
, &n
, &extra
, (unsigned char**)&p
);
259 return (y
==IconicState
) ? 1 : 0;
268 int WMInterface::getAttributes(Window win
) {
271 unsigned long n
, extra
;
277 status
= XGetWindowProperty(bbtool
->getXDisplay(), win
,
278 bbtool
->getBlackboxAttributesAtom(), 0L, 1L,
279 False
, bbtool
->getBlackboxAttributesAtom(),
280 &real_type
, &format
,&n
, &extra
,
281 (unsigned char**)&p
);
295 void WMInterface::NETNotifyStartup() {
296 // bbtool->setNETInit();
299 void WMInterface::NETNotifyWindowAdd(Window win
,int desktop_nr
) {
300 bbtool
->addWindow(win
, desktop_nr
);
303 void WMInterface::NETNotifyDel(Window win
) {
304 bbtool
->removeWindow(win
);
307 void WMInterface::NETNotifyAttributes(Window win
)
309 bbtool
->windowAttributeChange(win
);
312 void WMInterface::NETNotifyFocus(Window win
) {
315 bbtool
->focusWindow(win
);
317 setWindowFocus(bbtool
->getFocusWindow());
322 void WMInterface::NETNotifyCurrentWorkspace(int desktop_nr
) {
323 bbtool
->focusDesktop(desktop_nr
);
326 void WMInterface::NETNotifyWorkspaceCount(int count
) {
327 bbtool
->setDesktopCount(count
);