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