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