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