]> Dogcows Code - chaz/openbox/blob - src/Screen.cc
when a window is iconified, set its workspace to 'all workspaces' so it shows up...
[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 lists, 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::saveAAFonts(bool f) {
392 resource.aa_fonts = f;
393 reconfigure();
394 config->setValue(screenstr + "antialiasFonts", resource.aa_fonts);
395 }
396
397
398 void BScreen::saveHideToolbar(bool h) {
399 resource.hide_toolbar = h;
400 if (resource.hide_toolbar)
401 toolbar->unmapToolbar();
402 else
403 toolbar->mapToolbar();
404 config->setValue(screenstr + "hideToolbar", resource.hide_toolbar);
405 }
406
407
408 void BScreen::saveWindowToWindowSnap(bool s) {
409 resource.window_to_window_snap = s;
410 config->setValue(screenstr + "windowToWindowSnap",
411 resource.window_to_window_snap);
412 }
413
414
415 void BScreen::saveWindowCornerSnap(bool s) {
416 resource.window_corner_snap = s;
417 config->setValue(screenstr + "windowCornerSnap",
418 resource.window_corner_snap);
419 }
420
421
422 void BScreen::saveWorkspaces(unsigned int w) {
423 resource.workspaces = w;
424 config->setValue(screenstr + "workspaces", resource.workspaces);
425 }
426
427
428 void BScreen::savePlacementPolicy(int p) {
429 resource.placement_policy = p;
430 const char *placement;
431 switch (resource.placement_policy) {
432 case CascadePlacement: placement = "CascadePlacement"; break;
433 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
434 case RowSmartPlacement: default: placement = "RowSmartPlacement"; break;
435 }
436 config->setValue(screenstr + "windowPlacement", placement);
437 }
438
439
440 void BScreen::saveEdgeSnapThreshold(int t) {
441 resource.edge_snap_threshold = t;
442 config->setValue(screenstr + "edgeSnapThreshold",
443 resource.edge_snap_threshold);
444 }
445
446
447 void BScreen::saveRowPlacementDirection(int d) {
448 resource.row_direction = d;
449 config->setValue(screenstr + "rowPlacementDirection",
450 resource.row_direction == LeftRight ?
451 "LeftToRight" : "RightToLeft");
452 }
453
454
455 void BScreen::saveColPlacementDirection(int d) {
456 resource.col_direction = d;
457 config->setValue(screenstr + "colPlacementDirection",
458 resource.col_direction == TopBottom ?
459 "TopToBottom" : "BottomToTop");
460 }
461
462
463 #ifdef HAVE_STRFTIME
464 void BScreen::saveStrftimeFormat(const std::string& format) {
465 resource.strftime_format = format;
466 config->setValue(screenstr + "strftimeFormat", resource.strftime_format);
467 }
468
469 #else // !HAVE_STRFTIME
470
471 void BScreen::saveDateFormat(int f) {
472 resource.date_format = f;
473 config->setValue(screenstr + "dateFormat",
474 resource.date_format == B_EuropeanDate ?
475 "European" : "American");
476 }
477
478
479 void BScreen::saveClock24Hour(Bool c) {
480 resource.clock24hour = c;
481 config->setValue(screenstr + "clockFormat", resource.clock24hour ? 24 : 12);
482 }
483 #endif // HAVE_STRFTIME
484
485
486 void BScreen::saveWorkspaceNames() {
487 XAtom::StringVect nameList;
488 unsigned long numnames = (unsigned) -1;
489 string names;
490
491 if (numnames > 0 &&
492 xatom->getValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
493 numnames, nameList)) {
494 for (unsigned int i = 0; i < nameList.size(); ++i) {
495 if (i > 0) names += ",";
496 names += nameList[i];
497 }
498 }
499 config->setValue(screenstr + "workspaceNames", names);
500 }
501
502
503 void BScreen::save_rc(void) {
504 saveSloppyFocus(resource.sloppy_focus);
505 saveAutoRaise(resource.auto_raise);
506 saveImageDither(doImageDither());
507 saveAAFonts(resource.aa_fonts);
508 saveOpaqueMove(resource.opaque_move);
509 saveFullMax(resource.full_max);
510 saveFocusNew(resource.focus_new);
511 saveFocusLast(resource.focus_last);
512 saveHideToolbar(resource.hide_toolbar);
513 saveWindowToWindowSnap(resource.window_to_window_snap);
514 saveWindowCornerSnap(resource.window_corner_snap);
515 saveWorkspaces(resource.workspaces);
516 savePlacementPolicy(resource.placement_policy);
517 saveEdgeSnapThreshold(resource.edge_snap_threshold);
518 saveRowPlacementDirection(resource.row_direction);
519 saveColPlacementDirection(resource.col_direction);
520 #ifdef HAVE_STRFTIME
521 saveStrftimeFormat(resource.strftime_format);
522 #else // !HAVE_STRFTIME
523 saveDateFormat(resource.date_format);
524 savwClock24Hour(resource.clock24hour);
525 #endif // HAVE_STRFTIME
526
527 toolbar->save_rc();
528 slit->save_rc();
529 }
530
531
532 void BScreen::load_rc(void) {
533 std::string s;
534 bool b;
535
536 if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
537 resource.full_max = false;
538
539 if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
540 resource.focus_new = false;
541
542 if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
543 resource.focus_last = false;
544
545 if (! config->getValue(screenstr + "workspaces", resource.workspaces))
546 resource.workspaces = 1;
547
548 if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
549 resource.opaque_move = false;
550
551 if (! config->getValue(screenstr + "antialiasFonts", resource.aa_fonts))
552 resource.aa_fonts = true;
553
554 if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
555 resource.hide_toolbar = false;
556
557 if (! config->getValue(screenstr + "windowToWindowSnap",
558 resource.window_to_window_snap))
559 resource.window_to_window_snap = true;
560
561 if (! config->getValue(screenstr + "windowCornerSnap",
562 resource.window_corner_snap))
563 resource.window_corner_snap = true;
564
565 if (! config->getValue(screenstr + "imageDither", b))
566 b = true;
567 image_control->setDither(b);
568
569 if (! config->getValue(screenstr + "edgeSnapThreshold",
570 resource.edge_snap_threshold))
571 resource.edge_snap_threshold = 4;
572
573 if (config->getValue(screenstr + "rowPlacementDirection", s) &&
574 s == "RightToLeft")
575 resource.row_direction = RightLeft;
576 else
577 resource.row_direction = LeftRight;
578
579 if (config->getValue(screenstr + "colPlacementDirection", s) &&
580 s == "BottomToTop")
581 resource.col_direction = BottomTop;
582 else
583 resource.col_direction = TopBottom;
584
585 XAtom::StringVect workspaceNames;
586 if (config->getValue(screenstr + "workspaceNames", s)) {
587 string::const_iterator it = s.begin(), end = s.end();
588 while(1) {
589 string::const_iterator tmp = it; // current string.begin()
590 it = std::find(tmp, end, ','); // look for comma between tmp and end
591 workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
592 if (it == end)
593 break;
594 ++it;
595 }
596 }
597 xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
598 workspaceNames);
599
600 resource.sloppy_focus = true;
601 resource.auto_raise = false;
602 resource.click_raise = false;
603 if (config->getValue(screenstr + "focusModel", s)) {
604 if (s.find("ClickToFocus") != string::npos) {
605 resource.sloppy_focus = false;
606 } else {
607 // must be sloppy
608 if (s.find("AutoRaise") != string::npos)
609 resource.auto_raise = true;
610 if (s.find("ClickRaise") != string::npos)
611 resource.click_raise = true;
612 }
613 }
614
615 if (config->getValue(screenstr + "windowPlacement", s)) {
616 if (s == "CascadePlacement")
617 resource.placement_policy = CascadePlacement;
618 else if (s == "ColSmartPlacement")
619 resource.placement_policy = ColSmartPlacement;
620 else //if (s == "RowSmartPlacement")
621 resource.placement_policy = RowSmartPlacement;
622 } else
623 resource.placement_policy = RowSmartPlacement;
624
625 #ifdef HAVE_STRFTIME
626 if (config->getValue(screenstr + "strftimeFormat", s))
627 resource.strftime_format = s;
628 else
629 resource.strftime_format = "%I:%M %p";
630 #else // !HAVE_STRFTIME
631 long l;
632
633 if (config->getValue(screenstr + "dateFormat", s) && s == "European")
634 resource.date_format = B_EuropeanDate;
635 else
636 resource.date_format = B_AmericanDate;
637
638 if (! config->getValue(screenstr + "clockFormat", l))
639 l = 12;
640 resource.clock24hour = l == 24;
641 #endif // HAVE_STRFTIME
642 }
643
644
645 void BScreen::reconfigure(void) {
646 load_rc();
647 toolbar->load_rc();
648 slit->load_rc();
649 LoadStyle();
650
651 XGCValues gcv;
652 gcv.foreground = WhitePixel(blackbox->getXDisplay(),
653 getScreenNumber());
654 gcv.function = GXinvert;
655 gcv.subwindow_mode = IncludeInferiors;
656 XChangeGC(blackbox->getXDisplay(), opGC,
657 GCForeground | GCFunction | GCSubwindowMode, &gcv);
658
659 const char *s = i18n(ScreenSet, ScreenPositionLength,
660 "0: 0000 x 0: 0000");
661
662 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
663 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
664
665 BTexture* texture = &(resource.wstyle.l_focus);
666 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
667 if (geom_pixmap == ParentRelative) {
668 texture = &(resource.wstyle.t_focus);
669 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
670 }
671 if (! geom_pixmap)
672 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
673 texture->color().pixel());
674 else
675 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
676 geom_window, geom_pixmap);
677
678 XSetWindowBorderWidth(blackbox->getXDisplay(), geom_window,
679 resource.border_width);
680 XSetWindowBorder(blackbox->getXDisplay(), geom_window,
681 resource.border_color.pixel());
682
683 workspacemenu->reconfigure();
684 iconmenu->reconfigure();
685
686 typedef std::vector<int> SubList;
687 SubList remember_subs;
688
689 // save the current open menus
690 Basemenu *menu = rootmenu;
691 int submenu;
692 while ((submenu = menu->getCurrentSubmenu()) >= 0) {
693 remember_subs.push_back(submenu);
694 menu = menu->find(submenu)->submenu();
695 assert(menu);
696 }
697
698 InitMenu();
699 raiseWindows(0, 0);
700 rootmenu->reconfigure();
701
702 // reopen the saved menus
703 menu = rootmenu;
704 const SubList::iterator subs_end = remember_subs.end();
705 for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
706 menu->drawSubmenu(*it);
707 menu = menu->find(*it)->submenu();
708 if (! menu)
709 break;
710 }
711
712 configmenu->reconfigure();
713
714 toolbar->reconfigure();
715
716 slit->reconfigure();
717
718 std::for_each(workspacesList.begin(), workspacesList.end(),
719 std::mem_fun(&Workspace::reconfigure));
720
721 BlackboxWindowList::iterator iit = iconList.begin();
722 for (; iit != iconList.end(); ++iit) {
723 BlackboxWindow *bw = *iit;
724 if (bw->validateClient())
725 bw->reconfigure();
726 }
727
728 image_control->timeout();
729 }
730
731
732 void BScreen::rereadMenu(void) {
733 InitMenu();
734 raiseWindows(0, 0);
735
736 rootmenu->reconfigure();
737 }
738
739
740 void BScreen::LoadStyle(void) {
741 Configuration style(False);
742
743 const char *sfile = blackbox->getStyleFilename();
744 if (sfile != NULL) {
745 style.setFile(sfile);
746 if (! style.load()) {
747 style.setFile(DEFAULTSTYLE);
748 if (! style.load())
749 style.create(); // hardcoded default values will be used.
750 }
751 }
752
753 // merge in the rc file
754 style.merge(config->file(), True);
755
756 string s;
757
758 // load fonts/fontsets
759 if (resource.wstyle.font)
760 delete resource.wstyle.font;
761 if (resource.tstyle.font)
762 delete resource.tstyle.font;
763 if (resource.mstyle.f_font)
764 delete resource.mstyle.f_font;
765 if (resource.mstyle.t_font)
766 delete resource.mstyle.t_font;
767 resource.wstyle.font = resource.tstyle.font = resource.mstyle.f_font =
768 resource.mstyle.t_font = (BFont *) 0;
769
770 resource.wstyle.font = readDatabaseFont("window.", style);
771 resource.tstyle.font = readDatabaseFont("toolbar.", style);
772 resource.mstyle.t_font = readDatabaseFont("menu.title.", style);
773 resource.mstyle.f_font = readDatabaseFont("menu.frame.", style);
774
775 // load window config
776 resource.wstyle.t_focus =
777 readDatabaseTexture("window.title.focus", "white", style);
778 resource.wstyle.t_unfocus =
779 readDatabaseTexture("window.title.unfocus", "black", style);
780 resource.wstyle.l_focus =
781 readDatabaseTexture("window.label.focus", "white", style);
782 resource.wstyle.l_unfocus =
783 readDatabaseTexture("window.label.unfocus", "black", style);
784 resource.wstyle.h_focus =
785 readDatabaseTexture("window.handle.focus", "white", style);
786 resource.wstyle.h_unfocus =
787 readDatabaseTexture("window.handle.unfocus", "black", style);
788 resource.wstyle.g_focus =
789 readDatabaseTexture("window.grip.focus", "white", style);
790 resource.wstyle.g_unfocus =
791 readDatabaseTexture("window.grip.unfocus", "black", style);
792 resource.wstyle.b_focus =
793 readDatabaseTexture("window.button.focus", "white", style);
794 resource.wstyle.b_unfocus =
795 readDatabaseTexture("window.button.unfocus", "black", style);
796 resource.wstyle.b_pressed =
797 readDatabaseTexture("window.button.pressed", "black", style);
798 resource.wstyle.f_focus =
799 readDatabaseColor("window.frame.focusColor", "white", style);
800 resource.wstyle.f_unfocus =
801 readDatabaseColor("window.frame.unfocusColor", "black", style);
802 resource.wstyle.l_text_focus =
803 readDatabaseColor("window.label.focus.textColor", "black", style);
804 resource.wstyle.l_text_unfocus =
805 readDatabaseColor("window.label.unfocus.textColor", "white", style);
806 resource.wstyle.b_pic_focus =
807 readDatabaseColor("window.button.focus.picColor", "black", style);
808 resource.wstyle.b_pic_unfocus =
809 readDatabaseColor("window.button.unfocus.picColor", "white", style);
810
811 resource.wstyle.justify = LeftJustify;
812 if (style.getValue("window.justify", s)) {
813 if (s == "right" || s == "Right")
814 resource.wstyle.justify = RightJustify;
815 else if (s == "center" || s == "Center")
816 resource.wstyle.justify = CenterJustify;
817 }
818
819 // load toolbar config
820 resource.tstyle.toolbar =
821 readDatabaseTexture("toolbar", "black", style);
822 resource.tstyle.label =
823 readDatabaseTexture("toolbar.label", "black", style);
824 resource.tstyle.window =
825 readDatabaseTexture("toolbar.windowLabel", "black", style);
826 resource.tstyle.button =
827 readDatabaseTexture("toolbar.button", "white", style);
828 resource.tstyle.pressed =
829 readDatabaseTexture("toolbar.button.pressed", "black", style);
830 resource.tstyle.clock =
831 readDatabaseTexture("toolbar.clock", "black", style);
832 resource.tstyle.l_text =
833 readDatabaseColor("toolbar.label.textColor", "white", style);
834 resource.tstyle.w_text =
835 readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
836 resource.tstyle.c_text =
837 readDatabaseColor("toolbar.clock.textColor", "white", style);
838 resource.tstyle.b_pic =
839 readDatabaseColor("toolbar.button.picColor", "black", style);
840
841 resource.tstyle.justify = LeftJustify;
842 if (style.getValue("toolbar.justify", s)) {
843 if (s == "right" || s == "Right")
844 resource.tstyle.justify = RightJustify;
845 else if (s == "center" || s == "Center")
846 resource.tstyle.justify = CenterJustify;
847 }
848
849 // load menu config
850 resource.mstyle.title =
851 readDatabaseTexture("menu.title", "white", style);
852 resource.mstyle.frame =
853 readDatabaseTexture("menu.frame", "black", style);
854 resource.mstyle.hilite =
855 readDatabaseTexture("menu.hilite", "white", style);
856 resource.mstyle.t_text =
857 readDatabaseColor("menu.title.textColor", "black", style);
858 resource.mstyle.f_text =
859 readDatabaseColor("menu.frame.textColor", "white", style);
860 resource.mstyle.d_text =
861 readDatabaseColor("menu.frame.disableColor", "black", style);
862 resource.mstyle.h_text =
863 readDatabaseColor("menu.hilite.textColor", "black", style);
864
865 resource.mstyle.t_justify = LeftJustify;
866 if (style.getValue("menu.title.justify", s)) {
867 if (s == "right" || s == "Right")
868 resource.mstyle.t_justify = RightJustify;
869 else if (s == "center" || s == "Center")
870 resource.mstyle.t_justify = CenterJustify;
871 }
872
873 resource.mstyle.f_justify = LeftJustify;
874 if (style.getValue("menu.frame.justify", s)) {
875 if (s == "right" || s == "Right")
876 resource.mstyle.f_justify = RightJustify;
877 else if (s == "center" || s == "Center")
878 resource.mstyle.f_justify = CenterJustify;
879 }
880
881 resource.mstyle.bullet = Basemenu::Triangle;
882 if (style.getValue("menu.bullet", s)) {
883 if (s == "empty" || s == "Empty")
884 resource.mstyle.bullet = Basemenu::Empty;
885 else if (s == "square" || s == "Square")
886 resource.mstyle.bullet = Basemenu::Square;
887 else if (s == "diamond" || s == "Diamond")
888 resource.mstyle.bullet = Basemenu::Diamond;
889 }
890
891 resource.mstyle.bullet_pos = Basemenu::Left;
892 if (style.getValue("menu.bullet.position", s)) {
893 if (s == "right" || s == "Right")
894 resource.mstyle.bullet_pos = Basemenu::Right;
895 }
896
897 resource.border_color =
898 readDatabaseColor("borderColor", "black", style);
899
900 // load bevel, border and handle widths
901 if (! style.getValue("handleWidth", resource.handle_width) ||
902 resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
903 resource.handle_width = 6;
904
905 if (! style.getValue("borderWidth", resource.border_width))
906 resource.border_width = 1;
907
908 if (! style.getValue("bevelWidth", resource.bevel_width) ||
909 resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
910 resource.bevel_width = 3;
911
912 if (! style.getValue("frameWidth", resource.frame_width) ||
913 resource.frame_width > (getWidth() / 2))
914 resource.frame_width = resource.bevel_width;
915
916 if (style.getValue("rootCommand", s))
917 bexec(s, displayString());
918 }
919
920
921 void BScreen::addIcon(BlackboxWindow *w) {
922 if (! w) return;
923
924 // we set the workspace to 'all workspaces' so that taskbars will show the
925 // window. otherwise, it made uniconifying a window impoosible without the
926 // blackbox workspace menu
927 w->setWorkspace(0xffffffff);
928 w->setWindowNumber(iconList.size());
929
930 iconList.push_back(w);
931
932 const char* title = w->getIconTitle();
933 iconmenu->insert(title);
934 iconmenu->update();
935 }
936
937
938 void BScreen::removeIcon(BlackboxWindow *w) {
939 if (! w) return;
940
941 iconList.remove(w);
942
943 iconmenu->remove(w->getWindowNumber());
944 iconmenu->update();
945
946 BlackboxWindowList::iterator it = iconList.begin(),
947 end = iconList.end();
948 for (int i = 0; it != end; ++it)
949 (*it)->setWindowNumber(i++);
950 }
951
952
953 BlackboxWindow *BScreen::getIcon(unsigned int index) {
954 if (index < iconList.size()) {
955 BlackboxWindowList::iterator it = iconList.begin();
956 for (; index > 0; --index, ++it) ; /* increment to index */
957 return *it;
958 }
959
960 return (BlackboxWindow *) 0;
961 }
962
963
964 unsigned int BScreen::addWorkspace(void) {
965 Workspace *wkspc = new Workspace(this, workspacesList.size());
966 workspacesList.push_back(wkspc);
967 saveWorkspaces(getWorkspaceCount());
968
969 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
970 wkspc->getID() + 2);
971 workspacemenu->update();
972
973 toolbar->reconfigure();
974
975 updateNetizenWorkspaceCount();
976
977 return workspacesList.size();
978 }
979
980
981 unsigned int BScreen::removeLastWorkspace(void) {
982 if (workspacesList.size() == 1)
983 return 1;
984
985 Workspace *wkspc = workspacesList.back();
986
987 if (current_workspace->getID() == wkspc->getID())
988 changeWorkspaceID(current_workspace->getID() - 1);
989
990 wkspc->removeAll();
991
992 workspacemenu->remove(wkspc->getID() + 2);
993 workspacemenu->update();
994
995 workspacesList.pop_back();
996 delete wkspc;
997
998 saveWorkspaces(getWorkspaceCount());
999
1000 toolbar->reconfigure();
1001
1002 updateNetizenWorkspaceCount();
1003
1004 return workspacesList.size();
1005 }
1006
1007
1008 void BScreen::changeWorkspaceID(unsigned int id) {
1009 if (! current_workspace) return;
1010
1011 if (id != current_workspace->getID()) {
1012 BlackboxWindow *focused = blackbox->getFocusedWindow();
1013 if (focused && focused->getScreen() == this && ! focused->isStuck()) {
1014 if (focused->getWorkspaceNumber() != current_workspace->getID()) {
1015 fprintf(stderr, "%s is on the wrong workspace, aborting\n",
1016 focused->getTitle());
1017 abort();
1018 }
1019 current_workspace->setLastFocusedWindow(focused);
1020 } else {
1021 // if no window had focus, no need to store a last focus
1022 current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
1023 }
1024 // when we switch workspaces, unfocus whatever was focused
1025 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1026
1027 current_workspace->hideAll();
1028 workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1029
1030 current_workspace = getWorkspace(id);
1031
1032 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
1033 XAtom::cardinal, id);
1034
1035 workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1036 toolbar->redrawWorkspaceLabel(True);
1037
1038 current_workspace->showAll();
1039
1040 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1041 XSync(blackbox->getXDisplay(), False);
1042 current_workspace->getLastFocusedWindow()->setInputFocus();
1043 }
1044 }
1045
1046 updateNetizenCurrentWorkspace();
1047 }
1048
1049
1050 /*
1051 * Set the _NET_CLIENT_LIST root window property.
1052 */
1053 void BScreen::updateClientList(void) {
1054 if (windowList.size() > 0) {
1055 Window *windows = new Window[windowList.size()];
1056 Window *win_it = windows;
1057 BlackboxWindowList::iterator it = windowList.begin();
1058 const BlackboxWindowList::iterator end = windowList.end();
1059 for (; it != end; ++it, ++win_it)
1060 *win_it = (*it)->getClientWindow();
1061 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1062 windows, windowList.size());
1063 delete [] windows;
1064 } else
1065 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1066 0, 0);
1067
1068 updateStackingList();
1069 }
1070
1071
1072 /*
1073 * Set the _NET_CLIENT_LIST_STACKING root window property.
1074 */
1075 void BScreen::updateStackingList(void) {
1076
1077 BlackboxWindowList stack_order;
1078
1079 /*
1080 * Get the stacking order from all of the workspaces.
1081 * We start with the current workspace so that the sticky windows will be
1082 * in the right order on the current workspace.
1083 * XXX: Do we need to have sticky windows in the list once for each workspace?
1084 */
1085 getCurrentWorkspace()->appendStackOrder(stack_order);
1086 for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
1087 if (i != getCurrentWorkspaceID())
1088 getWorkspace(i)->appendStackOrder(stack_order);
1089
1090 if (stack_order.size() > 0) {
1091 // set the client list atoms
1092 Window *windows = new Window[stack_order.size()];
1093 Window *win_it = windows;
1094 BlackboxWindowList::iterator it = stack_order.begin(),
1095 end = stack_order.end();
1096 for (; it != end; ++it, ++win_it)
1097 *win_it = (*it)->getClientWindow();
1098 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1099 XAtom::window, windows, stack_order.size());
1100 delete [] windows;
1101 } else
1102 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1103 XAtom::window, 0, 0);
1104 }
1105
1106
1107 void BScreen::addSystrayWindow(Window window) {
1108 systrayWindowList.push_back(window);
1109 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1110 XAtom::window,
1111 &systrayWindowList[0], systrayWindowList.size());
1112 blackbox->saveSystrayWindowSearch(window, this);
1113 }
1114
1115
1116 void BScreen::removeSystrayWindow(Window window) {
1117 WindowList::iterator it = systrayWindowList.begin();
1118 const WindowList::iterator end = systrayWindowList.end();
1119 for (; it != end; ++it)
1120 if (*it == window) {
1121 systrayWindowList.erase(it);
1122 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1123 XAtom::window,
1124 &systrayWindowList[0], systrayWindowList.size());
1125 blackbox->removeSystrayWindowSearch(window);
1126 break;
1127 }
1128 }
1129
1130
1131 void BScreen::addDesktopWindow(Window window) {
1132 desktopWindowList.push_back(window);
1133 XLowerWindow(blackbox->getXDisplay(), window);
1134 XSelectInput(blackbox->getXDisplay(), window, StructureNotifyMask);
1135 blackbox->saveDesktopWindowSearch(window, this);
1136 }
1137
1138
1139 void BScreen::removeDesktopWindow(Window window) {
1140 WindowList::iterator it = desktopWindowList.begin();
1141 const WindowList::iterator end = desktopWindowList.end();
1142 for (; it != end; ++it)
1143 if (*it == window) {
1144 desktopWindowList.erase(it);
1145 XSelectInput(blackbox->getXDisplay(), window, None);
1146 blackbox->removeDesktopWindowSearch(window);
1147 break;
1148 }
1149 }
1150
1151
1152 void BScreen::manageWindow(Window w) {
1153 new BlackboxWindow(blackbox, w, this);
1154
1155 BlackboxWindow *win = blackbox->searchWindow(w);
1156 if (! win)
1157 return;
1158 if (win->isDesktop()) {
1159 // desktop windows cant do anything, so we remove all the normal window
1160 // stuff from them, they are only kept around so that we can keep them on
1161 // the bottom of the z-order
1162 win->restore(True);
1163 addDesktopWindow(win->getClientWindow());
1164 delete win;
1165 return;
1166 }
1167
1168 windowList.push_back(win);
1169 updateClientList();
1170
1171 XMapRequestEvent mre;
1172 mre.window = w;
1173 if (blackbox->isStartup()) win->restoreAttributes();
1174 win->mapRequestEvent(&mre);
1175 }
1176
1177
1178 void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
1179 w->restore(remap);
1180
1181 if (w->getWorkspaceNumber() != BSENTINEL &&
1182 w->getWindowNumber() != BSENTINEL)
1183 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1184 else if (w->isIconic())
1185 removeIcon(w);
1186
1187 windowList.remove(w);
1188 updateClientList();
1189
1190 if (blackbox->getFocusedWindow() == w)
1191 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1192
1193 removeNetizen(w->getClientWindow());
1194
1195 /*
1196 some managed windows can also be window group controllers. when
1197 unmanaging such windows, we should also delete the window group.
1198 */
1199 BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
1200 delete group;
1201
1202 delete w;
1203 }
1204
1205
1206 void BScreen::addNetizen(Netizen *n) {
1207 netizenList.push_back(n);
1208
1209 n->sendWorkspaceCount();
1210 n->sendCurrentWorkspace();
1211
1212 WorkspaceList::iterator it = workspacesList.begin();
1213 const WorkspaceList::iterator end = workspacesList.end();
1214 for (; it != end; ++it)
1215 (*it)->sendWindowList(*n);
1216
1217 Window f = ((blackbox->getFocusedWindow()) ?
1218 blackbox->getFocusedWindow()->getClientWindow() : None);
1219 n->sendWindowFocus(f);
1220 }
1221
1222
1223 void BScreen::removeNetizen(Window w) {
1224 NetizenList::iterator it = netizenList.begin();
1225 for (; it != netizenList.end(); ++it) {
1226 if ((*it)->getWindowID() == w) {
1227 delete *it;
1228 netizenList.erase(it);
1229 break;
1230 }
1231 }
1232 }
1233
1234
1235 void BScreen::updateWorkArea(void) {
1236 if (workspacesList.size() > 0) {
1237 unsigned long *dims = new unsigned long[4 * workspacesList.size()];
1238 for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
1239 // XXX: this could be different for each workspace
1240 const Rect &area = availableArea();
1241 dims[(i * 4) + 0] = area.x();
1242 dims[(i * 4) + 1] = area.y();
1243 dims[(i * 4) + 2] = area.width();
1244 dims[(i * 4) + 3] = area.height();
1245 }
1246 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1247 dims, 4 * workspacesList.size());
1248 delete [] dims;
1249 } else
1250 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1251 0, 0);
1252 }
1253
1254
1255 void BScreen::updateNetizenCurrentWorkspace(void) {
1256 std::for_each(netizenList.begin(), netizenList.end(),
1257 std::mem_fun(&Netizen::sendCurrentWorkspace));
1258 }
1259
1260
1261 void BScreen::updateNetizenWorkspaceCount(void) {
1262 xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
1263 XAtom::cardinal, workspacesList.size());
1264
1265 updateWorkArea();
1266
1267 std::for_each(netizenList.begin(), netizenList.end(),
1268 std::mem_fun(&Netizen::sendWorkspaceCount));
1269 }
1270
1271
1272 void BScreen::updateNetizenWindowFocus(void) {
1273 Window f = ((blackbox->getFocusedWindow()) ?
1274 blackbox->getFocusedWindow()->getClientWindow() : None);
1275
1276 xatom->setValue(getRootWindow(), XAtom::net_active_window,
1277 XAtom::window, f);
1278
1279 NetizenList::iterator it = netizenList.begin();
1280 for (; it != netizenList.end(); ++it)
1281 (*it)->sendWindowFocus(f);
1282 }
1283
1284
1285 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1286 NetizenList::iterator it = netizenList.begin();
1287 for (; it != netizenList.end(); ++it) {
1288 (*it)->sendWindowAdd(w, p);
1289 }
1290 }
1291
1292
1293 void BScreen::updateNetizenWindowDel(Window w) {
1294 NetizenList::iterator it = netizenList.begin();
1295 for (; it != netizenList.end(); ++it)
1296 (*it)->sendWindowDel(w);
1297 }
1298
1299
1300 void BScreen::updateNetizenWindowRaise(Window w) {
1301 NetizenList::iterator it = netizenList.begin();
1302 for (; it != netizenList.end(); ++it)
1303 (*it)->sendWindowRaise(w);
1304 }
1305
1306
1307 void BScreen::updateNetizenWindowLower(Window w) {
1308 NetizenList::iterator it = netizenList.begin();
1309 for (; it != netizenList.end(); ++it)
1310 (*it)->sendWindowLower(w);
1311 }
1312
1313
1314 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1315 NetizenList::iterator it = netizenList.begin();
1316 for (; it != netizenList.end(); ++it)
1317 (*it)->sendConfigNotify(e);
1318 }
1319
1320
1321 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
1322 // the 13 represents the number of blackbox windows such as menus
1323 Window *session_stack = new
1324 Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
1325 unsigned int i = 0, k = num;
1326
1327 XRaiseWindow(blackbox->getXDisplay(), iconmenu->getWindowID());
1328 *(session_stack + i++) = iconmenu->getWindowID();
1329
1330 WorkspaceList::iterator wit = workspacesList.begin();
1331 const WorkspaceList::iterator w_end = workspacesList.end();
1332 for (; wit != w_end; ++wit)
1333 *(session_stack + i++) = (*wit)->getMenu()->getWindowID();
1334
1335 *(session_stack + i++) = workspacemenu->getWindowID();
1336
1337 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1338 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1339 *(session_stack + i++) = configmenu->getWindowID();
1340
1341 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1342 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1343 *(session_stack + i++) = slit->getMenu()->getWindowID();
1344
1345 *(session_stack + i++) =
1346 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1347 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1348
1349 RootmenuList::iterator rit = rootmenuList.begin();
1350 for (; rit != rootmenuList.end(); ++rit)
1351 *(session_stack + i++) = (*rit)->getWindowID();
1352 *(session_stack + i++) = rootmenu->getWindowID();
1353
1354 if (toolbar->isOnTop())
1355 *(session_stack + i++) = toolbar->getWindowID();
1356
1357 if (slit->isOnTop())
1358 *(session_stack + i++) = slit->getWindowID();
1359
1360 while (k--)
1361 *(session_stack + i++) = *(workspace_stack + k);
1362
1363 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1364
1365 delete [] session_stack;
1366
1367 updateStackingList();
1368 }
1369
1370
1371 void BScreen::lowerDesktops(void) {
1372 if (desktopWindowList.empty()) return;
1373
1374 XLowerWindow(blackbox->getXDisplay(), desktopWindowList[0]);
1375 if (desktopWindowList.size() > 1)
1376 XRestackWindows(blackbox->getXDisplay(), &desktopWindowList[0],
1377 desktopWindowList.size());
1378 }
1379
1380
1381 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
1382 bool ignore_sticky) {
1383 if (! w) return;
1384
1385 if (wkspc_id == BSENTINEL)
1386 wkspc_id = current_workspace->getID();
1387
1388 if (w->getWorkspaceNumber() == wkspc_id)
1389 return;
1390
1391 if (w->isIconic()) {
1392 removeIcon(w);
1393 getWorkspace(wkspc_id)->addWindow(w);
1394 } else if (ignore_sticky || ! w->isStuck()) {
1395 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1396 getWorkspace(wkspc_id)->addWindow(w);
1397 }
1398 updateStackingList();
1399 }
1400
1401
1402 void BScreen::propagateWindowName(const BlackboxWindow *bw) {
1403 if (bw->isIconic()) {
1404 iconmenu->changeItemLabel(bw->getWindowNumber(), bw->getIconTitle());
1405 iconmenu->update();
1406 }
1407 else {
1408 Clientmenu *clientmenu = getWorkspace(bw->getWorkspaceNumber())->getMenu();
1409 clientmenu->changeItemLabel(bw->getWindowNumber(), bw->getTitle());
1410 clientmenu->update();
1411
1412 if (blackbox->getFocusedWindow() == bw)
1413 toolbar->redrawWindowLabel(True);
1414 }
1415 }
1416
1417
1418 void BScreen::nextFocus(void) {
1419 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1420 *next = focused;
1421
1422 if (focused) {
1423 // if window is not on this screen, ignore it
1424 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1425 focused = (BlackboxWindow*) 0;
1426 }
1427
1428 if (focused && current_workspace->getCount() > 1) {
1429 // next is the next window to recieve focus, current is a place holder
1430 BlackboxWindow *current;
1431 do {
1432 current = next;
1433 next = current_workspace->getNextWindowInList(current);
1434 } while(! next->setInputFocus() && next != focused);
1435
1436 if (next != focused)
1437 current_workspace->raiseWindow(next);
1438 } else if (current_workspace->getCount() >= 1) {
1439 next = current_workspace->getTopWindowOnStack();
1440
1441 current_workspace->raiseWindow(next);
1442 next->setInputFocus();
1443 }
1444 }
1445
1446
1447 void BScreen::prevFocus(void) {
1448 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1449 *next = focused;
1450
1451 if (focused) {
1452 // if window is not on this screen, ignore it
1453 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1454 focused = (BlackboxWindow*) 0;
1455 }
1456
1457 if (focused && current_workspace->getCount() > 1) {
1458 // next is the next window to recieve focus, current is a place holder
1459 BlackboxWindow *current;
1460 do {
1461 current = next;
1462 next = current_workspace->getPrevWindowInList(current);
1463 } while(! next->setInputFocus() && next != focused);
1464
1465 if (next != focused)
1466 current_workspace->raiseWindow(next);
1467 } else if (current_workspace->getCount() >= 1) {
1468 next = current_workspace->getTopWindowOnStack();
1469
1470 current_workspace->raiseWindow(next);
1471 next->setInputFocus();
1472 }
1473 }
1474
1475
1476 void BScreen::raiseFocus(void) {
1477 BlackboxWindow *focused = blackbox->getFocusedWindow();
1478 if (! focused)
1479 return;
1480
1481 // if on this Screen, raise it
1482 if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
1483 Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
1484 workspace->raiseWindow(focused);
1485 }
1486 }
1487
1488
1489 void BScreen::InitMenu(void) {
1490 if (rootmenu) {
1491 rootmenuList.clear();
1492
1493 while (rootmenu->getCount())
1494 rootmenu->remove(0);
1495 } else {
1496 rootmenu = new Rootmenu(this);
1497 }
1498 bool defaultMenu = True;
1499
1500 FILE *menu_file = (FILE *) 0;
1501 const char *menu_filename = blackbox->getMenuFilename();
1502
1503 if (menu_filename)
1504 if (! (menu_file = fopen(menu_filename, "r")))
1505 perror(menu_filename);
1506 if (! menu_file) { // opening the menu file failed, try the default menu
1507 menu_filename = DEFAULTMENU;
1508 if (! (menu_file = fopen(menu_filename, "r")))
1509 perror(menu_filename);
1510 }
1511
1512 if (menu_file) {
1513 if (feof(menu_file)) {
1514 fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
1515 "%s: Empty menu file"),
1516 menu_filename);
1517 } else {
1518 char line[1024], label[1024];
1519 memset(line, 0, 1024);
1520 memset(label, 0, 1024);
1521
1522 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
1523 if (line[0] != '#') {
1524 int i, key = 0, index = -1, len = strlen(line);
1525
1526 for (i = 0; i < len; i++) {
1527 if (line[i] == '[') index = 0;
1528 else if (line[i] == ']') break;
1529 else if (line[i] != ' ')
1530 if (index++ >= 0)
1531 key += tolower(line[i]);
1532 }
1533
1534 if (key == 517) { // [begin]
1535 index = -1;
1536 for (i = index; i < len; i++) {
1537 if (line[i] == '(') index = 0;
1538 else if (line[i] == ')') break;
1539 else if (index++ >= 0) {
1540 if (line[i] == '\\' && i < len - 1) i++;
1541 label[index - 1] = line[i];
1542 }
1543 }
1544
1545 if (index == -1) index = 0;
1546 label[index] = '\0';
1547
1548 rootmenu->setLabel(label);
1549 defaultMenu = parseMenuFile(menu_file, rootmenu);
1550 if (! defaultMenu)
1551 blackbox->addMenuTimestamp(menu_filename);
1552 break;
1553 }
1554 }
1555 }
1556 }
1557 fclose(menu_file);
1558 }
1559
1560 if (defaultMenu) {
1561 rootmenu->setInternalMenu();
1562 rootmenu->insert(i18n(ScreenSet, Screenxterm, "xterm"),
1563 BScreen::Execute,
1564 i18n(ScreenSet, Screenxterm, "xterm"));
1565 rootmenu->insert(i18n(ScreenSet, ScreenRestart, "Restart"),
1566 BScreen::Restart);
1567 rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
1568 BScreen::Exit);
1569 rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
1570 "Openbox Menu"));
1571 }
1572 }
1573
1574
1575 bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
1576 char line[1024], label[1024], command[1024];
1577
1578 while (! feof(file)) {
1579 memset(line, 0, 1024);
1580 memset(label, 0, 1024);
1581 memset(command, 0, 1024);
1582
1583 if (fgets(line, 1024, file)) {
1584 if (line[0] != '#') {
1585 int i, key = 0, parse = 0, index = -1, line_length = strlen(line);
1586
1587 // determine the keyword
1588 for (i = 0; i < line_length; i++) {
1589 if (line[i] == '[') parse = 1;
1590 else if (line[i] == ']') break;
1591 else if (line[i] != ' ')
1592 if (parse)
1593 key += tolower(line[i]);
1594 }
1595
1596 // get the label enclosed in ()'s
1597 parse = 0;
1598
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 label[index - 1] = line[i];
1607 }
1608 }
1609
1610 if (parse) {
1611 label[index] = '\0';
1612 } else {
1613 label[0] = '\0';
1614 }
1615
1616 // get the command enclosed in {}'s
1617 parse = 0;
1618 index = -1;
1619 for (i = 0; i < line_length; i++) {
1620 if (line[i] == '{') {
1621 index = 0;
1622 parse = 1;
1623 } else if (line[i] == '}') break;
1624 else if (index++ >= 0) {
1625 if (line[i] == '\\' && i < line_length - 1) i++;
1626 command[index - 1] = line[i];
1627 }
1628 }
1629
1630 if (parse) {
1631 command[index] = '\0';
1632 } else {
1633 command[0] = '\0';
1634 }
1635
1636 switch (key) {
1637 case 311: // end
1638 return ((menu->getCount() == 0) ? True : False);
1639
1640 break;
1641
1642 case 333: // nop
1643 if (! *label)
1644 label[0] = '\0';
1645 menu->insert(label);
1646
1647 break;
1648
1649 case 421: // exec
1650 if ((! *label) && (! *command)) {
1651 fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
1652 "BScreen::parseMenuFile: [exec] error, "
1653 "no menu label and/or command defined\n"));
1654 continue;
1655 }
1656
1657 menu->insert(label, BScreen::Execute, command);
1658
1659 break;
1660
1661 case 442: // exit
1662 if (! *label) {
1663 fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
1664 "BScreen::parseMenuFile: [exit] error, "
1665 "no menu label defined\n"));
1666 continue;
1667 }
1668
1669 menu->insert(label, BScreen::Exit);
1670
1671 break;
1672
1673 case 561: // style
1674 {
1675 if ((! *label) || (! *command)) {
1676 fprintf(stderr,
1677 i18n(ScreenSet, ScreenSTYLEError,
1678 "BScreen::parseMenuFile: [style] error, "
1679 "no menu label and/or filename defined\n"));
1680 continue;
1681 }
1682
1683 string style = expandTilde(command);
1684
1685 menu->insert(label, BScreen::SetStyle, style.c_str());
1686 }
1687
1688 break;
1689
1690 case 630: // config
1691 if (! *label) {
1692 fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
1693 "BScreen::parseMenufile: [config] error, "
1694 "no label defined"));
1695 continue;
1696 }
1697
1698 menu->insert(label, configmenu);
1699
1700 break;
1701
1702 case 740: // include
1703 {
1704 if (! *label) {
1705 fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
1706 "BScreen::parseMenuFile: [include] error, "
1707 "no filename defined\n"));
1708 continue;
1709 }
1710
1711 string newfile = expandTilde(label);
1712 FILE *submenufile = fopen(newfile.c_str(), "r");
1713
1714 if (submenufile) {
1715 struct stat buf;
1716 if (fstat(fileno(submenufile), &buf) ||
1717 (! S_ISREG(buf.st_mode))) {
1718 fprintf(stderr,
1719 i18n(ScreenSet, ScreenINCLUDEErrorReg,
1720 "BScreen::parseMenuFile: [include] error: "
1721 "'%s' is not a regular file\n"), newfile.c_str());
1722 break;
1723 }
1724
1725 if (! feof(submenufile)) {
1726 if (! parseMenuFile(submenufile, menu))
1727 blackbox->addMenuTimestamp(newfile);
1728
1729 fclose(submenufile);
1730 }
1731 } else {
1732 perror(newfile.c_str());
1733 }
1734 }
1735
1736 break;
1737
1738 case 767: // submenu
1739 {
1740 if (! *label) {
1741 fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
1742 "BScreen::parseMenuFile: [submenu] error, "
1743 "no menu label defined\n"));
1744 continue;
1745 }
1746
1747 Rootmenu *submenu = new Rootmenu(this);
1748
1749 if (*command)
1750 submenu->setLabel(command);
1751 else
1752 submenu->setLabel(label);
1753
1754 parseMenuFile(file, submenu);
1755 submenu->update();
1756 menu->insert(label, submenu);
1757 rootmenuList.push_back(submenu);
1758 }
1759
1760 break;
1761
1762 case 773: // restart
1763 {
1764 if (! *label) {
1765 fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
1766 "BScreen::parseMenuFile: [restart] error, "
1767 "no menu label defined\n"));
1768 continue;
1769 }
1770
1771 if (*command)
1772 menu->insert(label, BScreen::RestartOther, command);
1773 else
1774 menu->insert(label, BScreen::Restart);
1775 }
1776
1777 break;
1778
1779 case 845: // reconfig
1780 {
1781 if (! *label) {
1782 fprintf(stderr,
1783 i18n(ScreenSet, ScreenRECONFIGError,
1784 "BScreen::parseMenuFile: [reconfig] error, "
1785 "no menu label defined\n"));
1786 continue;
1787 }
1788
1789 menu->insert(label, BScreen::Reconfigure);
1790 }
1791
1792 break;
1793
1794 case 995: // stylesdir
1795 case 1113: // stylesmenu
1796 {
1797 bool newmenu = ((key == 1113) ? True : False);
1798
1799 if ((! *label) || ((! *command) && newmenu)) {
1800 fprintf(stderr,
1801 i18n(ScreenSet, ScreenSTYLESDIRError,
1802 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1803 " error, no directory defined\n"));
1804 continue;
1805 }
1806
1807 char *directory = ((newmenu) ? command : label);
1808
1809 string stylesdir = expandTilde(directory);
1810
1811 struct stat statbuf;
1812
1813 if (! stat(stylesdir.c_str(), &statbuf)) {
1814 if (S_ISDIR(statbuf.st_mode)) {
1815 Rootmenu *stylesmenu;
1816
1817 if (newmenu)
1818 stylesmenu = new Rootmenu(this);
1819 else
1820 stylesmenu = menu;
1821
1822 DIR *d = opendir(stylesdir.c_str());
1823 struct dirent *p;
1824 std::vector<string> ls;
1825
1826 while((p = readdir(d)))
1827 ls.push_back(p->d_name);
1828
1829 closedir(d);
1830
1831 std::sort(ls.begin(), ls.end());
1832
1833 std::vector<string>::iterator it = ls.begin(),
1834 end = ls.end();
1835 for (; it != end; ++it) {
1836 const string& fname = *it;
1837
1838 if (fname[fname.size()-1] == '~')
1839 continue;
1840
1841 string style = stylesdir;
1842 style += '/';
1843 style += fname;
1844
1845 if ((! stat(style.c_str(), &statbuf)) &&
1846 S_ISREG(statbuf.st_mode))
1847 stylesmenu->insert(fname, BScreen::SetStyle, style);
1848 }
1849
1850 stylesmenu->update();
1851
1852 if (newmenu) {
1853 stylesmenu->setLabel(label);
1854 menu->insert(label, stylesmenu);
1855 rootmenuList.push_back(stylesmenu);
1856 }
1857
1858 blackbox->addMenuTimestamp(stylesdir);
1859 } else {
1860 fprintf(stderr,
1861 i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
1862 "BScreen::parseMenuFile:"
1863 " [stylesdir/stylesmenu] error, %s is not a"
1864 " directory\n"), stylesdir.c_str());
1865 }
1866 } else {
1867 fprintf(stderr,
1868 i18n(ScreenSet, ScreenSTYLESDIRErrorNoExist,
1869 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1870 " error, %s does not exist\n"), stylesdir.c_str());
1871 }
1872 break;
1873 }
1874
1875 case 1090: // workspaces
1876 {
1877 if (! *label) {
1878 fprintf(stderr,
1879 i18n(ScreenSet, ScreenWORKSPACESError,
1880 "BScreen:parseMenuFile: [workspaces] error, "
1881 "no menu label defined\n"));
1882 continue;
1883 }
1884
1885 menu->insert(label, workspacemenu);
1886
1887 break;
1888 }
1889 }
1890 }
1891 }
1892 }
1893
1894 return ((menu->getCount() == 0) ? True : False);
1895 }
1896
1897
1898 void BScreen::shutdown(void) {
1899 XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
1900 XSync(blackbox->getXDisplay(), False);
1901
1902 while(! windowList.empty())
1903 unmanageWindow(windowList.front(), True);
1904
1905 slit->shutdown();
1906 }
1907
1908
1909 void BScreen::showPosition(int x, int y) {
1910 if (! geom_visible) {
1911 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1912 (getWidth() - geom_w) / 2,
1913 (getHeight() - geom_h) / 2, geom_w, geom_h);
1914 XMapWindow(blackbox->getXDisplay(), geom_window);
1915 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1916
1917 geom_visible = True;
1918 }
1919
1920 char label[1024];
1921
1922 sprintf(label, i18n(ScreenSet, ScreenPositionFormat,
1923 "X: %4d x Y: %4d"), x, y);
1924
1925 XClearWindow(blackbox->getXDisplay(), geom_window);
1926
1927 resource.wstyle.font->drawString(geom_window,
1928 resource.bevel_width, resource.bevel_width,
1929 resource.wstyle.l_text_focus,
1930 label);
1931 }
1932
1933
1934 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
1935 if (! geom_visible) {
1936 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1937 (getWidth() - geom_w) / 2,
1938 (getHeight() - geom_h) / 2, geom_w, geom_h);
1939 XMapWindow(blackbox->getXDisplay(), geom_window);
1940 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1941
1942 geom_visible = True;
1943 }
1944
1945 char label[1024];
1946
1947 sprintf(label, i18n(ScreenSet, ScreenGeometryFormat,
1948 "W: %4d x H: %4d"), gx, gy);
1949
1950 XClearWindow(blackbox->getXDisplay(), geom_window);
1951
1952 resource.wstyle.font->drawString(geom_window,
1953 resource.bevel_width, resource.bevel_width,
1954 resource.wstyle.l_text_focus,
1955 label);
1956 }
1957
1958
1959 void BScreen::hideGeometry(void) {
1960 if (geom_visible) {
1961 XUnmapWindow(blackbox->getXDisplay(), geom_window);
1962 geom_visible = False;
1963 }
1964 }
1965
1966
1967 void BScreen::addStrut(Strut *strut) {
1968 strutList.push_back(strut);
1969 }
1970
1971
1972 void BScreen::removeStrut(Strut *strut) {
1973 strutList.remove(strut);
1974 }
1975
1976
1977 const Rect& BScreen::availableArea(void) const {
1978 if (doFullMax())
1979 return getRect(); // return the full screen
1980 return usableArea;
1981 }
1982
1983
1984 void BScreen::updateAvailableArea(void) {
1985 Rect old_area = usableArea;
1986 usableArea = getRect(); // reset to full screen
1987
1988 /* these values represent offsets from the screen edge
1989 * we look for the biggest offset on each edge and then apply them
1990 * all at once
1991 * do not be confused by the similarity to the names of Rect's members
1992 */
1993 unsigned int current_left = 0, current_right = 0, current_top = 0,
1994 current_bottom = 0;
1995
1996 StrutList::const_iterator it = strutList.begin(), end = strutList.end();
1997
1998 for(; it != end; ++it) {
1999 Strut *strut = *it;
2000 if (strut->left > current_left)
2001 current_left = strut->left;
2002 if (strut->top > current_top)
2003 current_top = strut->top;
2004 if (strut->right > current_right)
2005 current_right = strut->right;
2006 if (strut->bottom > current_bottom)
2007 current_bottom = strut->bottom;
2008 }
2009
2010 usableArea.setPos(current_left, current_top);
2011 usableArea.setSize(usableArea.width() - (current_left + current_right),
2012 usableArea.height() - (current_top + current_bottom));
2013
2014 if (old_area != usableArea) {
2015 BlackboxWindowList::iterator it = windowList.begin(),
2016 end = windowList.end();
2017 for (; it != end; ++it)
2018 if ((*it)->isMaximized()) (*it)->remaximize();
2019 }
2020
2021 updateWorkArea();
2022 }
2023
2024
2025 Workspace* BScreen::getWorkspace(unsigned int index) {
2026 assert(index < workspacesList.size());
2027 return workspacesList[index];
2028 }
2029
2030
2031 void BScreen::buttonPressEvent(const XButtonEvent *xbutton) {
2032 if (xbutton->button == 1) {
2033 if (! isRootColormapInstalled())
2034 image_control->installRootColormap();
2035
2036 if (workspacemenu->isVisible())
2037 workspacemenu->hide();
2038
2039 if (rootmenu->isVisible())
2040 rootmenu->hide();
2041 } else if (xbutton->button == 2) {
2042 int mx = xbutton->x_root - (workspacemenu->getWidth() / 2);
2043 int my = xbutton->y_root - (workspacemenu->getTitleHeight() / 2);
2044
2045 if (mx < 0) mx = 0;
2046 if (my < 0) my = 0;
2047
2048 if (mx + workspacemenu->getWidth() > getWidth())
2049 mx = getWidth() - workspacemenu->getWidth() - getBorderWidth();
2050
2051 if (my + workspacemenu->getHeight() > getHeight())
2052 my = getHeight() - workspacemenu->getHeight() - getBorderWidth();
2053
2054 workspacemenu->move(mx, my);
2055
2056 if (! workspacemenu->isVisible()) {
2057 workspacemenu->removeParent();
2058 workspacemenu->show();
2059 }
2060 } else if (xbutton->button == 3) {
2061 int mx = xbutton->x_root - (rootmenu->getWidth() / 2);
2062 int my = xbutton->y_root - (rootmenu->getTitleHeight() / 2);
2063
2064 if (mx < 0) mx = 0;
2065 if (my < 0) my = 0;
2066
2067 if (mx + rootmenu->getWidth() > getWidth())
2068 mx = getWidth() - rootmenu->getWidth() - getBorderWidth();
2069
2070 if (my + rootmenu->getHeight() > getHeight())
2071 my = getHeight() - rootmenu->getHeight() - getBorderWidth();
2072
2073 rootmenu->move(mx, my);
2074
2075 if (! rootmenu->isVisible()) {
2076 blackbox->checkMenu();
2077 rootmenu->show();
2078 }
2079 // mouse wheel up
2080 } else if (xbutton->button == 4) {
2081 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2082 changeWorkspaceID(0);
2083 else
2084 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2085 // mouse wheel down
2086 } else if (xbutton->button == 5) {
2087 if (getCurrentWorkspaceID() == 0)
2088 changeWorkspaceID(getWorkspaceCount() - 1);
2089 else
2090 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2091 }
2092 }
2093
2094
2095 void BScreen::toggleFocusModel(FocusModel model) {
2096 std::for_each(windowList.begin(), windowList.end(),
2097 std::mem_fun(&BlackboxWindow::ungrabButtons));
2098
2099 if (model == SloppyFocus) {
2100 saveSloppyFocus(True);
2101 } else {
2102 // we're cheating here to save writing the config file 3 times
2103 resource.auto_raise = False;
2104 resource.click_raise = False;
2105 saveSloppyFocus(False);
2106 }
2107
2108 std::for_each(windowList.begin(), windowList.end(),
2109 std::mem_fun(&BlackboxWindow::grabButtons));
2110 }
2111
2112
2113 BTexture BScreen::readDatabaseTexture(const string &rname,
2114 const string &default_color,
2115 const Configuration &style) {
2116 BTexture texture;
2117 string s;
2118
2119 if (style.getValue(rname, s))
2120 texture = BTexture(s);
2121 else
2122 texture.setTexture(BTexture::Solid | BTexture::Flat);
2123
2124 // associate this texture with this screen
2125 texture.setDisplay(getBaseDisplay(), getScreenNumber());
2126 texture.setImageControl(image_control);
2127
2128 if (texture.texture() & BTexture::Solid) {
2129 texture.setColor(readDatabaseColor(rname + ".color",
2130 default_color, style));
2131 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2132 default_color, style));
2133 } else if (texture.texture() & BTexture::Gradient) {
2134 texture.setColor(readDatabaseColor(rname + ".color",
2135 default_color, style));
2136 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2137 default_color, style));
2138 }
2139
2140 return texture;
2141 }
2142
2143
2144 BColor BScreen::readDatabaseColor(const string &rname,
2145 const string &default_color,
2146 const Configuration &style) {
2147 BColor color;
2148 string s;
2149 if (style.getValue(rname, s))
2150 color = BColor(s, getBaseDisplay(), getScreenNumber());
2151 else
2152 color = BColor(default_color, getBaseDisplay(), getScreenNumber());
2153 return color;
2154 }
2155
2156
2157 BFont *BScreen::readDatabaseFont(const string &rbasename,
2158 const Configuration &style) {
2159 string fontname;
2160
2161 string s;
2162
2163 #ifdef XFT
2164 int i;
2165 if (style.getValue(rbasename + "xft.font", s) &&
2166 style.getValue(rbasename + "xft.size", i)) {
2167 string family = s;
2168 bool bold = False;
2169 bool italic = False;
2170 if (style.getValue(rbasename + "xft.flags", s)) {
2171 if (s.find("bold") != string::npos)
2172 bold = True;
2173 if (s.find("italic") != string::npos)
2174 italic = True;
2175 }
2176
2177 BFont *b = new BFont(blackbox->getXDisplay(), this, family, i, bold,
2178 italic, resource.aa_fonts);
2179 if (b->valid())
2180 return b;
2181 else
2182 delete b; // fall back to the normal X font stuff
2183 }
2184 #endif // XFT
2185
2186 style.getValue(rbasename + "font", s);
2187 // if this fails, a blank string will be used, which will cause the fallback
2188 // font to load.
2189
2190 BFont *b = new BFont(blackbox->getXDisplay(), this, s);
2191 if (! b->valid())
2192 exit(2); // can't continue without a font
2193 return b;
2194 }
This page took 0.134166 seconds and 5 git commands to generate.