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