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