aboutsummaryrefslogtreecommitdiff
path: root/src/Gnome.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Gnome.cc')
-rw-r--r--src/Gnome.cc466
1 files changed, 0 insertions, 466 deletions
diff --git a/src/Gnome.cc b/src/Gnome.cc
deleted file mode 100644
index 0c3b6f1..0000000
--- a/src/Gnome.cc
+++ /dev/null
@@ -1,466 +0,0 @@
1// Gnome.cc for fluxbox
2// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#include "Gnome.hh"
23
24#include "FbTk/App.hh"
25#include "FbTk/I18n.hh"
26#include "Window.hh"
27#include "Screen.hh"
28#include "WinClient.hh"
29#include "Workspace.hh"
30#include "Layer.hh"
31#include "Debug.hh"
32
33#include <iostream>
34#ifdef HAVE_CSTRING
35 #include <cstring>
36#else
37 #include <string.h>
38#endif
39
40using std::cerr;
41using std::endl;
42using std::list;
43using std::hex;
44using std::dec;
45
46Gnome::Gnome() {
47 setName("gnome");
48 createAtoms();
49 enableUpdate();
50}
51
52Gnome::~Gnome() {
53 // destroy gnome windows
54 while (!m_gnomewindows.empty()) {
55 XDestroyWindow(FbTk::App::instance()->display(), m_gnomewindows.back());
56 m_gnomewindows.pop_back();
57 }
58}
59
60
61void Gnome::initForScreen(BScreen &screen) {
62 Display *disp = FbTk::App::instance()->display();
63 // create the GNOME window
64 Window gnome_win = XCreateSimpleWindow(disp,
65 screen.rootWindow().window(), 0, 0, 5, 5, 0, 0, 0);
66 // supported WM check
67 screen.rootWindow().changeProperty(m_gnome_wm_supporting_wm_check,
68 XA_WINDOW, 32,
69 PropModeReplace, (unsigned char *) &gnome_win, 1);
70
71 XChangeProperty(disp, gnome_win,
72 m_gnome_wm_supporting_wm_check,
73 XA_WINDOW, 32, PropModeReplace, (unsigned char *) &gnome_win, 1);
74
75 // supported gnome atoms
76 Atom gnomeatomlist[] = {
77 m_gnome_wm_supporting_wm_check,
78 m_gnome_wm_win_workspace_names,
79 m_gnome_wm_win_client_list,
80 m_gnome_wm_win_state,
81 m_gnome_wm_win_hints,
82 m_gnome_wm_win_layer
83 };
84 //list atoms that we support
85 screen.rootWindow().changeProperty(m_gnome_wm_prot,
86 XA_ATOM, 32, PropModeReplace,
87 (unsigned char *)gnomeatomlist,
88 (sizeof gnomeatomlist)/sizeof gnomeatomlist[0]);
89
90 m_gnomewindows.push_back(gnome_win);
91
92 updateClientList(screen);
93 updateWorkspaceNames(screen);
94 updateWorkspaceCount(screen);
95 updateCurrentWorkspace(screen);
96
97}
98
99void Gnome::setupFrame(FluxboxWindow &win) {
100 // load gnome state (take queues from the main window of the frame)
101 long flags;
102 bool exists;
103 flags=win.winClient().cardinalProperty(m_gnome_wm_win_state,&exists);
104 if (exists) {
105 setState(&win, flags);
106 } else {
107 updateState(win);
108 }
109
110 // load gnome layer atom
111 flags=win.winClient().cardinalProperty(m_gnome_wm_win_layer,&exists);
112 if (exists) {
113 setLayer(&win, flags);
114 } else {
115 updateLayer(win);
116 }
117
118 // load gnome workspace atom
119 flags=win.winClient().cardinalProperty(m_gnome_wm_win_workspace,&exists);
120 if (exists)
121 {
122 unsigned int workspace_num = flags;
123 if (win.workspaceNumber() != workspace_num)
124 win.setWorkspace(workspace_num);
125 } else {
126 updateWorkspace(win);
127 }
128
129}
130
131
132bool Gnome::propertyNotify(WinClient &winclient, Atom the_property) {
133 if (the_property == m_gnome_wm_win_state) {
134 fbdbg<<"("<<__FUNCTION__<<"): _WIN_STATE"<<endl;
135 return true;
136 } else if (the_property == m_gnome_wm_win_layer) {
137 fbdbg<<"("<<__FUNCTION__<<"): _WIN_LAYER"<<endl;
138 return true;
139 }
140 return false;
141}
142
143
144void Gnome::updateClientList(BScreen &screen) {
145 size_t num=0;
146
147 // count window clients in each workspace
148 BScreen::Workspaces::const_iterator workspace_it =
149 screen.getWorkspacesList().begin();
150 BScreen::Workspaces::const_iterator workspace_it_end =
151 screen.getWorkspacesList().end();
152 for (; workspace_it != workspace_it_end; ++workspace_it) {
153 Workspace::Windows::iterator win_it =
154 (*workspace_it)->windowList().begin();
155 Workspace::Windows::iterator win_it_end =
156 (*workspace_it)->windowList().end();
157 for (; win_it != win_it_end; ++win_it)
158 num += (*win_it)->numClients();
159 }
160
161 Window *wl = new Window[num];
162 if (wl == 0) {
163 _FB_USES_NLS;
164 cerr<<_FB_CONSOLETEXT(Gnome, OutOfMemoryClientList, "Fatal: Out of memory, can't allocate for GNOME client list", "")<<endl;
165 return;
166 }
167
168 //add client windows to buffer
169 workspace_it = screen.getWorkspacesList().begin();
170 int win=0;
171 for (; workspace_it != workspace_it_end; ++workspace_it) {
172
173 // Fill in array of window ID's
174 Workspace::Windows::const_iterator it =
175 (*workspace_it)->windowList().begin();
176 Workspace::Windows::const_iterator it_end =
177 (*workspace_it)->windowList().end();
178 for (; it != it_end; ++it) {
179 // TODO!
180 //check if the window don't want to be visible in the list
181 //if (! ( (*it)->getGnomeHints() & WIN_STATE_HIDDEN) ) {
182 list<WinClient *>::iterator client_it =
183 (*it)->clientList().begin();
184 list<WinClient *>::iterator client_it_end =
185 (*it)->clientList().end();
186 for (; client_it != client_it_end; ++client_it)
187 wl[win++] = (*client_it)->window();
188
189 }
190 }
191 //number of windows to show in client list
192 num = win;
193 screen.rootWindow().changeProperty(m_gnome_wm_win_client_list,
194 XA_WINDOW, 32,
195 PropModeReplace, (unsigned char *)wl, num);
196
197 delete[] wl;
198}
199
200void Gnome::updateClientClose(WinClient &client) {
201 if (!client.screen().isShuttingdown()) {
202 XDeleteProperty(FbTk::App::instance()->display(), client.window(),
203 m_gnome_wm_win_workspace);
204 XDeleteProperty(FbTk::App::instance()->display(), client.window(),
205 m_gnome_wm_win_layer);
206 XDeleteProperty(FbTk::App::instance()->display(), client.window(),
207 m_gnome_wm_win_state);
208 }
209}
210
211void Gnome::updateWorkspaceNames(BScreen &screen) {
212
213 size_t number_of_desks = screen.getWorkspaceNames().size();
214 const BScreen::WorkspaceNames &workspace_names = screen.getWorkspaceNames();
215 // convert our desktop names to a char * so we can send it
216 char** names = new char*[number_of_desks];
217
218 for (size_t i = 0; i < number_of_desks; i++) {
219 names[i] = new char[workspace_names[i].size() + 1];
220 strcpy(names[i], workspace_names[i].c_str());
221 }
222
223 XTextProperty text;
224 if (XStringListToTextProperty(names, number_of_desks, &text)) {
225 XSetTextProperty(FbTk::App::instance()->display(), screen.rootWindow().window(),
226 &text, m_gnome_wm_win_workspace_names);
227 XFree(text.value);
228 }
229
230 // destroy name buffers
231 for (size_t i = 0; i < number_of_desks; i++)
232 delete[] names[i];
233
234 delete[] names;
235}
236
237void Gnome::updateCurrentWorkspace(BScreen &screen) {
238 long workspace = screen.currentWorkspaceID();
239 screen.rootWindow().changeProperty(m_gnome_wm_win_workspace, XA_CARDINAL, 32, PropModeReplace,
240 (unsigned char *)&workspace, 1);
241
242 updateClientList(screen); // make sure the client list is updated too
243}
244
245void Gnome::updateWorkspaceCount(BScreen &screen) {
246 long numworkspaces = screen.numberOfWorkspaces();
247 screen.rootWindow().changeProperty(m_gnome_wm_win_workspace_count, XA_CARDINAL, 32, PropModeReplace,
248 (unsigned char *)&numworkspaces, 1);
249}
250
251void Gnome::updateWorkspace(FluxboxWindow &win) {
252 long val = win.workspaceNumber();
253 if (win.isStuck()) {
254 val = -1;
255 }
256
257 fbdbg<<"setting workspace("<<val<<") for window("<<&win<<")"<<endl;
258
259 FluxboxWindow::ClientList::iterator client_it = win.clientList().begin();
260 FluxboxWindow::ClientList::iterator client_it_end = win.clientList().end();
261 for (; client_it != client_it_end; ++client_it)
262 (*client_it)->changeProperty(m_gnome_wm_win_workspace,
263 XA_CARDINAL, 32, PropModeReplace,
264 (unsigned char *)&val, 1);
265}
266
267void Gnome::updateState(FluxboxWindow &win) {
268 //translate to gnome win state
269 long state=0;
270 if (win.isStuck())
271 state |= WIN_STATE_STICKY;
272 if (win.isIconic())
273 state |= WIN_STATE_MINIMIZED;
274 if (win.isShaded())
275 state |= WIN_STATE_SHADED;
276
277 FluxboxWindow::ClientList::iterator client_it = win.clientList().begin();
278 FluxboxWindow::ClientList::iterator client_it_end = win.clientList().end();
279 for (; client_it != client_it_end; ++client_it) {
280 (*client_it)->changeProperty(m_gnome_wm_win_state,
281 XA_CARDINAL, 32,
282 PropModeReplace, (unsigned char *)&state, 1);
283 }
284}
285
286void Gnome::updateLayer(FluxboxWindow &win) {
287 //TODO - map from flux layers to gnome ones
288 // our layers are in the opposite direction to GNOME
289 long layernum = ResourceLayer::DESKTOP - win.layerNum();
290
291 FluxboxWindow::ClientList::iterator client_it = win.clientList().begin();
292 FluxboxWindow::ClientList::iterator client_it_end = win.clientList().end();
293 for (; client_it != client_it_end; ++client_it)
294 (*client_it)->changeProperty(m_gnome_wm_win_layer,
295 XA_CARDINAL, 32, PropModeReplace,
296 (unsigned char *)&layernum, 1);
297
298}
299
300void Gnome::updateHints(FluxboxWindow &win) {
301 //TODO
302
303}
304
305bool Gnome::checkClientMessage(const XClientMessageEvent &ce, BScreen * screen, WinClient * const winclient) {
306 if (ce.message_type == m_gnome_wm_win_workspace) {
307
308 fbdbg<<"Got workspace atom="<<ce.data.l[0]<<endl;
309
310 if ( winclient !=0 && // the message sent to client window?
311 ce.data.l[0] >= 0 &&
312 ce.data.l[0] < (signed)winclient->screen().numberOfWorkspaces()) {
313 winclient->screen().changeWorkspaceID(ce.data.l[0]);
314
315 } else if (screen!=0 && //the message sent to root window?
316 ce.data.l[0] >= 0 &&
317 ce.data.l[0] < (signed)screen->numberOfWorkspaces())
318 screen->changeWorkspaceID(ce.data.l[0]);
319 return true;
320 } else if (winclient == 0)
321 return false;
322
323
324 if (ce.message_type == m_gnome_wm_win_state) {
325
326 fbdbg<<"_WIN_STATE"<<endl;
327 fbdbg<<"Mask of members to change:"<<
328 hex<<ce.data.l[0]<<dec<<endl; // mask_of_members_to_change
329 fbdbg<<"New members:"<<ce.data.l[1]<<endl;
330
331
332 if (winclient && winclient->fbwindow()) {
333 //get new states
334 int flag = ce.data.l[0] & ce.data.l[1];
335 //don't update this when when we set new state
336 disableUpdate();
337 // convert to Fluxbox state
338 setState(winclient->fbwindow(), flag);
339 // enable update of atom states
340 enableUpdate();
341 }
342 } else if (ce.message_type == m_gnome_wm_win_hints) {
343 fbdbg<<"_WIN_HINTS"<<endl;
344 } else if (ce.message_type == m_gnome_wm_win_layer) {
345 fbdbg<<"_WIN_LAYER"<<endl;
346 if (winclient && winclient->fbwindow())
347 setLayer(winclient->fbwindow(), ce.data.l[0]);
348 } else
349 return false; //the gnome atom wasn't found or not supported
350
351 return true; // we handled the atom
352}
353
354void Gnome::setState(FluxboxWindow *win, int state) {
355 fbdbg<<"Gnome: state=0x"<<hex<<state<<dec<<endl;
356
357 if (state & WIN_STATE_STICKY) {
358
359 fbdbg<<"Gnome state: Sticky"<<endl;
360
361 if (!win->isStuck())
362 win->stick();
363 } else if (win->isStuck())
364 win->stick();
365
366 if (state & WIN_STATE_MINIMIZED) {
367 fbdbg<<"Gnome state: Minimized"<<endl;
368
369 if (win->isIconic())
370 win->iconify();
371 } else if (win->isIconic())
372 win->deiconify(true);
373
374 if (state & WIN_STATE_SHADED) {
375
376 fbdbg<<"Gnome state: Shade"<<endl;
377
378 if (!win->isShaded())
379 win->shade();
380 } else if (win->isShaded())
381 win->shade();
382
383 if (state & WIN_STATE_HIDDEN)
384 {
385 win->setFocusHidden(! win->isFocusHidden());
386 win->setIconHidden(! win->isIconHidden());
387 }
388
389
390 /*
391 if (state & WIN_STATE_MAXIMIZED_VERT)
392 cerr<<"Maximize Vert"<<endl;
393 if (state & WIN_STATE_MAXIMIZED_HORIZ)
394 cerr<<"Maximize Horiz"<<endl;
395
396 if (state & WIN_STATE_HID_WORKSPACE)
397 cerr<<"HID Workspace"<<endl;
398 if (state & WIN_STATE_HID_TRANSIENT)
399 cerr<<"HID Transient"<<endl;
400 if (state & WIN_STATE_FIXED_POSITION)
401 cerr<<"Fixed Position"<<endl;
402 if (state & WIN_STATE_ARRANGE_IGNORE)
403 cerr<<"Arrange Ignore"<<endl;
404 */
405}
406
407void Gnome::setLayer(FluxboxWindow *win, int layer) {
408 if (!win) return;
409
410 const FbTk::FbString& title = win->title().logical();
411 switch (layer) {
412 case WIN_LAYER_DESKTOP:
413 fbdbg<<"Gnome::setLayer("<<title<<", WIN_LAYER_DESKTOP)"<<endl;
414 layer = ResourceLayer::DESKTOP;
415 break;
416 case WIN_LAYER_BELOW:
417 fbdbg<<"Gnome::setLayer("<<title<<", WIN_LAYER_BELOW)"<<endl;
418 layer = ResourceLayer::BOTTOM;
419 break;
420 case WIN_LAYER_NORMAL:
421 fbdbg<<"Gnome::setLayer("<<title<<", WIN_LAYER_NORMAL)"<<endl;
422 layer = ResourceLayer::NORMAL;
423 break;
424 case WIN_LAYER_ONTOP:
425 fbdbg<<"Gnome::setLayer("<<title<<", WIN_LAYER_ONTOP)"<<endl;
426 layer = ResourceLayer::TOP;
427 break;
428 case WIN_LAYER_DOCK:
429 fbdbg<<"Gnome::setLayer("<<title<<", WIN_LAYER_DOCK)"<<endl;
430 layer = ResourceLayer::DOCK;
431 break;
432 case WIN_LAYER_ABOVE_DOCK:
433 fbdbg<<"Gnome::setLayer("<<title<<", WIN_LAYER_ABOVE_DOCK)"<<endl;
434 layer = ResourceLayer::ABOVE_DOCK;
435 break;
436 case WIN_LAYER_MENU:
437 fbdbg<<"Gnome::setLayer("<<title<<", WIN_LAYER_MENU)"<<endl;
438 layer = ResourceLayer::MENU;
439 break;
440 default:
441 // our windows are in the opposite direction to gnome
442 layer = ResourceLayer::DESKTOP - layer;
443 fbdbg<<"Gnome::setLayer("<<win->title().logical()<<", "<<layer<<")"<<endl;
444
445 break;
446 }
447
448 win->moveToLayer(layer);
449
450}
451
452void Gnome::createAtoms() {
453 Display *disp = FbTk::App::instance()->display();
454 m_gnome_wm_win_layer = XInternAtom(disp, "_WIN_LAYER", False);
455 m_gnome_wm_win_state = XInternAtom(disp, "_WIN_STATE", False);
456 m_gnome_wm_win_hints = XInternAtom(disp, "_WIN_HINTS", False);
457 m_gnome_wm_win_app_state = XInternAtom(disp, "_WIN_APP_STATE", False);
458 m_gnome_wm_win_expanded_size = XInternAtom(disp, "_WIN_EXPANDED_SIZE", False);
459 m_gnome_wm_win_icons = XInternAtom(disp, "_WIN_ICONS", False);
460 m_gnome_wm_win_workspace = XInternAtom(disp, "_WIN_WORKSPACE", False);
461 m_gnome_wm_win_workspace_count = XInternAtom(disp, "_WIN_WORKSPACE_COUNT", False);
462 m_gnome_wm_win_workspace_names = XInternAtom(disp, "_WIN_WORKSPACE_NAMES", False);
463 m_gnome_wm_win_client_list = XInternAtom(disp, "_WIN_CLIENT_LIST", False);
464 m_gnome_wm_prot = XInternAtom(disp, "_WIN_PROTOCOLS", False);
465 m_gnome_wm_supporting_wm_check = XInternAtom(disp, "_WIN_SUPPORTING_WM_CHECK", False);
466}