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