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