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