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