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::save_rc(void) {
530 saveSloppyFocus(resource.sloppy_focus);
531 saveAutoRaise(resource.auto_raise);
532 saveImageDither(doImageDither());
533 saveAAFonts(resource.aa_fonts);
534 saveResizeZones(resource.resize_zones);
535 saveOpaqueMove(resource.opaque_move);
536 saveFullMax(resource.full_max);
537 saveFocusNew(resource.focus_new);
538 saveFocusLast(resource.focus_last);
539 saveHideToolbar(resource.hide_toolbar);
540 saveWindowToWindowSnap(resource.window_to_window_snap);
541 saveWindowCornerSnap(resource.window_corner_snap);
542 saveWorkspaces(resource.workspaces);
543 savePlacementPolicy(resource.placement_policy);
544 saveEdgeSnapThreshold(resource.edge_snap_threshold);
545 saveRowPlacementDirection(resource.row_direction);
546 saveColPlacementDirection(resource.col_direction);
548 saveStrftimeFormat(resource.strftime_format);
549 #else // !HAVE_STRFTIME
550 saveDateFormat(resource.date_format);
551 savwClock24Hour(resource.clock24hour);
552 #endif // HAVE_STRFTIME
553 savePlaceIgnoreShaded(resource.ignore_shaded);
554 savePlaceIgnoreMaximized(resource.ignore_maximized);
561 void BScreen::load_rc(void) {
565 if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
566 resource.full_max = false;
568 if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
569 resource.focus_new = false;
571 if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
572 resource.focus_last = false;
574 if (! config->getValue(screenstr + "workspaces", resource.workspaces))
575 resource.workspaces = 1;
577 if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
578 resource.opaque_move = false;
580 if (! config->getValue(screenstr + "antialiasFonts", resource.aa_fonts))
581 resource.aa_fonts = true;
583 if (! config->getValue(screenstr + "resizeZones", resource.resize_zones) ||
584 (resource.resize_zones != 1 && resource.resize_zones != 2 &&
585 resource.resize_zones != 4))
586 resource.resize_zones = 4;
588 if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
589 resource.hide_toolbar = false;
591 if (! config->getValue(screenstr + "windowToWindowSnap",
592 resource.window_to_window_snap))
593 resource.window_to_window_snap = true;
595 if (! config->getValue(screenstr + "windowCornerSnap",
596 resource.window_corner_snap))
597 resource.window_corner_snap = true;
599 if (! config->getValue(screenstr + "imageDither", b))
601 image_control->setDither(b);
603 if (! config->getValue(screenstr + "edgeSnapThreshold",
604 resource.edge_snap_threshold))
605 resource.edge_snap_threshold = 4;
607 if (config->getValue(screenstr + "rowPlacementDirection", s) &&
609 resource.row_direction = RightLeft;
611 resource.row_direction = LeftRight;
613 if (config->getValue(screenstr + "colPlacementDirection", s) &&
615 resource.col_direction = BottomTop;
617 resource.col_direction = TopBottom;
619 if (config->getValue(screenstr + "workspaceNames", s)) {
620 XAtom::StringVect workspaceNames;
622 string::const_iterator it = s.begin(), end = s.end();
624 string::const_iterator tmp = it; // current string.begin()
625 it = std::find(tmp, end, ','); // look for comma between tmp and end
626 workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
632 xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
636 resource.sloppy_focus = true;
637 resource.auto_raise = false;
638 resource.click_raise = false;
639 if (config->getValue(screenstr + "focusModel", s)) {
640 if (s.find("ClickToFocus") != string::npos) {
641 resource.sloppy_focus = false;
644 if (s.find("AutoRaise") != string::npos)
645 resource.auto_raise = true;
646 if (s.find("ClickRaise") != string::npos)
647 resource.click_raise = true;
651 if (config->getValue(screenstr + "windowPlacement", s)) {
652 if (s == "CascadePlacement")
653 resource.placement_policy = CascadePlacement;
654 else if (s == "UnderMousePlacement")
655 resource.placement_policy = UnderMousePlacement;
656 else if (s == "ClickMousePlacement")
657 resource.placement_policy = ClickMousePlacement;
658 else if (s == "ColSmartPlacement")
659 resource.placement_policy = ColSmartPlacement;
660 else //if (s == "RowSmartPlacement")
661 resource.placement_policy = RowSmartPlacement;
663 resource.placement_policy = RowSmartPlacement;
666 if (! config->getValue(screenstr + "strftimeFormat",
667 resource.strftime_format))
668 resource.strftime_format = "%I:%M %p";
669 #else // !HAVE_STRFTIME
672 if (config->getValue(screenstr + "dateFormat", s) && s == "European")
673 resource.date_format = B_EuropeanDate;
675 resource.date_format = B_AmericanDate;
677 if (! config->getValue(screenstr + "clockFormat", l))
679 resource.clock24hour = l == 24;
680 #endif // HAVE_STRFTIME
682 if (! config->getValue(screenstr + "placementIgnoreShaded",
683 resource.ignore_shaded))
684 resource.ignore_shaded = true;
686 if (! config->getValue(screenstr + "placementIgnoreMaximized",
687 resource.ignore_maximized))
688 resource.ignore_maximized = true;
692 void BScreen::changeWorkspaceCount(unsigned int new_count) {
693 assert(new_count > 0);
695 if (new_count < workspacesList.size()) {
697 for (unsigned int i = workspacesList.size(); i > new_count; --i)
698 removeLastWorkspace();
699 // removeLast already sets the current workspace to the
700 // last available one.
701 } else if (new_count > workspacesList.size()) {
703 for(unsigned int i = workspacesList.size(); i < new_count; ++i)
709 void BScreen::reconfigure(void) {
710 // don't reconfigure while saving the initial rc file, it's a waste and it
711 // breaks somethings (workspace names)
712 if (blackbox->isStartup()) return;
719 // we need to do this explicitly, because just loading this value from the rc
721 changeWorkspaceCount(resource.workspaces);
724 gcv.foreground = WhitePixel(blackbox->getXDisplay(),
726 gcv.function = GXinvert;
727 gcv.subwindow_mode = IncludeInferiors;
728 XChangeGC(blackbox->getXDisplay(), opGC,
729 GCForeground | GCFunction | GCSubwindowMode, &gcv);
731 const char *s = i18n(ScreenSet, ScreenPositionLength,
732 "0: 0000 x 0: 0000");
734 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
735 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
737 BTexture* texture = &(resource.wstyle.l_focus);
738 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
739 if (geom_pixmap == ParentRelative) {
740 texture = &(resource.wstyle.t_focus);
741 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
744 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
745 texture->color().pixel());
747 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
748 geom_window, geom_pixmap);
750 XSetWindowBorderWidth(blackbox->getXDisplay(), geom_window,
751 resource.border_width);
752 XSetWindowBorder(blackbox->getXDisplay(), geom_window,
753 resource.border_color.pixel());
755 workspacemenu->reconfigure();
756 iconmenu->reconfigure();
758 typedef std::vector<int> SubList;
759 SubList remember_subs;
761 // save the current open menus
762 Basemenu *menu = rootmenu;
764 while ((submenu = menu->getCurrentSubmenu()) >= 0) {
765 remember_subs.push_back(submenu);
766 menu = menu->find(submenu)->submenu();
772 rootmenu->reconfigure();
774 // reopen the saved menus
776 const SubList::iterator subs_end = remember_subs.end();
777 for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
778 menu->drawSubmenu(*it);
779 menu = menu->find(*it)->submenu();
784 configmenu->reconfigure();
786 toolbar->reconfigure();
790 std::for_each(workspacesList.begin(), workspacesList.end(),
791 std::mem_fun(&Workspace::reconfigure));
793 BlackboxWindowList::iterator iit = iconList.begin();
794 for (; iit != iconList.end(); ++iit) {
795 BlackboxWindow *bw = *iit;
796 if (bw->validateClient())
800 image_control->timeout();
804 void BScreen::rereadMenu(void) {
808 rootmenu->reconfigure();
812 void BScreen::LoadStyle(void) {
813 Configuration style(False);
815 const char *sfile = blackbox->getStyleFilename();
817 style.setFile(sfile);
818 if (! style.load()) {
819 style.setFile(DEFAULTSTYLE);
821 style.create(); // hardcoded default values will be used.
825 // merge in the rc file
826 style.merge(config->file(), True);
830 // load fonts/fontsets
831 if (resource.wstyle.font)
832 delete resource.wstyle.font;
833 if (resource.tstyle.font)
834 delete resource.tstyle.font;
835 if (resource.mstyle.f_font)
836 delete resource.mstyle.f_font;
837 if (resource.mstyle.t_font)
838 delete resource.mstyle.t_font;
839 resource.wstyle.font = resource.tstyle.font = resource.mstyle.f_font =
840 resource.mstyle.t_font = (BFont *) 0;
842 resource.wstyle.font = readDatabaseFont("window.", style);
843 resource.tstyle.font = readDatabaseFont("toolbar.", style);
844 resource.mstyle.t_font = readDatabaseFont("menu.title.", style);
845 resource.mstyle.f_font = readDatabaseFont("menu.frame.", style);
847 // load window config
848 resource.wstyle.t_focus =
849 readDatabaseTexture("window.title.focus", "white", style);
850 resource.wstyle.t_unfocus =
851 readDatabaseTexture("window.title.unfocus", "black", style);
852 resource.wstyle.l_focus =
853 readDatabaseTexture("window.label.focus", "white", style);
854 resource.wstyle.l_unfocus =
855 readDatabaseTexture("window.label.unfocus", "black", style);
856 resource.wstyle.h_focus =
857 readDatabaseTexture("window.handle.focus", "white", style);
858 resource.wstyle.h_unfocus =
859 readDatabaseTexture("window.handle.unfocus", "black", style);
860 resource.wstyle.g_focus =
861 readDatabaseTexture("window.grip.focus", "white", style);
862 resource.wstyle.g_unfocus =
863 readDatabaseTexture("window.grip.unfocus", "black", style);
864 resource.wstyle.b_focus =
865 readDatabaseTexture("window.button.focus", "white", style);
866 resource.wstyle.b_unfocus =
867 readDatabaseTexture("window.button.unfocus", "black", style);
868 resource.wstyle.b_pressed =
869 readDatabaseTexture("window.button.pressed", "black", style);
870 resource.wstyle.f_focus =
871 readDatabaseColor("window.frame.focusColor", "white", style);
872 resource.wstyle.f_unfocus =
873 readDatabaseColor("window.frame.unfocusColor", "black", style);
874 resource.wstyle.l_text_focus =
875 readDatabaseColor("window.label.focus.textColor", "black", style);
876 resource.wstyle.l_text_unfocus =
877 readDatabaseColor("window.label.unfocus.textColor", "white", style);
878 resource.wstyle.b_pic_focus =
879 readDatabaseColor("window.button.focus.picColor", "black", style);
880 resource.wstyle.b_pic_unfocus =
881 readDatabaseColor("window.button.unfocus.picColor", "white", style);
883 resource.wstyle.justify = LeftJustify;
884 if (style.getValue("window.justify", s)) {
885 if (s == "right" || s == "Right")
886 resource.wstyle.justify = RightJustify;
887 else if (s == "center" || s == "Center")
888 resource.wstyle.justify = CenterJustify;
891 // load toolbar config
892 resource.tstyle.toolbar =
893 readDatabaseTexture("toolbar", "black", style);
894 resource.tstyle.label =
895 readDatabaseTexture("toolbar.label", "black", style);
896 resource.tstyle.window =
897 readDatabaseTexture("toolbar.windowLabel", "black", style);
898 resource.tstyle.button =
899 readDatabaseTexture("toolbar.button", "white", style);
900 resource.tstyle.pressed =
901 readDatabaseTexture("toolbar.button.pressed", "black", style);
902 resource.tstyle.clock =
903 readDatabaseTexture("toolbar.clock", "black", style);
904 resource.tstyle.l_text =
905 readDatabaseColor("toolbar.label.textColor", "white", style);
906 resource.tstyle.w_text =
907 readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
908 resource.tstyle.c_text =
909 readDatabaseColor("toolbar.clock.textColor", "white", style);
910 resource.tstyle.b_pic =
911 readDatabaseColor("toolbar.button.picColor", "black", style);
913 resource.tstyle.justify = LeftJustify;
914 if (style.getValue("toolbar.justify", s)) {
915 if (s == "right" || s == "Right")
916 resource.tstyle.justify = RightJustify;
917 else if (s == "center" || s == "Center")
918 resource.tstyle.justify = CenterJustify;
922 resource.mstyle.title =
923 readDatabaseTexture("menu.title", "white", style);
924 resource.mstyle.frame =
925 readDatabaseTexture("menu.frame", "black", style);
926 resource.mstyle.hilite =
927 readDatabaseTexture("menu.hilite", "white", style);
928 resource.mstyle.t_text =
929 readDatabaseColor("menu.title.textColor", "black", style);
930 resource.mstyle.f_text =
931 readDatabaseColor("menu.frame.textColor", "white", style);
932 resource.mstyle.d_text =
933 readDatabaseColor("menu.frame.disableColor", "black", style);
934 resource.mstyle.h_text =
935 readDatabaseColor("menu.hilite.textColor", "black", style);
937 resource.mstyle.t_justify = LeftJustify;
938 if (style.getValue("menu.title.justify", s)) {
939 if (s == "right" || s == "Right")
940 resource.mstyle.t_justify = RightJustify;
941 else if (s == "center" || s == "Center")
942 resource.mstyle.t_justify = CenterJustify;
945 resource.mstyle.f_justify = LeftJustify;
946 if (style.getValue("menu.frame.justify", s)) {
947 if (s == "right" || s == "Right")
948 resource.mstyle.f_justify = RightJustify;
949 else if (s == "center" || s == "Center")
950 resource.mstyle.f_justify = CenterJustify;
953 resource.mstyle.bullet = Basemenu::Triangle;
954 if (style.getValue("menu.bullet", s)) {
955 if (s == "empty" || s == "Empty")
956 resource.mstyle.bullet = Basemenu::Empty;
957 else if (s == "square" || s == "Square")
958 resource.mstyle.bullet = Basemenu::Square;
959 else if (s == "diamond" || s == "Diamond")
960 resource.mstyle.bullet = Basemenu::Diamond;
963 resource.mstyle.bullet_pos = Basemenu::Left;
964 if (style.getValue("menu.bullet.position", s)) {
965 if (s == "right" || s == "Right")
966 resource.mstyle.bullet_pos = Basemenu::Right;
969 resource.border_color =
970 readDatabaseColor("borderColor", "black", style);
972 // load bevel, border and handle widths
973 if (! style.getValue("handleWidth", resource.handle_width) ||
974 resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
975 resource.handle_width = 6;
977 if (! style.getValue("borderWidth", resource.border_width))
978 resource.border_width = 1;
980 if (! style.getValue("bevelWidth", resource.bevel_width) ||
981 resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
982 resource.bevel_width = 3;
984 if (! style.getValue("frameWidth", resource.frame_width) ||
985 resource.frame_width > (getWidth() / 2))
986 resource.frame_width = resource.bevel_width;
988 if (style.getValue("rootCommand", s))
989 bexec(s, displayString());
993 void BScreen::addIcon(BlackboxWindow *w) {
996 w->setWorkspace(BSENTINEL);
997 w->setWindowNumber(iconList.size());
999 iconList.push_back(w);
1001 const char* title = w->getIconTitle();
1002 iconmenu->insert(title);
1007 void BScreen::removeIcon(BlackboxWindow *w) {
1012 iconmenu->remove(w->getWindowNumber());
1015 BlackboxWindowList::iterator it = iconList.begin(),
1016 end = iconList.end();
1017 for (int i = 0; it != end; ++it)
1018 (*it)->setWindowNumber(i++);
1022 BlackboxWindow *BScreen::getIcon(unsigned int index) {
1023 if (index < iconList.size()) {
1024 BlackboxWindowList::iterator it = iconList.begin();
1025 for (; index > 0; --index, ++it) ; /* increment to index */
1029 return (BlackboxWindow *) 0;
1033 unsigned int BScreen::addWorkspace(void) {
1034 Workspace *wkspc = new Workspace(this, workspacesList.size());
1035 workspacesList.push_back(wkspc);
1036 saveWorkspaces(getWorkspaceCount());
1037 saveWorkspaceNames();
1039 workspacemenu->insertWorkspace(wkspc);
1040 workspacemenu->update();
1042 toolbar->reconfigure();
1044 updateNetizenWorkspaceCount();
1046 return workspacesList.size();
1050 unsigned int BScreen::removeLastWorkspace(void) {
1051 if (workspacesList.size() == 1)
1054 Workspace *wkspc = workspacesList.back();
1056 if (current_workspace->getID() == wkspc->getID())
1057 changeWorkspaceID(current_workspace->getID() - 1);
1061 workspacemenu->removeWorkspace(wkspc);
1062 workspacemenu->update();
1064 workspacesList.pop_back();
1067 saveWorkspaces(getWorkspaceCount());
1068 saveWorkspaceNames();
1070 toolbar->reconfigure();
1072 updateNetizenWorkspaceCount();
1074 return workspacesList.size();
1078 void BScreen::changeWorkspaceID(unsigned int id) {
1079 if (! current_workspace || id == current_workspace->getID()) return;
1081 BlackboxWindow *focused = blackbox->getFocusedWindow();
1082 if (focused && focused->getScreen() == this) {
1083 assert(focused->isStuck() ||
1084 focused->getWorkspaceNumber() == current_workspace->getID());
1086 current_workspace->setLastFocusedWindow(focused);
1088 // if no window had focus, no need to store a last focus
1089 current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
1092 // when we switch workspaces, unfocus whatever was focused
1093 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1095 current_workspace->hideAll();
1096 workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1098 current_workspace = getWorkspace(id);
1100 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
1101 XAtom::cardinal, id);
1103 workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1104 toolbar->redrawWorkspaceLabel(True);
1106 current_workspace->showAll();
1108 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1109 XSync(blackbox->getXDisplay(), False);
1110 current_workspace->getLastFocusedWindow()->setInputFocus();
1113 updateNetizenCurrentWorkspace();
1118 * Set the _NET_CLIENT_LIST root window property.
1120 void BScreen::updateClientList(void) {
1121 if (windowList.size() > 0) {
1122 Window *windows = new Window[windowList.size()];
1123 Window *win_it = windows;
1124 BlackboxWindowList::iterator it = windowList.begin();
1125 const BlackboxWindowList::iterator end = windowList.end();
1126 for (; it != end; ++it, ++win_it)
1127 *win_it = (*it)->getClientWindow();
1128 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1129 windows, windowList.size());
1132 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1135 updateStackingList();
1140 * Set the _NET_CLIENT_LIST_STACKING root window property.
1142 void BScreen::updateStackingList(void) {
1144 BlackboxWindowList stack_order;
1147 * Get the stacking order from all of the workspaces.
1148 * We start with the current workspace so that the sticky windows will be
1149 * in the right order on the current workspace.
1150 * XXX: Do we need to have sticky windows in the list once for each workspace?
1152 getCurrentWorkspace()->appendStackOrder(stack_order);
1153 for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
1154 if (i != getCurrentWorkspaceID())
1155 getWorkspace(i)->appendStackOrder(stack_order);
1157 if (stack_order.size() > 0) {
1158 // set the client list atoms
1159 Window *windows = new Window[stack_order.size()];
1160 Window *win_it = windows;
1161 BlackboxWindowList::iterator it = stack_order.begin(),
1162 end = stack_order.end();
1163 for (; it != end; ++it, ++win_it)
1164 *win_it = (*it)->getClientWindow();
1165 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1166 XAtom::window, windows, stack_order.size());
1169 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1170 XAtom::window, 0, 0);
1174 void BScreen::addSystrayWindow(Window window) {
1175 systrayWindowList.push_back(window);
1176 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1178 &systrayWindowList[0], systrayWindowList.size());
1179 blackbox->saveSystrayWindowSearch(window, this);
1183 void BScreen::removeSystrayWindow(Window window) {
1184 WindowList::iterator it = systrayWindowList.begin();
1185 const WindowList::iterator end = systrayWindowList.end();
1186 for (; it != end; ++it)
1187 if (*it == window) {
1188 systrayWindowList.erase(it);
1189 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1191 &systrayWindowList[0], systrayWindowList.size());
1192 blackbox->removeSystrayWindowSearch(window);
1198 void BScreen::manageWindow(Window w) {
1199 // is the window a KDE systray window?
1201 if (xatom->getValue(w, XAtom::kde_net_wm_system_tray_window_for,
1202 XAtom::window, systray) && systray) {
1203 addSystrayWindow(w);
1207 new BlackboxWindow(blackbox, w, this);
1209 BlackboxWindow *win = blackbox->searchWindow(w);
1214 if (win->isNormal()) {
1215 // don't list non-normal windows as managed windows
1216 windowList.push_back(win);
1218 } else if (win->isDesktop()) {
1219 desktopWindowList.push_back(win->getFrameWindow());
1222 XMapRequestEvent mre;
1224 if (blackbox->isStartup() && win->isNormal()) win->restoreAttributes();
1225 win->mapRequestEvent(&mre);
1229 void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
1232 if (w->getWorkspaceNumber() != BSENTINEL &&
1233 w->getWindowNumber() != BSENTINEL)
1234 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1235 else if (w->isIconic())
1238 if (w->isNormal()) {
1239 // we don't list non-normal windows as managed windows
1240 windowList.remove(w);
1242 } else if (w->isDesktop()) {
1243 WindowList::iterator it = desktopWindowList.begin();
1244 const WindowList::iterator end = desktopWindowList.end();
1245 for (; it != end; ++it)
1246 if (*it == w->getFrameWindow()) {
1247 desktopWindowList.erase(it);
1250 assert(it != end); // the window wasnt a desktop window?
1253 if (blackbox->getFocusedWindow() == w)
1254 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1256 removeNetizen(w->getClientWindow());
1259 some managed windows can also be window group controllers. when
1260 unmanaging such windows, we should also delete the window group.
1262 BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
1269 void BScreen::addNetizen(Netizen *n) {
1270 netizenList.push_back(n);
1272 n->sendWorkspaceCount();
1273 n->sendCurrentWorkspace();
1275 WorkspaceList::iterator it = workspacesList.begin();
1276 const WorkspaceList::iterator end = workspacesList.end();
1277 for (; it != end; ++it)
1278 (*it)->sendWindowList(*n);
1280 Window f = ((blackbox->getFocusedWindow()) ?
1281 blackbox->getFocusedWindow()->getClientWindow() : None);
1282 n->sendWindowFocus(f);
1286 void BScreen::removeNetizen(Window w) {
1287 NetizenList::iterator it = netizenList.begin();
1288 for (; it != netizenList.end(); ++it) {
1289 if ((*it)->getWindowID() == w) {
1291 netizenList.erase(it);
1298 void BScreen::updateWorkArea(void) {
1299 if (workspacesList.size() > 0) {
1300 unsigned long *dims = new unsigned long[4 * workspacesList.size()];
1301 for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
1302 // XXX: this could be different for each workspace
1303 const Rect &area = availableArea();
1304 dims[(i * 4) + 0] = area.x();
1305 dims[(i * 4) + 1] = area.y();
1306 dims[(i * 4) + 2] = area.width();
1307 dims[(i * 4) + 3] = area.height();
1309 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1310 dims, 4 * workspacesList.size());
1313 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1318 void BScreen::updateNetizenCurrentWorkspace(void) {
1319 std::for_each(netizenList.begin(), netizenList.end(),
1320 std::mem_fun(&Netizen::sendCurrentWorkspace));
1324 void BScreen::updateNetizenWorkspaceCount(void) {
1325 xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
1326 XAtom::cardinal, workspacesList.size());
1330 std::for_each(netizenList.begin(), netizenList.end(),
1331 std::mem_fun(&Netizen::sendWorkspaceCount));
1335 void BScreen::updateNetizenWindowFocus(void) {
1336 Window f = ((blackbox->getFocusedWindow()) ?
1337 blackbox->getFocusedWindow()->getClientWindow() : None);
1339 xatom->setValue(getRootWindow(), XAtom::net_active_window,
1342 NetizenList::iterator it = netizenList.begin();
1343 for (; it != netizenList.end(); ++it)
1344 (*it)->sendWindowFocus(f);
1348 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1349 NetizenList::iterator it = netizenList.begin();
1350 for (; it != netizenList.end(); ++it) {
1351 (*it)->sendWindowAdd(w, p);
1356 void BScreen::updateNetizenWindowDel(Window w) {
1357 NetizenList::iterator it = netizenList.begin();
1358 for (; it != netizenList.end(); ++it)
1359 (*it)->sendWindowDel(w);
1363 void BScreen::updateNetizenWindowRaise(Window w) {
1364 NetizenList::iterator it = netizenList.begin();
1365 for (; it != netizenList.end(); ++it)
1366 (*it)->sendWindowRaise(w);
1370 void BScreen::updateNetizenWindowLower(Window w) {
1371 NetizenList::iterator it = netizenList.begin();
1372 for (; it != netizenList.end(); ++it)
1373 (*it)->sendWindowLower(w);
1377 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1378 NetizenList::iterator it = netizenList.begin();
1379 for (; it != netizenList.end(); ++it)
1380 (*it)->sendConfigNotify(e);
1384 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
1385 // the 13 represents the number of blackbox windows such as menus
1386 Window *session_stack = new
1387 Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
1388 unsigned int i = 0, k = num;
1390 XRaiseWindow(blackbox->getXDisplay(), iconmenu->getWindowID());
1391 *(session_stack + i++) = iconmenu->getWindowID();
1393 WorkspaceList::iterator wit = workspacesList.begin();
1394 const WorkspaceList::iterator w_end = workspacesList.end();
1395 for (; wit != w_end; ++wit)
1396 *(session_stack + i++) = (*wit)->getMenu()->getWindowID();
1398 *(session_stack + i++) = workspacemenu->getWindowID();
1400 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1401 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1402 *(session_stack + i++) = configmenu->getWindowID();
1404 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1405 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1406 *(session_stack + i++) = slit->getMenu()->getWindowID();
1408 *(session_stack + i++) =
1409 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1410 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1412 RootmenuList::iterator rit = rootmenuList.begin();
1413 for (; rit != rootmenuList.end(); ++rit)
1414 *(session_stack + i++) = (*rit)->getWindowID();
1415 *(session_stack + i++) = rootmenu->getWindowID();
1417 if (toolbar->isOnTop())
1418 *(session_stack + i++) = toolbar->getWindowID();
1420 if (slit->isOnTop())
1421 *(session_stack + i++) = slit->getWindowID();
1424 *(session_stack + i++) = *(workspace_stack + k);
1426 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1428 delete [] session_stack;
1430 updateStackingList();
1434 void BScreen::lowerWindows(Window *workspace_stack, unsigned int num) {
1435 assert(num > 0); // this would cause trouble in the XRaiseWindow call
1437 Window *session_stack = new Window[(num + desktopWindowList.size())];
1438 unsigned int i = 0, k = num;
1440 XLowerWindow(blackbox->getXDisplay(), workspace_stack[0]);
1443 *(session_stack + i++) = *(workspace_stack + k);
1445 WindowList::iterator dit = desktopWindowList.begin();
1446 const WindowList::iterator d_end = desktopWindowList.end();
1447 for (; dit != d_end; ++dit)
1448 *(session_stack + i++) = *dit;
1450 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1452 delete [] session_stack;
1454 updateStackingList();
1458 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
1459 bool ignore_sticky) {
1462 if (wkspc_id == BSENTINEL)
1463 wkspc_id = current_workspace->getID();
1465 if (w->getWorkspaceNumber() == wkspc_id)
1468 if (w->isIconic()) {
1470 getWorkspace(wkspc_id)->addWindow(w);
1471 } else if (ignore_sticky || ! w->isStuck()) {
1472 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1473 getWorkspace(wkspc_id)->addWindow(w);
1475 updateStackingList();
1479 void BScreen::propagateWindowName(const BlackboxWindow *bw) {
1480 if (bw->isIconic()) {
1481 iconmenu->changeItemLabel(bw->getWindowNumber(), bw->getIconTitle());
1485 Clientmenu *clientmenu = getWorkspace(bw->getWorkspaceNumber())->getMenu();
1486 clientmenu->changeItemLabel(bw->getWindowNumber(), bw->getTitle());
1487 clientmenu->update();
1489 if (blackbox->getFocusedWindow() == bw)
1490 toolbar->redrawWindowLabel(True);
1495 void BScreen::nextFocus(void) {
1496 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1500 // if window is not on this screen, ignore it
1501 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1502 focused = (BlackboxWindow*) 0;
1505 if (focused && current_workspace->getCount() > 1) {
1506 // next is the next window to recieve focus, current is a place holder
1507 BlackboxWindow *current;
1510 next = current_workspace->getNextWindowInList(current);
1511 } while(! next->setInputFocus() && next != focused);
1513 if (next != focused)
1514 current_workspace->raiseWindow(next);
1515 } else if (current_workspace->getCount() >= 1) {
1516 next = current_workspace->getTopWindowOnStack();
1518 current_workspace->raiseWindow(next);
1519 next->setInputFocus();
1524 void BScreen::prevFocus(void) {
1525 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1529 // if window is not on this screen, ignore it
1530 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1531 focused = (BlackboxWindow*) 0;
1534 if (focused && current_workspace->getCount() > 1) {
1535 // next is the next window to recieve focus, current is a place holder
1536 BlackboxWindow *current;
1539 next = current_workspace->getPrevWindowInList(current);
1540 } while(! next->setInputFocus() && next != focused);
1542 if (next != focused)
1543 current_workspace->raiseWindow(next);
1544 } else if (current_workspace->getCount() >= 1) {
1545 next = current_workspace->getTopWindowOnStack();
1547 current_workspace->raiseWindow(next);
1548 next->setInputFocus();
1553 void BScreen::raiseFocus(void) {
1554 BlackboxWindow *focused = blackbox->getFocusedWindow();
1558 // if on this Screen, raise it
1559 if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
1560 Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
1561 workspace->raiseWindow(focused);
1566 void BScreen::InitMenu(void) {
1568 rootmenuList.clear();
1570 while (rootmenu->getCount())
1571 rootmenu->remove(0);
1573 rootmenu = new Rootmenu(this);
1575 bool defaultMenu = True;
1577 FILE *menu_file = (FILE *) 0;
1578 const char *menu_filename = blackbox->getMenuFilename();
1581 if (! (menu_file = fopen(menu_filename, "r")))
1582 perror(menu_filename);
1583 if (! menu_file) { // opening the menu file failed, try the default menu
1584 menu_filename = DEFAULTMENU;
1585 if (! (menu_file = fopen(menu_filename, "r")))
1586 perror(menu_filename);
1590 if (feof(menu_file)) {
1591 fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
1592 "%s: Empty menu file"),
1595 char line[1024], label[1024];
1596 memset(line, 0, 1024);
1597 memset(label, 0, 1024);
1599 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
1600 if (line[0] != '#') {
1601 int i, key = 0, index = -1, len = strlen(line);
1603 for (i = 0; i < len; i++) {
1604 if (line[i] == '[') index = 0;
1605 else if (line[i] == ']') break;
1606 else if (line[i] != ' ')
1608 key += tolower(line[i]);
1611 if (key == 517) { // [begin]
1613 for (i = index; i < len; i++) {
1614 if (line[i] == '(') index = 0;
1615 else if (line[i] == ')') break;
1616 else if (index++ >= 0) {
1617 if (line[i] == '\\' && i < len - 1) i++;
1618 label[index - 1] = line[i];
1622 if (index == -1) index = 0;
1623 label[index] = '\0';
1625 rootmenu->setLabel(label);
1626 defaultMenu = parseMenuFile(menu_file, rootmenu);
1628 blackbox->addMenuTimestamp(menu_filename);
1638 rootmenu->setInternalMenu();
1639 rootmenu->insert(i18n(ScreenSet, Screenxterm, "xterm"),
1641 i18n(ScreenSet, Screenxterm, "xterm"));
1642 rootmenu->insert(i18n(ScreenSet, ScreenRestart, "Restart"),
1644 rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
1646 rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
1652 bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
1653 char line[1024], label[1024], command[1024];
1655 while (! feof(file)) {
1656 memset(line, 0, 1024);
1657 memset(label, 0, 1024);
1658 memset(command, 0, 1024);
1660 if (fgets(line, 1024, file)) {
1661 if (line[0] != '#') {
1662 int i, key = 0, parse = 0, index = -1, line_length = strlen(line);
1664 // determine the keyword
1665 for (i = 0; i < line_length; i++) {
1666 if (line[i] == '[') parse = 1;
1667 else if (line[i] == ']') break;
1668 else if (line[i] != ' ')
1670 key += tolower(line[i]);
1673 // get the label enclosed in ()'s
1676 for (i = 0; i < line_length; i++) {
1677 if (line[i] == '(') {
1680 } else if (line[i] == ')') break;
1681 else if (index++ >= 0) {
1682 if (line[i] == '\\' && i < line_length - 1) i++;
1683 label[index - 1] = line[i];
1688 label[index] = '\0';
1693 // get the command enclosed in {}'s
1696 for (i = 0; i < line_length; i++) {
1697 if (line[i] == '{') {
1700 } else if (line[i] == '}') break;
1701 else if (index++ >= 0) {
1702 if (line[i] == '\\' && i < line_length - 1) i++;
1703 command[index - 1] = line[i];
1708 command[index] = '\0';
1715 return ((menu->getCount() == 0) ? True : False);
1722 menu->insert(label);
1727 if ((! *label) && (! *command)) {
1728 fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
1729 "BScreen::parseMenuFile: [exec] error, "
1730 "no menu label and/or command defined\n"));
1734 menu->insert(label, BScreen::Execute, command);
1740 fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
1741 "BScreen::parseMenuFile: [exit] error, "
1742 "no menu label defined\n"));
1746 menu->insert(label, BScreen::Exit);
1752 if ((! *label) || (! *command)) {
1754 i18n(ScreenSet, ScreenSTYLEError,
1755 "BScreen::parseMenuFile: [style] error, "
1756 "no menu label and/or filename defined\n"));
1760 string style = expandTilde(command);
1762 menu->insert(label, BScreen::SetStyle, style.c_str());
1769 fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
1770 "BScreen::parseMenufile: [config] error, "
1771 "no label defined"));
1775 menu->insert(label, configmenu);
1779 case 740: // include
1782 fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
1783 "BScreen::parseMenuFile: [include] error, "
1784 "no filename defined\n"));
1788 string newfile = expandTilde(label);
1789 FILE *submenufile = fopen(newfile.c_str(), "r");
1793 if (fstat(fileno(submenufile), &buf) ||
1794 (! S_ISREG(buf.st_mode))) {
1796 i18n(ScreenSet, ScreenINCLUDEErrorReg,
1797 "BScreen::parseMenuFile: [include] error: "
1798 "'%s' is not a regular file\n"), newfile.c_str());
1802 if (! feof(submenufile)) {
1803 if (! parseMenuFile(submenufile, menu))
1804 blackbox->addMenuTimestamp(newfile);
1806 fclose(submenufile);
1809 perror(newfile.c_str());
1815 case 767: // submenu
1818 fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
1819 "BScreen::parseMenuFile: [submenu] error, "
1820 "no menu label defined\n"));
1824 Rootmenu *submenu = new Rootmenu(this);
1827 submenu->setLabel(command);
1829 submenu->setLabel(label);
1831 parseMenuFile(file, submenu);
1833 menu->insert(label, submenu);
1834 rootmenuList.push_back(submenu);
1839 case 773: // restart
1842 fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
1843 "BScreen::parseMenuFile: [restart] error, "
1844 "no menu label defined\n"));
1849 menu->insert(label, BScreen::RestartOther, command);
1851 menu->insert(label, BScreen::Restart);
1856 case 845: // reconfig
1860 i18n(ScreenSet, ScreenRECONFIGError,
1861 "BScreen::parseMenuFile: [reconfig] error, "
1862 "no menu label defined\n"));
1866 menu->insert(label, BScreen::Reconfigure);
1871 case 995: // stylesdir
1872 case 1113: // stylesmenu
1874 bool newmenu = ((key == 1113) ? True : False);
1876 if ((! *label) || ((! *command) && newmenu)) {
1878 i18n(ScreenSet, ScreenSTYLESDIRError,
1879 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1880 " error, no directory defined\n"));
1884 char *directory = ((newmenu) ? command : label);
1886 string stylesdir = expandTilde(directory);
1888 struct stat statbuf;
1890 if (! stat(stylesdir.c_str(), &statbuf)) {
1891 if (S_ISDIR(statbuf.st_mode)) {
1892 Rootmenu *stylesmenu;
1895 stylesmenu = new Rootmenu(this);
1899 DIR *d = opendir(stylesdir.c_str());
1901 std::vector<string> ls;
1903 while((p = readdir(d)))
1904 ls.push_back(p->d_name);
1908 std::sort(ls.begin(), ls.end());
1910 std::vector<string>::iterator it = ls.begin(),
1912 for (; it != end; ++it) {
1913 const string& fname = *it;
1915 if (fname[fname.size()-1] == '~')
1918 string style = stylesdir;
1922 if ((! stat(style.c_str(), &statbuf)) &&
1923 S_ISREG(statbuf.st_mode))
1924 stylesmenu->insert(fname, BScreen::SetStyle, style);
1927 stylesmenu->update();
1930 stylesmenu->setLabel(label);
1931 menu->insert(label, stylesmenu);
1932 rootmenuList.push_back(stylesmenu);
1935 blackbox->addMenuTimestamp(stylesdir);
1938 i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
1939 "BScreen::parseMenuFile:"
1940 " [stylesdir/stylesmenu] error, %s is not a"
1941 " directory\n"), stylesdir.c_str());
1945 i18n(ScreenSet, ScreenSTYLESDIRErrorNoExist,
1946 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1947 " error, %s does not exist\n"), stylesdir.c_str());
1952 case 1090: // workspaces
1956 i18n(ScreenSet, ScreenWORKSPACESError,
1957 "BScreen:parseMenuFile: [workspaces] error, "
1958 "no menu label defined\n"));
1962 menu->insert(label, workspacemenu);
1971 return ((menu->getCount() == 0) ? True : False);
1975 void BScreen::shutdown(void) {
1976 XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
1977 XSync(blackbox->getXDisplay(), False);
1979 while(! windowList.empty())
1980 unmanageWindow(windowList.front(), True);
1986 void BScreen::showPosition(int x, int y) {
1987 if (! geom_visible) {
1988 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1989 (getWidth() - geom_w) / 2,
1990 (getHeight() - geom_h) / 2, geom_w, geom_h);
1991 XMapWindow(blackbox->getXDisplay(), geom_window);
1992 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1994 geom_visible = True;
1999 sprintf(label, i18n(ScreenSet, ScreenPositionFormat,
2000 "X: %4d x Y: %4d"), x, y);
2002 XClearWindow(blackbox->getXDisplay(), geom_window);
2004 resource.wstyle.font->drawString(geom_window,
2005 resource.bevel_width, resource.bevel_width,
2006 resource.wstyle.l_text_focus,
2011 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
2012 if (! geom_visible) {
2013 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
2014 (getWidth() - geom_w) / 2,
2015 (getHeight() - geom_h) / 2, geom_w, geom_h);
2016 XMapWindow(blackbox->getXDisplay(), geom_window);
2017 XRaiseWindow(blackbox->getXDisplay(), geom_window);
2019 geom_visible = True;
2024 sprintf(label, i18n(ScreenSet, ScreenGeometryFormat,
2025 "W: %4d x H: %4d"), gx, gy);
2027 XClearWindow(blackbox->getXDisplay(), geom_window);
2029 resource.wstyle.font->drawString(geom_window,
2030 resource.bevel_width, resource.bevel_width,
2031 resource.wstyle.l_text_focus,
2036 void BScreen::hideGeometry(void) {
2038 XUnmapWindow(blackbox->getXDisplay(), geom_window);
2039 geom_visible = False;
2044 void BScreen::addStrut(Strut *strut) {
2045 strutList.push_back(strut);
2049 void BScreen::removeStrut(Strut *strut) {
2050 strutList.remove(strut);
2054 const Rect& BScreen::availableArea(void) const {
2056 return getRect(); // return the full screen
2061 void BScreen::updateAvailableArea(void) {
2062 Rect old_area = usableArea;
2063 usableArea = getRect(); // reset to full screen
2065 /* these values represent offsets from the screen edge
2066 * we look for the biggest offset on each edge and then apply them
2068 * do not be confused by the similarity to the names of Rect's members
2070 unsigned int current_left = 0, current_right = 0, current_top = 0,
2073 StrutList::const_iterator it = strutList.begin(), end = strutList.end();
2075 for(; it != end; ++it) {
2077 if (strut->left > current_left)
2078 current_left = strut->left;
2079 if (strut->top > current_top)
2080 current_top = strut->top;
2081 if (strut->right > current_right)
2082 current_right = strut->right;
2083 if (strut->bottom > current_bottom)
2084 current_bottom = strut->bottom;
2087 usableArea.setPos(current_left, current_top);
2088 usableArea.setSize(usableArea.width() - (current_left + current_right),
2089 usableArea.height() - (current_top + current_bottom));
2091 if (old_area != usableArea) {
2092 BlackboxWindowList::iterator it = windowList.begin(),
2093 end = windowList.end();
2094 for (; it != end; ++it)
2095 if ((*it)->isMaximized()) (*it)->remaximize();
2102 Workspace* BScreen::getWorkspace(unsigned int index) {
2103 assert(index < workspacesList.size());
2104 return workspacesList[index];
2108 void BScreen::buttonPressEvent(const XButtonEvent *xbutton) {
2109 if (xbutton->button == 1) {
2110 if (! isRootColormapInstalled())
2111 image_control->installRootColormap();
2113 if (workspacemenu->isVisible())
2114 workspacemenu->hide();
2116 if (rootmenu->isVisible())
2118 } else if (xbutton->button == 2) {
2119 int mx = xbutton->x_root - (workspacemenu->getWidth() / 2);
2120 int my = xbutton->y_root - (workspacemenu->getTitleHeight() / 2);
2125 if (mx + workspacemenu->getWidth() > getWidth())
2126 mx = getWidth() - workspacemenu->getWidth() - getBorderWidth();
2128 if (my + workspacemenu->getHeight() > getHeight())
2129 my = getHeight() - workspacemenu->getHeight() - getBorderWidth();
2131 workspacemenu->move(mx, my);
2133 if (! workspacemenu->isVisible()) {
2134 workspacemenu->removeParent();
2135 workspacemenu->show();
2137 } else if (xbutton->button == 3) {
2138 int mx = xbutton->x_root - (rootmenu->getWidth() / 2);
2139 int my = xbutton->y_root - (rootmenu->getTitleHeight() / 2);
2144 if (mx + rootmenu->getWidth() > getWidth())
2145 mx = getWidth() - rootmenu->getWidth() - getBorderWidth();
2147 if (my + rootmenu->getHeight() > getHeight())
2148 my = getHeight() - rootmenu->getHeight() - getBorderWidth();
2150 rootmenu->move(mx, my);
2152 if (! rootmenu->isVisible()) {
2153 blackbox->checkMenu();
2157 } else if (xbutton->button == 4) {
2158 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2159 changeWorkspaceID(0);
2161 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2163 } else if (xbutton->button == 5) {
2164 if (getCurrentWorkspaceID() == 0)
2165 changeWorkspaceID(getWorkspaceCount() - 1);
2167 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2172 void BScreen::propertyNotifyEvent(const XPropertyEvent *pe) {
2173 if (pe->atom == xatom->getAtom(XAtom::net_desktop_names)) {
2174 // _NET_WM_DESKTOP_NAMES
2175 WorkspaceList::iterator it = workspacesList.begin();
2176 const WorkspaceList::iterator end = workspacesList.end();
2177 for (; it != end; ++it) {
2178 (*it)->readName(); // re-read its name from the window property
2179 workspacemenu->changeWorkspaceLabel((*it)->getID(), (*it)->getName());
2181 workspacemenu->update();
2182 toolbar->reconfigure();
2183 saveWorkspaceNames();
2188 void BScreen::toggleFocusModel(FocusModel model) {
2189 std::for_each(windowList.begin(), windowList.end(),
2190 std::mem_fun(&BlackboxWindow::ungrabButtons));
2192 if (model == SloppyFocus) {
2193 saveSloppyFocus(True);
2195 // we're cheating here to save writing the config file 3 times
2196 resource.auto_raise = False;
2197 resource.click_raise = False;
2198 saveSloppyFocus(False);
2201 std::for_each(windowList.begin(), windowList.end(),
2202 std::mem_fun(&BlackboxWindow::grabButtons));
2206 BTexture BScreen::readDatabaseTexture(const string &rname,
2207 const string &default_color,
2208 const Configuration &style) {
2212 if (style.getValue(rname, s))
2213 texture = BTexture(s);
2215 texture.setTexture(BTexture::Solid | BTexture::Flat);
2217 // associate this texture with this screen
2218 texture.setDisplay(getBaseDisplay(), getScreenNumber());
2219 texture.setImageControl(image_control);
2221 if (texture.texture() & BTexture::Solid) {
2222 texture.setColor(readDatabaseColor(rname + ".color",
2223 default_color, style));
2224 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2225 default_color, style));
2226 } else if (texture.texture() & BTexture::Gradient) {
2227 texture.setColor(readDatabaseColor(rname + ".color",
2228 default_color, style));
2229 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2230 default_color, style));
2237 BColor BScreen::readDatabaseColor(const string &rname,
2238 const string &default_color,
2239 const Configuration &style) {
2242 if (style.getValue(rname, s))
2243 color = BColor(s, getBaseDisplay(), getScreenNumber());
2245 color = BColor(default_color, getBaseDisplay(), getScreenNumber());
2250 BFont *BScreen::readDatabaseFont(const string &rbasename,
2251 const Configuration &style) {
2258 if (style.getValue(rbasename + "xft.font", s) &&
2259 style.getValue(rbasename + "xft.size", i)) {
2262 bool italic = False;
2263 if (style.getValue(rbasename + "xft.flags", s)) {
2264 if (s.find("bold") != string::npos)
2266 if (s.find("italic") != string::npos)
2270 BFont *b = new BFont(blackbox->getXDisplay(), this, family, i, bold,
2271 italic, resource.aa_fonts);
2275 delete b; // fall back to the normal X font stuff
2279 style.getValue(rbasename + "font", s);
2280 // if this fails, a blank string will be used, which will cause the fallback
2283 BFont *b = new BFont(blackbox->getXDisplay(), this, s);
2285 exit(2); // can't continue without a font