1 // wminterface.cc for bbtools.
3 // Copyright (c) 1998-1999 by John Kennis, jkennis@chello.nl
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.
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
) {
30 WMInterface::~WMInterface() {
33 void WMInterface::sendClientMessage(Atom atom
, XID data
) {
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(),
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
) {
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(),
72 bbtool
->moveWinToDesktop(win
, desk_number
);
75 void WMInterface::decorateToggleWindow(Window win
)
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
;
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
;
103 e
.xclient
.data
.l
[4] = DecorNone
;
105 XFree((void *) net_attributes
);
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
) {
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(),
131 void WMInterface::shadeWindow(Window win
) {
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;
142 unsigned long ulfoo
, nitems
;
143 BlackboxAttributes
*net
;
144 if (XGetWindowProperty(bbtool
->getXDisplay(), win
,
145 bbtool
->getBlackboxAttributesAtom(),
147 PropBlackboxAttributesElements
,
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
;
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
) {
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;
176 unsigned long ulfoo
, nitems
;
177 BlackboxAttributes
*net
;
178 if (XGetWindowProperty(bbtool
->getXDisplay(),
180 bbtool
->getBlackboxAttributesAtom(),
182 PropBlackboxAttributesElements
,
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));
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
)
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;
212 unsigned long ulfoo
, nitems
;
213 BlackboxAttributes
*net
;
214 if (XGetWindowProperty(bbtool
->getXDisplay(),
216 bbtool
->getBlackboxAttributesAtom(),
218 PropBlackboxAttributesElements
,
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
;
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
) {
238 unsigned long n
, extra
;
243 status
= XGetWindowProperty(bbtool
->getXDisplay(), win
,
244 bbtool
->getWMStateAtom(), 0L, 1L,
245 False
, bbtool
->getWMStateAtom(), &real_type
,
246 &format
, &n
, &extra
, (unsigned char**)&p
);
251 return (y
==IconicState
) ? 1 : 0;
260 int WMInterface::getAttributes(Window win
) {
263 unsigned long n
, extra
;
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
);
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
);