]> icculus.org git repositories - mikachu/openbox.git/blob - src/Screen.cc
allow style options in the rc file to override those found in the style
[mikachu/openbox.git] / 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   // merge in the rc file
743   style.merge(config->file(), True);
744
745   string s;
746
747   // load fonts/fontsets
748   if (resource.wstyle.font)
749     delete resource.wstyle.font;
750   if (resource.tstyle.font)
751     delete resource.tstyle.font;
752   if (resource.mstyle.f_font)
753     delete resource.mstyle.f_font;
754   if (resource.mstyle.t_font)
755     delete resource.mstyle.t_font;
756   resource.wstyle.font = resource.tstyle.font = resource.mstyle.f_font =
757     resource.mstyle.t_font = (BFont *) 0;
758
759   resource.wstyle.font = readDatabaseFont("window.font", style);
760   resource.tstyle.font = readDatabaseFont("toolbar.font", style);
761   resource.mstyle.t_font = readDatabaseFont("menu.title.font", style);
762   resource.mstyle.f_font = readDatabaseFont("menu.frame.font", style);
763
764   // load window config
765   resource.wstyle.t_focus =
766     readDatabaseTexture("window.title.focus", "white", style);
767   resource.wstyle.t_unfocus =
768     readDatabaseTexture("window.title.unfocus", "black", style);
769   resource.wstyle.l_focus =
770     readDatabaseTexture("window.label.focus", "white", style);
771   resource.wstyle.l_unfocus =
772     readDatabaseTexture("window.label.unfocus", "black", style);
773   resource.wstyle.h_focus =
774     readDatabaseTexture("window.handle.focus", "white", style);
775   resource.wstyle.h_unfocus =
776     readDatabaseTexture("window.handle.unfocus", "black", style);
777   resource.wstyle.g_focus =
778     readDatabaseTexture("window.grip.focus", "white", style);
779   resource.wstyle.g_unfocus =
780     readDatabaseTexture("window.grip.unfocus", "black", style);
781   resource.wstyle.b_focus =
782     readDatabaseTexture("window.button.focus", "white", style);
783   resource.wstyle.b_unfocus =
784     readDatabaseTexture("window.button.unfocus", "black", style);
785   resource.wstyle.b_pressed =
786     readDatabaseTexture("window.button.pressed", "black", style);
787   resource.wstyle.f_focus =
788     readDatabaseColor("window.frame.focusColor", "white", style);
789   resource.wstyle.f_unfocus =
790     readDatabaseColor("window.frame.unfocusColor", "black", style);
791   resource.wstyle.l_text_focus =
792     readDatabaseColor("window.label.focus.textColor", "black", style);
793   resource.wstyle.l_text_unfocus =
794     readDatabaseColor("window.label.unfocus.textColor", "white", style);
795   resource.wstyle.b_pic_focus =
796     readDatabaseColor("window.button.focus.picColor", "black", style);
797   resource.wstyle.b_pic_unfocus =
798     readDatabaseColor("window.button.unfocus.picColor", "white", style);
799
800   resource.wstyle.justify = LeftJustify;
801   if (style.getValue("window.justify", s)) {
802     if (s == "right" || s == "Right")
803       resource.wstyle.justify = RightJustify;
804     else if (s == "center" || s == "Center")
805       resource.wstyle.justify = CenterJustify;
806   }
807
808   // load toolbar config
809   resource.tstyle.toolbar =
810     readDatabaseTexture("toolbar", "black", style);
811   resource.tstyle.label =
812     readDatabaseTexture("toolbar.label", "black", style);
813   resource.tstyle.window =
814     readDatabaseTexture("toolbar.windowLabel", "black", style);
815   resource.tstyle.button =
816     readDatabaseTexture("toolbar.button", "white", style);
817   resource.tstyle.pressed =
818     readDatabaseTexture("toolbar.button.pressed", "black", style);
819   resource.tstyle.clock =
820     readDatabaseTexture("toolbar.clock", "black", style);
821   resource.tstyle.l_text =
822     readDatabaseColor("toolbar.label.textColor", "white", style);
823   resource.tstyle.w_text =
824     readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
825   resource.tstyle.c_text =
826     readDatabaseColor("toolbar.clock.textColor", "white", style);
827   resource.tstyle.b_pic =
828     readDatabaseColor("toolbar.button.picColor", "black", style);
829
830   resource.tstyle.justify = LeftJustify;
831   if (style.getValue("toolbar.justify", s)) {
832     if (s == "right" || s == "Right")
833       resource.tstyle.justify = RightJustify;
834     else if (s == "center" || s == "Center")
835       resource.tstyle.justify = CenterJustify;
836   }
837
838   // load menu config
839   resource.mstyle.title =
840     readDatabaseTexture("menu.title", "white", style);
841   resource.mstyle.frame =
842     readDatabaseTexture("menu.frame", "black", style);
843   resource.mstyle.hilite =
844     readDatabaseTexture("menu.hilite", "white", style);
845   resource.mstyle.t_text =
846     readDatabaseColor("menu.title.textColor", "black", style);
847   resource.mstyle.f_text =
848     readDatabaseColor("menu.frame.textColor", "white", style);
849   resource.mstyle.d_text =
850     readDatabaseColor("menu.frame.disableColor", "black", style);
851   resource.mstyle.h_text =
852     readDatabaseColor("menu.hilite.textColor", "black", style);
853
854   resource.mstyle.t_justify = LeftJustify;
855   if (style.getValue("menu.title.justify", s)) {
856     if (s == "right" || s == "Right")
857       resource.mstyle.t_justify = RightJustify;
858     else if (s == "center" || s == "Center")
859       resource.mstyle.t_justify = CenterJustify;
860   }
861
862   resource.mstyle.f_justify = LeftJustify;
863   if (style.getValue("menu.frame.justify", s)) {
864     if (s == "right" || s == "Right")
865       resource.mstyle.f_justify = RightJustify;
866     else if (s == "center" || s == "Center")
867       resource.mstyle.f_justify = CenterJustify;
868   }
869
870   resource.mstyle.bullet = Basemenu::Triangle;
871   if (style.getValue("menu.bullet", s)) {
872     if (s == "empty" || s == "Empty")
873       resource.mstyle.bullet = Basemenu::Empty;
874     else if (s == "square" || s == "Square")
875       resource.mstyle.bullet = Basemenu::Square;
876     else if (s == "diamond" || s == "Diamond")
877       resource.mstyle.bullet = Basemenu::Diamond;
878   }
879
880   resource.mstyle.bullet_pos = Basemenu::Left;
881   if (style.getValue("menu.bullet.position", s)) {
882     if (s == "right" || s == "Right")
883       resource.mstyle.bullet_pos = Basemenu::Right;
884   }
885
886   resource.border_color =
887     readDatabaseColor("borderColor", "black", style);
888
889   // load bevel, border and handle widths
890   if (! style.getValue("handleWidth", resource.handle_width) ||
891       resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
892     resource.handle_width = 6;
893
894   if (! style.getValue("borderWidth", resource.border_width))
895     resource.border_width = 1;
896
897   if (! style.getValue("bevelWidth", resource.bevel_width) ||
898       resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
899     resource.bevel_width = 3;
900
901   if (! style.getValue("frameWidth", resource.frame_width) ||
902       resource.frame_width > (getWidth() / 2))
903     resource.frame_width = resource.bevel_width;
904
905   if (style.getValue("rootCommand", s))
906     bexec(s, displayString());
907 }
908
909
910 void BScreen::addIcon(BlackboxWindow *w) {
911   if (! w) return;
912
913   w->setWorkspace(BSENTINEL);
914   w->setWindowNumber(iconList.size());
915
916   iconList.push_back(w);
917
918   const char* title = w->getIconTitle();
919   iconmenu->insert(title);
920   iconmenu->update();
921 }
922
923
924 void BScreen::removeIcon(BlackboxWindow *w) {
925   if (! w) return;
926
927   iconList.remove(w);
928
929   iconmenu->remove(w->getWindowNumber());
930   iconmenu->update();
931
932   BlackboxWindowList::iterator it = iconList.begin(),
933     end = iconList.end();
934   for (int i = 0; it != end; ++it)
935     (*it)->setWindowNumber(i++);
936 }
937
938
939 BlackboxWindow *BScreen::getIcon(unsigned int index) {
940   if (index < iconList.size()) {
941     BlackboxWindowList::iterator it = iconList.begin();
942     for (; index > 0; --index, ++it) ; /* increment to index */
943     return *it;
944   }
945
946   return (BlackboxWindow *) 0;
947 }
948
949
950 unsigned int BScreen::addWorkspace(void) {
951   Workspace *wkspc = new Workspace(this, workspacesList.size());
952   workspacesList.push_back(wkspc);
953   saveWorkspaces(getWorkspaceCount());
954
955   workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
956                         wkspc->getID() + 2);
957   workspacemenu->update();
958
959   toolbar->reconfigure();
960
961   updateNetizenWorkspaceCount();
962
963   return workspacesList.size();
964 }
965
966
967 unsigned int BScreen::removeLastWorkspace(void) {
968   if (workspacesList.size() == 1)
969     return 1;
970
971   Workspace *wkspc = workspacesList.back();
972
973   if (current_workspace->getID() == wkspc->getID())
974     changeWorkspaceID(current_workspace->getID() - 1);
975
976   wkspc->removeAll();
977
978   workspacemenu->remove(wkspc->getID() + 2);
979   workspacemenu->update();
980
981   workspacesList.pop_back();
982   delete wkspc;
983
984   saveWorkspaces(getWorkspaceCount());
985
986   toolbar->reconfigure();
987
988   updateNetizenWorkspaceCount();
989
990   return workspacesList.size();
991 }
992
993
994 void BScreen::changeWorkspaceID(unsigned int id) {
995   if (! current_workspace) return;
996
997   if (id != current_workspace->getID()) {
998     BlackboxWindow *focused = blackbox->getFocusedWindow();
999     if (focused && focused->getScreen() == this && ! focused->isStuck()) {
1000       if (focused->getWorkspaceNumber() != current_workspace->getID()) {
1001         fprintf(stderr, "%s is on the wrong workspace, aborting\n",
1002                 focused->getTitle());
1003         abort();
1004       }
1005       current_workspace->setLastFocusedWindow(focused);
1006     } else {
1007       // if no window had focus, no need to store a last focus
1008       current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
1009     }
1010     // when we switch workspaces, unfocus whatever was focused
1011     blackbox->setFocusedWindow((BlackboxWindow *) 0);
1012     
1013     current_workspace->hideAll();
1014     workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1015
1016     current_workspace = getWorkspace(id);
1017
1018     xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
1019                     XAtom::cardinal, id);
1020
1021     workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1022     toolbar->redrawWorkspaceLabel(True);
1023
1024     current_workspace->showAll();
1025
1026     if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1027       XSync(blackbox->getXDisplay(), False);
1028       current_workspace->getLastFocusedWindow()->setInputFocus();
1029     }
1030   }
1031
1032   updateNetizenCurrentWorkspace();
1033 }
1034
1035
1036 /*
1037  * Set the _NET_CLIENT_LIST root window property.
1038  */
1039 void BScreen::updateClientList(void) {
1040   if (windowList.size() > 0) {
1041     Window *windows = new Window[windowList.size()];
1042     Window *win_it = windows;
1043     BlackboxWindowList::iterator it = windowList.begin();
1044     const BlackboxWindowList::iterator end = windowList.end();
1045     for (; it != end; ++it, ++win_it)
1046       *win_it = (*it)->getClientWindow();
1047     xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1048                     windows, windowList.size());
1049     delete [] windows;
1050   } else
1051     xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1052                     0, 0);
1053 }
1054
1055
1056 /*
1057  * Set the _NET_CLIENT_LIST_STACKING root window property.
1058  */
1059 void BScreen::updateStackingList(void) {
1060
1061   BlackboxWindowList stack_order;
1062
1063   /*
1064    * Get the atacking order from all of the workspaces.
1065    * We start with the current workspace so that the sticky windows will be
1066    * in the right order on the current workspace.
1067    * XXX: Do we need to have sticky windows in the list once for each workspace?
1068    */
1069   getCurrentWorkspace()->appendStackOrder(stack_order);
1070   for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
1071     if (i != getCurrentWorkspaceID())
1072       getWorkspace(i)->appendStackOrder(stack_order);
1073  
1074   if (stack_order.size() > 0) {
1075     // set the client list atoms
1076     Window *windows = new Window[stack_order.size()];
1077     Window *win_it = windows;
1078     BlackboxWindowList::iterator it = stack_order.begin();
1079     const BlackboxWindowList::iterator end = stack_order.end();
1080     for (; it != end; ++it, ++win_it)
1081       *win_it = (*it)->getClientWindow();
1082     xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1083                     XAtom::window, windows, stack_order.size());
1084     delete [] windows;
1085   } else
1086     xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1087                     XAtom::window, 0, 0);
1088 }
1089
1090
1091 void BScreen::addSystrayWindow(Window window) {
1092   systrayWindowList.push_back(window);
1093   xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1094                   XAtom::window,
1095                   &systrayWindowList[0], systrayWindowList.size());
1096   blackbox->saveSystrayWindowSearch(window, this);
1097 }
1098
1099
1100 void BScreen::removeSystrayWindow(Window window) {
1101   WindowList::iterator it = systrayWindowList.begin();
1102   const WindowList::iterator end = systrayWindowList.end();
1103   for (; it != end; ++it)
1104     if (*it == window) {
1105       systrayWindowList.erase(it);
1106       xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1107                       XAtom::window,
1108                       &systrayWindowList[0], systrayWindowList.size());
1109       blackbox->removeSystrayWindowSearch(window);
1110       break;
1111     }
1112 }
1113
1114
1115 void BScreen::addDesktopWindow(Window window) {
1116   desktopWindowList.push_back(window);
1117   XLowerWindow(blackbox->getXDisplay(), window);
1118   XSelectInput(blackbox->getXDisplay(), window, StructureNotifyMask);
1119   blackbox->saveDesktopWindowSearch(window, this);
1120 }
1121
1122
1123 void BScreen::removeDesktopWindow(Window window) {
1124   WindowList::iterator it = desktopWindowList.begin();
1125   const WindowList::iterator end = desktopWindowList.end();
1126   for (; it != end; ++it)
1127     if (*it == window) {
1128       desktopWindowList.erase(it);
1129       XSelectInput(blackbox->getXDisplay(), window, None);
1130       blackbox->removeDesktopWindowSearch(window);
1131       break;
1132     }
1133 }
1134
1135
1136 void BScreen::manageWindow(Window w) {
1137   new BlackboxWindow(blackbox, w, this);
1138
1139   BlackboxWindow *win = blackbox->searchWindow(w);
1140   if (! win)
1141     return;
1142   if (win->isDesktop()) {
1143     // desktop windows cant do anything, so we remove all the normal window
1144     // stuff from them, they are only kept around so that we can keep them on
1145     // the bottom of the z-order
1146     win->restore(True);
1147     addDesktopWindow(win->getClientWindow());
1148     delete win;
1149     return;
1150   }
1151
1152   windowList.push_back(win);
1153   updateClientList();
1154
1155   XMapRequestEvent mre;
1156   mre.window = w;
1157   if (blackbox->isStartup()) win->restoreAttributes();
1158   win->mapRequestEvent(&mre);
1159 }
1160
1161
1162 void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
1163   w->restore(remap);
1164
1165   if (w->getWorkspaceNumber() != BSENTINEL &&
1166       w->getWindowNumber() != BSENTINEL)
1167     getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1168   else if (w->isIconic())
1169     removeIcon(w);
1170
1171   windowList.remove(w);
1172   updateClientList();
1173
1174   if (blackbox->getFocusedWindow() == w)
1175     blackbox->setFocusedWindow((BlackboxWindow *) 0);
1176
1177   removeNetizen(w->getClientWindow());
1178
1179   /*
1180     some managed windows can also be window group controllers.  when
1181     unmanaging such windows, we should also delete the window group.
1182   */
1183   BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
1184   delete group;
1185
1186   delete w;
1187 }
1188
1189
1190 void BScreen::addNetizen(Netizen *n) {
1191   netizenList.push_back(n);
1192
1193   n->sendWorkspaceCount();
1194   n->sendCurrentWorkspace();
1195
1196   WorkspaceList::iterator it = workspacesList.begin();
1197   const WorkspaceList::iterator end = workspacesList.end();
1198   for (; it != end; ++it)
1199     (*it)->sendWindowList(*n);
1200
1201   Window f = ((blackbox->getFocusedWindow()) ?
1202               blackbox->getFocusedWindow()->getClientWindow() : None);
1203   n->sendWindowFocus(f);
1204 }
1205
1206
1207 void BScreen::removeNetizen(Window w) {
1208   NetizenList::iterator it = netizenList.begin();
1209   for (; it != netizenList.end(); ++it) {
1210     if ((*it)->getWindowID() == w) {
1211       delete *it;
1212       netizenList.erase(it);
1213       break;
1214     }
1215   }
1216 }
1217
1218
1219 void BScreen::updateWorkArea(void) {
1220   if (workspacesList.size() > 0) {
1221     unsigned long *dims = new unsigned long[4 * workspacesList.size()];
1222     for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
1223       // XXX: this could be different for each workspace
1224       const Rect &area = availableArea();
1225       dims[(i * 4) + 0] = area.x();
1226       dims[(i * 4) + 1] = area.y();
1227       dims[(i * 4) + 2] = area.width();
1228       dims[(i * 4) + 3] = area.height();
1229     }
1230     xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1231                     dims, 4 * workspacesList.size());
1232     delete [] dims;
1233   } else
1234     xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1235                     0, 0);
1236 }
1237
1238
1239 void BScreen::updateNetizenCurrentWorkspace(void) {
1240   std::for_each(netizenList.begin(), netizenList.end(),
1241                 std::mem_fun(&Netizen::sendCurrentWorkspace));
1242 }
1243
1244
1245 void BScreen::updateNetizenWorkspaceCount(void) {
1246   xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
1247                   XAtom::cardinal, workspacesList.size());
1248
1249   updateWorkArea();
1250   
1251   std::for_each(netizenList.begin(), netizenList.end(),
1252                 std::mem_fun(&Netizen::sendWorkspaceCount));
1253 }
1254
1255
1256 void BScreen::updateNetizenWindowFocus(void) {
1257   Window f = ((blackbox->getFocusedWindow()) ?
1258               blackbox->getFocusedWindow()->getClientWindow() : None);
1259
1260   xatom->setValue(getRootWindow(), XAtom::net_active_window,
1261                   XAtom::window, f);
1262
1263   NetizenList::iterator it = netizenList.begin();
1264   for (; it != netizenList.end(); ++it)
1265     (*it)->sendWindowFocus(f);
1266 }
1267
1268
1269 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1270   NetizenList::iterator it = netizenList.begin();
1271   for (; it != netizenList.end(); ++it) {
1272     (*it)->sendWindowAdd(w, p);
1273   }
1274 }
1275
1276
1277 void BScreen::updateNetizenWindowDel(Window w) {
1278   NetizenList::iterator it = netizenList.begin();
1279   for (; it != netizenList.end(); ++it)
1280     (*it)->sendWindowDel(w);
1281 }
1282
1283
1284 void BScreen::updateNetizenWindowRaise(Window w) {
1285   NetizenList::iterator it = netizenList.begin();
1286   for (; it != netizenList.end(); ++it)
1287     (*it)->sendWindowRaise(w);
1288 }
1289
1290
1291 void BScreen::updateNetizenWindowLower(Window w) {
1292   NetizenList::iterator it = netizenList.begin();
1293   for (; it != netizenList.end(); ++it)
1294     (*it)->sendWindowLower(w);
1295 }
1296
1297
1298 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1299   NetizenList::iterator it = netizenList.begin();
1300   for (; it != netizenList.end(); ++it)
1301     (*it)->sendConfigNotify(e);
1302 }
1303
1304
1305 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
1306   // the 13 represents the number of blackbox windows such as menus
1307   Window *session_stack = new
1308     Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
1309   unsigned int i = 0, k = num;
1310
1311   XRaiseWindow(blackbox->getXDisplay(), iconmenu->getWindowID());
1312   *(session_stack + i++) = iconmenu->getWindowID();
1313
1314   WorkspaceList::iterator wit = workspacesList.begin();
1315   const WorkspaceList::iterator w_end = workspacesList.end();
1316   for (; wit != w_end; ++wit)
1317     *(session_stack + i++) = (*wit)->getMenu()->getWindowID();
1318
1319   *(session_stack + i++) = workspacemenu->getWindowID();
1320
1321   *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1322   *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1323   *(session_stack + i++) = configmenu->getWindowID();
1324
1325   *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1326   *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1327   *(session_stack + i++) = slit->getMenu()->getWindowID();
1328
1329   *(session_stack + i++) =
1330     toolbar->getMenu()->getPlacementmenu()->getWindowID();
1331   *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1332
1333   RootmenuList::iterator rit = rootmenuList.begin();
1334   for (; rit != rootmenuList.end(); ++rit)
1335     *(session_stack + i++) = (*rit)->getWindowID();
1336   *(session_stack + i++) = rootmenu->getWindowID();
1337
1338   if (toolbar->isOnTop())
1339     *(session_stack + i++) = toolbar->getWindowID();
1340
1341   if (slit->isOnTop())
1342     *(session_stack + i++) = slit->getWindowID();
1343
1344   while (k--)
1345     *(session_stack + i++) = *(workspace_stack + k);
1346
1347   XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1348
1349   delete [] session_stack;
1350
1351   updateStackingList();
1352 }
1353
1354
1355 void BScreen::lowerDesktops(void) {
1356   if (desktopWindowList.empty()) return;
1357
1358   XLowerWindow(blackbox->getXDisplay(), desktopWindowList[0]);
1359   if (desktopWindowList.size() > 1)
1360     XRestackWindows(blackbox->getXDisplay(), &desktopWindowList[0],
1361                     desktopWindowList.size());
1362 }
1363
1364
1365 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
1366                                 bool ignore_sticky) {
1367   if (! w) return;
1368
1369   if (wkspc_id == BSENTINEL)
1370     wkspc_id = current_workspace->getID();
1371
1372   if (w->getWorkspaceNumber() == wkspc_id)
1373     return;
1374
1375   if (w->isIconic()) {
1376     removeIcon(w);
1377     getWorkspace(wkspc_id)->addWindow(w);
1378   } else if (ignore_sticky || ! w->isStuck()) {
1379     getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1380     getWorkspace(wkspc_id)->addWindow(w);
1381   }
1382 }
1383
1384
1385 void BScreen::propagateWindowName(const BlackboxWindow *bw) {
1386   if (bw->isIconic()) {
1387     iconmenu->changeItemLabel(bw->getWindowNumber(), bw->getIconTitle());
1388     iconmenu->update();
1389   }
1390   else {
1391     Clientmenu *clientmenu = getWorkspace(bw->getWorkspaceNumber())->getMenu();
1392     clientmenu->changeItemLabel(bw->getWindowNumber(), bw->getTitle());
1393     clientmenu->update();
1394
1395     if (blackbox->getFocusedWindow() == bw)
1396       toolbar->redrawWindowLabel(True);
1397   }
1398 }
1399
1400
1401 void BScreen::nextFocus(void) {
1402   BlackboxWindow *focused = blackbox->getFocusedWindow(),
1403     *next = focused;
1404
1405   if (focused) {
1406     // if window is not on this screen, ignore it
1407     if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1408       focused = (BlackboxWindow*) 0;
1409   }
1410
1411   if (focused && current_workspace->getCount() > 1) {
1412     // next is the next window to recieve focus, current is a place holder
1413     BlackboxWindow *current;
1414     do {
1415       current = next;
1416       next = current_workspace->getNextWindowInList(current);
1417     } while(! next->setInputFocus() && next != focused);
1418
1419     if (next != focused)
1420       current_workspace->raiseWindow(next);
1421   } else if (current_workspace->getCount() >= 1) {
1422     next = current_workspace->getTopWindowOnStack();
1423
1424     current_workspace->raiseWindow(next);
1425     next->setInputFocus();
1426   }
1427 }
1428
1429
1430 void BScreen::prevFocus(void) {
1431   BlackboxWindow *focused = blackbox->getFocusedWindow(),
1432     *next = focused;
1433
1434   if (focused) {
1435     // if window is not on this screen, ignore it
1436     if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1437       focused = (BlackboxWindow*) 0;
1438   }
1439
1440   if (focused && current_workspace->getCount() > 1) {
1441     // next is the next window to recieve focus, current is a place holder
1442     BlackboxWindow *current;
1443     do {
1444       current = next;
1445       next = current_workspace->getPrevWindowInList(current);
1446     } while(! next->setInputFocus() && next != focused);
1447
1448     if (next != focused)
1449       current_workspace->raiseWindow(next);
1450   } else if (current_workspace->getCount() >= 1) {
1451     next = current_workspace->getTopWindowOnStack();
1452
1453     current_workspace->raiseWindow(next);
1454     next->setInputFocus();
1455   }
1456 }
1457
1458
1459 void BScreen::raiseFocus(void) {
1460   BlackboxWindow *focused = blackbox->getFocusedWindow();
1461   if (! focused)
1462     return;
1463
1464   // if on this Screen, raise it
1465   if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
1466     Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
1467     workspace->raiseWindow(focused);
1468   }
1469 }
1470
1471
1472 void BScreen::InitMenu(void) {
1473   if (rootmenu) {
1474     rootmenuList.clear();
1475
1476     while (rootmenu->getCount())
1477       rootmenu->remove(0);
1478   } else {
1479     rootmenu = new Rootmenu(this);
1480   }
1481   bool defaultMenu = True;
1482
1483   FILE *menu_file = (FILE *) 0;
1484   const char *menu_filename = blackbox->getMenuFilename();
1485
1486   if (menu_filename) 
1487     if (! (menu_file = fopen(menu_filename, "r")))
1488       perror(menu_filename);
1489   if (! menu_file) {     // opening the menu file failed, try the default menu
1490     menu_filename = DEFAULTMENU;
1491     if (! (menu_file = fopen(menu_filename, "r")))
1492       perror(menu_filename);
1493   } 
1494
1495   if (menu_file) {
1496     if (feof(menu_file)) {
1497       fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
1498                            "%s: Empty menu file"),
1499               menu_filename);
1500     } else {
1501       char line[1024], label[1024];
1502       memset(line, 0, 1024);
1503       memset(label, 0, 1024);
1504
1505       while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
1506         if (line[0] != '#') {
1507           int i, key = 0, index = -1, len = strlen(line);
1508
1509           for (i = 0; i < len; i++) {
1510             if (line[i] == '[') index = 0;
1511             else if (line[i] == ']') break;
1512             else if (line[i] != ' ')
1513               if (index++ >= 0)
1514                 key += tolower(line[i]);
1515           }
1516
1517           if (key == 517) { // [begin]
1518             index = -1;
1519             for (i = index; i < len; i++) {
1520               if (line[i] == '(') index = 0;
1521               else if (line[i] == ')') break;
1522               else if (index++ >= 0) {
1523                 if (line[i] == '\\' && i < len - 1) i++;
1524                 label[index - 1] = line[i];
1525               }
1526             }
1527
1528             if (index == -1) index = 0;
1529             label[index] = '\0';
1530
1531             rootmenu->setLabel(label);
1532             defaultMenu = parseMenuFile(menu_file, rootmenu);
1533             if (! defaultMenu)
1534               blackbox->addMenuTimestamp(menu_filename);
1535             break;
1536           }
1537         }
1538       }
1539     }
1540     fclose(menu_file);
1541   }
1542
1543   if (defaultMenu) {
1544     rootmenu->setInternalMenu();
1545     rootmenu->insert(i18n(ScreenSet, Screenxterm, "xterm"),
1546                      BScreen::Execute,
1547                      i18n(ScreenSet, Screenxterm, "xterm"));
1548     rootmenu->insert(i18n(ScreenSet, ScreenRestart, "Restart"),
1549                      BScreen::Restart);
1550     rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
1551                      BScreen::Exit);
1552     rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
1553                             "Openbox Menu"));
1554   }
1555 }
1556
1557
1558 bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
1559   char line[1024], label[1024], command[1024];
1560
1561   while (! feof(file)) {
1562     memset(line, 0, 1024);
1563     memset(label, 0, 1024);
1564     memset(command, 0, 1024);
1565
1566     if (fgets(line, 1024, file)) {
1567       if (line[0] != '#') {
1568         int i, key = 0, parse = 0, index = -1, line_length = strlen(line);
1569
1570         // determine the keyword
1571         for (i = 0; i < line_length; i++) {
1572           if (line[i] == '[') parse = 1;
1573           else if (line[i] == ']') break;
1574           else if (line[i] != ' ')
1575             if (parse)
1576               key += tolower(line[i]);
1577         }
1578
1579         // get the label enclosed in ()'s
1580         parse = 0;
1581
1582         for (i = 0; i < line_length; i++) {
1583           if (line[i] == '(') {
1584             index = 0;
1585             parse = 1;
1586           } else if (line[i] == ')') break;
1587           else if (index++ >= 0) {
1588             if (line[i] == '\\' && i < line_length - 1) i++;
1589             label[index - 1] = line[i];
1590           }
1591         }
1592
1593         if (parse) {
1594           label[index] = '\0';
1595         } else {
1596           label[0] = '\0';
1597         }
1598
1599         // get the command enclosed in {}'s
1600         parse = 0;
1601         index = -1;
1602         for (i = 0; i < line_length; i++) {
1603           if (line[i] == '{') {
1604             index = 0;
1605             parse = 1;
1606           } else if (line[i] == '}') break;
1607           else if (index++ >= 0) {
1608             if (line[i] == '\\' && i < line_length - 1) i++;
1609             command[index - 1] = line[i];
1610           }
1611         }
1612
1613         if (parse) {
1614           command[index] = '\0';
1615         } else {
1616           command[0] = '\0';
1617         }
1618
1619         switch (key) {
1620         case 311: // end
1621           return ((menu->getCount() == 0) ? True : False);
1622
1623           break;
1624
1625         case 333: // nop
1626           if (! *label)
1627             label[0] = '\0';
1628           menu->insert(label);
1629
1630           break;
1631
1632         case 421: // exec
1633           if ((! *label) && (! *command)) {
1634             fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
1635                                  "BScreen::parseMenuFile: [exec] error, "
1636                                  "no menu label and/or command defined\n"));
1637             continue;
1638           }
1639
1640           menu->insert(label, BScreen::Execute, command);
1641
1642           break;
1643
1644         case 442: // exit
1645           if (! *label) {
1646             fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
1647                                  "BScreen::parseMenuFile: [exit] error, "
1648                                  "no menu label defined\n"));
1649             continue;
1650           }
1651
1652           menu->insert(label, BScreen::Exit);
1653
1654           break;
1655
1656         case 561: // style
1657           {
1658             if ((! *label) || (! *command)) {
1659               fprintf(stderr,
1660                       i18n(ScreenSet, ScreenSTYLEError,
1661                            "BScreen::parseMenuFile: [style] error, "
1662                            "no menu label and/or filename defined\n"));
1663               continue;
1664             }
1665
1666             string style = expandTilde(command);
1667
1668             menu->insert(label, BScreen::SetStyle, style.c_str());
1669           }
1670
1671           break;
1672
1673         case 630: // config
1674           if (! *label) {
1675             fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
1676                                  "BScreen::parseMenufile: [config] error, "
1677                                  "no label defined"));
1678             continue;
1679           }
1680
1681           menu->insert(label, configmenu);
1682
1683           break;
1684
1685         case 740: // include
1686           {
1687             if (! *label) {
1688               fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
1689                                    "BScreen::parseMenuFile: [include] error, "
1690                                    "no filename defined\n"));
1691               continue;
1692             }
1693
1694             string newfile = expandTilde(label);
1695             FILE *submenufile = fopen(newfile.c_str(), "r");
1696
1697             if (submenufile) {
1698               struct stat buf;
1699               if (fstat(fileno(submenufile), &buf) ||
1700                   (! S_ISREG(buf.st_mode))) {
1701                 fprintf(stderr,
1702                         i18n(ScreenSet, ScreenINCLUDEErrorReg,
1703                              "BScreen::parseMenuFile: [include] error: "
1704                              "'%s' is not a regular file\n"), newfile.c_str());
1705                 break;
1706               }
1707
1708               if (! feof(submenufile)) {
1709                 if (! parseMenuFile(submenufile, menu))
1710                   blackbox->addMenuTimestamp(newfile);
1711
1712                 fclose(submenufile);
1713               }
1714             } else {
1715               perror(newfile.c_str());
1716             }
1717           }
1718
1719           break;
1720
1721         case 767: // submenu
1722           {
1723             if (! *label) {
1724               fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
1725                                    "BScreen::parseMenuFile: [submenu] error, "
1726                                    "no menu label defined\n"));
1727               continue;
1728             }
1729
1730             Rootmenu *submenu = new Rootmenu(this);
1731
1732             if (*command)
1733               submenu->setLabel(command);
1734             else
1735               submenu->setLabel(label);
1736
1737             parseMenuFile(file, submenu);
1738             submenu->update();
1739             menu->insert(label, submenu);
1740             rootmenuList.push_back(submenu);
1741           }
1742
1743           break;
1744
1745         case 773: // restart
1746           {
1747             if (! *label) {
1748               fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
1749                                    "BScreen::parseMenuFile: [restart] error, "
1750                                    "no menu label defined\n"));
1751               continue;
1752             }
1753
1754             if (*command)
1755               menu->insert(label, BScreen::RestartOther, command);
1756             else
1757               menu->insert(label, BScreen::Restart);
1758           }
1759
1760           break;
1761
1762         case 845: // reconfig
1763           {
1764             if (! *label) {
1765               fprintf(stderr,
1766                       i18n(ScreenSet, ScreenRECONFIGError,
1767                            "BScreen::parseMenuFile: [reconfig] error, "
1768                            "no menu label defined\n"));
1769               continue;
1770             }
1771
1772             menu->insert(label, BScreen::Reconfigure);
1773           }
1774
1775           break;
1776
1777         case 995: // stylesdir
1778         case 1113: // stylesmenu
1779           {
1780             bool newmenu = ((key == 1113) ? True : False);
1781
1782             if ((! *label) || ((! *command) && newmenu)) {
1783               fprintf(stderr,
1784                       i18n(ScreenSet, ScreenSTYLESDIRError,
1785                            "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1786                            " error, no directory defined\n"));
1787               continue;
1788             }
1789
1790             char *directory = ((newmenu) ? command : label);
1791
1792             string stylesdir = expandTilde(directory);
1793
1794             struct stat statbuf;
1795
1796             if (! stat(stylesdir.c_str(), &statbuf)) {
1797               if (S_ISDIR(statbuf.st_mode)) {
1798                 Rootmenu *stylesmenu;
1799
1800                 if (newmenu)
1801                   stylesmenu = new Rootmenu(this);
1802                 else
1803                   stylesmenu = menu;
1804
1805                 DIR *d = opendir(stylesdir.c_str());
1806                 struct dirent *p;
1807                 std::vector<string> ls;
1808
1809                 while((p = readdir(d)))
1810                   ls.push_back(p->d_name);
1811
1812                 closedir(d);
1813
1814                 std::sort(ls.begin(), ls.end());
1815
1816                 std::vector<string>::iterator it = ls.begin(),
1817                   end = ls.end();
1818                 for (; it != end; ++it) {
1819                   const string& fname = *it;
1820
1821                   if (fname[fname.size()-1] == '~')
1822                     continue;
1823
1824                   string style = stylesdir;
1825                   style += '/';
1826                   style += fname;
1827
1828                   if ((! stat(style.c_str(), &statbuf)) &&
1829                       S_ISREG(statbuf.st_mode))
1830                     stylesmenu->insert(fname, BScreen::SetStyle, style);
1831                 }
1832
1833                 stylesmenu->update();
1834
1835                 if (newmenu) {
1836                   stylesmenu->setLabel(label);
1837                   menu->insert(label, stylesmenu);
1838                   rootmenuList.push_back(stylesmenu);
1839                 }
1840
1841                 blackbox->addMenuTimestamp(stylesdir);
1842               } else {
1843                 fprintf(stderr,
1844                         i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
1845                              "BScreen::parseMenuFile:"
1846                              " [stylesdir/stylesmenu] error, %s is not a"
1847                              " directory\n"), stylesdir.c_str());
1848               }
1849             } else {
1850               fprintf(stderr,
1851                       i18n(ScreenSet, ScreenSTYLESDIRErrorNoExist,
1852                            "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1853                            " error, %s does not exist\n"), stylesdir.c_str());
1854             }
1855             break;
1856           }
1857
1858         case 1090: // workspaces
1859           {
1860             if (! *label) {
1861               fprintf(stderr,
1862                       i18n(ScreenSet, ScreenWORKSPACESError,
1863                            "BScreen:parseMenuFile: [workspaces] error, "
1864                            "no menu label defined\n"));
1865               continue;
1866             }
1867
1868             menu->insert(label, workspacemenu);
1869
1870             break;
1871           }
1872         }
1873       }
1874     }
1875   }
1876
1877   return ((menu->getCount() == 0) ? True : False);
1878 }
1879
1880
1881 void BScreen::shutdown(void) {
1882   XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
1883   XSync(blackbox->getXDisplay(), False);
1884
1885   while(! windowList.empty())
1886     unmanageWindow(windowList.front(), True);
1887
1888   slit->shutdown();
1889 }
1890
1891
1892 void BScreen::showPosition(int x, int y) {
1893   if (! geom_visible) {
1894     XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1895                       (getWidth() - geom_w) / 2,
1896                       (getHeight() - geom_h) / 2, geom_w, geom_h);
1897     XMapWindow(blackbox->getXDisplay(), geom_window);
1898     XRaiseWindow(blackbox->getXDisplay(), geom_window);
1899
1900     geom_visible = True;
1901   }
1902
1903   char label[1024];
1904
1905   sprintf(label, i18n(ScreenSet, ScreenPositionFormat,
1906                       "X: %4d x Y: %4d"), x, y);
1907
1908   XClearWindow(blackbox->getXDisplay(), geom_window);
1909
1910   resource.wstyle.font->drawString(geom_window,
1911                                    resource.bevel_width, resource.bevel_width,
1912                                    resource.wstyle.l_text_focus,
1913                                    label);
1914 }
1915
1916
1917 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
1918   if (! geom_visible) {
1919     XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1920                       (getWidth() - geom_w) / 2,
1921                       (getHeight() - geom_h) / 2, geom_w, geom_h);
1922     XMapWindow(blackbox->getXDisplay(), geom_window);
1923     XRaiseWindow(blackbox->getXDisplay(), geom_window);
1924
1925     geom_visible = True;
1926   }
1927
1928   char label[1024];
1929
1930   sprintf(label, i18n(ScreenSet, ScreenGeometryFormat,
1931                       "W: %4d x H: %4d"), gx, gy);
1932
1933   XClearWindow(blackbox->getXDisplay(), geom_window);
1934
1935   resource.wstyle.font->drawString(geom_window,
1936                                    resource.bevel_width, resource.bevel_width,
1937                                    resource.wstyle.l_text_focus,
1938                                    label);
1939 }
1940
1941
1942 void BScreen::hideGeometry(void) {
1943   if (geom_visible) {
1944     XUnmapWindow(blackbox->getXDisplay(), geom_window);
1945     geom_visible = False;
1946   }
1947 }
1948
1949
1950 void BScreen::addStrut(Strut *strut) {
1951   strutList.push_back(strut);
1952 }
1953
1954
1955 void BScreen::removeStrut(Strut *strut) {
1956   strutList.remove(strut);
1957 }
1958
1959
1960 const Rect& BScreen::availableArea(void) const {
1961   if (doFullMax())
1962     return getRect(); // return the full screen
1963   return usableArea;
1964 }
1965
1966
1967 void BScreen::updateAvailableArea(void) {
1968   Rect old_area = usableArea;
1969   usableArea = getRect(); // reset to full screen
1970
1971   /* these values represent offsets from the screen edge
1972    * we look for the biggest offset on each edge and then apply them
1973    * all at once
1974    * do not be confused by the similarity to the names of Rect's members
1975    */
1976   unsigned int current_left = 0, current_right = 0, current_top = 0,
1977     current_bottom = 0;
1978
1979   StrutList::const_iterator it = strutList.begin(), end = strutList.end();
1980
1981   for(; it != end; ++it) {
1982     Strut *strut = *it;
1983     if (strut->left > current_left)
1984       current_left = strut->left;
1985     if (strut->top > current_top)
1986       current_top = strut->top;
1987     if (strut->right > current_right)
1988       current_right = strut->right;
1989     if (strut->bottom > current_bottom)
1990       current_bottom = strut->bottom;
1991   }
1992
1993   usableArea.setPos(current_left, current_top);
1994   usableArea.setSize(usableArea.width() - (current_left + current_right),
1995                      usableArea.height() - (current_top + current_bottom));
1996
1997   if (old_area != usableArea) {
1998     BlackboxWindowList::iterator it = windowList.begin(),
1999       end = windowList.end();
2000     for (; it != end; ++it)
2001       if ((*it)->isMaximized()) (*it)->remaximize();
2002   }
2003
2004   updateWorkArea();  
2005 }
2006
2007
2008 Workspace* BScreen::getWorkspace(unsigned int index) {
2009   assert(index < workspacesList.size());
2010   return workspacesList[index];
2011 }
2012
2013
2014 void BScreen::buttonPressEvent(const XButtonEvent *xbutton) {
2015   if (xbutton->button == 1) {
2016     if (! isRootColormapInstalled())
2017       image_control->installRootColormap();
2018
2019     if (workspacemenu->isVisible())
2020       workspacemenu->hide();
2021
2022     if (rootmenu->isVisible())
2023       rootmenu->hide();
2024   } else if (xbutton->button == 2) {
2025     int mx = xbutton->x_root - (workspacemenu->getWidth() / 2);
2026     int my = xbutton->y_root - (workspacemenu->getTitleHeight() / 2);
2027
2028     if (mx < 0) mx = 0;
2029     if (my < 0) my = 0;
2030
2031     if (mx + workspacemenu->getWidth() > getWidth())
2032       mx = getWidth() - workspacemenu->getWidth() - getBorderWidth();
2033
2034     if (my + workspacemenu->getHeight() > getHeight())
2035       my = getHeight() - workspacemenu->getHeight() - getBorderWidth();
2036
2037     workspacemenu->move(mx, my);
2038
2039     if (! workspacemenu->isVisible()) {
2040       workspacemenu->removeParent();
2041       workspacemenu->show();
2042     }
2043   } else if (xbutton->button == 3) {
2044     int mx = xbutton->x_root - (rootmenu->getWidth() / 2);
2045     int my = xbutton->y_root - (rootmenu->getTitleHeight() / 2);
2046
2047     if (mx < 0) mx = 0;
2048     if (my < 0) my = 0;
2049
2050     if (mx + rootmenu->getWidth() > getWidth())
2051       mx = getWidth() - rootmenu->getWidth() - getBorderWidth();
2052
2053     if (my + rootmenu->getHeight() > getHeight())
2054       my = getHeight() - rootmenu->getHeight() - getBorderWidth();
2055
2056     rootmenu->move(mx, my);
2057
2058     if (! rootmenu->isVisible()) {
2059       blackbox->checkMenu();
2060       rootmenu->show();
2061     }
2062   // mouse wheel up
2063   } else if (xbutton->button == 4) {
2064     if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2065       changeWorkspaceID(0);
2066     else
2067       changeWorkspaceID(getCurrentWorkspaceID() + 1);
2068   // mouse wheel down
2069   } else if (xbutton->button == 5) {
2070     if (getCurrentWorkspaceID() == 0)
2071       changeWorkspaceID(getWorkspaceCount() - 1);
2072     else
2073       changeWorkspaceID(getCurrentWorkspaceID() - 1);
2074   }
2075 }
2076
2077
2078 void BScreen::toggleFocusModel(FocusModel model) {
2079   std::for_each(windowList.begin(), windowList.end(),
2080                 std::mem_fun(&BlackboxWindow::ungrabButtons));
2081
2082   if (model == SloppyFocus) {
2083     saveSloppyFocus(True);
2084   } else {
2085     // we're cheating here to save writing the config file 3 times
2086     resource.auto_raise = False;
2087     resource.click_raise = False;
2088     saveSloppyFocus(False);
2089   }
2090
2091   std::for_each(windowList.begin(), windowList.end(),
2092                 std::mem_fun(&BlackboxWindow::grabButtons));
2093 }
2094
2095
2096 BTexture BScreen::readDatabaseTexture(const string &rname,
2097                                       const string &default_color,
2098                                       const Configuration &style) {
2099   BTexture texture;
2100   string s;
2101
2102   if (style.getValue(rname, s))
2103     texture = BTexture(s);
2104   else
2105     texture.setTexture(BTexture::Solid | BTexture::Flat);
2106
2107   // associate this texture with this screen
2108   texture.setDisplay(getBaseDisplay(), getScreenNumber());
2109   texture.setImageControl(image_control);
2110
2111   if (texture.texture() & BTexture::Solid) {
2112     texture.setColor(readDatabaseColor(rname + ".color",
2113                                        default_color, style));
2114     texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2115                                          default_color, style));
2116   } else if (texture.texture() & BTexture::Gradient) {
2117     texture.setColor(readDatabaseColor(rname + ".color",
2118                                        default_color, style));
2119     texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2120                                          default_color, style));
2121   }
2122
2123   return texture;
2124 }
2125
2126
2127 BColor BScreen::readDatabaseColor(const string &rname,
2128                                   const string &default_color,
2129                                   const Configuration &style) {
2130   BColor color;
2131   string s;
2132   if (style.getValue(rname, s))
2133     color = BColor(s, getBaseDisplay(), getScreenNumber());
2134   else
2135     color = BColor(default_color, getBaseDisplay(), getScreenNumber());
2136   return color;
2137 }
2138
2139
2140 BFont *BScreen::readDatabaseFont(const string &rname,
2141                                  const Configuration &style) {
2142   string fontname;
2143
2144   string s;
2145   style.getValue(rname, s); // if this fails, a blank string will be used,
2146                             // which will cause the fallback font to load.
2147
2148   BFont *b = new BFont(blackbox->getXDisplay(), this, s);
2149   if (! b->valid())
2150     exit(2);  // can't continue without a font
2151   return b;
2152 }