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