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