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