]> Dogcows Code - chaz/openbox/blob - src/Screen.cc
dont need to XrmInit outside of the Config class. fix indenting.
[chaz/openbox] / src / Screen.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Screen.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #include "../config.h"
25
26 extern "C" {
27 #include <X11/Xatom.h>
28 #include <X11/keysym.h>
29
30 #ifdef HAVE_STDLIB_H
31 # include <stdlib.h>
32 #endif // HAVE_STDLIB_H
33
34 #ifdef HAVE_STRING_H
35 # include <string.h>
36 #endif // HAVE_STRING_H
37
38 #ifdef HAVE_CTYPE_H
39 # include <ctype.h>
40 #endif // HAVE_CTYPE_H
41
42 #ifdef HAVE_UNISTD_H
43 # include <sys/types.h>
44 # include <unistd.h>
45 #endif // HAVE_UNISTD_H
46
47 #ifdef HAVE_DIRENT_H
48 # include <dirent.h>
49 #endif // HAVE_DIRENT_H
50
51 #ifdef HAVE_LOCALE_H
52 # include <locale.h>
53 #endif // HAVE_LOCALE_H
54
55 #ifdef HAVE_SYS_STAT_H
56 # include <sys/stat.h>
57 #endif // HAVE_SYS_STAT_H
58
59 #ifdef HAVE_STDARG_H
60 # include <stdarg.h>
61 #endif // HAVE_STDARG_H
62 }
63
64 #include <assert.h>
65
66 #include <algorithm>
67 #include <functional>
68 #include <string>
69 using std::string;
70
71 #include "i18n.hh"
72 #include "blackbox.hh"
73 #include "Clientmenu.hh"
74 #include "Font.hh"
75 #include "GCCache.hh"
76 #include "Iconmenu.hh"
77 #include "Image.hh"
78 #include "Screen.hh"
79 #include "Slit.hh"
80 #include "Rootmenu.hh"
81 #include "Toolbar.hh"
82 #include "Util.hh"
83 #include "Window.hh"
84 #include "Workspace.hh"
85 #include "Workspacemenu.hh"
86 #include "XAtom.hh"
87
88 #ifndef FONT_ELEMENT_SIZE
89 #define FONT_ELEMENT_SIZE 50
90 #endif // FONT_ELEMENT_SIZE
91
92
93 static bool running = True;
94
95 static int anotherWMRunning(Display *display, XErrorEvent *) {
96 fprintf(stderr, i18n(ScreenSet, ScreenAnotherWMRunning,
97 "BScreen::BScreen: an error occured while querying the X server.\n"
98 " another window manager already running on display %s.\n"),
99 DisplayString(display));
100
101 running = False;
102
103 return(-1);
104 }
105
106
107 BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
108 blackbox = bb;
109 screenstr = "session.screen" + itostring(scrn) + '.';
110 config = blackbox->getConfig();
111 xatom = blackbox->getXAtom();
112
113 event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
114 SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask;
115
116 XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
117 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask);
118 XSync(getBaseDisplay()->getXDisplay(), False);
119 XSetErrorHandler((XErrorHandler) old);
120
121 managed = running;
122 if (! managed) return;
123
124 fprintf(stderr, i18n(ScreenSet, ScreenManagingScreen,
125 "BScreen::BScreen: managing screen %d "
126 "using visual 0x%lx, depth %d\n"),
127 getScreenNumber(), XVisualIDFromVisual(getVisual()),
128 getDepth());
129
130 rootmenu = 0;
131
132 resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
133 resource.wstyle.font = (BFont *) 0;
134
135 geom_pixmap = None;
136
137 xatom->setSupported(this); // set-up netwm support
138 #ifdef HAVE_GETPID
139 xatom->setValue(getRootWindow(), XAtom::blackbox_pid, XAtom::cardinal,
140 (unsigned long) getpid());
141 #endif // HAVE_GETPID
142 unsigned long geometry[] = { getWidth(),
143 getHeight()};
144 xatom->setValue(getRootWindow(), XAtom::net_desktop_geometry,
145 XAtom::cardinal, geometry, 2);
146 unsigned long viewport[] = {0,0};
147 xatom->setValue(getRootWindow(), XAtom::net_desktop_viewport,
148 XAtom::cardinal, viewport, 2);
149
150
151 XDefineCursor(blackbox->getXDisplay(), getRootWindow(),
152 blackbox->getSessionCursor());
153
154 // start off full screen, top left.
155 usableArea.setSize(getWidth(), getHeight());
156
157 image_control =
158 new BImageControl(blackbox, this, True, blackbox->getColorsPerChannel(),
159 blackbox->getCacheLife(), blackbox->getCacheMax());
160 image_control->installRootColormap();
161 root_colormap_installed = True;
162
163 load_rc();
164 LoadStyle();
165
166 XGCValues gcv;
167 gcv.foreground = WhitePixel(blackbox->getXDisplay(), getScreenNumber())
168 ^ BlackPixel(blackbox->getXDisplay(), getScreenNumber());
169 gcv.function = GXxor;
170 gcv.subwindow_mode = IncludeInferiors;
171 opGC = XCreateGC(blackbox->getXDisplay(), getRootWindow(),
172 GCForeground | GCFunction | GCSubwindowMode, &gcv);
173
174 const char *s = i18n(ScreenSet, ScreenPositionLength,
175 "0: 0000 x 0: 0000");
176 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
177 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
178
179 XSetWindowAttributes attrib;
180 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
181 attrib.border_pixel = getBorderColor()->pixel();
182 attrib.colormap = getColormap();
183 attrib.save_under = True;
184
185 geom_window = XCreateWindow(blackbox->getXDisplay(), getRootWindow(),
186 0, 0, geom_w, geom_h, resource.border_width,
187 getDepth(), InputOutput, getVisual(),
188 mask, &attrib);
189 geom_visible = False;
190
191 BTexture* texture = &(resource.wstyle.l_focus);
192 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
193 if (geom_pixmap == ParentRelative) {
194 texture = &(resource.wstyle.t_focus);
195 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
196 }
197 if (! geom_pixmap)
198 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
199 texture->color().pixel());
200 else
201 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
202 geom_window, geom_pixmap);
203
204 workspacemenu = new Workspacemenu(this);
205 iconmenu = new Iconmenu(this);
206 configmenu = new Configmenu(this);
207
208 Workspace *wkspc = (Workspace *) 0;
209 if (resource.workspaces != 0) {
210 for (unsigned int i = 0; i < resource.workspaces; ++i) {
211 wkspc = new Workspace(this, workspacesList.size());
212 workspacesList.push_back(wkspc);
213 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
214 }
215 } else {
216 wkspc = new Workspace(this, workspacesList.size());
217 workspacesList.push_back(wkspc);
218 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
219 }
220 saveWorkspaceNames();
221
222 updateNetizenWorkspaceCount();
223
224 workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
225 workspacemenu->update();
226
227 current_workspace = workspacesList.front();
228
229 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
230 XAtom::cardinal, 0); //first workspace
231
232 workspacemenu->setItemSelected(2, True);
233
234 toolbar = new Toolbar(this);
235
236 slit = new Slit(this);
237
238 InitMenu();
239
240 raiseWindows(0, 0); // this also initializes the empty stacking list
241 rootmenu->update();
242
243 updateClientList(); // initialize the client list, which will be empty
244 updateAvailableArea();
245
246 changeWorkspaceID(0);
247
248 unsigned int i, j, nchild;
249 Window r, p, *children;
250 XQueryTree(blackbox->getXDisplay(), getRootWindow(), &r, &p,
251 &children, &nchild);
252
253 // preen the window list of all icon windows... for better dockapp support
254 for (i = 0; i < nchild; i++) {
255 if (children[i] == None) continue;
256
257 XWMHints *wmhints = XGetWMHints(blackbox->getXDisplay(),
258 children[i]);
259
260 if (wmhints) {
261 if ((wmhints->flags & IconWindowHint) &&
262 (wmhints->icon_window != children[i])) {
263 for (j = 0; j < nchild; j++) {
264 if (children[j] == wmhints->icon_window) {
265 children[j] = None;
266 break;
267 }
268 }
269 }
270
271 XFree(wmhints);
272 }
273 }
274
275 // manage shown windows
276 for (i = 0; i < nchild; ++i) {
277 if (children[i] == None || (! blackbox->validateWindow(children[i])))
278 continue;
279
280 XWindowAttributes attrib;
281 if (XGetWindowAttributes(blackbox->getXDisplay(), children[i], &attrib)) {
282 if (attrib.override_redirect) continue;
283
284 if (attrib.map_state != IsUnmapped) {
285 manageWindow(children[i]);
286 }
287 }
288 }
289
290 XFree(children);
291
292 // call this again just in case a window we found updates the Strut list
293 updateAvailableArea();
294 }
295
296
297 BScreen::~BScreen(void) {
298 if (! managed) return;
299
300 if (geom_pixmap != None)
301 image_control->removeImage(geom_pixmap);
302
303 if (geom_window != None)
304 XDestroyWindow(blackbox->getXDisplay(), geom_window);
305
306 std::for_each(workspacesList.begin(), workspacesList.end(),
307 PointerAssassin());
308
309 std::for_each(iconList.begin(), iconList.end(), PointerAssassin());
310
311 std::for_each(netizenList.begin(), netizenList.end(), PointerAssassin());
312
313 delete rootmenu;
314 delete workspacemenu;
315 delete iconmenu;
316 delete configmenu;
317 delete slit;
318 delete toolbar;
319 delete image_control;
320
321 if (resource.wstyle.font)
322 delete resource.wstyle.font;
323 if (resource.mstyle.t_font)
324 delete resource.mstyle.t_font;
325 if (resource.mstyle.f_font)
326 delete resource.mstyle.f_font;
327 if (resource.tstyle.font)
328 delete resource.tstyle.font;
329
330 XFreeGC(blackbox->getXDisplay(), opGC);
331 }
332
333
334 void BScreen::saveSloppyFocus(bool s) {
335 resource.sloppy_focus = s;
336
337 string fmodel;
338 if (resource.sloppy_focus) {
339 fmodel = "SloppyFocus";
340 if (resource.auto_raise) fmodel += " AutoRaise";
341 if (resource.click_raise) fmodel += " ClickRaise";
342 } else {
343 fmodel = "ClickToFocus";
344 }
345 config->setValue(screenstr + "focusModel", fmodel);
346 }
347
348
349 void BScreen::saveAutoRaise(bool a) {
350 resource.auto_raise = a;
351 saveSloppyFocus(resource.sloppy_focus);
352 }
353
354
355 void BScreen::saveClickRaise(bool c) {
356 resource.click_raise = c;
357 saveSloppyFocus(resource.sloppy_focus);
358 }
359
360
361 void BScreen::saveImageDither(bool d) {
362 image_control->setDither(d);
363 config->setValue(screenstr + "imageDither", doImageDither());
364 }
365
366
367 void BScreen::saveOpaqueMove(bool o) {
368 resource.opaque_move = o;
369 config->setValue(screenstr + "opaqueMove", resource.opaque_move);
370 }
371
372
373 void BScreen::saveFullMax(bool f) {
374 resource.full_max = f;
375 config->setValue(screenstr + "fullMaximization", resource.full_max);
376 }
377
378
379 void BScreen::saveFocusNew(bool f) {
380 resource.focus_new = f;
381 config->setValue(screenstr + "focusNewWindows", resource.focus_new);
382 }
383
384
385 void BScreen::saveFocusLast(bool f) {
386 resource.focus_last = f;
387 config->setValue(screenstr + "focusLastWindow", resource.focus_last);
388 }
389
390
391 void BScreen::saveHideToolbar(bool h) {
392 resource.hide_toolbar = h;
393 if (resource.hide_toolbar)
394 toolbar->unmapToolbar();
395 else
396 toolbar->mapToolbar();
397 config->setValue(screenstr + "hideToolbar", resource.hide_toolbar);
398 }
399
400
401 void BScreen::saveWindowToWindowSnap(bool s) {
402 resource.window_to_window_snap = s;
403 config->setValue(screenstr + "windowToWindowSnap",
404 resource.window_to_window_snap);
405 }
406
407
408 void BScreen::saveWindowCornerSnap(bool s) {
409 resource.window_corner_snap = s;
410 config->setValue(screenstr + "windowCornerSnap",
411 resource.window_corner_snap);
412 }
413
414
415 void BScreen::saveWorkspaces(unsigned int w) {
416 resource.workspaces = w;
417 config->setValue(screenstr + "workspaces", resource.workspaces);
418 }
419
420
421 void BScreen::savePlacementPolicy(int p) {
422 resource.placement_policy = p;
423 const char *placement;
424 switch (resource.placement_policy) {
425 case CascadePlacement: placement = "CascadePlacement"; break;
426 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
427 case RowSmartPlacement: default: placement = "RowSmartPlacement"; break;
428 }
429 config->setValue(screenstr + "windowPlacement", placement);
430 }
431
432
433 void BScreen::saveEdgeSnapThreshold(int t) {
434 resource.edge_snap_threshold = t;
435 config->setValue(screenstr + "edgeSnapThreshold",
436 resource.edge_snap_threshold);
437 }
438
439
440 void BScreen::saveRowPlacementDirection(int d) {
441 resource.row_direction = d;
442 config->setValue(screenstr + "rowPlacementDirection",
443 resource.row_direction == LeftRight ?
444 "LeftToRight" : "RightToLeft");
445 }
446
447
448 void BScreen::saveColPlacementDirection(int d) {
449 resource.col_direction = d;
450 config->setValue(screenstr + "colPlacementDirection",
451 resource.col_direction == TopBottom ?
452 "TopToBottom" : "BottomToTop");
453 }
454
455
456 #ifdef HAVE_STRFTIME
457 void BScreen::saveStrftimeFormat(const std::string& format) {
458 resource.strftime_format = format;
459 config->setValue(screenstr + "strftimeFormat", resource.strftime_format);
460 }
461
462 #else // !HAVE_STRFTIME
463
464 void BScreen::saveDateFormat(int f) {
465 resource.date_format = f;
466 config->setValue(screenstr + "dateFormat",
467 resource.date_format == B_EuropeanDate ?
468 "European" : "American");
469 }
470
471
472 void BScreen::saveClock24Hour(Bool c) {
473 resource.clock24hour = c;
474 config->setValue(screenstr + "clockFormat", resource.clock24hour ? 24 : 12);
475 }
476 #endif // HAVE_STRFTIME
477
478
479 void BScreen::saveWorkspaceNames() {
480 XAtom::StringVect nameList;
481 unsigned long numnames = (unsigned) -1;
482 string names;
483
484 if (numnames > 0 &&
485 xatom->getValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
486 numnames, nameList)) {
487 for (unsigned int i = 0; i < nameList.size(); ++i) {
488 if (i > 0) names += ",";
489 names += nameList[i];
490 }
491 }
492 config->setValue(screenstr + "workspaceNames", names);
493 }
494
495
496 void BScreen::save_rc(void) {
497 saveSloppyFocus(resource.sloppy_focus);
498 saveAutoRaise(resource.auto_raise);
499 saveImageDither(doImageDither());
500 saveOpaqueMove(resource.opaque_move);
501 saveFullMax(resource.full_max);
502 saveFocusNew(resource.focus_new);
503 saveFocusLast(resource.focus_last);
504 saveHideToolbar(resource.hide_toolbar);
505 saveWindowToWindowSnap(resource.window_to_window_snap);
506 saveWindowCornerSnap(resource.window_corner_snap);
507 saveWorkspaces(resource.workspaces);
508 savePlacementPolicy(resource.placement_policy);
509 saveEdgeSnapThreshold(resource.edge_snap_threshold);
510 saveRowPlacementDirection(resource.row_direction);
511 saveColPlacementDirection(resource.col_direction);
512 #ifdef HAVE_STRFTIME
513 saveStrftimeFormat(resource.strftime_format);
514 #else // !HAVE_STRFTIME
515 saveDateFormat(resource.date_format);
516 savwClock24Hour(resource.clock24hour);
517 #endif // HAVE_STRFTIME
518
519 toolbar->save_rc();
520 slit->save_rc();
521 }
522
523
524 void BScreen::load_rc(void) {
525 std::string s;
526 bool b;
527
528 if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
529 resource.full_max = false;
530
531 if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
532 resource.focus_new = false;
533
534 if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
535 resource.focus_last = false;
536
537 if (! config->getValue(screenstr + "workspaces", resource.workspaces))
538 resource.workspaces = 1;
539
540 if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
541 resource.opaque_move = false;
542
543 if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
544 resource.hide_toolbar = false;
545
546 if (! config->getValue(screenstr + "windowToWindowSnap",
547 resource.window_to_window_snap))
548 resource.window_to_window_snap = true;
549
550 if (! config->getValue(screenstr + "windowCornerSnap",
551 resource.window_corner_snap))
552 resource.window_corner_snap = true;
553
554 if (! config->getValue(screenstr + "imageDither", b))
555 b = true;
556 image_control->setDither(b);
557
558 if (! config->getValue(screenstr + "edgeSnapThreshold",
559 resource.edge_snap_threshold))
560 resource.edge_snap_threshold = 4;
561
562 if (config->getValue(screenstr + "rowPlacementDirection", s) &&
563 s == "RightToLeft")
564 resource.row_direction = RightLeft;
565 else
566 resource.row_direction = LeftRight;
567
568 if (config->getValue(screenstr + "colPlacementDirection", s) &&
569 s == "BottomToTop")
570 resource.col_direction = BottomTop;
571 else
572 resource.col_direction = TopBottom;
573
574 XAtom::StringVect workspaceNames;
575 if (config->getValue(screenstr + "workspaceNames", s)) {
576 string::const_iterator it = s.begin(), end = s.end();
577 while(1) {
578 string::const_iterator tmp = it; // current string.begin()
579 it = std::find(tmp, end, ','); // look for comma between tmp and end
580 workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
581 if (it == end)
582 break;
583 ++it;
584 }
585 }
586 xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
587 workspaceNames);
588
589 resource.sloppy_focus = true;
590 resource.auto_raise = false;
591 resource.click_raise = false;
592 if (config->getValue(screenstr + "focusModel", s)) {
593 if (s.find("ClickToFocus") != string::npos) {
594 resource.sloppy_focus = false;
595 } else {
596 // must be sloppy
597 if (s.find("AutoRaise") != string::npos)
598 resource.auto_raise = true;
599 if (s.find("ClickRaise") != string::npos)
600 resource.click_raise = true;
601 }
602 }
603
604 if (config->getValue(screenstr + "windowPlacement", s)) {
605 if (s == "CascadePlacement")
606 resource.placement_policy = CascadePlacement;
607 else if (s == "ColSmartPlacement")
608 resource.placement_policy = ColSmartPlacement;
609 else //if (s == "RowSmartPlacement")
610 resource.placement_policy = RowSmartPlacement;
611 } else
612 resource.placement_policy = RowSmartPlacement;
613
614 #ifdef HAVE_STRFTIME
615 if (config->getValue(screenstr + "strftimeFormat", s))
616 resource.strftime_format = s;
617 else
618 resource.strftime_format = "%I:%M %p";
619 #else // !HAVE_STRFTIME
620 long l;
621
622 if (config->getValue(screenstr + "dateFormat", s) && s == "European")
623 resource.date_format = B_EuropeanDate;
624 else
625 resource.date_format = B_AmericanDate;
626
627 if (! config->getValue(screenstr + "clockFormat", l))
628 l = 12;
629 resource.clock24hour = l == 24;
630 #endif // HAVE_STRFTIME
631 }
632
633
634 void BScreen::reconfigure(void) {
635 load_rc();
636 toolbar->load_rc();
637 slit->load_rc();
638 LoadStyle();
639
640 XGCValues gcv;
641 gcv.foreground = WhitePixel(blackbox->getXDisplay(),
642 getScreenNumber());
643 gcv.function = GXinvert;
644 gcv.subwindow_mode = IncludeInferiors;
645 XChangeGC(blackbox->getXDisplay(), opGC,
646 GCForeground | GCFunction | GCSubwindowMode, &gcv);
647
648 const char *s = i18n(ScreenSet, ScreenPositionLength,
649 "0: 0000 x 0: 0000");
650
651 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
652 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
653
654 BTexture* texture = &(resource.wstyle.l_focus);
655 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
656 if (geom_pixmap == ParentRelative) {
657 texture = &(resource.wstyle.t_focus);
658 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
659 }
660 if (! geom_pixmap)
661 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
662 texture->color().pixel());
663 else
664 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
665 geom_window, geom_pixmap);
666
667 XSetWindowBorderWidth(blackbox->getXDisplay(), geom_window,
668 resource.border_width);
669 XSetWindowBorder(blackbox->getXDisplay(), geom_window,
670 resource.border_color.pixel());
671
672 workspacemenu->reconfigure();
673 iconmenu->reconfigure();
674
675 typedef std::vector<int> SubList;
676 SubList remember_subs;
677
678 // save the current open menus
679 Basemenu *menu = rootmenu;
680 int submenu;
681 while ((submenu = menu->getCurrentSubmenu()) >= 0) {
682 remember_subs.push_back(submenu);
683 menu = menu->find(submenu)->submenu();
684 assert(menu);
685 }
686
687 InitMenu();
688 raiseWindows(0, 0);
689 rootmenu->reconfigure();
690
691 // reopen the saved menus
692 menu = rootmenu;
693 const SubList::iterator subs_end = remember_subs.end();
694 for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
695 menu->drawSubmenu(*it);
696 menu = menu->find(*it)->submenu();
697 if (! menu)
698 break;
699 }
700
701 configmenu->reconfigure();
702
703 toolbar->reconfigure();
704
705 slit->reconfigure();
706
707 std::for_each(workspacesList.begin(), workspacesList.end(),
708 std::mem_fun(&Workspace::reconfigure));
709
710 BlackboxWindowList::iterator iit = iconList.begin();
711 for (; iit != iconList.end(); ++iit) {
712 BlackboxWindow *bw = *iit;
713 if (bw->validateClient())
714 bw->reconfigure();
715 }
716
717 image_control->timeout();
718 }
719
720
721 void BScreen::rereadMenu(void) {
722 InitMenu();
723 raiseWindows(0, 0);
724
725 rootmenu->reconfigure();
726 }
727
728
729 void BScreen::LoadStyle(void) {
730 Configuration style(False);
731
732 const char *sfile = blackbox->getStyleFilename();
733 if (sfile != NULL) {
734 style.setFile(sfile);
735 if (! style.load()) {
736 style.setFile(DEFAULTSTYLE);
737 if (! style.load())
738 style.create(); // hardcoded default values will be used.
739 }
740 }
741
742 string s;
743
744 if (config->getValue("rootCommand", s))
745 printf("config.rootCommand: %s\n", s.c_str());
746
747 if (style.getValue("rootCommand", s))
748 printf("style.rootCommand: %s\n", s.c_str());
749
750 // merge in the rc file
751 style.merge(config, True);
752
753 printf("merged databases\n");
754
755 if (style.getValue("rootCommand", s))
756 printf("style.rootCommand: %s\n", s.c_str());
757
758 if (style.getValue("session.cacheMax", s))
759 printf("session.cacheMax: %s\n", s.c_str());
760
761 // load fonts/fontsets
762 if (resource.wstyle.font)
763 delete resource.wstyle.font;
764 if (resource.tstyle.font)
765 delete resource.tstyle.font;
766 if (resource.mstyle.f_font)
767 delete resource.mstyle.f_font;
768 if (resource.mstyle.t_font)
769 delete resource.mstyle.t_font;
770 resource.wstyle.font = resource.tstyle.font = resource.mstyle.f_font =
771 resource.mstyle.t_font = (BFont *) 0;
772
773 resource.wstyle.font = readDatabaseFont("window.font", style);
774 resource.tstyle.font = readDatabaseFont("toolbar.font", style);
775 resource.mstyle.t_font = readDatabaseFont("menu.title.font", style);
776 resource.mstyle.f_font = readDatabaseFont("menu.frame.font", style);
777
778 // load window config
779 resource.wstyle.t_focus =
780 readDatabaseTexture("window.title.focus", "white", style);
781 resource.wstyle.t_unfocus =
782 readDatabaseTexture("window.title.unfocus", "black", style);
783 resource.wstyle.l_focus =
784 readDatabaseTexture("window.label.focus", "white", style);
785 resource.wstyle.l_unfocus =
786 readDatabaseTexture("window.label.unfocus", "black", style);
787 resource.wstyle.h_focus =
788 readDatabaseTexture("window.handle.focus", "white", style);
789 resource.wstyle.h_unfocus =
790 readDatabaseTexture("window.handle.unfocus", "black", style);
791 resource.wstyle.g_focus =
792 readDatabaseTexture("window.grip.focus", "white", style);
793 resource.wstyle.g_unfocus =
794 readDatabaseTexture("window.grip.unfocus", "black", style);
795 resource.wstyle.b_focus =
796 readDatabaseTexture("window.button.focus", "white", style);
797 resource.wstyle.b_unfocus =
798 readDatabaseTexture("window.button.unfocus", "black", style);
799 resource.wstyle.b_pressed =
800 readDatabaseTexture("window.button.pressed", "black", style);
801 resource.wstyle.f_focus =
802 readDatabaseColor("window.frame.focusColor", "white", style);
803 resource.wstyle.f_unfocus =
804 readDatabaseColor("window.frame.unfocusColor", "black", style);
805 resource.wstyle.l_text_focus =
806 readDatabaseColor("window.label.focus.textColor", "black", style);
807 resource.wstyle.l_text_unfocus =
808 readDatabaseColor("window.label.unfocus.textColor", "white", style);
809 resource.wstyle.b_pic_focus =
810 readDatabaseColor("window.button.focus.picColor", "black", style);
811 resource.wstyle.b_pic_unfocus =
812 readDatabaseColor("window.button.unfocus.picColor", "white", style);
813
814 resource.wstyle.justify = LeftJustify;
815 if (style.getValue("window.justify", s)) {
816 if (s == "right" || s == "Right")
817 resource.wstyle.justify = RightJustify;
818 else if (s == "center" || s == "Center")
819 resource.wstyle.justify = CenterJustify;
820 }
821
822 // load toolbar config
823 resource.tstyle.toolbar =
824 readDatabaseTexture("toolbar", "black", style);
825 resource.tstyle.label =
826 readDatabaseTexture("toolbar.label", "black", style);
827 resource.tstyle.window =
828 readDatabaseTexture("toolbar.windowLabel", "black", style);
829 resource.tstyle.button =
830 readDatabaseTexture("toolbar.button", "white", style);
831 resource.tstyle.pressed =
832 readDatabaseTexture("toolbar.button.pressed", "black", style);
833 resource.tstyle.clock =
834 readDatabaseTexture("toolbar.clock", "black", style);
835 resource.tstyle.l_text =
836 readDatabaseColor("toolbar.label.textColor", "white", style);
837 resource.tstyle.w_text =
838 readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
839 resource.tstyle.c_text =
840 readDatabaseColor("toolbar.clock.textColor", "white", style);
841 resource.tstyle.b_pic =
842 readDatabaseColor("toolbar.button.picColor", "black", style);
843
844 resource.tstyle.justify = LeftJustify;
845 if (style.getValue("toolbar.justify", s)) {
846 if (s == "right" || s == "Right")
847 resource.tstyle.justify = RightJustify;
848 else if (s == "center" || s == "Center")
849 resource.tstyle.justify = CenterJustify;
850 }
851
852 // load menu config
853 resource.mstyle.title =
854 readDatabaseTexture("menu.title", "white", style);
855 resource.mstyle.frame =
856 readDatabaseTexture("menu.frame", "black", style);
857 resource.mstyle.hilite =
858 readDatabaseTexture("menu.hilite", "white", style);
859 resource.mstyle.t_text =
860 readDatabaseColor("menu.title.textColor", "black", style);
861 resource.mstyle.f_text =
862 readDatabaseColor("menu.frame.textColor", "white", style);
863 resource.mstyle.d_text =
864 readDatabaseColor("menu.frame.disableColor", "black", style);
865 resource.mstyle.h_text =
866 readDatabaseColor("menu.hilite.textColor", "black", style);
867
868 resource.mstyle.t_justify = LeftJustify;
869 if (style.getValue("menu.title.justify", s)) {
870 if (s == "right" || s == "Right")
871 resource.mstyle.t_justify = RightJustify;
872 else if (s == "center" || s == "Center")
873 resource.mstyle.t_justify = CenterJustify;
874 }
875
876 resource.mstyle.f_justify = LeftJustify;
877 if (style.getValue("menu.frame.justify", s)) {
878 if (s == "right" || s == "Right")
879 resource.mstyle.f_justify = RightJustify;
880 else if (s == "center" || s == "Center")
881 resource.mstyle.f_justify = CenterJustify;
882 }
883
884 resource.mstyle.bullet = Basemenu::Triangle;
885 if (style.getValue("menu.bullet", s)) {
886 if (s == "empty" || s == "Empty")
887 resource.mstyle.bullet = Basemenu::Empty;
888 else if (s == "square" || s == "Square")
889 resource.mstyle.bullet = Basemenu::Square;
890 else if (s == "diamond" || s == "Diamond")
891 resource.mstyle.bullet = Basemenu::Diamond;
892 }
893
894 resource.mstyle.bullet_pos = Basemenu::Left;
895 if (style.getValue("menu.bullet.position", s)) {
896 if (s == "right" || s == "Right")
897 resource.mstyle.bullet_pos = Basemenu::Right;
898 }
899
900 resource.border_color =
901 readDatabaseColor("borderColor", "black", style);
902
903 // load bevel, border and handle widths
904 if (! style.getValue("handleWidth", resource.handle_width) ||
905 resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
906 resource.handle_width = 6;
907
908 if (! style.getValue("borderWidth", resource.border_width))
909 resource.border_width = 1;
910
911 if (! style.getValue("bevelWidth", resource.bevel_width) ||
912 resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
913 resource.bevel_width = 3;
914
915 if (! style.getValue("frameWidth", resource.frame_width) ||
916 resource.frame_width > (getWidth() / 2))
917 resource.frame_width = resource.bevel_width;
918
919 if (style.getValue("rootCommand", s))
920 bexec(s, displayString());
921 }
922
923
924 void BScreen::addIcon(BlackboxWindow *w) {
925 if (! w) return;
926
927 w->setWorkspace(BSENTINEL);
928 w->setWindowNumber(iconList.size());
929
930 iconList.push_back(w);
931
932 const char* title = w->getIconTitle();
933 iconmenu->insert(title);
934 iconmenu->update();
935 }
936
937
938 void BScreen::removeIcon(BlackboxWindow *w) {
939 if (! w) return;
940
941 iconList.remove(w);
942
943 iconmenu->remove(w->getWindowNumber());
944 iconmenu->update();
945
946 BlackboxWindowList::iterator it = iconList.begin(),
947 end = iconList.end();
948 for (int i = 0; it != end; ++it)
949 (*it)->setWindowNumber(i++);
950 }
951
952
953 BlackboxWindow *BScreen::getIcon(unsigned int index) {
954 if (index < iconList.size()) {
955 BlackboxWindowList::iterator it = iconList.begin();
956 for (; index > 0; --index, ++it) ; /* increment to index */
957 return *it;
958 }
959
960 return (BlackboxWindow *) 0;
961 }
962
963
964 unsigned int BScreen::addWorkspace(void) {
965 Workspace *wkspc = new Workspace(this, workspacesList.size());
966 workspacesList.push_back(wkspc);
967 saveWorkspaces(getWorkspaceCount());
968
969 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
970 wkspc->getID() + 2);
971 workspacemenu->update();
972
973 toolbar->reconfigure();
974
975 updateNetizenWorkspaceCount();
976
977 return workspacesList.size();
978 }
979
980
981 unsigned int BScreen::removeLastWorkspace(void) {
982 if (workspacesList.size() == 1)
983 return 1;
984
985 Workspace *wkspc = workspacesList.back();
986
987 if (current_workspace->getID() == wkspc->getID())
988 changeWorkspaceID(current_workspace->getID() - 1);
989
990 wkspc->removeAll();
991
992 workspacemenu->remove(wkspc->getID() + 2);
993 workspacemenu->update();
994
995 workspacesList.pop_back();
996 delete wkspc;
997
998 saveWorkspaces(getWorkspaceCount());
999
1000 toolbar->reconfigure();
1001
1002 updateNetizenWorkspaceCount();
1003
1004 return workspacesList.size();
1005 }
1006
1007
1008 void BScreen::changeWorkspaceID(unsigned int id) {
1009 if (! current_workspace) return;
1010
1011 if (id != current_workspace->getID()) {
1012 BlackboxWindow *focused = blackbox->getFocusedWindow();
1013 if (focused && focused->getScreen() == this && ! focused->isStuck()) {
1014 if (focused->getWorkspaceNumber() != current_workspace->getID()) {
1015 fprintf(stderr, "%s is on the wrong workspace, aborting\n",
1016 focused->getTitle());
1017 abort();
1018 }
1019 current_workspace->setLastFocusedWindow(focused);
1020 } else {
1021 // if no window had focus, no need to store a last focus
1022 current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
1023 }
1024 // when we switch workspaces, unfocus whatever was focused
1025 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1026
1027 current_workspace->hideAll();
1028 workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1029
1030 current_workspace = getWorkspace(id);
1031
1032 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
1033 XAtom::cardinal, id);
1034
1035 workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1036 toolbar->redrawWorkspaceLabel(True);
1037
1038 current_workspace->showAll();
1039
1040 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1041 XSync(blackbox->getXDisplay(), False);
1042 current_workspace->getLastFocusedWindow()->setInputFocus();
1043 }
1044 }
1045
1046 updateNetizenCurrentWorkspace();
1047 }
1048
1049
1050 /*
1051 * Set the _NET_CLIENT_LIST root window property.
1052 */
1053 void BScreen::updateClientList(void) {
1054 if (windowList.size() > 0) {
1055 Window *windows = new Window[windowList.size()];
1056 Window *win_it = windows;
1057 BlackboxWindowList::iterator it = windowList.begin();
1058 const BlackboxWindowList::iterator end = windowList.end();
1059 for (; it != end; ++it, ++win_it)
1060 *win_it = (*it)->getClientWindow();
1061 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1062 windows, windowList.size());
1063 delete [] windows;
1064 } else
1065 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1066 0, 0);
1067 }
1068
1069
1070 /*
1071 * Set the _NET_CLIENT_LIST_STACKING root window property.
1072 */
1073 void BScreen::updateStackingList(void) {
1074
1075 BlackboxWindowList stack_order;
1076
1077 /*
1078 * Get the atacking order from all of the workspaces.
1079 * We start with the current workspace so that the sticky windows will be
1080 * in the right order on the current workspace.
1081 * XXX: Do we need to have sticky windows in the list once for each workspace?
1082 */
1083 getCurrentWorkspace()->appendStackOrder(stack_order);
1084 for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
1085 if (i != getCurrentWorkspaceID())
1086 getWorkspace(i)->appendStackOrder(stack_order);
1087
1088 if (stack_order.size() > 0) {
1089 // set the client list atoms
1090 Window *windows = new Window[stack_order.size()];
1091 Window *win_it = windows;
1092 BlackboxWindowList::iterator it = stack_order.begin();
1093 const BlackboxWindowList::iterator end = stack_order.end();
1094 for (; it != end; ++it, ++win_it)
1095 *win_it = (*it)->getClientWindow();
1096 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1097 XAtom::window, windows, stack_order.size());
1098 delete [] windows;
1099 } else
1100 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1101 XAtom::window, 0, 0);
1102 }
1103
1104
1105 void BScreen::addSystrayWindow(Window window) {
1106 systrayWindowList.push_back(window);
1107 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1108 XAtom::window,
1109 &systrayWindowList[0], systrayWindowList.size());
1110 blackbox->saveSystrayWindowSearch(window, this);
1111 }
1112
1113
1114 void BScreen::removeSystrayWindow(Window window) {
1115 WindowList::iterator it = systrayWindowList.begin();
1116 const WindowList::iterator end = systrayWindowList.end();
1117 for (; it != end; ++it)
1118 if (*it == window) {
1119 systrayWindowList.erase(it);
1120 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1121 XAtom::window,
1122 &systrayWindowList[0], systrayWindowList.size());
1123 blackbox->removeSystrayWindowSearch(window);
1124 break;
1125 }
1126 }
1127
1128
1129 void BScreen::addDesktopWindow(Window window) {
1130 desktopWindowList.push_back(window);
1131 XLowerWindow(blackbox->getXDisplay(), window);
1132 XSelectInput(blackbox->getXDisplay(), window, StructureNotifyMask);
1133 blackbox->saveDesktopWindowSearch(window, this);
1134 }
1135
1136
1137 void BScreen::removeDesktopWindow(Window window) {
1138 WindowList::iterator it = desktopWindowList.begin();
1139 const WindowList::iterator end = desktopWindowList.end();
1140 for (; it != end; ++it)
1141 if (*it == window) {
1142 desktopWindowList.erase(it);
1143 XSelectInput(blackbox->getXDisplay(), window, None);
1144 blackbox->removeDesktopWindowSearch(window);
1145 break;
1146 }
1147 }
1148
1149
1150 void BScreen::manageWindow(Window w) {
1151 new BlackboxWindow(blackbox, w, this);
1152
1153 BlackboxWindow *win = blackbox->searchWindow(w);
1154 if (! win)
1155 return;
1156 if (win->isDesktop()) {
1157 // desktop windows cant do anything, so we remove all the normal window
1158 // stuff from them, they are only kept around so that we can keep them on
1159 // the bottom of the z-order
1160 win->restore(True);
1161 addDesktopWindow(win->getClientWindow());
1162 delete win;
1163 return;
1164 }
1165
1166 windowList.push_back(win);
1167 updateClientList();
1168
1169 XMapRequestEvent mre;
1170 mre.window = w;
1171 if (blackbox->isStartup()) win->restoreAttributes();
1172 win->mapRequestEvent(&mre);
1173 }
1174
1175
1176 void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
1177 w->restore(remap);
1178
1179 if (w->getWorkspaceNumber() != BSENTINEL &&
1180 w->getWindowNumber() != BSENTINEL)
1181 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1182 else if (w->isIconic())
1183 removeIcon(w);
1184
1185 windowList.remove(w);
1186 updateClientList();
1187
1188 if (blackbox->getFocusedWindow() == w)
1189 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1190
1191 removeNetizen(w->getClientWindow());
1192
1193 /*
1194 some managed windows can also be window group controllers. when
1195 unmanaging such windows, we should also delete the window group.
1196 */
1197 BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
1198 delete group;
1199
1200 delete w;
1201 }
1202
1203
1204 void BScreen::addNetizen(Netizen *n) {
1205 netizenList.push_back(n);
1206
1207 n->sendWorkspaceCount();
1208 n->sendCurrentWorkspace();
1209
1210 WorkspaceList::iterator it = workspacesList.begin();
1211 const WorkspaceList::iterator end = workspacesList.end();
1212 for (; it != end; ++it)
1213 (*it)->sendWindowList(*n);
1214
1215 Window f = ((blackbox->getFocusedWindow()) ?
1216 blackbox->getFocusedWindow()->getClientWindow() : None);
1217 n->sendWindowFocus(f);
1218 }
1219
1220
1221 void BScreen::removeNetizen(Window w) {
1222 NetizenList::iterator it = netizenList.begin();
1223 for (; it != netizenList.end(); ++it) {
1224 if ((*it)->getWindowID() == w) {
1225 delete *it;
1226 netizenList.erase(it);
1227 break;
1228 }
1229 }
1230 }
1231
1232
1233 void BScreen::updateWorkArea(void) {
1234 if (workspacesList.size() > 0) {
1235 unsigned long *dims = new unsigned long[4 * workspacesList.size()];
1236 for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
1237 // XXX: this could be different for each workspace
1238 const Rect &area = availableArea();
1239 dims[(i * 4) + 0] = area.x();
1240 dims[(i * 4) + 1] = area.y();
1241 dims[(i * 4) + 2] = area.width();
1242 dims[(i * 4) + 3] = area.height();
1243 }
1244 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1245 dims, 4 * workspacesList.size());
1246 delete [] dims;
1247 } else
1248 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1249 0, 0);
1250 }
1251
1252
1253 void BScreen::updateNetizenCurrentWorkspace(void) {
1254 std::for_each(netizenList.begin(), netizenList.end(),
1255 std::mem_fun(&Netizen::sendCurrentWorkspace));
1256 }
1257
1258
1259 void BScreen::updateNetizenWorkspaceCount(void) {
1260 xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
1261 XAtom::cardinal, workspacesList.size());
1262
1263 updateWorkArea();
1264
1265 std::for_each(netizenList.begin(), netizenList.end(),
1266 std::mem_fun(&Netizen::sendWorkspaceCount));
1267 }
1268
1269
1270 void BScreen::updateNetizenWindowFocus(void) {
1271 Window f = ((blackbox->getFocusedWindow()) ?
1272 blackbox->getFocusedWindow()->getClientWindow() : None);
1273
1274 xatom->setValue(getRootWindow(), XAtom::net_active_window,
1275 XAtom::window, f);
1276
1277 NetizenList::iterator it = netizenList.begin();
1278 for (; it != netizenList.end(); ++it)
1279 (*it)->sendWindowFocus(f);
1280 }
1281
1282
1283 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1284 NetizenList::iterator it = netizenList.begin();
1285 for (; it != netizenList.end(); ++it) {
1286 (*it)->sendWindowAdd(w, p);
1287 }
1288 }
1289
1290
1291 void BScreen::updateNetizenWindowDel(Window w) {
1292 NetizenList::iterator it = netizenList.begin();
1293 for (; it != netizenList.end(); ++it)
1294 (*it)->sendWindowDel(w);
1295 }
1296
1297
1298 void BScreen::updateNetizenWindowRaise(Window w) {
1299 NetizenList::iterator it = netizenList.begin();
1300 for (; it != netizenList.end(); ++it)
1301 (*it)->sendWindowRaise(w);
1302 }
1303
1304
1305 void BScreen::updateNetizenWindowLower(Window w) {
1306 NetizenList::iterator it = netizenList.begin();
1307 for (; it != netizenList.end(); ++it)
1308 (*it)->sendWindowLower(w);
1309 }
1310
1311
1312 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1313 NetizenList::iterator it = netizenList.begin();
1314 for (; it != netizenList.end(); ++it)
1315 (*it)->sendConfigNotify(e);
1316 }
1317
1318
1319 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
1320 // the 13 represents the number of blackbox windows such as menus
1321 Window *session_stack = new
1322 Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
1323 unsigned int i = 0, k = num;
1324
1325 XRaiseWindow(blackbox->getXDisplay(), iconmenu->getWindowID());
1326 *(session_stack + i++) = iconmenu->getWindowID();
1327
1328 WorkspaceList::iterator wit = workspacesList.begin();
1329 const WorkspaceList::iterator w_end = workspacesList.end();
1330 for (; wit != w_end; ++wit)
1331 *(session_stack + i++) = (*wit)->getMenu()->getWindowID();
1332
1333 *(session_stack + i++) = workspacemenu->getWindowID();
1334
1335 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1336 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1337 *(session_stack + i++) = configmenu->getWindowID();
1338
1339 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1340 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1341 *(session_stack + i++) = slit->getMenu()->getWindowID();
1342
1343 *(session_stack + i++) =
1344 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1345 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1346
1347 RootmenuList::iterator rit = rootmenuList.begin();
1348 for (; rit != rootmenuList.end(); ++rit)
1349 *(session_stack + i++) = (*rit)->getWindowID();
1350 *(session_stack + i++) = rootmenu->getWindowID();
1351
1352 if (toolbar->isOnTop())
1353 *(session_stack + i++) = toolbar->getWindowID();
1354
1355 if (slit->isOnTop())
1356 *(session_stack + i++) = slit->getWindowID();
1357
1358 while (k--)
1359 *(session_stack + i++) = *(workspace_stack + k);
1360
1361 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1362
1363 delete [] session_stack;
1364
1365 updateStackingList();
1366 }
1367
1368
1369 void BScreen::lowerDesktops(void) {
1370 if (desktopWindowList.empty()) return;
1371
1372 XLowerWindow(blackbox->getXDisplay(), desktopWindowList[0]);
1373 if (desktopWindowList.size() > 1)
1374 XRestackWindows(blackbox->getXDisplay(), &desktopWindowList[0],
1375 desktopWindowList.size());
1376 }
1377
1378
1379 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
1380 bool ignore_sticky) {
1381 if (! w) return;
1382
1383 if (wkspc_id == BSENTINEL)
1384 wkspc_id = current_workspace->getID();
1385
1386 if (w->getWorkspaceNumber() == wkspc_id)
1387 return;
1388
1389 if (w->isIconic()) {
1390 removeIcon(w);
1391 getWorkspace(wkspc_id)->addWindow(w);
1392 } else if (ignore_sticky || ! w->isStuck()) {
1393 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1394 getWorkspace(wkspc_id)->addWindow(w);
1395 }
1396 }
1397
1398
1399 void BScreen::propagateWindowName(const BlackboxWindow *bw) {
1400 if (bw->isIconic()) {
1401 iconmenu->changeItemLabel(bw->getWindowNumber(), bw->getIconTitle());
1402 iconmenu->update();
1403 }
1404 else {
1405 Clientmenu *clientmenu = getWorkspace(bw->getWorkspaceNumber())->getMenu();
1406 clientmenu->changeItemLabel(bw->getWindowNumber(), bw->getTitle());
1407 clientmenu->update();
1408
1409 if (blackbox->getFocusedWindow() == bw)
1410 toolbar->redrawWindowLabel(True);
1411 }
1412 }
1413
1414
1415 void BScreen::nextFocus(void) {
1416 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1417 *next = focused;
1418
1419 if (focused) {
1420 // if window is not on this screen, ignore it
1421 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1422 focused = (BlackboxWindow*) 0;
1423 }
1424
1425 if (focused && current_workspace->getCount() > 1) {
1426 // next is the next window to recieve focus, current is a place holder
1427 BlackboxWindow *current;
1428 do {
1429 current = next;
1430 next = current_workspace->getNextWindowInList(current);
1431 } while(! next->setInputFocus() && next != focused);
1432
1433 if (next != focused)
1434 current_workspace->raiseWindow(next);
1435 } else if (current_workspace->getCount() >= 1) {
1436 next = current_workspace->getTopWindowOnStack();
1437
1438 current_workspace->raiseWindow(next);
1439 next->setInputFocus();
1440 }
1441 }
1442
1443
1444 void BScreen::prevFocus(void) {
1445 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1446 *next = focused;
1447
1448 if (focused) {
1449 // if window is not on this screen, ignore it
1450 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1451 focused = (BlackboxWindow*) 0;
1452 }
1453
1454 if (focused && current_workspace->getCount() > 1) {
1455 // next is the next window to recieve focus, current is a place holder
1456 BlackboxWindow *current;
1457 do {
1458 current = next;
1459 next = current_workspace->getPrevWindowInList(current);
1460 } while(! next->setInputFocus() && next != focused);
1461
1462 if (next != focused)
1463 current_workspace->raiseWindow(next);
1464 } else if (current_workspace->getCount() >= 1) {
1465 next = current_workspace->getTopWindowOnStack();
1466
1467 current_workspace->raiseWindow(next);
1468 next->setInputFocus();
1469 }
1470 }
1471
1472
1473 void BScreen::raiseFocus(void) {
1474 BlackboxWindow *focused = blackbox->getFocusedWindow();
1475 if (! focused)
1476 return;
1477
1478 // if on this Screen, raise it
1479 if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
1480 Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
1481 workspace->raiseWindow(focused);
1482 }
1483 }
1484
1485
1486 void BScreen::InitMenu(void) {
1487 if (rootmenu) {
1488 rootmenuList.clear();
1489
1490 while (rootmenu->getCount())
1491 rootmenu->remove(0);
1492 } else {
1493 rootmenu = new Rootmenu(this);
1494 }
1495 bool defaultMenu = True;
1496
1497 FILE *menu_file = (FILE *) 0;
1498 const char *menu_filename = blackbox->getMenuFilename();
1499
1500 if (menu_filename)
1501 if (! (menu_file = fopen(menu_filename, "r")))
1502 perror(menu_filename);
1503 if (! menu_file) { // opening the menu file failed, try the default menu
1504 menu_filename = DEFAULTMENU;
1505 if (! (menu_file = fopen(menu_filename, "r")))
1506 perror(menu_filename);
1507 }
1508
1509 if (menu_file) {
1510 if (feof(menu_file)) {
1511 fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
1512 "%s: Empty menu file"),
1513 menu_filename);
1514 } else {
1515 char line[1024], label[1024];
1516 memset(line, 0, 1024);
1517 memset(label, 0, 1024);
1518
1519 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
1520 if (line[0] != '#') {
1521 int i, key = 0, index = -1, len = strlen(line);
1522
1523 for (i = 0; i < len; i++) {
1524 if (line[i] == '[') index = 0;
1525 else if (line[i] == ']') break;
1526 else if (line[i] != ' ')
1527 if (index++ >= 0)
1528 key += tolower(line[i]);
1529 }
1530
1531 if (key == 517) { // [begin]
1532 index = -1;
1533 for (i = index; i < len; i++) {
1534 if (line[i] == '(') index = 0;
1535 else if (line[i] == ')') break;
1536 else if (index++ >= 0) {
1537 if (line[i] == '\\' && i < len - 1) i++;
1538 label[index - 1] = line[i];
1539 }
1540 }
1541
1542 if (index == -1) index = 0;
1543 label[index] = '\0';
1544
1545 rootmenu->setLabel(label);
1546 defaultMenu = parseMenuFile(menu_file, rootmenu);
1547 if (! defaultMenu)
1548 blackbox->addMenuTimestamp(menu_filename);
1549 break;
1550 }
1551 }
1552 }
1553 }
1554 fclose(menu_file);
1555 }
1556
1557 if (defaultMenu) {
1558 rootmenu->setInternalMenu();
1559 rootmenu->insert(i18n(ScreenSet, Screenxterm, "xterm"),
1560 BScreen::Execute,
1561 i18n(ScreenSet, Screenxterm, "xterm"));
1562 rootmenu->insert(i18n(ScreenSet, ScreenRestart, "Restart"),
1563 BScreen::Restart);
1564 rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
1565 BScreen::Exit);
1566 rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
1567 "Openbox Menu"));
1568 }
1569 }
1570
1571
1572 bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
1573 char line[1024], label[1024], command[1024];
1574
1575 while (! feof(file)) {
1576 memset(line, 0, 1024);
1577 memset(label, 0, 1024);
1578 memset(command, 0, 1024);
1579
1580 if (fgets(line, 1024, file)) {
1581 if (line[0] != '#') {
1582 int i, key = 0, parse = 0, index = -1, line_length = strlen(line);
1583
1584 // determine the keyword
1585 for (i = 0; i < line_length; i++) {
1586 if (line[i] == '[') parse = 1;
1587 else if (line[i] == ']') break;
1588 else if (line[i] != ' ')
1589 if (parse)
1590 key += tolower(line[i]);
1591 }
1592
1593 // get the label enclosed in ()'s
1594 parse = 0;
1595
1596 for (i = 0; i < line_length; i++) {
1597 if (line[i] == '(') {
1598 index = 0;
1599 parse = 1;
1600 } else if (line[i] == ')') break;
1601 else if (index++ >= 0) {
1602 if (line[i] == '\\' && i < line_length - 1) i++;
1603 label[index - 1] = line[i];
1604 }
1605 }
1606
1607 if (parse) {
1608 label[index] = '\0';
1609 } else {
1610 label[0] = '\0';
1611 }
1612
1613 // get the command enclosed in {}'s
1614 parse = 0;
1615 index = -1;
1616 for (i = 0; i < line_length; i++) {
1617 if (line[i] == '{') {
1618 index = 0;
1619 parse = 1;
1620 } else if (line[i] == '}') break;
1621 else if (index++ >= 0) {
1622 if (line[i] == '\\' && i < line_length - 1) i++;
1623 command[index - 1] = line[i];
1624 }
1625 }
1626
1627 if (parse) {
1628 command[index] = '\0';
1629 } else {
1630 command[0] = '\0';
1631 }
1632
1633 switch (key) {
1634 case 311: // end
1635 return ((menu->getCount() == 0) ? True : False);
1636
1637 break;
1638
1639 case 333: // nop
1640 if (! *label)
1641 label[0] = '\0';
1642 menu->insert(label);
1643
1644 break;
1645
1646 case 421: // exec
1647 if ((! *label) && (! *command)) {
1648 fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
1649 "BScreen::parseMenuFile: [exec] error, "
1650 "no menu label and/or command defined\n"));
1651 continue;
1652 }
1653
1654 menu->insert(label, BScreen::Execute, command);
1655
1656 break;
1657
1658 case 442: // exit
1659 if (! *label) {
1660 fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
1661 "BScreen::parseMenuFile: [exit] error, "
1662 "no menu label defined\n"));
1663 continue;
1664 }
1665
1666 menu->insert(label, BScreen::Exit);
1667
1668 break;
1669
1670 case 561: // style
1671 {
1672 if ((! *label) || (! *command)) {
1673 fprintf(stderr,
1674 i18n(ScreenSet, ScreenSTYLEError,
1675 "BScreen::parseMenuFile: [style] error, "
1676 "no menu label and/or filename defined\n"));
1677 continue;
1678 }
1679
1680 string style = expandTilde(command);
1681
1682 menu->insert(label, BScreen::SetStyle, style.c_str());
1683 }
1684
1685 break;
1686
1687 case 630: // config
1688 if (! *label) {
1689 fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
1690 "BScreen::parseMenufile: [config] error, "
1691 "no label defined"));
1692 continue;
1693 }
1694
1695 menu->insert(label, configmenu);
1696
1697 break;
1698
1699 case 740: // include
1700 {
1701 if (! *label) {
1702 fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
1703 "BScreen::parseMenuFile: [include] error, "
1704 "no filename defined\n"));
1705 continue;
1706 }
1707
1708 string newfile = expandTilde(label);
1709 FILE *submenufile = fopen(newfile.c_str(), "r");
1710
1711 if (submenufile) {
1712 struct stat buf;
1713 if (fstat(fileno(submenufile), &buf) ||
1714 (! S_ISREG(buf.st_mode))) {
1715 fprintf(stderr,
1716 i18n(ScreenSet, ScreenINCLUDEErrorReg,
1717 "BScreen::parseMenuFile: [include] error: "
1718 "'%s' is not a regular file\n"), newfile.c_str());
1719 break;
1720 }
1721
1722 if (! feof(submenufile)) {
1723 if (! parseMenuFile(submenufile, menu))
1724 blackbox->addMenuTimestamp(newfile);
1725
1726 fclose(submenufile);
1727 }
1728 } else {
1729 perror(newfile.c_str());
1730 }
1731 }
1732
1733 break;
1734
1735 case 767: // submenu
1736 {
1737 if (! *label) {
1738 fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
1739 "BScreen::parseMenuFile: [submenu] error, "
1740 "no menu label defined\n"));
1741 continue;
1742 }
1743
1744 Rootmenu *submenu = new Rootmenu(this);
1745
1746 if (*command)
1747 submenu->setLabel(command);
1748 else
1749 submenu->setLabel(label);
1750
1751 parseMenuFile(file, submenu);
1752 submenu->update();
1753 menu->insert(label, submenu);
1754 rootmenuList.push_back(submenu);
1755 }
1756
1757 break;
1758
1759 case 773: // restart
1760 {
1761 if (! *label) {
1762 fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
1763 "BScreen::parseMenuFile: [restart] error, "
1764 "no menu label defined\n"));
1765 continue;
1766 }
1767
1768 if (*command)
1769 menu->insert(label, BScreen::RestartOther, command);
1770 else
1771 menu->insert(label, BScreen::Restart);
1772 }
1773
1774 break;
1775
1776 case 845: // reconfig
1777 {
1778 if (! *label) {
1779 fprintf(stderr,
1780 i18n(ScreenSet, ScreenRECONFIGError,
1781 "BScreen::parseMenuFile: [reconfig] error, "
1782 "no menu label defined\n"));
1783 continue;
1784 }
1785
1786 menu->insert(label, BScreen::Reconfigure);
1787 }
1788
1789 break;
1790
1791 case 995: // stylesdir
1792 case 1113: // stylesmenu
1793 {
1794 bool newmenu = ((key == 1113) ? True : False);
1795
1796 if ((! *label) || ((! *command) && newmenu)) {
1797 fprintf(stderr,
1798 i18n(ScreenSet, ScreenSTYLESDIRError,
1799 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1800 " error, no directory defined\n"));
1801 continue;
1802 }
1803
1804 char *directory = ((newmenu) ? command : label);
1805
1806 string stylesdir = expandTilde(directory);
1807
1808 struct stat statbuf;
1809
1810 if (! stat(stylesdir.c_str(), &statbuf)) {
1811 if (S_ISDIR(statbuf.st_mode)) {
1812 Rootmenu *stylesmenu;
1813
1814 if (newmenu)
1815 stylesmenu = new Rootmenu(this);
1816 else
1817 stylesmenu = menu;
1818
1819 DIR *d = opendir(stylesdir.c_str());
1820 struct dirent *p;
1821 std::vector<string> ls;
1822
1823 while((p = readdir(d)))
1824 ls.push_back(p->d_name);
1825
1826 closedir(d);
1827
1828 std::sort(ls.begin(), ls.end());
1829
1830 std::vector<string>::iterator it = ls.begin(),
1831 end = ls.end();
1832 for (; it != end; ++it) {
1833 const string& fname = *it;
1834
1835 if (fname[fname.size()-1] == '~')
1836 continue;
1837
1838 string style = stylesdir;
1839 style += '/';
1840 style += fname;
1841
1842 if ((! stat(style.c_str(), &statbuf)) &&
1843 S_ISREG(statbuf.st_mode))
1844 stylesmenu->insert(fname, BScreen::SetStyle, style);
1845 }
1846
1847 stylesmenu->update();
1848
1849 if (newmenu) {
1850 stylesmenu->setLabel(label);
1851 menu->insert(label, stylesmenu);
1852 rootmenuList.push_back(stylesmenu);
1853 }
1854
1855 blackbox->addMenuTimestamp(stylesdir);
1856 } else {
1857 fprintf(stderr,
1858 i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
1859 "BScreen::parseMenuFile:"
1860 " [stylesdir/stylesmenu] error, %s is not a"
1861 " directory\n"), stylesdir.c_str());
1862 }
1863 } else {
1864 fprintf(stderr,
1865 i18n(ScreenSet, ScreenSTYLESDIRErrorNoExist,
1866 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1867 " error, %s does not exist\n"), stylesdir.c_str());
1868 }
1869 break;
1870 }
1871
1872 case 1090: // workspaces
1873 {
1874 if (! *label) {
1875 fprintf(stderr,
1876 i18n(ScreenSet, ScreenWORKSPACESError,
1877 "BScreen:parseMenuFile: [workspaces] error, "
1878 "no menu label defined\n"));
1879 continue;
1880 }
1881
1882 menu->insert(label, workspacemenu);
1883
1884 break;
1885 }
1886 }
1887 }
1888 }
1889 }
1890
1891 return ((menu->getCount() == 0) ? True : False);
1892 }
1893
1894
1895 void BScreen::shutdown(void) {
1896 XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
1897 XSync(blackbox->getXDisplay(), False);
1898
1899 while(! windowList.empty())
1900 unmanageWindow(windowList.front(), True);
1901
1902 slit->shutdown();
1903 }
1904
1905
1906 void BScreen::showPosition(int x, int y) {
1907 if (! geom_visible) {
1908 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1909 (getWidth() - geom_w) / 2,
1910 (getHeight() - geom_h) / 2, geom_w, geom_h);
1911 XMapWindow(blackbox->getXDisplay(), geom_window);
1912 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1913
1914 geom_visible = True;
1915 }
1916
1917 char label[1024];
1918
1919 sprintf(label, i18n(ScreenSet, ScreenPositionFormat,
1920 "X: %4d x Y: %4d"), x, y);
1921
1922 XClearWindow(blackbox->getXDisplay(), geom_window);
1923
1924 resource.wstyle.font->drawString(geom_window,
1925 resource.bevel_width, resource.bevel_width,
1926 resource.wstyle.l_text_focus,
1927 label);
1928 }
1929
1930
1931 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
1932 if (! geom_visible) {
1933 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1934 (getWidth() - geom_w) / 2,
1935 (getHeight() - geom_h) / 2, geom_w, geom_h);
1936 XMapWindow(blackbox->getXDisplay(), geom_window);
1937 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1938
1939 geom_visible = True;
1940 }
1941
1942 char label[1024];
1943
1944 sprintf(label, i18n(ScreenSet, ScreenGeometryFormat,
1945 "W: %4d x H: %4d"), gx, gy);
1946
1947 XClearWindow(blackbox->getXDisplay(), geom_window);
1948
1949 resource.wstyle.font->drawString(geom_window,
1950 resource.bevel_width, resource.bevel_width,
1951 resource.wstyle.l_text_focus,
1952 label);
1953 }
1954
1955
1956 void BScreen::hideGeometry(void) {
1957 if (geom_visible) {
1958 XUnmapWindow(blackbox->getXDisplay(), geom_window);
1959 geom_visible = False;
1960 }
1961 }
1962
1963
1964 void BScreen::addStrut(Strut *strut) {
1965 strutList.push_back(strut);
1966 }
1967
1968
1969 void BScreen::removeStrut(Strut *strut) {
1970 strutList.remove(strut);
1971 }
1972
1973
1974 const Rect& BScreen::availableArea(void) const {
1975 if (doFullMax())
1976 return getRect(); // return the full screen
1977 return usableArea;
1978 }
1979
1980
1981 void BScreen::updateAvailableArea(void) {
1982 Rect old_area = usableArea;
1983 usableArea = getRect(); // reset to full screen
1984
1985 /* these values represent offsets from the screen edge
1986 * we look for the biggest offset on each edge and then apply them
1987 * all at once
1988 * do not be confused by the similarity to the names of Rect's members
1989 */
1990 unsigned int current_left = 0, current_right = 0, current_top = 0,
1991 current_bottom = 0;
1992
1993 StrutList::const_iterator it = strutList.begin(), end = strutList.end();
1994
1995 for(; it != end; ++it) {
1996 Strut *strut = *it;
1997 if (strut->left > current_left)
1998 current_left = strut->left;
1999 if (strut->top > current_top)
2000 current_top = strut->top;
2001 if (strut->right > current_right)
2002 current_right = strut->right;
2003 if (strut->bottom > current_bottom)
2004 current_bottom = strut->bottom;
2005 }
2006
2007 usableArea.setPos(current_left, current_top);
2008 usableArea.setSize(usableArea.width() - (current_left + current_right),
2009 usableArea.height() - (current_top + current_bottom));
2010
2011 if (old_area != usableArea) {
2012 BlackboxWindowList::iterator it = windowList.begin(),
2013 end = windowList.end();
2014 for (; it != end; ++it)
2015 if ((*it)->isMaximized()) (*it)->remaximize();
2016 }
2017
2018 updateWorkArea();
2019 }
2020
2021
2022 Workspace* BScreen::getWorkspace(unsigned int index) {
2023 assert(index < workspacesList.size());
2024 return workspacesList[index];
2025 }
2026
2027
2028 void BScreen::buttonPressEvent(const XButtonEvent *xbutton) {
2029 if (xbutton->button == 1) {
2030 if (! isRootColormapInstalled())
2031 image_control->installRootColormap();
2032
2033 if (workspacemenu->isVisible())
2034 workspacemenu->hide();
2035
2036 if (rootmenu->isVisible())
2037 rootmenu->hide();
2038 } else if (xbutton->button == 2) {
2039 int mx = xbutton->x_root - (workspacemenu->getWidth() / 2);
2040 int my = xbutton->y_root - (workspacemenu->getTitleHeight() / 2);
2041
2042 if (mx < 0) mx = 0;
2043 if (my < 0) my = 0;
2044
2045 if (mx + workspacemenu->getWidth() > getWidth())
2046 mx = getWidth() - workspacemenu->getWidth() - getBorderWidth();
2047
2048 if (my + workspacemenu->getHeight() > getHeight())
2049 my = getHeight() - workspacemenu->getHeight() - getBorderWidth();
2050
2051 workspacemenu->move(mx, my);
2052
2053 if (! workspacemenu->isVisible()) {
2054 workspacemenu->removeParent();
2055 workspacemenu->show();
2056 }
2057 } else if (xbutton->button == 3) {
2058 int mx = xbutton->x_root - (rootmenu->getWidth() / 2);
2059 int my = xbutton->y_root - (rootmenu->getTitleHeight() / 2);
2060
2061 if (mx < 0) mx = 0;
2062 if (my < 0) my = 0;
2063
2064 if (mx + rootmenu->getWidth() > getWidth())
2065 mx = getWidth() - rootmenu->getWidth() - getBorderWidth();
2066
2067 if (my + rootmenu->getHeight() > getHeight())
2068 my = getHeight() - rootmenu->getHeight() - getBorderWidth();
2069
2070 rootmenu->move(mx, my);
2071
2072 if (! rootmenu->isVisible()) {
2073 blackbox->checkMenu();
2074 rootmenu->show();
2075 }
2076 // mouse wheel up
2077 } else if (xbutton->button == 4) {
2078 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2079 changeWorkspaceID(0);
2080 else
2081 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2082 // mouse wheel down
2083 } else if (xbutton->button == 5) {
2084 if (getCurrentWorkspaceID() == 0)
2085 changeWorkspaceID(getWorkspaceCount() - 1);
2086 else
2087 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2088 }
2089 }
2090
2091
2092 void BScreen::toggleFocusModel(FocusModel model) {
2093 std::for_each(windowList.begin(), windowList.end(),
2094 std::mem_fun(&BlackboxWindow::ungrabButtons));
2095
2096 if (model == SloppyFocus) {
2097 saveSloppyFocus(True);
2098 } else {
2099 // we're cheating here to save writing the config file 3 times
2100 resource.auto_raise = False;
2101 resource.click_raise = False;
2102 saveSloppyFocus(False);
2103 }
2104
2105 std::for_each(windowList.begin(), windowList.end(),
2106 std::mem_fun(&BlackboxWindow::grabButtons));
2107 }
2108
2109
2110 BTexture BScreen::readDatabaseTexture(const string &rname,
2111 const string &default_color,
2112 const Configuration &style) {
2113 BTexture texture;
2114 string s;
2115
2116 if (style.getValue(rname, s))
2117 texture = BTexture(s);
2118 else
2119 texture.setTexture(BTexture::Solid | BTexture::Flat);
2120
2121 // associate this texture with this screen
2122 texture.setDisplay(getBaseDisplay(), getScreenNumber());
2123 texture.setImageControl(image_control);
2124
2125 if (texture.texture() & BTexture::Solid) {
2126 texture.setColor(readDatabaseColor(rname + ".color",
2127 default_color, style));
2128 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2129 default_color, style));
2130 } else if (texture.texture() & BTexture::Gradient) {
2131 texture.setColor(readDatabaseColor(rname + ".color",
2132 default_color, style));
2133 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2134 default_color, style));
2135 }
2136
2137 return texture;
2138 }
2139
2140
2141 BColor BScreen::readDatabaseColor(const string &rname,
2142 const string &default_color,
2143 const Configuration &style) {
2144 BColor color;
2145 string s;
2146 if (style.getValue(rname, s))
2147 color = BColor(s, getBaseDisplay(), getScreenNumber());
2148 else
2149 color = BColor(default_color, getBaseDisplay(), getScreenNumber());
2150 return color;
2151 }
2152
2153
2154 BFont *BScreen::readDatabaseFont(const string &rname,
2155 const Configuration &style) {
2156 string fontname;
2157
2158 string s;
2159 style.getValue(rname, s); // if this fails, a blank string will be used,
2160 // which will cause the fallback font to load.
2161
2162 BFont *b = new BFont(blackbox->getXDisplay(), this, s);
2163 if (! b->valid())
2164 exit(2); // can't continue without a font
2165 return b;
2166 }
This page took 0.139658 seconds and 5 git commands to generate.