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)
26 #endif // HAVE_CONFIG_H
28 #include "wminterface.hh"
31 WMInterface::WMInterface(ToolWindow
*toolwindow
) : NETInterface(toolwindow
) {
35 WMInterface::~WMInterface() {
38 void WMInterface::sendClientMessage(Atom atom
, XID data
) {
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(),
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
) {
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(),
77 bbtool
->moveWinToDesktop(win
, desk_number
);
80 void WMInterface::decorateToggleWindow(Window win
)
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
;
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
;
108 e
.xclient
.data
.l
[4] = DecorNone
;
110 XFree((void *) net_attributes
);
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
) {
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(),
136 void WMInterface::shadeWindow(Window win
) {
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;
147 unsigned long ulfoo
, nitems
;
148 BlackboxAttributes
*net
;
149 if (XGetWindowProperty(bbtool
->getXDisplay(), win
,
150 bbtool
->getBlackboxAttributesAtom(),
152 PropBlackboxAttributesElements
,
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
;
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
) {
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;
181 unsigned long ulfoo
, nitems
;
182 BlackboxAttributes
*net
;
183 if (XGetWindowProperty(bbtool
->getXDisplay(),
185 bbtool
->getBlackboxAttributesAtom(),
187 PropBlackboxAttributesElements
,
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));
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
)
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;
217 unsigned long ulfoo
, nitems
;
218 BlackboxAttributes
*net
;
219 if (XGetWindowProperty(bbtool
->getXDisplay(),
221 bbtool
->getBlackboxAttributesAtom(),
223 PropBlackboxAttributesElements
,
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
;
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
) {
243 unsigned long n
, extra
;
248 status
= XGetWindowProperty(bbtool
->getXDisplay(), win
,
249 bbtool
->getWMStateAtom(), 0L, 1L,
250 False
, bbtool
->getWMStateAtom(), &real_type
,
251 &format
, &n
, &extra
, (unsigned char**)&p
);
256 return (y
==IconicState
) ? 1 : 0;
265 int WMInterface::getAttributes(Window win
) {
268 unsigned long n
, extra
;
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
);
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
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
);