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)
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:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
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.
25 #include "../config.h"
26 #endif // HAVE_CONFIG_H
29 #include <X11/Xatom.h>
30 #include <X11/keysym.h>
34 #endif // HAVE_STDLIB_H
38 #endif // HAVE_STRING_H
42 #endif // HAVE_CTYPE_H
45 # include <sys/types.h>
47 #endif // HAVE_UNISTD_H
51 #endif // HAVE_DIRENT_H
55 #endif // HAVE_LOCALE_H
57 #ifdef HAVE_SYS_STAT_H
58 # include <sys/stat.h>
59 #endif // HAVE_SYS_STAT_H
63 #endif // HAVE_STDARG_H
74 #include "blackbox.hh"
75 #include "Clientmenu.hh"
78 #include "Iconmenu.hh"
82 #include "Rootmenu.hh"
86 #include "Workspace.hh"
87 #include "Workspacemenu.hh"
91 #ifndef FONT_ELEMENT_SIZE
92 #define FONT_ELEMENT_SIZE 50
93 #endif // FONT_ELEMENT_SIZE
96 static bool running = True;
98 static int anotherWMRunning(Display *display, XErrorEvent *) {
99 fprintf(stderr, i18n(ScreenSet, ScreenAnotherWMRunning,
100 "BScreen::BScreen: an error occured while querying the X server.\n"
101 " another window manager already running on display %s.\n"),
102 DisplayString(display));
110 BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
112 screenstr = "session.screen" + itostring(scrn) + '.';
113 config = blackbox->getConfig();
114 xatom = blackbox->getXAtom();
116 event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
117 SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask;
119 XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
120 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask);
121 XSync(getBaseDisplay()->getXDisplay(), False);
122 XSetErrorHandler((XErrorHandler) old);
125 if (! managed) return;
127 fprintf(stderr, i18n(ScreenSet, ScreenManagingScreen,
128 "BScreen::BScreen: managing screen %d "
129 "using visual 0x%lx, depth %d\n"),
130 getScreenNumber(), XVisualIDFromVisual(getVisual()),
135 resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
136 resource.wstyle.font = (BFont *) 0;
140 xatom->setSupported(this); // set-up netwm support
142 xatom->setValue(getRootWindow(), XAtom::blackbox_pid, XAtom::cardinal,
143 (unsigned long) getpid());
144 #endif // HAVE_GETPID
145 unsigned long geometry[] = { getWidth(),
147 xatom->setValue(getRootWindow(), XAtom::net_desktop_geometry,
148 XAtom::cardinal, geometry, 2);
149 unsigned long viewport[] = {0,0};
150 xatom->setValue(getRootWindow(), XAtom::net_desktop_viewport,
151 XAtom::cardinal, viewport, 2);
154 XDefineCursor(blackbox->getXDisplay(), getRootWindow(),
155 blackbox->getSessionCursor());
157 // start off full screen, top left.
158 usableArea.setSize(getWidth(), getHeight());
161 new BImageControl(blackbox, this, True, blackbox->getColorsPerChannel(),
162 blackbox->getCacheLife(), blackbox->getCacheMax());
163 image_control->installRootColormap();
164 root_colormap_installed = True;
170 gcv.foreground = WhitePixel(blackbox->getXDisplay(), getScreenNumber())
171 ^ BlackPixel(blackbox->getXDisplay(), getScreenNumber());
172 gcv.function = GXxor;
173 gcv.subwindow_mode = IncludeInferiors;
174 opGC = XCreateGC(blackbox->getXDisplay(), getRootWindow(),
175 GCForeground | GCFunction | GCSubwindowMode, &gcv);
177 const char *s = i18n(ScreenSet, ScreenPositionLength,
178 "0: 0000 x 0: 0000");
179 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
180 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
182 XSetWindowAttributes attrib;
183 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
184 attrib.border_pixel = getBorderColor()->pixel();
185 attrib.colormap = getColormap();
186 attrib.save_under = True;
188 geom_window = XCreateWindow(blackbox->getXDisplay(), getRootWindow(),
189 0, 0, geom_w, geom_h, resource.border_width,
190 getDepth(), InputOutput, getVisual(),
192 geom_visible = False;
194 BTexture* texture = &(resource.wstyle.l_focus);
195 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
196 if (geom_pixmap == ParentRelative) {
197 texture = &(resource.wstyle.t_focus);
198 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
201 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
202 texture->color().pixel());
204 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
205 geom_window, geom_pixmap);
207 workspacemenu = new Workspacemenu(this);
208 iconmenu = new Iconmenu(this);
209 configmenu = new Configmenu(this);
211 if (resource.workspaces != 0) {
212 for (unsigned int i = 0; i < resource.workspaces; ++i) {
213 Workspace *wkspc = new Workspace(this, workspacesList.size());
214 workspacesList.push_back(wkspc);
215 workspacemenu->insertWorkspace(wkspc);
216 workspacemenu->update();
220 Workspace *wkspc = new Workspace(this, workspacesList.size());
221 workspacesList.push_back(wkspc);
222 workspacemenu->insertWorkspace(wkspc);
223 workspacemenu->update();
225 saveWorkspaceNames();
227 updateNetizenWorkspaceCount();
229 workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
230 workspacemenu->update();
232 current_workspace = workspacesList.front();
234 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
235 XAtom::cardinal, 0); //first workspace
237 workspacemenu->setItemSelected(2, True);
239 toolbar = new Toolbar(this);
241 slit = new Slit(this);
245 raiseWindows(0, 0); // this also initializes the empty stacking list
248 updateClientList(); // initialize the client lists, which will be empty
249 updateAvailableArea();
251 changeWorkspaceID(0);
253 unsigned int i, j, nchild;
254 Window r, p, *children;
255 XQueryTree(blackbox->getXDisplay(), getRootWindow(), &r, &p,
258 // preen the window list of all icon windows... for better dockapp support
259 for (i = 0; i < nchild; i++) {
260 if (children[i] == None) continue;
262 XWMHints *wmhints = XGetWMHints(blackbox->getXDisplay(),
266 if ((wmhints->flags & IconWindowHint) &&
267 (wmhints->icon_window != children[i])) {
268 for (j = 0; j < nchild; j++) {
269 if (children[j] == wmhints->icon_window) {
280 // manage shown windows
281 for (i = 0; i < nchild; ++i) {
282 if (children[i] == None || (! blackbox->validateWindow(children[i])))
285 XWindowAttributes attrib;
286 if (XGetWindowAttributes(blackbox->getXDisplay(), children[i], &attrib)) {
287 if (attrib.override_redirect) continue;
289 if (attrib.map_state != IsUnmapped) {
290 manageWindow(children[i]);
297 // call this again just in case a window we found updates the Strut list
298 updateAvailableArea();
302 BScreen::~BScreen(void) {
303 if (! managed) return;
305 if (geom_pixmap != None)
306 image_control->removeImage(geom_pixmap);
308 if (geom_window != None)
309 XDestroyWindow(blackbox->getXDisplay(), geom_window);
311 std::for_each(workspacesList.begin(), workspacesList.end(),
314 std::for_each(iconList.begin(), iconList.end(), PointerAssassin());
316 std::for_each(netizenList.begin(), netizenList.end(), PointerAssassin());
318 while (! systrayWindowList.empty())
319 removeSystrayWindow(systrayWindowList[0]);
322 delete workspacemenu;
327 delete image_control;
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;
338 XFreeGC(blackbox->getXDisplay(), opGC);
342 void BScreen::saveSloppyFocus(bool s) {
343 resource.sloppy_focus = s;
346 if (resource.sloppy_focus) {
347 fmodel = "SloppyFocus";
348 if (resource.auto_raise) fmodel += " AutoRaise";
349 if (resource.click_raise) fmodel += " ClickRaise";
351 fmodel = "ClickToFocus";
353 config->setValue(screenstr + "focusModel", fmodel);
357 void BScreen::saveAutoRaise(bool a) {
358 resource.auto_raise = a;
359 saveSloppyFocus(resource.sloppy_focus);
363 void BScreen::saveClickRaise(bool c) {
364 resource.click_raise = c;
365 saveSloppyFocus(resource.sloppy_focus);
369 void BScreen::saveImageDither(bool d) {
370 image_control->setDither(d);
371 config->setValue(screenstr + "imageDither", doImageDither());
375 void BScreen::saveOpaqueMove(bool o) {
376 resource.opaque_move = o;
377 config->setValue(screenstr + "opaqueMove", resource.opaque_move);
381 void BScreen::saveFullMax(bool f) {
382 resource.full_max = f;
383 config->setValue(screenstr + "fullMaximization", resource.full_max);
387 void BScreen::saveFocusNew(bool f) {
388 resource.focus_new = f;
389 config->setValue(screenstr + "focusNewWindows", resource.focus_new);
393 void BScreen::saveFocusLast(bool f) {
394 resource.focus_last = f;
395 config->setValue(screenstr + "focusLastWindow", resource.focus_last);
399 void BScreen::saveAAFonts(bool f) {
400 resource.aa_fonts = f;
402 config->setValue(screenstr + "antialiasFonts", resource.aa_fonts);
406 void BScreen::saveHideToolbar(bool h) {
407 resource.hide_toolbar = h;
408 if (resource.hide_toolbar)
409 toolbar->unmapToolbar();
411 toolbar->mapToolbar();
412 config->setValue(screenstr + "hideToolbar", resource.hide_toolbar);
416 void BScreen::saveWindowToWindowSnap(bool s) {
417 resource.window_to_window_snap = s;
418 config->setValue(screenstr + "windowToWindowSnap",
419 resource.window_to_window_snap);
423 void BScreen::saveResizeZones(unsigned int z) {
424 resource.resize_zones = z;
425 config->setValue(screenstr + "resizeZones", resource.resize_zones);
429 void BScreen::saveWindowCornerSnap(bool s) {
430 resource.window_corner_snap = s;
431 config->setValue(screenstr + "windowCornerSnap",
432 resource.window_corner_snap);
436 void BScreen::saveWorkspaces(unsigned int w) {
437 resource.workspaces = w;
438 config->setValue(screenstr + "workspaces", resource.workspaces);
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;
452 config->setValue(screenstr + "windowPlacement", placement);
456 void BScreen::saveEdgeSnapThreshold(int t) {
457 resource.edge_snap_threshold = t;
458 config->setValue(screenstr + "edgeSnapThreshold",
459 resource.edge_snap_threshold);
463 void BScreen::saveRowPlacementDirection(int d) {
464 resource.row_direction = d;
465 config->setValue(screenstr + "rowPlacementDirection",
466 resource.row_direction == LeftRight ?
467 "LeftToRight" : "RightToLeft");
471 void BScreen::saveColPlacementDirection(int d) {
472 resource.col_direction = d;
473 config->setValue(screenstr + "colPlacementDirection",
474 resource.col_direction == TopBottom ?
475 "TopToBottom" : "BottomToTop");
480 void BScreen::saveStrftimeFormat(const std::string& format) {
481 resource.strftime_format = format;
482 config->setValue(screenstr + "strftimeFormat", resource.strftime_format);
485 #else // !HAVE_STRFTIME
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");
495 void BScreen::saveClock24Hour(bool c) {
496 resource.clock24hour = c;
497 config->setValue(screenstr + "clockFormat", resource.clock24hour ? 24 : 12);
499 #endif // HAVE_STRFTIME
502 void BScreen::saveWorkspaceNames() {
505 for (unsigned int i = 0; i < workspacesList.size(); ++i) {
506 names += workspacesList[i]->getName();
507 if (i < workspacesList.size() - 1)
511 config->setValue(screenstr + "workspaceNames", names);
515 void BScreen::savePlaceIgnoreShaded(bool i) {
516 resource.ignore_shaded = i;
517 config->setValue(screenstr + "placementIgnoreShaded",
518 resource.ignore_shaded);
522 void BScreen::savePlaceIgnoreMaximized(bool i) {
523 resource.ignore_maximized = i;
524 config->setValue(screenstr + "placementIgnoreMaximized",
525 resource.ignore_maximized);
529 void BScreen::saveAllowScrollLock(bool a) {
530 resource.allow_scroll_lock = a;
531 config->setValue(screenstr + "disableBindingsWithScrollLock",
532 resource.allow_scroll_lock);
536 void BScreen::save_rc(void) {
537 saveSloppyFocus(resource.sloppy_focus);
538 saveAutoRaise(resource.auto_raise);
539 saveImageDither(doImageDither());
540 saveAAFonts(resource.aa_fonts);
541 saveResizeZones(resource.resize_zones);
542 saveOpaqueMove(resource.opaque_move);
543 saveFullMax(resource.full_max);
544 saveFocusNew(resource.focus_new);
545 saveFocusLast(resource.focus_last);
546 saveHideToolbar(resource.hide_toolbar);
547 saveWindowToWindowSnap(resource.window_to_window_snap);
548 saveWindowCornerSnap(resource.window_corner_snap);
549 saveWorkspaces(resource.workspaces);
550 savePlacementPolicy(resource.placement_policy);
551 saveEdgeSnapThreshold(resource.edge_snap_threshold);
552 saveRowPlacementDirection(resource.row_direction);
553 saveColPlacementDirection(resource.col_direction);
555 saveStrftimeFormat(resource.strftime_format);
556 #else // !HAVE_STRFTIME
557 saveDateFormat(resource.date_format);
558 savwClock24Hour(resource.clock24hour);
559 #endif // HAVE_STRFTIME
560 savePlaceIgnoreShaded(resource.ignore_shaded);
561 savePlaceIgnoreMaximized(resource.ignore_maximized);
562 saveAllowScrollLock(resource.allow_scroll_lock);
569 void BScreen::load_rc(void) {
573 if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
574 resource.full_max = false;
576 if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
577 resource.focus_new = false;
579 if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
580 resource.focus_last = false;
582 if (! config->getValue(screenstr + "workspaces", resource.workspaces))
583 resource.workspaces = 1;
585 if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
586 resource.opaque_move = false;
588 if (! config->getValue(screenstr + "antialiasFonts", resource.aa_fonts))
589 resource.aa_fonts = true;
591 if (! config->getValue(screenstr + "resizeZones", resource.resize_zones) ||
592 (resource.resize_zones != 1 && resource.resize_zones != 2 &&
593 resource.resize_zones != 4))
594 resource.resize_zones = 4;
596 if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
597 resource.hide_toolbar = false;
599 if (! config->getValue(screenstr + "windowToWindowSnap",
600 resource.window_to_window_snap))
601 resource.window_to_window_snap = true;
603 if (! config->getValue(screenstr + "windowCornerSnap",
604 resource.window_corner_snap))
605 resource.window_corner_snap = true;
607 if (! config->getValue(screenstr + "imageDither", b))
609 image_control->setDither(b);
611 if (! config->getValue(screenstr + "edgeSnapThreshold",
612 resource.edge_snap_threshold))
613 resource.edge_snap_threshold = 4;
615 if (config->getValue(screenstr + "rowPlacementDirection", s) &&
617 resource.row_direction = RightLeft;
619 resource.row_direction = LeftRight;
621 if (config->getValue(screenstr + "colPlacementDirection", s) &&
623 resource.col_direction = BottomTop;
625 resource.col_direction = TopBottom;
627 if (config->getValue(screenstr + "workspaceNames", s)) {
628 XAtom::StringVect workspaceNames;
630 string::const_iterator it = s.begin(), end = s.end();
632 string::const_iterator tmp = it; // current string.begin()
633 it = std::find(tmp, end, ','); // look for comma between tmp and end
634 workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
640 xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
644 resource.sloppy_focus = true;
645 resource.auto_raise = false;
646 resource.click_raise = false;
647 if (config->getValue(screenstr + "focusModel", s)) {
648 if (s.find("ClickToFocus") != string::npos) {
649 resource.sloppy_focus = false;
652 if (s.find("AutoRaise") != string::npos)
653 resource.auto_raise = true;
654 if (s.find("ClickRaise") != string::npos)
655 resource.click_raise = true;
659 if (config->getValue(screenstr + "windowPlacement", s)) {
660 if (s == "CascadePlacement")
661 resource.placement_policy = CascadePlacement;
662 else if (s == "UnderMousePlacement")
663 resource.placement_policy = UnderMousePlacement;
664 else if (s == "ClickMousePlacement")
665 resource.placement_policy = ClickMousePlacement;
666 else if (s == "ColSmartPlacement")
667 resource.placement_policy = ColSmartPlacement;
668 else //if (s == "RowSmartPlacement")
669 resource.placement_policy = RowSmartPlacement;
671 resource.placement_policy = RowSmartPlacement;
674 if (! config->getValue(screenstr + "strftimeFormat",
675 resource.strftime_format))
676 resource.strftime_format = "%I:%M %p";
677 #else // !HAVE_STRFTIME
680 if (config->getValue(screenstr + "dateFormat", s) && s == "European")
681 resource.date_format = B_EuropeanDate;
683 resource.date_format = B_AmericanDate;
685 if (! config->getValue(screenstr + "clockFormat", l))
687 resource.clock24hour = l == 24;
688 #endif // HAVE_STRFTIME
690 if (! config->getValue(screenstr + "placementIgnoreShaded",
691 resource.ignore_shaded))
692 resource.ignore_shaded = true;
694 if (! config->getValue(screenstr + "placementIgnoreMaximized",
695 resource.ignore_maximized))
696 resource.ignore_maximized = true;
698 if (! config->getValue(screenstr + "disableBindingsWithScrollLock",
699 resource.allow_scroll_lock))
700 resource.allow_scroll_lock = false;
704 void BScreen::changeWorkspaceCount(unsigned int new_count) {
705 assert(new_count > 0);
707 if (new_count < workspacesList.size()) {
709 for (unsigned int i = workspacesList.size(); i > new_count; --i)
710 removeLastWorkspace();
711 // removeLast already sets the current workspace to the
712 // last available one.
713 } else if (new_count > workspacesList.size()) {
715 for(unsigned int i = workspacesList.size(); i < new_count; ++i)
721 void BScreen::reconfigure(void) {
722 // don't reconfigure while saving the initial rc file, it's a waste and it
723 // breaks somethings (workspace names)
724 if (blackbox->isStartup()) return;
731 // we need to do this explicitly, because just loading this value from the rc
733 changeWorkspaceCount(resource.workspaces);
736 gcv.foreground = WhitePixel(blackbox->getXDisplay(),
738 gcv.function = GXinvert;
739 gcv.subwindow_mode = IncludeInferiors;
740 XChangeGC(blackbox->getXDisplay(), opGC,
741 GCForeground | GCFunction | GCSubwindowMode, &gcv);
743 const char *s = i18n(ScreenSet, ScreenPositionLength,
744 "0: 0000 x 0: 0000");
746 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
747 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
749 BTexture* texture = &(resource.wstyle.l_focus);
750 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
751 if (geom_pixmap == ParentRelative) {
752 texture = &(resource.wstyle.t_focus);
753 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
756 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
757 texture->color().pixel());
759 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
760 geom_window, geom_pixmap);
762 XSetWindowBorderWidth(blackbox->getXDisplay(), geom_window,
763 resource.border_width);
764 XSetWindowBorder(blackbox->getXDisplay(), geom_window,
765 resource.border_color.pixel());
767 workspacemenu->reconfigure();
768 iconmenu->reconfigure();
770 typedef std::vector<int> SubList;
771 SubList remember_subs;
773 // save the current open menus
774 Basemenu *menu = rootmenu;
776 while ((submenu = menu->getCurrentSubmenu()) >= 0) {
777 remember_subs.push_back(submenu);
778 menu = menu->find(submenu)->submenu();
784 rootmenu->reconfigure();
786 // reopen the saved menus
788 const SubList::iterator subs_end = remember_subs.end();
789 for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
790 menu->drawSubmenu(*it);
791 menu = menu->find(*it)->submenu();
796 configmenu->reconfigure();
798 toolbar->reconfigure();
802 std::for_each(workspacesList.begin(), workspacesList.end(),
803 std::mem_fun(&Workspace::reconfigure));
805 BlackboxWindowList::iterator iit = iconList.begin();
806 for (; iit != iconList.end(); ++iit) {
807 BlackboxWindow *bw = *iit;
808 if (bw->validateClient())
812 image_control->timeout();
816 void BScreen::rereadMenu(void) {
820 rootmenu->reconfigure();
824 void BScreen::LoadStyle(void) {
825 Configuration style(False);
827 const char *sfile = blackbox->getStyleFilename();
829 style.setFile(sfile);
830 if (! style.load()) {
831 style.setFile(DEFAULTSTYLE);
833 style.create(); // hardcoded default values will be used.
837 // merge in the rc file
838 style.merge(config->file(), True);
842 // load fonts/fontsets
843 if (resource.wstyle.font)
844 delete resource.wstyle.font;
845 if (resource.tstyle.font)
846 delete resource.tstyle.font;
847 if (resource.mstyle.f_font)
848 delete resource.mstyle.f_font;
849 if (resource.mstyle.t_font)
850 delete resource.mstyle.t_font;
851 resource.wstyle.font = resource.tstyle.font = resource.mstyle.f_font =
852 resource.mstyle.t_font = (BFont *) 0;
854 resource.wstyle.font = readDatabaseFont("window.", style);
855 resource.tstyle.font = readDatabaseFont("toolbar.", style);
856 resource.mstyle.t_font = readDatabaseFont("menu.title.", style);
857 resource.mstyle.f_font = readDatabaseFont("menu.frame.", style);
859 // load window config
860 resource.wstyle.t_focus =
861 readDatabaseTexture("window.title.focus", "white", style);
862 resource.wstyle.t_unfocus =
863 readDatabaseTexture("window.title.unfocus", "black", style);
864 resource.wstyle.l_focus =
865 readDatabaseTexture("window.label.focus", "white", style);
866 resource.wstyle.l_unfocus =
867 readDatabaseTexture("window.label.unfocus", "black", style);
868 resource.wstyle.h_focus =
869 readDatabaseTexture("window.handle.focus", "white", style);
870 resource.wstyle.h_unfocus =
871 readDatabaseTexture("window.handle.unfocus", "black", style);
872 resource.wstyle.g_focus =
873 readDatabaseTexture("window.grip.focus", "white", style);
874 resource.wstyle.g_unfocus =
875 readDatabaseTexture("window.grip.unfocus", "black", style);
876 resource.wstyle.b_focus =
877 readDatabaseTexture("window.button.focus", "white", style);
878 resource.wstyle.b_unfocus =
879 readDatabaseTexture("window.button.unfocus", "black", style);
880 resource.wstyle.b_pressed =
881 readDatabaseTexture("window.button.pressed", "black", style);
882 resource.wstyle.f_focus =
883 readDatabaseColor("window.frame.focusColor", "white", style);
884 resource.wstyle.f_unfocus =
885 readDatabaseColor("window.frame.unfocusColor", "black", style);
886 resource.wstyle.l_text_focus =
887 readDatabaseColor("window.label.focus.textColor", "black", style);
888 resource.wstyle.l_text_unfocus =
889 readDatabaseColor("window.label.unfocus.textColor", "white", style);
890 resource.wstyle.b_pic_focus =
891 readDatabaseColor("window.button.focus.picColor", "black", style);
892 resource.wstyle.b_pic_unfocus =
893 readDatabaseColor("window.button.unfocus.picColor", "white", style);
895 resource.wstyle.justify = LeftJustify;
896 if (style.getValue("window.justify", s)) {
897 if (s == "right" || s == "Right")
898 resource.wstyle.justify = RightJustify;
899 else if (s == "center" || s == "Center")
900 resource.wstyle.justify = CenterJustify;
903 // load toolbar config
904 resource.tstyle.toolbar =
905 readDatabaseTexture("toolbar", "black", style);
906 resource.tstyle.label =
907 readDatabaseTexture("toolbar.label", "black", style);
908 resource.tstyle.window =
909 readDatabaseTexture("toolbar.windowLabel", "black", style);
910 resource.tstyle.button =
911 readDatabaseTexture("toolbar.button", "white", style);
912 resource.tstyle.pressed =
913 readDatabaseTexture("toolbar.button.pressed", "black", style);
914 resource.tstyle.clock =
915 readDatabaseTexture("toolbar.clock", "black", style);
916 resource.tstyle.l_text =
917 readDatabaseColor("toolbar.label.textColor", "white", style);
918 resource.tstyle.w_text =
919 readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
920 resource.tstyle.c_text =
921 readDatabaseColor("toolbar.clock.textColor", "white", style);
922 resource.tstyle.b_pic =
923 readDatabaseColor("toolbar.button.picColor", "black", style);
925 resource.tstyle.justify = LeftJustify;
926 if (style.getValue("toolbar.justify", s)) {
927 if (s == "right" || s == "Right")
928 resource.tstyle.justify = RightJustify;
929 else if (s == "center" || s == "Center")
930 resource.tstyle.justify = CenterJustify;
934 resource.mstyle.title =
935 readDatabaseTexture("menu.title", "white", style);
936 resource.mstyle.frame =
937 readDatabaseTexture("menu.frame", "black", style);
938 resource.mstyle.hilite =
939 readDatabaseTexture("menu.hilite", "white", style);
940 resource.mstyle.t_text =
941 readDatabaseColor("menu.title.textColor", "black", style);
942 resource.mstyle.f_text =
943 readDatabaseColor("menu.frame.textColor", "white", style);
944 resource.mstyle.d_text =
945 readDatabaseColor("menu.frame.disableColor", "black", style);
946 resource.mstyle.h_text =
947 readDatabaseColor("menu.hilite.textColor", "black", style);
949 resource.mstyle.t_justify = LeftJustify;
950 if (style.getValue("menu.title.justify", s)) {
951 if (s == "right" || s == "Right")
952 resource.mstyle.t_justify = RightJustify;
953 else if (s == "center" || s == "Center")
954 resource.mstyle.t_justify = CenterJustify;
957 resource.mstyle.f_justify = LeftJustify;
958 if (style.getValue("menu.frame.justify", s)) {
959 if (s == "right" || s == "Right")
960 resource.mstyle.f_justify = RightJustify;
961 else if (s == "center" || s == "Center")
962 resource.mstyle.f_justify = CenterJustify;
965 resource.mstyle.bullet = Basemenu::Triangle;
966 if (style.getValue("menu.bullet", s)) {
967 if (s == "empty" || s == "Empty")
968 resource.mstyle.bullet = Basemenu::Empty;
969 else if (s == "square" || s == "Square")
970 resource.mstyle.bullet = Basemenu::Square;
971 else if (s == "diamond" || s == "Diamond")
972 resource.mstyle.bullet = Basemenu::Diamond;
975 resource.mstyle.bullet_pos = Basemenu::Left;
976 if (style.getValue("menu.bullet.position", s)) {
977 if (s == "right" || s == "Right")
978 resource.mstyle.bullet_pos = Basemenu::Right;
981 resource.border_color =
982 readDatabaseColor("borderColor", "black", style);
984 // load bevel, border and handle widths
985 if (! style.getValue("handleWidth", resource.handle_width) ||
986 resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
987 resource.handle_width = 6;
989 if (! style.getValue("borderWidth", resource.border_width))
990 resource.border_width = 1;
992 if (! style.getValue("bevelWidth", resource.bevel_width) ||
993 resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
994 resource.bevel_width = 3;
996 if (! style.getValue("frameWidth", resource.frame_width) ||
997 resource.frame_width > (getWidth() / 2))
998 resource.frame_width = resource.bevel_width;
1000 if (style.getValue("rootCommand", s))
1001 bexec(s, displayString());
1005 void BScreen::addIcon(BlackboxWindow *w) {
1008 w->setWorkspace(BSENTINEL);
1009 w->setWindowNumber(iconList.size());
1011 iconList.push_back(w);
1013 const char* title = w->getIconTitle();
1014 iconmenu->insert(title);
1019 void BScreen::removeIcon(BlackboxWindow *w) {
1024 iconmenu->remove(w->getWindowNumber());
1027 BlackboxWindowList::iterator it = iconList.begin(),
1028 end = iconList.end();
1029 for (int i = 0; it != end; ++it)
1030 (*it)->setWindowNumber(i++);
1034 BlackboxWindow *BScreen::getIcon(unsigned int index) {
1035 if (index < iconList.size()) {
1036 BlackboxWindowList::iterator it = iconList.begin();
1037 for (; index > 0; --index, ++it) ; /* increment to index */
1041 return (BlackboxWindow *) 0;
1045 unsigned int BScreen::addWorkspace(void) {
1046 Workspace *wkspc = new Workspace(this, workspacesList.size());
1047 workspacesList.push_back(wkspc);
1048 saveWorkspaces(getWorkspaceCount());
1049 saveWorkspaceNames();
1051 workspacemenu->insertWorkspace(wkspc);
1052 workspacemenu->update();
1054 toolbar->reconfigure();
1056 updateNetizenWorkspaceCount();
1058 return workspacesList.size();
1062 unsigned int BScreen::removeLastWorkspace(void) {
1063 if (workspacesList.size() == 1)
1066 Workspace *wkspc = workspacesList.back();
1068 if (current_workspace->getID() == wkspc->getID())
1069 changeWorkspaceID(current_workspace->getID() - 1);
1073 workspacemenu->removeWorkspace(wkspc);
1074 workspacemenu->update();
1076 workspacesList.pop_back();
1079 saveWorkspaces(getWorkspaceCount());
1080 saveWorkspaceNames();
1082 toolbar->reconfigure();
1084 updateNetizenWorkspaceCount();
1086 return workspacesList.size();
1090 void BScreen::changeWorkspaceID(unsigned int id) {
1091 if (! current_workspace || id == current_workspace->getID()) return;
1093 BlackboxWindow *focused = blackbox->getFocusedWindow();
1094 if (focused && focused->getScreen() == this) {
1095 assert(focused->isStuck() ||
1096 focused->getWorkspaceNumber() == current_workspace->getID());
1098 current_workspace->setLastFocusedWindow(focused);
1100 // if no window had focus, no need to store a last focus
1101 current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
1104 // when we switch workspaces, unfocus whatever was focused
1105 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1107 current_workspace->hideAll();
1108 workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1110 current_workspace = getWorkspace(id);
1112 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
1113 XAtom::cardinal, id);
1115 workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1116 toolbar->redrawWorkspaceLabel(True);
1118 current_workspace->showAll();
1120 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1121 XSync(blackbox->getXDisplay(), False);
1122 current_workspace->getLastFocusedWindow()->setInputFocus();
1125 updateNetizenCurrentWorkspace();
1130 * Set the _NET_CLIENT_LIST root window property.
1132 void BScreen::updateClientList(void) {
1133 if (windowList.size() > 0) {
1134 Window *windows = new Window[windowList.size()];
1135 Window *win_it = windows;
1136 BlackboxWindowList::iterator it = windowList.begin();
1137 const BlackboxWindowList::iterator end = windowList.end();
1138 for (; it != end; ++it, ++win_it)
1139 *win_it = (*it)->getClientWindow();
1140 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1141 windows, windowList.size());
1144 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1147 updateStackingList();
1152 * Set the _NET_CLIENT_LIST_STACKING root window property.
1154 void BScreen::updateStackingList(void) {
1156 BlackboxWindowList stack_order;
1159 * Get the stacking order from all of the workspaces.
1160 * We start with the current workspace so that the sticky windows will be
1161 * in the right order on the current workspace.
1162 * XXX: Do we need to have sticky windows in the list once for each workspace?
1164 getCurrentWorkspace()->appendStackOrder(stack_order);
1165 for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
1166 if (i != getCurrentWorkspaceID())
1167 getWorkspace(i)->appendStackOrder(stack_order);
1169 if (stack_order.size() > 0) {
1170 // set the client list atoms
1171 Window *windows = new Window[stack_order.size()];
1172 Window *win_it = windows;
1173 BlackboxWindowList::iterator it = stack_order.begin(),
1174 end = stack_order.end();
1175 for (; it != end; ++it, ++win_it)
1176 *win_it = (*it)->getClientWindow();
1177 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1178 XAtom::window, windows, stack_order.size());
1181 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1182 XAtom::window, 0, 0);
1186 void BScreen::addSystrayWindow(Window window) {
1187 systrayWindowList.push_back(window);
1188 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1190 &systrayWindowList[0], systrayWindowList.size());
1191 blackbox->saveSystrayWindowSearch(window, this);
1195 void BScreen::removeSystrayWindow(Window window) {
1196 WindowList::iterator it = systrayWindowList.begin();
1197 const WindowList::iterator end = systrayWindowList.end();
1198 for (; it != end; ++it)
1199 if (*it == window) {
1200 systrayWindowList.erase(it);
1201 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1203 &systrayWindowList[0], systrayWindowList.size());
1204 blackbox->removeSystrayWindowSearch(window);
1210 void BScreen::manageWindow(Window w) {
1211 // is the window a KDE systray window?
1213 if (xatom->getValue(w, XAtom::kde_net_wm_system_tray_window_for,
1214 XAtom::window, systray) && systray) {
1215 addSystrayWindow(w);
1219 new BlackboxWindow(blackbox, w, this);
1221 BlackboxWindow *win = blackbox->searchWindow(w);
1226 if (win->isNormal()) {
1227 // don't list non-normal windows as managed windows
1228 windowList.push_back(win);
1230 } else if (win->isDesktop()) {
1231 desktopWindowList.push_back(win->getFrameWindow());
1234 XMapRequestEvent mre;
1236 if (blackbox->isStartup() && win->isNormal()) win->restoreAttributes();
1237 win->mapRequestEvent(&mre);
1241 void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
1244 if (w->getWorkspaceNumber() != BSENTINEL &&
1245 w->getWindowNumber() != BSENTINEL)
1246 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1247 else if (w->isIconic())
1250 if (w->isNormal()) {
1251 // we don't list non-normal windows as managed windows
1252 windowList.remove(w);
1254 } else if (w->isDesktop()) {
1255 WindowList::iterator it = desktopWindowList.begin();
1256 const WindowList::iterator end = desktopWindowList.end();
1257 for (; it != end; ++it)
1258 if (*it == w->getFrameWindow()) {
1259 desktopWindowList.erase(it);
1262 assert(it != end); // the window wasnt a desktop window?
1265 if (blackbox->getFocusedWindow() == w)
1266 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1268 removeNetizen(w->getClientWindow());
1271 some managed windows can also be window group controllers. when
1272 unmanaging such windows, we should also delete the window group.
1274 BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
1281 void BScreen::addNetizen(Netizen *n) {
1282 netizenList.push_back(n);
1284 n->sendWorkspaceCount();
1285 n->sendCurrentWorkspace();
1287 WorkspaceList::iterator it = workspacesList.begin();
1288 const WorkspaceList::iterator end = workspacesList.end();
1289 for (; it != end; ++it)
1290 (*it)->sendWindowList(*n);
1292 Window f = ((blackbox->getFocusedWindow()) ?
1293 blackbox->getFocusedWindow()->getClientWindow() : None);
1294 n->sendWindowFocus(f);
1298 void BScreen::removeNetizen(Window w) {
1299 NetizenList::iterator it = netizenList.begin();
1300 for (; it != netizenList.end(); ++it) {
1301 if ((*it)->getWindowID() == w) {
1303 netizenList.erase(it);
1310 void BScreen::updateWorkArea(void) {
1311 if (workspacesList.size() > 0) {
1312 unsigned long *dims = new unsigned long[4 * workspacesList.size()];
1313 for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
1314 // XXX: this could be different for each workspace
1315 const Rect &area = availableArea();
1316 dims[(i * 4) + 0] = area.x();
1317 dims[(i * 4) + 1] = area.y();
1318 dims[(i * 4) + 2] = area.width();
1319 dims[(i * 4) + 3] = area.height();
1321 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1322 dims, 4 * workspacesList.size());
1325 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1330 void BScreen::updateNetizenCurrentWorkspace(void) {
1331 std::for_each(netizenList.begin(), netizenList.end(),
1332 std::mem_fun(&Netizen::sendCurrentWorkspace));
1336 void BScreen::updateNetizenWorkspaceCount(void) {
1337 xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
1338 XAtom::cardinal, workspacesList.size());
1342 std::for_each(netizenList.begin(), netizenList.end(),
1343 std::mem_fun(&Netizen::sendWorkspaceCount));
1347 void BScreen::updateNetizenWindowFocus(void) {
1348 Window f = ((blackbox->getFocusedWindow()) ?
1349 blackbox->getFocusedWindow()->getClientWindow() : None);
1351 xatom->setValue(getRootWindow(), XAtom::net_active_window,
1354 NetizenList::iterator it = netizenList.begin();
1355 for (; it != netizenList.end(); ++it)
1356 (*it)->sendWindowFocus(f);
1360 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1361 NetizenList::iterator it = netizenList.begin();
1362 for (; it != netizenList.end(); ++it) {
1363 (*it)->sendWindowAdd(w, p);
1368 void BScreen::updateNetizenWindowDel(Window w) {
1369 NetizenList::iterator it = netizenList.begin();
1370 for (; it != netizenList.end(); ++it)
1371 (*it)->sendWindowDel(w);
1375 void BScreen::updateNetizenWindowRaise(Window w) {
1376 NetizenList::iterator it = netizenList.begin();
1377 for (; it != netizenList.end(); ++it)
1378 (*it)->sendWindowRaise(w);
1382 void BScreen::updateNetizenWindowLower(Window w) {
1383 NetizenList::iterator it = netizenList.begin();
1384 for (; it != netizenList.end(); ++it)
1385 (*it)->sendWindowLower(w);
1389 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1390 NetizenList::iterator it = netizenList.begin();
1391 for (; it != netizenList.end(); ++it)
1392 (*it)->sendConfigNotify(e);
1396 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
1397 // the 13 represents the number of blackbox windows such as menus
1398 Window *session_stack = new
1399 Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
1400 unsigned int i = 0, k = num;
1402 XRaiseWindow(blackbox->getXDisplay(), iconmenu->getWindowID());
1403 *(session_stack + i++) = iconmenu->getWindowID();
1405 WorkspaceList::iterator wit = workspacesList.begin();
1406 const WorkspaceList::iterator w_end = workspacesList.end();
1407 for (; wit != w_end; ++wit)
1408 *(session_stack + i++) = (*wit)->getMenu()->getWindowID();
1410 *(session_stack + i++) = workspacemenu->getWindowID();
1412 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1413 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1414 *(session_stack + i++) = configmenu->getWindowID();
1416 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1417 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1418 *(session_stack + i++) = slit->getMenu()->getWindowID();
1420 *(session_stack + i++) =
1421 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1422 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1424 RootmenuList::iterator rit = rootmenuList.begin();
1425 for (; rit != rootmenuList.end(); ++rit)
1426 *(session_stack + i++) = (*rit)->getWindowID();
1427 *(session_stack + i++) = rootmenu->getWindowID();
1429 if (toolbar->isOnTop())
1430 *(session_stack + i++) = toolbar->getWindowID();
1432 if (slit->isOnTop())
1433 *(session_stack + i++) = slit->getWindowID();
1436 *(session_stack + i++) = *(workspace_stack + k);
1438 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1440 delete [] session_stack;
1442 updateStackingList();
1446 void BScreen::lowerWindows(Window *workspace_stack, unsigned int num) {
1447 assert(num > 0); // this would cause trouble in the XRaiseWindow call
1449 Window *session_stack = new Window[(num + desktopWindowList.size())];
1450 unsigned int i = 0, k = num;
1452 XLowerWindow(blackbox->getXDisplay(), workspace_stack[0]);
1455 *(session_stack + i++) = *(workspace_stack + k);
1457 WindowList::iterator dit = desktopWindowList.begin();
1458 const WindowList::iterator d_end = desktopWindowList.end();
1459 for (; dit != d_end; ++dit)
1460 *(session_stack + i++) = *dit;
1462 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1464 delete [] session_stack;
1466 updateStackingList();
1470 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
1471 bool ignore_sticky) {
1474 if (wkspc_id == BSENTINEL)
1475 wkspc_id = current_workspace->getID();
1477 if (w->getWorkspaceNumber() == wkspc_id)
1480 if (w->isIconic()) {
1482 getWorkspace(wkspc_id)->addWindow(w);
1483 } else if (ignore_sticky || ! w->isStuck()) {
1484 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1485 getWorkspace(wkspc_id)->addWindow(w);
1487 updateStackingList();
1491 void BScreen::propagateWindowName(const BlackboxWindow *bw) {
1492 if (bw->isIconic()) {
1493 iconmenu->changeItemLabel(bw->getWindowNumber(), bw->getIconTitle());
1497 Clientmenu *clientmenu = getWorkspace(bw->getWorkspaceNumber())->getMenu();
1498 clientmenu->changeItemLabel(bw->getWindowNumber(), bw->getTitle());
1499 clientmenu->update();
1501 if (blackbox->getFocusedWindow() == bw)
1502 toolbar->redrawWindowLabel(True);
1507 void BScreen::nextFocus(void) {
1508 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1512 // if window is not on this screen, ignore it
1513 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1514 focused = (BlackboxWindow*) 0;
1517 if (focused && current_workspace->getCount() > 1) {
1518 // next is the next window to recieve focus, current is a place holder
1519 BlackboxWindow *current;
1522 next = current_workspace->getNextWindowInList(current);
1523 } while(! next->setInputFocus() && next != focused);
1525 if (next != focused)
1526 current_workspace->raiseWindow(next);
1527 } else if (current_workspace->getCount() >= 1) {
1528 next = current_workspace->getTopWindowOnStack();
1530 current_workspace->raiseWindow(next);
1531 next->setInputFocus();
1536 void BScreen::prevFocus(void) {
1537 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1541 // if window is not on this screen, ignore it
1542 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1543 focused = (BlackboxWindow*) 0;
1546 if (focused && current_workspace->getCount() > 1) {
1547 // next is the next window to recieve focus, current is a place holder
1548 BlackboxWindow *current;
1551 next = current_workspace->getPrevWindowInList(current);
1552 } while(! next->setInputFocus() && next != focused);
1554 if (next != focused)
1555 current_workspace->raiseWindow(next);
1556 } else if (current_workspace->getCount() >= 1) {
1557 next = current_workspace->getTopWindowOnStack();
1559 current_workspace->raiseWindow(next);
1560 next->setInputFocus();
1565 void BScreen::raiseFocus(void) {
1566 BlackboxWindow *focused = blackbox->getFocusedWindow();
1570 // if on this Screen, raise it
1571 if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
1572 Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
1573 workspace->raiseWindow(focused);
1578 void BScreen::InitMenu(void) {
1580 rootmenuList.clear();
1582 while (rootmenu->getCount())
1583 rootmenu->remove(0);
1585 rootmenu = new Rootmenu(this);
1587 bool defaultMenu = True;
1589 FILE *menu_file = (FILE *) 0;
1590 const char *menu_filename = blackbox->getMenuFilename();
1593 if (! (menu_file = fopen(menu_filename, "r")))
1594 perror(menu_filename);
1595 if (! menu_file) { // opening the menu file failed, try the default menu
1596 menu_filename = DEFAULTMENU;
1597 if (! (menu_file = fopen(menu_filename, "r")))
1598 perror(menu_filename);
1602 if (feof(menu_file)) {
1603 fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
1604 "%s: Empty menu file"),
1607 char line[1024], label[1024];
1608 memset(line, 0, 1024);
1609 memset(label, 0, 1024);
1611 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
1612 if (line[0] != '#') {
1613 int i, key = 0, index = -1, len = strlen(line);
1615 for (i = 0; i < len; i++) {
1616 if (line[i] == '[') index = 0;
1617 else if (line[i] == ']') break;
1618 else if (line[i] != ' ')
1620 key += tolower(line[i]);
1623 if (key == 517) { // [begin]
1625 for (i = index; i < len; i++) {
1626 if (line[i] == '(') index = 0;
1627 else if (line[i] == ')') break;
1628 else if (index++ >= 0) {
1629 if (line[i] == '\\' && i < len - 1) i++;
1630 label[index - 1] = line[i];
1634 if (index == -1) index = 0;
1635 label[index] = '\0';
1637 rootmenu->setLabel(label);
1638 defaultMenu = parseMenuFile(menu_file, rootmenu);
1640 blackbox->addMenuTimestamp(menu_filename);
1650 rootmenu->setInternalMenu();
1651 rootmenu->insert(i18n(ScreenSet, Screenxterm, "xterm"),
1653 i18n(ScreenSet, Screenxterm, "xterm"));
1654 rootmenu->insert(i18n(ScreenSet, ScreenRestart, "Restart"),
1656 rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
1658 rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
1664 bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
1665 char line[1024], label[1024], command[1024];
1667 while (! feof(file)) {
1668 memset(line, 0, 1024);
1669 memset(label, 0, 1024);
1670 memset(command, 0, 1024);
1672 if (fgets(line, 1024, file)) {
1673 if (line[0] != '#') {
1674 int i, key = 0, parse = 0, index = -1, line_length = strlen(line);
1676 // determine the keyword
1677 for (i = 0; i < line_length; i++) {
1678 if (line[i] == '[') parse = 1;
1679 else if (line[i] == ']') break;
1680 else if (line[i] != ' ')
1682 key += tolower(line[i]);
1685 // get the label enclosed in ()'s
1688 for (i = 0; i < line_length; i++) {
1689 if (line[i] == '(') {
1692 } else if (line[i] == ')') break;
1693 else if (index++ >= 0) {
1694 if (line[i] == '\\' && i < line_length - 1) i++;
1695 label[index - 1] = line[i];
1700 label[index] = '\0';
1705 // get the command enclosed in {}'s
1708 for (i = 0; i < line_length; i++) {
1709 if (line[i] == '{') {
1712 } else if (line[i] == '}') break;
1713 else if (index++ >= 0) {
1714 if (line[i] == '\\' && i < line_length - 1) i++;
1715 command[index - 1] = line[i];
1720 command[index] = '\0';
1727 return ((menu->getCount() == 0) ? True : False);
1734 menu->insert(label);
1739 if ((! *label) && (! *command)) {
1740 fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
1741 "BScreen::parseMenuFile: [exec] error, "
1742 "no menu label and/or command defined\n"));
1746 menu->insert(label, BScreen::Execute, command);
1752 fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
1753 "BScreen::parseMenuFile: [exit] error, "
1754 "no menu label defined\n"));
1758 menu->insert(label, BScreen::Exit);
1764 if ((! *label) || (! *command)) {
1766 i18n(ScreenSet, ScreenSTYLEError,
1767 "BScreen::parseMenuFile: [style] error, "
1768 "no menu label and/or filename defined\n"));
1772 string style = expandTilde(command);
1774 menu->insert(label, BScreen::SetStyle, style.c_str());
1781 fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
1782 "BScreen::parseMenufile: [config] error, "
1783 "no label defined"));
1787 menu->insert(label, configmenu);
1791 case 740: // include
1794 fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
1795 "BScreen::parseMenuFile: [include] error, "
1796 "no filename defined\n"));
1800 string newfile = expandTilde(label);
1801 FILE *submenufile = fopen(newfile.c_str(), "r");
1805 if (fstat(fileno(submenufile), &buf) ||
1806 (! S_ISREG(buf.st_mode))) {
1808 i18n(ScreenSet, ScreenINCLUDEErrorReg,
1809 "BScreen::parseMenuFile: [include] error: "
1810 "'%s' is not a regular file\n"), newfile.c_str());
1814 if (! feof(submenufile)) {
1815 if (! parseMenuFile(submenufile, menu))
1816 blackbox->addMenuTimestamp(newfile);
1818 fclose(submenufile);
1821 perror(newfile.c_str());
1827 case 767: // submenu
1830 fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
1831 "BScreen::parseMenuFile: [submenu] error, "
1832 "no menu label defined\n"));
1836 Rootmenu *submenu = new Rootmenu(this);
1839 submenu->setLabel(command);
1841 submenu->setLabel(label);
1843 parseMenuFile(file, submenu);
1845 menu->insert(label, submenu);
1846 rootmenuList.push_back(submenu);
1851 case 773: // restart
1854 fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
1855 "BScreen::parseMenuFile: [restart] error, "
1856 "no menu label defined\n"));
1861 menu->insert(label, BScreen::RestartOther, command);
1863 menu->insert(label, BScreen::Restart);
1868 case 845: // reconfig
1872 i18n(ScreenSet, ScreenRECONFIGError,
1873 "BScreen::parseMenuFile: [reconfig] error, "
1874 "no menu label defined\n"));
1878 menu->insert(label, BScreen::Reconfigure);
1883 case 995: // stylesdir
1884 case 1113: // stylesmenu
1886 bool newmenu = ((key == 1113) ? True : False);
1888 if ((! *label) || ((! *command) && newmenu)) {
1890 i18n(ScreenSet, ScreenSTYLESDIRError,
1891 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1892 " error, no directory defined\n"));
1896 char *directory = ((newmenu) ? command : label);
1898 string stylesdir = expandTilde(directory);
1900 struct stat statbuf;
1902 if (! stat(stylesdir.c_str(), &statbuf)) {
1903 if (S_ISDIR(statbuf.st_mode)) {
1904 Rootmenu *stylesmenu;
1907 stylesmenu = new Rootmenu(this);
1911 DIR *d = opendir(stylesdir.c_str());
1913 std::vector<string> ls;
1915 while((p = readdir(d)))
1916 ls.push_back(p->d_name);
1920 std::sort(ls.begin(), ls.end());
1922 std::vector<string>::iterator it = ls.begin(),
1924 for (; it != end; ++it) {
1925 const string& fname = *it;
1927 if (fname[fname.size()-1] == '~')
1930 string style = stylesdir;
1934 if ((! stat(style.c_str(), &statbuf)) &&
1935 S_ISREG(statbuf.st_mode))
1936 stylesmenu->insert(fname, BScreen::SetStyle, style);
1939 stylesmenu->update();
1942 stylesmenu->setLabel(label);
1943 menu->insert(label, stylesmenu);
1944 rootmenuList.push_back(stylesmenu);
1947 blackbox->addMenuTimestamp(stylesdir);
1950 i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
1951 "BScreen::parseMenuFile:"
1952 " [stylesdir/stylesmenu] error, %s is not a"
1953 " directory\n"), stylesdir.c_str());
1957 i18n(ScreenSet, ScreenSTYLESDIRErrorNoExist,
1958 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1959 " error, %s does not exist\n"), stylesdir.c_str());
1964 case 1090: // workspaces
1968 i18n(ScreenSet, ScreenWORKSPACESError,
1969 "BScreen:parseMenuFile: [workspaces] error, "
1970 "no menu label defined\n"));
1974 menu->insert(label, workspacemenu);
1983 return ((menu->getCount() == 0) ? True : False);
1987 void BScreen::shutdown(void) {
1988 XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
1989 XSync(blackbox->getXDisplay(), False);
1991 while(! windowList.empty())
1992 unmanageWindow(windowList.front(), True);
1998 void BScreen::showPosition(int x, int y) {
1999 if (! geom_visible) {
2000 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
2001 (getWidth() - geom_w) / 2,
2002 (getHeight() - geom_h) / 2, geom_w, geom_h);
2003 XMapWindow(blackbox->getXDisplay(), geom_window);
2004 XRaiseWindow(blackbox->getXDisplay(), geom_window);
2006 geom_visible = True;
2011 sprintf(label, i18n(ScreenSet, ScreenPositionFormat,
2012 "X: %4d x Y: %4d"), x, y);
2014 XClearWindow(blackbox->getXDisplay(), geom_window);
2016 resource.wstyle.font->drawString(geom_window,
2017 resource.bevel_width, resource.bevel_width,
2018 resource.wstyle.l_text_focus,
2023 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
2024 if (! geom_visible) {
2025 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
2026 (getWidth() - geom_w) / 2,
2027 (getHeight() - geom_h) / 2, geom_w, geom_h);
2028 XMapWindow(blackbox->getXDisplay(), geom_window);
2029 XRaiseWindow(blackbox->getXDisplay(), geom_window);
2031 geom_visible = True;
2036 sprintf(label, i18n(ScreenSet, ScreenGeometryFormat,
2037 "W: %4d x H: %4d"), gx, gy);
2039 XClearWindow(blackbox->getXDisplay(), geom_window);
2041 resource.wstyle.font->drawString(geom_window,
2042 resource.bevel_width, resource.bevel_width,
2043 resource.wstyle.l_text_focus,
2048 void BScreen::hideGeometry(void) {
2050 XUnmapWindow(blackbox->getXDisplay(), geom_window);
2051 geom_visible = False;
2056 void BScreen::addStrut(Strut *strut) {
2057 strutList.push_back(strut);
2061 void BScreen::removeStrut(Strut *strut) {
2062 strutList.remove(strut);
2066 const Rect& BScreen::availableArea(void) const {
2068 return getRect(); // return the full screen
2073 void BScreen::updateAvailableArea(void) {
2074 Rect old_area = usableArea;
2075 usableArea = getRect(); // reset to full screen
2077 /* these values represent offsets from the screen edge
2078 * we look for the biggest offset on each edge and then apply them
2080 * do not be confused by the similarity to the names of Rect's members
2082 unsigned int current_left = 0, current_right = 0, current_top = 0,
2085 StrutList::const_iterator it = strutList.begin(), end = strutList.end();
2087 for(; it != end; ++it) {
2089 if (strut->left > current_left)
2090 current_left = strut->left;
2091 if (strut->top > current_top)
2092 current_top = strut->top;
2093 if (strut->right > current_right)
2094 current_right = strut->right;
2095 if (strut->bottom > current_bottom)
2096 current_bottom = strut->bottom;
2099 usableArea.setPos(current_left, current_top);
2100 usableArea.setSize(usableArea.width() - (current_left + current_right),
2101 usableArea.height() - (current_top + current_bottom));
2103 if (old_area != usableArea) {
2104 BlackboxWindowList::iterator it = windowList.begin(),
2105 end = windowList.end();
2106 for (; it != end; ++it)
2107 if ((*it)->isMaximized()) (*it)->remaximize();
2114 Workspace* BScreen::getWorkspace(unsigned int index) {
2115 assert(index < workspacesList.size());
2116 return workspacesList[index];
2120 void BScreen::buttonPressEvent(const XButtonEvent *xbutton) {
2121 if (xbutton->button == 1) {
2122 if (! isRootColormapInstalled())
2123 image_control->installRootColormap();
2125 if (workspacemenu->isVisible())
2126 workspacemenu->hide();
2128 if (rootmenu->isVisible())
2130 } else if (xbutton->button == 2) {
2131 int mx = xbutton->x_root - (workspacemenu->getWidth() / 2);
2132 int my = xbutton->y_root - (workspacemenu->getTitleHeight() / 2);
2137 if (mx + workspacemenu->getWidth() > getWidth())
2138 mx = getWidth() - workspacemenu->getWidth() - getBorderWidth();
2140 if (my + workspacemenu->getHeight() > getHeight())
2141 my = getHeight() - workspacemenu->getHeight() - getBorderWidth();
2143 workspacemenu->move(mx, my);
2145 if (! workspacemenu->isVisible()) {
2146 workspacemenu->removeParent();
2147 workspacemenu->show();
2149 } else if (xbutton->button == 3) {
2150 int mx = xbutton->x_root - (rootmenu->getWidth() / 2);
2151 int my = xbutton->y_root - (rootmenu->getTitleHeight() / 2);
2156 if (mx + rootmenu->getWidth() > getWidth())
2157 mx = getWidth() - rootmenu->getWidth() - getBorderWidth();
2159 if (my + rootmenu->getHeight() > getHeight())
2160 my = getHeight() - rootmenu->getHeight() - getBorderWidth();
2162 rootmenu->move(mx, my);
2164 if (! rootmenu->isVisible()) {
2165 blackbox->checkMenu();
2169 } else if (xbutton->button == 4) {
2170 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2171 changeWorkspaceID(0);
2173 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2175 } else if (xbutton->button == 5) {
2176 if (getCurrentWorkspaceID() == 0)
2177 changeWorkspaceID(getWorkspaceCount() - 1);
2179 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2184 void BScreen::propertyNotifyEvent(const XPropertyEvent *pe) {
2185 if (pe->atom == xatom->getAtom(XAtom::net_desktop_names)) {
2186 // _NET_WM_DESKTOP_NAMES
2187 WorkspaceList::iterator it = workspacesList.begin();
2188 const WorkspaceList::iterator end = workspacesList.end();
2189 for (; it != end; ++it) {
2190 (*it)->readName(); // re-read its name from the window property
2191 workspacemenu->changeWorkspaceLabel((*it)->getID(), (*it)->getName());
2193 workspacemenu->update();
2194 toolbar->reconfigure();
2195 saveWorkspaceNames();
2200 void BScreen::toggleFocusModel(FocusModel model) {
2201 std::for_each(windowList.begin(), windowList.end(),
2202 std::mem_fun(&BlackboxWindow::ungrabButtons));
2204 if (model == SloppyFocus) {
2205 saveSloppyFocus(True);
2207 // we're cheating here to save writing the config file 3 times
2208 resource.auto_raise = False;
2209 resource.click_raise = False;
2210 saveSloppyFocus(False);
2213 std::for_each(windowList.begin(), windowList.end(),
2214 std::mem_fun(&BlackboxWindow::grabButtons));
2218 BTexture BScreen::readDatabaseTexture(const string &rname,
2219 const string &default_color,
2220 const Configuration &style) {
2224 if (style.getValue(rname, s))
2225 texture = BTexture(s);
2227 texture.setTexture(BTexture::Solid | BTexture::Flat);
2229 // associate this texture with this screen
2230 texture.setDisplay(getBaseDisplay(), getScreenNumber());
2231 texture.setImageControl(image_control);
2233 if (texture.texture() & BTexture::Solid) {
2234 texture.setColor(readDatabaseColor(rname + ".color",
2235 default_color, style));
2236 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2237 default_color, style));
2238 } else if (texture.texture() & BTexture::Gradient) {
2239 texture.setColor(readDatabaseColor(rname + ".color",
2240 default_color, style));
2241 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2242 default_color, style));
2249 BColor BScreen::readDatabaseColor(const string &rname,
2250 const string &default_color,
2251 const Configuration &style) {
2254 if (style.getValue(rname, s))
2255 color = BColor(s, getBaseDisplay(), getScreenNumber());
2257 color = BColor(default_color, getBaseDisplay(), getScreenNumber());
2262 BFont *BScreen::readDatabaseFont(const string &rbasename,
2263 const Configuration &style) {
2270 if (style.getValue(rbasename + "xft.font", s) &&
2271 style.getValue(rbasename + "xft.size", i)) {
2274 bool italic = False;
2275 if (style.getValue(rbasename + "xft.flags", s)) {
2276 if (s.find("bold") != string::npos)
2278 if (s.find("italic") != string::npos)
2282 BFont *b = new BFont(blackbox->getXDisplay(), this, family, i, bold,
2283 italic, resource.aa_fonts);
2287 delete b; // fall back to the normal X font stuff
2291 style.getValue(rbasename + "font", s);
2292 // if this fails, a blank string will be used, which will cause the fallback
2295 BFont *b = new BFont(blackbox->getXDisplay(), this, s);
2297 exit(2); // can't continue without a font