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