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"
90 #ifndef FONT_ELEMENT_SIZE
91 #define FONT_ELEMENT_SIZE 50
92 #endif // FONT_ELEMENT_SIZE
95 static bool running = True;
97 static int anotherWMRunning(Display *display, XErrorEvent *) {
98 fprintf(stderr, i18n(ScreenSet, ScreenAnotherWMRunning,
99 "BScreen::BScreen: an error occured while querying the X server.\n"
100 " another window manager already running on display %s.\n"),
101 DisplayString(display));
109 BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
111 screenstr = "session.screen" + itostring(scrn) + '.';
112 config = blackbox->getConfig();
113 xatom = blackbox->getXAtom();
115 event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
116 SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask;
118 XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
119 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask);
120 XSync(getBaseDisplay()->getXDisplay(), False);
121 XSetErrorHandler((XErrorHandler) old);
124 if (! managed) return;
126 fprintf(stderr, i18n(ScreenSet, ScreenManagingScreen,
127 "BScreen::BScreen: managing screen %d "
128 "using visual 0x%lx, depth %d\n"),
129 getScreenNumber(), XVisualIDFromVisual(getVisual()),
134 resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
135 resource.wstyle.font = (BFont *) 0;
139 xatom->setSupported(this); // set-up netwm support
141 xatom->setValue(getRootWindow(), XAtom::blackbox_pid, XAtom::cardinal,
142 (unsigned long) getpid());
143 #endif // HAVE_GETPID
144 unsigned long geometry[] = { getWidth(),
146 xatom->setValue(getRootWindow(), XAtom::net_desktop_geometry,
147 XAtom::cardinal, geometry, 2);
148 unsigned long viewport[] = {0,0};
149 xatom->setValue(getRootWindow(), XAtom::net_desktop_viewport,
150 XAtom::cardinal, viewport, 2);
153 XDefineCursor(blackbox->getXDisplay(), getRootWindow(),
154 blackbox->getSessionCursor());
156 // start off full screen, top left.
157 usableArea.setSize(getWidth(), getHeight());
160 new BImageControl(blackbox, this, True, blackbox->getColorsPerChannel(),
161 blackbox->getCacheLife(), blackbox->getCacheMax());
162 image_control->installRootColormap();
163 root_colormap_installed = True;
169 gcv.foreground = WhitePixel(blackbox->getXDisplay(), getScreenNumber())
170 ^ BlackPixel(blackbox->getXDisplay(), getScreenNumber());
171 gcv.function = GXxor;
172 gcv.subwindow_mode = IncludeInferiors;
173 opGC = XCreateGC(blackbox->getXDisplay(), getRootWindow(),
174 GCForeground | GCFunction | GCSubwindowMode, &gcv);
176 const char *s = i18n(ScreenSet, ScreenPositionLength,
177 "0: 0000 x 0: 0000");
178 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
179 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
181 XSetWindowAttributes attrib;
182 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
183 attrib.border_pixel = getBorderColor()->pixel();
184 attrib.colormap = getColormap();
185 attrib.save_under = True;
187 geom_window = XCreateWindow(blackbox->getXDisplay(), getRootWindow(),
188 0, 0, geom_w, geom_h, resource.border_width,
189 getDepth(), InputOutput, getVisual(),
191 geom_visible = False;
193 BTexture* texture = &(resource.wstyle.l_focus);
194 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
195 if (geom_pixmap == ParentRelative) {
196 texture = &(resource.wstyle.t_focus);
197 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
200 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
201 texture->color().pixel());
203 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
204 geom_window, geom_pixmap);
206 workspacemenu = new Workspacemenu(this);
207 iconmenu = new Iconmenu(this);
208 configmenu = new Configmenu(this);
210 if (resource.workspaces != 0) {
211 for (unsigned int i = 0; i < resource.workspaces; ++i) {
212 Workspace *wkspc = new Workspace(this, workspacesList.size());
213 workspacesList.push_back(wkspc);
214 workspacemenu->insertWorkspace(wkspc);
215 workspacemenu->update();
219 Workspace *wkspc = new Workspace(this, workspacesList.size());
220 workspacesList.push_back(wkspc);
221 workspacemenu->insertWorkspace(wkspc);
222 workspacemenu->update();
224 saveWorkspaceNames();
226 updateNetizenWorkspaceCount();
228 workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
229 workspacemenu->update();
231 current_workspace = workspacesList.front();
233 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
234 XAtom::cardinal, 0); //first workspace
236 workspacemenu->setItemSelected(2, True);
238 toolbar = new Toolbar(this);
240 slit = new Slit(this);
244 raiseWindows(0, 0); // this also initializes the empty stacking list
247 updateClientList(); // initialize the client lists, which will be empty
248 updateAvailableArea();
250 changeWorkspaceID(0);
252 unsigned int i, j, nchild;
253 Window r, p, *children;
254 XQueryTree(blackbox->getXDisplay(), getRootWindow(), &r, &p,
257 // preen the window list of all icon windows... for better dockapp support
258 for (i = 0; i < nchild; i++) {
259 if (children[i] == None) continue;
261 XWMHints *wmhints = XGetWMHints(blackbox->getXDisplay(),
265 if ((wmhints->flags & IconWindowHint) &&
266 (wmhints->icon_window != children[i])) {
267 for (j = 0; j < nchild; j++) {
268 if (children[j] == wmhints->icon_window) {
279 // manage shown windows
280 for (i = 0; i < nchild; ++i) {
281 if (children[i] == None || (! blackbox->validateWindow(children[i])))
284 XWindowAttributes attrib;
285 if (XGetWindowAttributes(blackbox->getXDisplay(), children[i], &attrib)) {
286 if (attrib.override_redirect) continue;
288 if (attrib.map_state != IsUnmapped) {
289 manageWindow(children[i]);
296 // call this again just in case a window we found updates the Strut list
297 updateAvailableArea();
301 BScreen::~BScreen(void) {
302 if (! managed) return;
304 if (geom_pixmap != None)
305 image_control->removeImage(geom_pixmap);
307 if (geom_window != None)
308 XDestroyWindow(blackbox->getXDisplay(), geom_window);
310 std::for_each(workspacesList.begin(), workspacesList.end(),
313 std::for_each(iconList.begin(), iconList.end(), PointerAssassin());
315 std::for_each(netizenList.begin(), netizenList.end(), PointerAssassin());
317 while (! systrayWindowList.empty())
318 removeSystrayWindow(systrayWindowList[0]);
321 delete workspacemenu;
326 delete image_control;
328 if (resource.wstyle.font)
329 delete resource.wstyle.font;
330 if (resource.mstyle.t_font)
331 delete resource.mstyle.t_font;
332 if (resource.mstyle.f_font)
333 delete resource.mstyle.f_font;
334 if (resource.tstyle.font)
335 delete resource.tstyle.font;
337 XFreeGC(blackbox->getXDisplay(), opGC);
341 void BScreen::saveSloppyFocus(bool s) {
342 resource.sloppy_focus = s;
345 if (resource.sloppy_focus) {
346 fmodel = "SloppyFocus";
347 if (resource.auto_raise) fmodel += " AutoRaise";
348 if (resource.click_raise) fmodel += " ClickRaise";
350 fmodel = "ClickToFocus";
352 config->setValue(screenstr + "focusModel", fmodel);
356 void BScreen::saveAutoRaise(bool a) {
357 resource.auto_raise = a;
358 saveSloppyFocus(resource.sloppy_focus);
362 void BScreen::saveClickRaise(bool c) {
363 resource.click_raise = c;
364 saveSloppyFocus(resource.sloppy_focus);
368 void BScreen::saveImageDither(bool d) {
369 image_control->setDither(d);
370 config->setValue(screenstr + "imageDither", doImageDither());
374 void BScreen::saveOpaqueMove(bool o) {
375 resource.opaque_move = o;
376 config->setValue(screenstr + "opaqueMove", resource.opaque_move);
380 void BScreen::saveFullMax(bool f) {
381 resource.full_max = f;
382 config->setValue(screenstr + "fullMaximization", resource.full_max);
386 void BScreen::saveFocusNew(bool f) {
387 resource.focus_new = f;
388 config->setValue(screenstr + "focusNewWindows", resource.focus_new);
392 void BScreen::saveFocusLast(bool f) {
393 resource.focus_last = f;
394 config->setValue(screenstr + "focusLastWindow", resource.focus_last);
398 void BScreen::saveAAFonts(bool f) {
399 resource.aa_fonts = f;
401 config->setValue(screenstr + "antialiasFonts", resource.aa_fonts);
405 void BScreen::saveHideToolbar(bool h) {
406 resource.hide_toolbar = h;
407 if (resource.hide_toolbar)
408 toolbar->unmapToolbar();
410 toolbar->mapToolbar();
411 config->setValue(screenstr + "hideToolbar", resource.hide_toolbar);
415 void BScreen::saveWindowToWindowSnap(bool s) {
416 resource.window_to_window_snap = s;
417 config->setValue(screenstr + "windowToWindowSnap",
418 resource.window_to_window_snap);
422 void BScreen::saveResizeZones(unsigned int z) {
423 resource.resize_zones = z;
424 config->setValue(screenstr + "resizeZones", resource.resize_zones);
428 void BScreen::saveWindowCornerSnap(bool s) {
429 resource.window_corner_snap = s;
430 config->setValue(screenstr + "windowCornerSnap",
431 resource.window_corner_snap);
435 void BScreen::saveWorkspaces(unsigned int w) {
436 resource.workspaces = w;
437 config->setValue(screenstr + "workspaces", resource.workspaces);
441 void BScreen::savePlacementPolicy(int p) {
442 resource.placement_policy = p;
443 const char *placement;
444 switch (resource.placement_policy) {
445 case CascadePlacement: placement = "CascadePlacement"; break;
446 case UnderMousePlacement: placement = "UnderMousePlacement"; break;
447 case ClickMousePlacement: placement = "ClickMousePlacement"; break;
448 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
449 case RowSmartPlacement: default: placement = "RowSmartPlacement"; break;
451 config->setValue(screenstr + "windowPlacement", placement);
455 void BScreen::saveEdgeSnapThreshold(int t) {
456 resource.edge_snap_threshold = t;
457 config->setValue(screenstr + "edgeSnapThreshold",
458 resource.edge_snap_threshold);
462 void BScreen::saveRowPlacementDirection(int d) {
463 resource.row_direction = d;
464 config->setValue(screenstr + "rowPlacementDirection",
465 resource.row_direction == LeftRight ?
466 "LeftToRight" : "RightToLeft");
470 void BScreen::saveColPlacementDirection(int d) {
471 resource.col_direction = d;
472 config->setValue(screenstr + "colPlacementDirection",
473 resource.col_direction == TopBottom ?
474 "TopToBottom" : "BottomToTop");
479 void BScreen::saveStrftimeFormat(const std::string& format) {
480 resource.strftime_format = format;
481 config->setValue(screenstr + "strftimeFormat", resource.strftime_format);
484 #else // !HAVE_STRFTIME
486 void BScreen::saveDateFormat(int f) {
487 resource.date_format = f;
488 config->setValue(screenstr + "dateFormat",
489 resource.date_format == B_EuropeanDate ?
490 "European" : "American");
494 void BScreen::saveClock24Hour(bool c) {
495 resource.clock24hour = c;
496 config->setValue(screenstr + "clockFormat", resource.clock24hour ? 24 : 12);
498 #endif // HAVE_STRFTIME
501 void BScreen::saveWorkspaceNames() {
504 for (unsigned int i = 0; i < workspacesList.size(); ++i) {
505 names += workspacesList[i]->getName();
506 if (i < workspacesList.size() - 1)
510 config->setValue(screenstr + "workspaceNames", names);
514 void BScreen::savePlaceIgnoreShaded(bool i) {
515 resource.ignore_shaded = i;
516 config->setValue(screenstr + "placementIgnoreShaded",
517 resource.ignore_shaded);
521 void BScreen::savePlaceIgnoreMaximized(bool i) {
522 resource.ignore_maximized = i;
523 config->setValue(screenstr + "placementIgnoreMaximized",
524 resource.ignore_maximized);
528 void BScreen::save_rc(void) {
529 saveSloppyFocus(resource.sloppy_focus);
530 saveAutoRaise(resource.auto_raise);
531 saveImageDither(doImageDither());
532 saveAAFonts(resource.aa_fonts);
533 saveResizeZones(resource.resize_zones);
534 saveOpaqueMove(resource.opaque_move);
535 saveFullMax(resource.full_max);
536 saveFocusNew(resource.focus_new);
537 saveFocusLast(resource.focus_last);
538 saveHideToolbar(resource.hide_toolbar);
539 saveWindowToWindowSnap(resource.window_to_window_snap);
540 saveWindowCornerSnap(resource.window_corner_snap);
541 saveWorkspaces(resource.workspaces);
542 savePlacementPolicy(resource.placement_policy);
543 saveEdgeSnapThreshold(resource.edge_snap_threshold);
544 saveRowPlacementDirection(resource.row_direction);
545 saveColPlacementDirection(resource.col_direction);
547 saveStrftimeFormat(resource.strftime_format);
548 #else // !HAVE_STRFTIME
549 saveDateFormat(resource.date_format);
550 savwClock24Hour(resource.clock24hour);
551 #endif // HAVE_STRFTIME
552 savePlaceIgnoreShaded(resource.ignore_shaded);
553 savePlaceIgnoreMaximized(resource.ignore_maximized);
560 void BScreen::load_rc(void) {
564 if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
565 resource.full_max = false;
567 if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
568 resource.focus_new = false;
570 if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
571 resource.focus_last = false;
573 if (! config->getValue(screenstr + "workspaces", resource.workspaces))
574 resource.workspaces = 1;
576 if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
577 resource.opaque_move = false;
579 if (! config->getValue(screenstr + "antialiasFonts", resource.aa_fonts))
580 resource.aa_fonts = true;
582 if (! config->getValue(screenstr + "resizeZones", resource.resize_zones) ||
583 (resource.resize_zones != 1 && resource.resize_zones != 2 &&
584 resource.resize_zones != 4))
585 resource.resize_zones = 4;
587 if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
588 resource.hide_toolbar = false;
590 if (! config->getValue(screenstr + "windowToWindowSnap",
591 resource.window_to_window_snap))
592 resource.window_to_window_snap = true;
594 if (! config->getValue(screenstr + "windowCornerSnap",
595 resource.window_corner_snap))
596 resource.window_corner_snap = true;
598 if (! config->getValue(screenstr + "imageDither", b))
600 image_control->setDither(b);
602 if (! config->getValue(screenstr + "edgeSnapThreshold",
603 resource.edge_snap_threshold))
604 resource.edge_snap_threshold = 4;
606 if (config->getValue(screenstr + "rowPlacementDirection", s) &&
608 resource.row_direction = RightLeft;
610 resource.row_direction = LeftRight;
612 if (config->getValue(screenstr + "colPlacementDirection", s) &&
614 resource.col_direction = BottomTop;
616 resource.col_direction = TopBottom;
618 if (config->getValue(screenstr + "workspaceNames", s)) {
619 XAtom::StringVect workspaceNames;
621 string::const_iterator it = s.begin(), end = s.end();
623 string::const_iterator tmp = it; // current string.begin()
624 it = std::find(tmp, end, ','); // look for comma between tmp and end
625 workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
631 xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
635 resource.sloppy_focus = true;
636 resource.auto_raise = false;
637 resource.click_raise = false;
638 if (config->getValue(screenstr + "focusModel", s)) {
639 if (s.find("ClickToFocus") != string::npos) {
640 resource.sloppy_focus = false;
643 if (s.find("AutoRaise") != string::npos)
644 resource.auto_raise = true;
645 if (s.find("ClickRaise") != string::npos)
646 resource.click_raise = true;
650 if (config->getValue(screenstr + "windowPlacement", s)) {
651 if (s == "CascadePlacement")
652 resource.placement_policy = CascadePlacement;
653 else if (s == "UnderMousePlacement")
654 resource.placement_policy = UnderMousePlacement;
655 else if (s == "ClickMousePlacement")
656 resource.placement_policy = ClickMousePlacement;
657 else if (s == "ColSmartPlacement")
658 resource.placement_policy = ColSmartPlacement;
659 else //if (s == "RowSmartPlacement")
660 resource.placement_policy = RowSmartPlacement;
662 resource.placement_policy = RowSmartPlacement;
665 if (! config->getValue(screenstr + "strftimeFormat",
666 resource.strftime_format))
667 resource.strftime_format = "%I:%M %p";
668 #else // !HAVE_STRFTIME
671 if (config->getValue(screenstr + "dateFormat", s) && s == "European")
672 resource.date_format = B_EuropeanDate;
674 resource.date_format = B_AmericanDate;
676 if (! config->getValue(screenstr + "clockFormat", l))
678 resource.clock24hour = l == 24;
679 #endif // HAVE_STRFTIME
681 if (! config->getValue(screenstr + "placementIgnoreShaded",
682 resource.ignore_shaded))
683 resource.ignore_shaded = true;
685 if (! config->getValue(screenstr + "placementIgnoreMaximized",
686 resource.ignore_maximized))
687 resource.ignore_maximized = true;
691 void BScreen::changeWorkspaceCount(unsigned int new_count) {
692 assert(new_count > 0);
694 if (new_count < workspacesList.size()) {
696 for (unsigned int i = workspacesList.size(); i > new_count; --i)
697 removeLastWorkspace();
698 // removeLast already sets the current workspace to the
699 // last available one.
700 } else if (new_count > workspacesList.size()) {
702 for(unsigned int i = workspacesList.size(); i < new_count; ++i)
708 void BScreen::reconfigure(void) {
709 // don't reconfigure while saving the initial rc file, it's a waste and it
710 // breaks somethings (workspace names)
711 if (blackbox->isStartup()) return;
718 // we need to do this explicitly, because just loading this value from the rc
720 changeWorkspaceCount(resource.workspaces);
723 gcv.foreground = WhitePixel(blackbox->getXDisplay(),
725 gcv.function = GXinvert;
726 gcv.subwindow_mode = IncludeInferiors;
727 XChangeGC(blackbox->getXDisplay(), opGC,
728 GCForeground | GCFunction | GCSubwindowMode, &gcv);
730 const char *s = i18n(ScreenSet, ScreenPositionLength,
731 "0: 0000 x 0: 0000");
733 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
734 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
736 BTexture* texture = &(resource.wstyle.l_focus);
737 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
738 if (geom_pixmap == ParentRelative) {
739 texture = &(resource.wstyle.t_focus);
740 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
743 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
744 texture->color().pixel());
746 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
747 geom_window, geom_pixmap);
749 XSetWindowBorderWidth(blackbox->getXDisplay(), geom_window,
750 resource.border_width);
751 XSetWindowBorder(blackbox->getXDisplay(), geom_window,
752 resource.border_color.pixel());
754 workspacemenu->reconfigure();
755 iconmenu->reconfigure();
757 typedef std::vector<int> SubList;
758 SubList remember_subs;
760 // save the current open menus
761 Basemenu *menu = rootmenu;
763 while ((submenu = menu->getCurrentSubmenu()) >= 0) {
764 remember_subs.push_back(submenu);
765 menu = menu->find(submenu)->submenu();
771 rootmenu->reconfigure();
773 // reopen the saved menus
775 const SubList::iterator subs_end = remember_subs.end();
776 for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
777 menu->drawSubmenu(*it);
778 menu = menu->find(*it)->submenu();
783 configmenu->reconfigure();
785 toolbar->reconfigure();
789 std::for_each(workspacesList.begin(), workspacesList.end(),
790 std::mem_fun(&Workspace::reconfigure));
792 BlackboxWindowList::iterator iit = iconList.begin();
793 for (; iit != iconList.end(); ++iit) {
794 BlackboxWindow *bw = *iit;
795 if (bw->validateClient())
799 image_control->timeout();
803 void BScreen::rereadMenu(void) {
807 rootmenu->reconfigure();
811 void BScreen::LoadStyle(void) {
812 Configuration style(False);
814 const char *sfile = blackbox->getStyleFilename();
816 style.setFile(sfile);
817 if (! style.load()) {
818 style.setFile(DEFAULTSTYLE);
820 style.create(); // hardcoded default values will be used.
824 // merge in the rc file
825 style.merge(config->file(), True);
829 // load fonts/fontsets
830 if (resource.wstyle.font)
831 delete resource.wstyle.font;
832 if (resource.tstyle.font)
833 delete resource.tstyle.font;
834 if (resource.mstyle.f_font)
835 delete resource.mstyle.f_font;
836 if (resource.mstyle.t_font)
837 delete resource.mstyle.t_font;
838 resource.wstyle.font = resource.tstyle.font = resource.mstyle.f_font =
839 resource.mstyle.t_font = (BFont *) 0;
841 resource.wstyle.font = readDatabaseFont("window.", style);
842 resource.tstyle.font = readDatabaseFont("toolbar.", style);
843 resource.mstyle.t_font = readDatabaseFont("menu.title.", style);
844 resource.mstyle.f_font = readDatabaseFont("menu.frame.", style);
846 // load window config
847 resource.wstyle.t_focus =
848 readDatabaseTexture("window.title.focus", "white", style);
849 resource.wstyle.t_unfocus =
850 readDatabaseTexture("window.title.unfocus", "black", style);
851 resource.wstyle.l_focus =
852 readDatabaseTexture("window.label.focus", "white", style);
853 resource.wstyle.l_unfocus =
854 readDatabaseTexture("window.label.unfocus", "black", style);
855 resource.wstyle.h_focus =
856 readDatabaseTexture("window.handle.focus", "white", style);
857 resource.wstyle.h_unfocus =
858 readDatabaseTexture("window.handle.unfocus", "black", style);
859 resource.wstyle.g_focus =
860 readDatabaseTexture("window.grip.focus", "white", style);
861 resource.wstyle.g_unfocus =
862 readDatabaseTexture("window.grip.unfocus", "black", style);
863 resource.wstyle.b_focus =
864 readDatabaseTexture("window.button.focus", "white", style);
865 resource.wstyle.b_unfocus =
866 readDatabaseTexture("window.button.unfocus", "black", style);
867 resource.wstyle.b_pressed =
868 readDatabaseTexture("window.button.pressed", "black", style);
869 resource.wstyle.f_focus =
870 readDatabaseColor("window.frame.focusColor", "white", style);
871 resource.wstyle.f_unfocus =
872 readDatabaseColor("window.frame.unfocusColor", "black", style);
873 resource.wstyle.l_text_focus =
874 readDatabaseColor("window.label.focus.textColor", "black", style);
875 resource.wstyle.l_text_unfocus =
876 readDatabaseColor("window.label.unfocus.textColor", "white", style);
877 resource.wstyle.b_pic_focus =
878 readDatabaseColor("window.button.focus.picColor", "black", style);
879 resource.wstyle.b_pic_unfocus =
880 readDatabaseColor("window.button.unfocus.picColor", "white", style);
882 resource.wstyle.justify = LeftJustify;
883 if (style.getValue("window.justify", s)) {
884 if (s == "right" || s == "Right")
885 resource.wstyle.justify = RightJustify;
886 else if (s == "center" || s == "Center")
887 resource.wstyle.justify = CenterJustify;
890 // load toolbar config
891 resource.tstyle.toolbar =
892 readDatabaseTexture("toolbar", "black", style);
893 resource.tstyle.label =
894 readDatabaseTexture("toolbar.label", "black", style);
895 resource.tstyle.window =
896 readDatabaseTexture("toolbar.windowLabel", "black", style);
897 resource.tstyle.button =
898 readDatabaseTexture("toolbar.button", "white", style);
899 resource.tstyle.pressed =
900 readDatabaseTexture("toolbar.button.pressed", "black", style);
901 resource.tstyle.clock =
902 readDatabaseTexture("toolbar.clock", "black", style);
903 resource.tstyle.l_text =
904 readDatabaseColor("toolbar.label.textColor", "white", style);
905 resource.tstyle.w_text =
906 readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
907 resource.tstyle.c_text =
908 readDatabaseColor("toolbar.clock.textColor", "white", style);
909 resource.tstyle.b_pic =
910 readDatabaseColor("toolbar.button.picColor", "black", style);
912 resource.tstyle.justify = LeftJustify;
913 if (style.getValue("toolbar.justify", s)) {
914 if (s == "right" || s == "Right")
915 resource.tstyle.justify = RightJustify;
916 else if (s == "center" || s == "Center")
917 resource.tstyle.justify = CenterJustify;
921 resource.mstyle.title =
922 readDatabaseTexture("menu.title", "white", style);
923 resource.mstyle.frame =
924 readDatabaseTexture("menu.frame", "black", style);
925 resource.mstyle.hilite =
926 readDatabaseTexture("menu.hilite", "white", style);
927 resource.mstyle.t_text =
928 readDatabaseColor("menu.title.textColor", "black", style);
929 resource.mstyle.f_text =
930 readDatabaseColor("menu.frame.textColor", "white", style);
931 resource.mstyle.d_text =
932 readDatabaseColor("menu.frame.disableColor", "black", style);
933 resource.mstyle.h_text =
934 readDatabaseColor("menu.hilite.textColor", "black", style);
936 resource.mstyle.t_justify = LeftJustify;
937 if (style.getValue("menu.title.justify", s)) {
938 if (s == "right" || s == "Right")
939 resource.mstyle.t_justify = RightJustify;
940 else if (s == "center" || s == "Center")
941 resource.mstyle.t_justify = CenterJustify;
944 resource.mstyle.f_justify = LeftJustify;
945 if (style.getValue("menu.frame.justify", s)) {
946 if (s == "right" || s == "Right")
947 resource.mstyle.f_justify = RightJustify;
948 else if (s == "center" || s == "Center")
949 resource.mstyle.f_justify = CenterJustify;
952 resource.mstyle.bullet = Basemenu::Triangle;
953 if (style.getValue("menu.bullet", s)) {
954 if (s == "empty" || s == "Empty")
955 resource.mstyle.bullet = Basemenu::Empty;
956 else if (s == "square" || s == "Square")
957 resource.mstyle.bullet = Basemenu::Square;
958 else if (s == "diamond" || s == "Diamond")
959 resource.mstyle.bullet = Basemenu::Diamond;
962 resource.mstyle.bullet_pos = Basemenu::Left;
963 if (style.getValue("menu.bullet.position", s)) {
964 if (s == "right" || s == "Right")
965 resource.mstyle.bullet_pos = Basemenu::Right;
968 resource.border_color =
969 readDatabaseColor("borderColor", "black", style);
971 // load bevel, border and handle widths
972 if (! style.getValue("handleWidth", resource.handle_width) ||
973 resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
974 resource.handle_width = 6;
976 if (! style.getValue("borderWidth", resource.border_width))
977 resource.border_width = 1;
979 if (! style.getValue("bevelWidth", resource.bevel_width) ||
980 resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
981 resource.bevel_width = 3;
983 if (! style.getValue("frameWidth", resource.frame_width) ||
984 resource.frame_width > (getWidth() / 2))
985 resource.frame_width = resource.bevel_width;
987 if (style.getValue("rootCommand", s))
988 bexec(s, displayString());
992 void BScreen::addIcon(BlackboxWindow *w) {
995 w->setWorkspace(BSENTINEL);
996 w->setWindowNumber(iconList.size());
998 iconList.push_back(w);
1000 const char* title = w->getIconTitle();
1001 iconmenu->insert(title);
1006 void BScreen::removeIcon(BlackboxWindow *w) {
1011 iconmenu->remove(w->getWindowNumber());
1014 BlackboxWindowList::iterator it = iconList.begin(),
1015 end = iconList.end();
1016 for (int i = 0; it != end; ++it)
1017 (*it)->setWindowNumber(i++);
1021 BlackboxWindow *BScreen::getIcon(unsigned int index) {
1022 if (index < iconList.size()) {
1023 BlackboxWindowList::iterator it = iconList.begin();
1024 for (; index > 0; --index, ++it) ; /* increment to index */
1028 return (BlackboxWindow *) 0;
1032 unsigned int BScreen::addWorkspace(void) {
1033 Workspace *wkspc = new Workspace(this, workspacesList.size());
1034 workspacesList.push_back(wkspc);
1035 saveWorkspaces(getWorkspaceCount());
1036 saveWorkspaceNames();
1038 workspacemenu->insertWorkspace(wkspc);
1039 workspacemenu->update();
1041 toolbar->reconfigure();
1043 updateNetizenWorkspaceCount();
1045 return workspacesList.size();
1049 unsigned int BScreen::removeLastWorkspace(void) {
1050 if (workspacesList.size() == 1)
1053 Workspace *wkspc = workspacesList.back();
1055 if (current_workspace->getID() == wkspc->getID())
1056 changeWorkspaceID(current_workspace->getID() - 1);
1060 workspacemenu->removeWorkspace(wkspc);
1061 workspacemenu->update();
1063 workspacesList.pop_back();
1066 saveWorkspaces(getWorkspaceCount());
1067 saveWorkspaceNames();
1069 toolbar->reconfigure();
1071 updateNetizenWorkspaceCount();
1073 return workspacesList.size();
1077 void BScreen::changeWorkspaceID(unsigned int id) {
1078 if (! current_workspace || id == current_workspace->getID()) return;
1080 BlackboxWindow *focused = blackbox->getFocusedWindow();
1081 if (focused && focused->getScreen() == this) {
1082 assert(focused->isStuck() ||
1083 focused->getWorkspaceNumber() == current_workspace->getID());
1085 current_workspace->setLastFocusedWindow(focused);
1087 // if no window had focus, no need to store a last focus
1088 current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
1091 // when we switch workspaces, unfocus whatever was focused
1092 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1094 current_workspace->hideAll();
1095 workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1097 current_workspace = getWorkspace(id);
1099 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
1100 XAtom::cardinal, id);
1102 workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1103 toolbar->redrawWorkspaceLabel(True);
1105 current_workspace->showAll();
1107 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1108 XSync(blackbox->getXDisplay(), False);
1109 current_workspace->getLastFocusedWindow()->setInputFocus();
1112 updateNetizenCurrentWorkspace();
1117 * Set the _NET_CLIENT_LIST root window property.
1119 void BScreen::updateClientList(void) {
1120 if (windowList.size() > 0) {
1121 Window *windows = new Window[windowList.size()];
1122 Window *win_it = windows;
1123 BlackboxWindowList::iterator it = windowList.begin();
1124 const BlackboxWindowList::iterator end = windowList.end();
1125 for (; it != end; ++it, ++win_it)
1126 *win_it = (*it)->getClientWindow();
1127 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1128 windows, windowList.size());
1131 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1134 updateStackingList();
1139 * Set the _NET_CLIENT_LIST_STACKING root window property.
1141 void BScreen::updateStackingList(void) {
1143 BlackboxWindowList stack_order;
1146 * Get the stacking order from all of the workspaces.
1147 * We start with the current workspace so that the sticky windows will be
1148 * in the right order on the current workspace.
1149 * XXX: Do we need to have sticky windows in the list once for each workspace?
1151 getCurrentWorkspace()->appendStackOrder(stack_order);
1152 for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
1153 if (i != getCurrentWorkspaceID())
1154 getWorkspace(i)->appendStackOrder(stack_order);
1156 if (stack_order.size() > 0) {
1157 // set the client list atoms
1158 Window *windows = new Window[stack_order.size()];
1159 Window *win_it = windows;
1160 BlackboxWindowList::iterator it = stack_order.begin(),
1161 end = stack_order.end();
1162 for (; it != end; ++it, ++win_it)
1163 *win_it = (*it)->getClientWindow();
1164 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1165 XAtom::window, windows, stack_order.size());
1168 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1169 XAtom::window, 0, 0);
1173 void BScreen::addSystrayWindow(Window window) {
1174 systrayWindowList.push_back(window);
1175 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1177 &systrayWindowList[0], systrayWindowList.size());
1178 blackbox->saveSystrayWindowSearch(window, this);
1182 void BScreen::removeSystrayWindow(Window window) {
1183 WindowList::iterator it = systrayWindowList.begin();
1184 const WindowList::iterator end = systrayWindowList.end();
1185 for (; it != end; ++it)
1186 if (*it == window) {
1187 systrayWindowList.erase(it);
1188 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1190 &systrayWindowList[0], systrayWindowList.size());
1191 blackbox->removeSystrayWindowSearch(window);
1197 void BScreen::manageWindow(Window w) {
1198 // is the window a KDE systray window?
1200 if (xatom->getValue(w, XAtom::kde_net_wm_system_tray_window_for,
1201 XAtom::window, systray) && systray) {
1202 addSystrayWindow(w);
1206 new BlackboxWindow(blackbox, w, this);
1208 BlackboxWindow *win = blackbox->searchWindow(w);
1213 if (win->isNormal()) {
1214 // don't list non-normal windows as managed windows
1215 windowList.push_back(win);
1217 } else if (win->isDesktop()) {
1218 desktopWindowList.push_back(win->getFrameWindow());
1221 XMapRequestEvent mre;
1223 if (blackbox->isStartup() && win->isNormal()) win->restoreAttributes();
1224 win->mapRequestEvent(&mre);
1228 void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
1231 if (w->getWorkspaceNumber() != BSENTINEL &&
1232 w->getWindowNumber() != BSENTINEL)
1233 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1234 else if (w->isIconic())
1237 if (w->isNormal()) {
1238 // we don't list non-normal windows as managed windows
1239 windowList.remove(w);
1241 } else if (w->isDesktop()) {
1242 WindowList::iterator it = desktopWindowList.begin();
1243 const WindowList::iterator end = desktopWindowList.end();
1244 for (; it != end; ++it)
1245 if (*it == w->getFrameWindow()) {
1246 desktopWindowList.erase(it);
1249 assert(it != end); // the window wasnt a desktop window?
1252 if (blackbox->getFocusedWindow() == w)
1253 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1255 removeNetizen(w->getClientWindow());
1258 some managed windows can also be window group controllers. when
1259 unmanaging such windows, we should also delete the window group.
1261 BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
1268 void BScreen::addNetizen(Netizen *n) {
1269 netizenList.push_back(n);
1271 n->sendWorkspaceCount();
1272 n->sendCurrentWorkspace();
1274 WorkspaceList::iterator it = workspacesList.begin();
1275 const WorkspaceList::iterator end = workspacesList.end();
1276 for (; it != end; ++it)
1277 (*it)->sendWindowList(*n);
1279 Window f = ((blackbox->getFocusedWindow()) ?
1280 blackbox->getFocusedWindow()->getClientWindow() : None);
1281 n->sendWindowFocus(f);
1285 void BScreen::removeNetizen(Window w) {
1286 NetizenList::iterator it = netizenList.begin();
1287 for (; it != netizenList.end(); ++it) {
1288 if ((*it)->getWindowID() == w) {
1290 netizenList.erase(it);
1297 void BScreen::updateWorkArea(void) {
1298 if (workspacesList.size() > 0) {
1299 unsigned long *dims = new unsigned long[4 * workspacesList.size()];
1300 for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
1301 // XXX: this could be different for each workspace
1302 const Rect &area = availableArea();
1303 dims[(i * 4) + 0] = area.x();
1304 dims[(i * 4) + 1] = area.y();
1305 dims[(i * 4) + 2] = area.width();
1306 dims[(i * 4) + 3] = area.height();
1308 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1309 dims, 4 * workspacesList.size());
1312 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1317 void BScreen::updateNetizenCurrentWorkspace(void) {
1318 std::for_each(netizenList.begin(), netizenList.end(),
1319 std::mem_fun(&Netizen::sendCurrentWorkspace));
1323 void BScreen::updateNetizenWorkspaceCount(void) {
1324 xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
1325 XAtom::cardinal, workspacesList.size());
1329 std::for_each(netizenList.begin(), netizenList.end(),
1330 std::mem_fun(&Netizen::sendWorkspaceCount));
1334 void BScreen::updateNetizenWindowFocus(void) {
1335 Window f = ((blackbox->getFocusedWindow()) ?
1336 blackbox->getFocusedWindow()->getClientWindow() : None);
1338 xatom->setValue(getRootWindow(), XAtom::net_active_window,
1341 NetizenList::iterator it = netizenList.begin();
1342 for (; it != netizenList.end(); ++it)
1343 (*it)->sendWindowFocus(f);
1347 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1348 NetizenList::iterator it = netizenList.begin();
1349 for (; it != netizenList.end(); ++it) {
1350 (*it)->sendWindowAdd(w, p);
1355 void BScreen::updateNetizenWindowDel(Window w) {
1356 NetizenList::iterator it = netizenList.begin();
1357 for (; it != netizenList.end(); ++it)
1358 (*it)->sendWindowDel(w);
1362 void BScreen::updateNetizenWindowRaise(Window w) {
1363 NetizenList::iterator it = netizenList.begin();
1364 for (; it != netizenList.end(); ++it)
1365 (*it)->sendWindowRaise(w);
1369 void BScreen::updateNetizenWindowLower(Window w) {
1370 NetizenList::iterator it = netizenList.begin();
1371 for (; it != netizenList.end(); ++it)
1372 (*it)->sendWindowLower(w);
1376 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1377 NetizenList::iterator it = netizenList.begin();
1378 for (; it != netizenList.end(); ++it)
1379 (*it)->sendConfigNotify(e);
1383 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
1384 // the 13 represents the number of blackbox windows such as menus
1385 Window *session_stack = new
1386 Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
1387 unsigned int i = 0, k = num;
1389 XRaiseWindow(blackbox->getXDisplay(), iconmenu->getWindowID());
1390 *(session_stack + i++) = iconmenu->getWindowID();
1392 WorkspaceList::iterator wit = workspacesList.begin();
1393 const WorkspaceList::iterator w_end = workspacesList.end();
1394 for (; wit != w_end; ++wit)
1395 *(session_stack + i++) = (*wit)->getMenu()->getWindowID();
1397 *(session_stack + i++) = workspacemenu->getWindowID();
1399 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1400 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1401 *(session_stack + i++) = configmenu->getWindowID();
1403 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1404 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1405 *(session_stack + i++) = slit->getMenu()->getWindowID();
1407 *(session_stack + i++) =
1408 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1409 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1411 RootmenuList::iterator rit = rootmenuList.begin();
1412 for (; rit != rootmenuList.end(); ++rit)
1413 *(session_stack + i++) = (*rit)->getWindowID();
1414 *(session_stack + i++) = rootmenu->getWindowID();
1416 if (toolbar->isOnTop())
1417 *(session_stack + i++) = toolbar->getWindowID();
1419 if (slit->isOnTop())
1420 *(session_stack + i++) = slit->getWindowID();
1423 *(session_stack + i++) = *(workspace_stack + k);
1425 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1427 delete [] session_stack;
1429 updateStackingList();
1433 void BScreen::lowerWindows(Window *workspace_stack, unsigned int num) {
1434 assert(num > 0); // this would cause trouble in the XRaiseWindow call
1436 Window *session_stack = new Window[(num + desktopWindowList.size())];
1437 unsigned int i = 0, k = num;
1439 XLowerWindow(blackbox->getXDisplay(), workspace_stack[0]);
1442 *(session_stack + i++) = *(workspace_stack + k);
1444 WindowList::iterator dit = desktopWindowList.begin();
1445 const WindowList::iterator d_end = desktopWindowList.end();
1446 for (; dit != d_end; ++dit)
1447 *(session_stack + i++) = *dit;
1449 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1451 delete [] session_stack;
1453 updateStackingList();
1457 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
1458 bool ignore_sticky) {
1461 if (wkspc_id == BSENTINEL)
1462 wkspc_id = current_workspace->getID();
1464 if (w->getWorkspaceNumber() == wkspc_id)
1467 if (w->isIconic()) {
1469 getWorkspace(wkspc_id)->addWindow(w);
1470 } else if (ignore_sticky || ! w->isStuck()) {
1471 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1472 getWorkspace(wkspc_id)->addWindow(w);
1474 updateStackingList();
1478 void BScreen::propagateWindowName(const BlackboxWindow *bw) {
1479 if (bw->isIconic()) {
1480 iconmenu->changeItemLabel(bw->getWindowNumber(), bw->getIconTitle());
1484 Clientmenu *clientmenu = getWorkspace(bw->getWorkspaceNumber())->getMenu();
1485 clientmenu->changeItemLabel(bw->getWindowNumber(), bw->getTitle());
1486 clientmenu->update();
1488 if (blackbox->getFocusedWindow() == bw)
1489 toolbar->redrawWindowLabel(True);
1494 void BScreen::nextFocus(void) {
1495 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1499 // if window is not on this screen, ignore it
1500 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1501 focused = (BlackboxWindow*) 0;
1504 if (focused && current_workspace->getCount() > 1) {
1505 // next is the next window to recieve focus, current is a place holder
1506 BlackboxWindow *current;
1509 next = current_workspace->getNextWindowInList(current);
1510 } while(! next->setInputFocus() && next != focused);
1512 if (next != focused)
1513 current_workspace->raiseWindow(next);
1514 } else if (current_workspace->getCount() >= 1) {
1515 next = current_workspace->getTopWindowOnStack();
1517 current_workspace->raiseWindow(next);
1518 next->setInputFocus();
1523 void BScreen::prevFocus(void) {
1524 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1528 // if window is not on this screen, ignore it
1529 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1530 focused = (BlackboxWindow*) 0;
1533 if (focused && current_workspace->getCount() > 1) {
1534 // next is the next window to recieve focus, current is a place holder
1535 BlackboxWindow *current;
1538 next = current_workspace->getPrevWindowInList(current);
1539 } while(! next->setInputFocus() && next != focused);
1541 if (next != focused)
1542 current_workspace->raiseWindow(next);
1543 } else if (current_workspace->getCount() >= 1) {
1544 next = current_workspace->getTopWindowOnStack();
1546 current_workspace->raiseWindow(next);
1547 next->setInputFocus();
1552 void BScreen::raiseFocus(void) {
1553 BlackboxWindow *focused = blackbox->getFocusedWindow();
1557 // if on this Screen, raise it
1558 if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
1559 Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
1560 workspace->raiseWindow(focused);
1565 void BScreen::InitMenu(void) {
1567 rootmenuList.clear();
1569 while (rootmenu->getCount())
1570 rootmenu->remove(0);
1572 rootmenu = new Rootmenu(this);
1574 bool defaultMenu = True;
1576 FILE *menu_file = (FILE *) 0;
1577 const char *menu_filename = blackbox->getMenuFilename();
1580 if (! (menu_file = fopen(menu_filename, "r")))
1581 perror(menu_filename);
1582 if (! menu_file) { // opening the menu file failed, try the default menu
1583 menu_filename = DEFAULTMENU;
1584 if (! (menu_file = fopen(menu_filename, "r")))
1585 perror(menu_filename);
1589 if (feof(menu_file)) {
1590 fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
1591 "%s: Empty menu file"),
1594 char line[1024], label[1024];
1595 memset(line, 0, 1024);
1596 memset(label, 0, 1024);
1598 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
1599 if (line[0] != '#') {
1600 int i, key = 0, index = -1, len = strlen(line);
1602 for (i = 0; i < len; i++) {
1603 if (line[i] == '[') index = 0;
1604 else if (line[i] == ']') break;
1605 else if (line[i] != ' ')
1607 key += tolower(line[i]);
1610 if (key == 517) { // [begin]
1612 for (i = index; i < len; i++) {
1613 if (line[i] == '(') index = 0;
1614 else if (line[i] == ')') break;
1615 else if (index++ >= 0) {
1616 if (line[i] == '\\' && i < len - 1) i++;
1617 label[index - 1] = line[i];
1621 if (index == -1) index = 0;
1622 label[index] = '\0';
1624 rootmenu->setLabel(label);
1625 defaultMenu = parseMenuFile(menu_file, rootmenu);
1627 blackbox->addMenuTimestamp(menu_filename);
1637 rootmenu->setInternalMenu();
1638 rootmenu->insert(i18n(ScreenSet, Screenxterm, "xterm"),
1640 i18n(ScreenSet, Screenxterm, "xterm"));
1641 rootmenu->insert(i18n(ScreenSet, ScreenRestart, "Restart"),
1643 rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
1645 rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
1651 bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
1652 char line[1024], label[1024], command[1024];
1654 while (! feof(file)) {
1655 memset(line, 0, 1024);
1656 memset(label, 0, 1024);
1657 memset(command, 0, 1024);
1659 if (fgets(line, 1024, file)) {
1660 if (line[0] != '#') {
1661 int i, key = 0, parse = 0, index = -1, line_length = strlen(line);
1663 // determine the keyword
1664 for (i = 0; i < line_length; i++) {
1665 if (line[i] == '[') parse = 1;
1666 else if (line[i] == ']') break;
1667 else if (line[i] != ' ')
1669 key += tolower(line[i]);
1672 // get the label enclosed in ()'s
1675 for (i = 0; i < line_length; i++) {
1676 if (line[i] == '(') {
1679 } else if (line[i] == ')') break;
1680 else if (index++ >= 0) {
1681 if (line[i] == '\\' && i < line_length - 1) i++;
1682 label[index - 1] = line[i];
1687 label[index] = '\0';
1692 // get the command enclosed in {}'s
1695 for (i = 0; i < line_length; i++) {
1696 if (line[i] == '{') {
1699 } else if (line[i] == '}') break;
1700 else if (index++ >= 0) {
1701 if (line[i] == '\\' && i < line_length - 1) i++;
1702 command[index - 1] = line[i];
1707 command[index] = '\0';
1714 return ((menu->getCount() == 0) ? True : False);
1721 menu->insert(label);
1726 if ((! *label) && (! *command)) {
1727 fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
1728 "BScreen::parseMenuFile: [exec] error, "
1729 "no menu label and/or command defined\n"));
1733 menu->insert(label, BScreen::Execute, command);
1739 fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
1740 "BScreen::parseMenuFile: [exit] error, "
1741 "no menu label defined\n"));
1745 menu->insert(label, BScreen::Exit);
1751 if ((! *label) || (! *command)) {
1753 i18n(ScreenSet, ScreenSTYLEError,
1754 "BScreen::parseMenuFile: [style] error, "
1755 "no menu label and/or filename defined\n"));
1759 string style = expandTilde(command);
1761 menu->insert(label, BScreen::SetStyle, style.c_str());
1768 fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
1769 "BScreen::parseMenufile: [config] error, "
1770 "no label defined"));
1774 menu->insert(label, configmenu);
1778 case 740: // include
1781 fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
1782 "BScreen::parseMenuFile: [include] error, "
1783 "no filename defined\n"));
1787 string newfile = expandTilde(label);
1788 FILE *submenufile = fopen(newfile.c_str(), "r");
1792 if (fstat(fileno(submenufile), &buf) ||
1793 (! S_ISREG(buf.st_mode))) {
1795 i18n(ScreenSet, ScreenINCLUDEErrorReg,
1796 "BScreen::parseMenuFile: [include] error: "
1797 "'%s' is not a regular file\n"), newfile.c_str());
1801 if (! feof(submenufile)) {
1802 if (! parseMenuFile(submenufile, menu))
1803 blackbox->addMenuTimestamp(newfile);
1805 fclose(submenufile);
1808 perror(newfile.c_str());
1814 case 767: // submenu
1817 fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
1818 "BScreen::parseMenuFile: [submenu] error, "
1819 "no menu label defined\n"));
1823 Rootmenu *submenu = new Rootmenu(this);
1826 submenu->setLabel(command);
1828 submenu->setLabel(label);
1830 parseMenuFile(file, submenu);
1832 menu->insert(label, submenu);
1833 rootmenuList.push_back(submenu);
1838 case 773: // restart
1841 fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
1842 "BScreen::parseMenuFile: [restart] error, "
1843 "no menu label defined\n"));
1848 menu->insert(label, BScreen::RestartOther, command);
1850 menu->insert(label, BScreen::Restart);
1855 case 845: // reconfig
1859 i18n(ScreenSet, ScreenRECONFIGError,
1860 "BScreen::parseMenuFile: [reconfig] error, "
1861 "no menu label defined\n"));
1865 menu->insert(label, BScreen::Reconfigure);
1870 case 995: // stylesdir
1871 case 1113: // stylesmenu
1873 bool newmenu = ((key == 1113) ? True : False);
1875 if ((! *label) || ((! *command) && newmenu)) {
1877 i18n(ScreenSet, ScreenSTYLESDIRError,
1878 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1879 " error, no directory defined\n"));
1883 char *directory = ((newmenu) ? command : label);
1885 string stylesdir = expandTilde(directory);
1887 struct stat statbuf;
1889 if (! stat(stylesdir.c_str(), &statbuf)) {
1890 if (S_ISDIR(statbuf.st_mode)) {
1891 Rootmenu *stylesmenu;
1894 stylesmenu = new Rootmenu(this);
1898 DIR *d = opendir(stylesdir.c_str());
1900 std::vector<string> ls;
1902 while((p = readdir(d)))
1903 ls.push_back(p->d_name);
1907 std::sort(ls.begin(), ls.end());
1909 std::vector<string>::iterator it = ls.begin(),
1911 for (; it != end; ++it) {
1912 const string& fname = *it;
1914 if (fname[fname.size()-1] == '~')
1917 string style = stylesdir;
1921 if ((! stat(style.c_str(), &statbuf)) &&
1922 S_ISREG(statbuf.st_mode))
1923 stylesmenu->insert(fname, BScreen::SetStyle, style);
1926 stylesmenu->update();
1929 stylesmenu->setLabel(label);
1930 menu->insert(label, stylesmenu);
1931 rootmenuList.push_back(stylesmenu);
1934 blackbox->addMenuTimestamp(stylesdir);
1937 i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
1938 "BScreen::parseMenuFile:"
1939 " [stylesdir/stylesmenu] error, %s is not a"
1940 " directory\n"), stylesdir.c_str());
1944 i18n(ScreenSet, ScreenSTYLESDIRErrorNoExist,
1945 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1946 " error, %s does not exist\n"), stylesdir.c_str());
1951 case 1090: // workspaces
1955 i18n(ScreenSet, ScreenWORKSPACESError,
1956 "BScreen:parseMenuFile: [workspaces] error, "
1957 "no menu label defined\n"));
1961 menu->insert(label, workspacemenu);
1970 return ((menu->getCount() == 0) ? True : False);
1974 void BScreen::shutdown(void) {
1975 XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
1976 XSync(blackbox->getXDisplay(), False);
1978 while(! windowList.empty())
1979 unmanageWindow(windowList.front(), True);
1985 void BScreen::showPosition(int x, int y) {
1986 if (! geom_visible) {
1987 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1988 (getWidth() - geom_w) / 2,
1989 (getHeight() - geom_h) / 2, geom_w, geom_h);
1990 XMapWindow(blackbox->getXDisplay(), geom_window);
1991 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1993 geom_visible = True;
1998 sprintf(label, i18n(ScreenSet, ScreenPositionFormat,
1999 "X: %4d x Y: %4d"), x, y);
2001 XClearWindow(blackbox->getXDisplay(), geom_window);
2003 resource.wstyle.font->drawString(geom_window,
2004 resource.bevel_width, resource.bevel_width,
2005 resource.wstyle.l_text_focus,
2010 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
2011 if (! geom_visible) {
2012 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
2013 (getWidth() - geom_w) / 2,
2014 (getHeight() - geom_h) / 2, geom_w, geom_h);
2015 XMapWindow(blackbox->getXDisplay(), geom_window);
2016 XRaiseWindow(blackbox->getXDisplay(), geom_window);
2018 geom_visible = True;
2023 sprintf(label, i18n(ScreenSet, ScreenGeometryFormat,
2024 "W: %4d x H: %4d"), gx, gy);
2026 XClearWindow(blackbox->getXDisplay(), geom_window);
2028 resource.wstyle.font->drawString(geom_window,
2029 resource.bevel_width, resource.bevel_width,
2030 resource.wstyle.l_text_focus,
2035 void BScreen::hideGeometry(void) {
2037 XUnmapWindow(blackbox->getXDisplay(), geom_window);
2038 geom_visible = False;
2043 void BScreen::addStrut(Strut *strut) {
2044 strutList.push_back(strut);
2048 void BScreen::removeStrut(Strut *strut) {
2049 strutList.remove(strut);
2053 const Rect& BScreen::availableArea(void) const {
2055 return getRect(); // return the full screen
2060 void BScreen::updateAvailableArea(void) {
2061 Rect old_area = usableArea;
2062 usableArea = getRect(); // reset to full screen
2064 /* these values represent offsets from the screen edge
2065 * we look for the biggest offset on each edge and then apply them
2067 * do not be confused by the similarity to the names of Rect's members
2069 unsigned int current_left = 0, current_right = 0, current_top = 0,
2072 StrutList::const_iterator it = strutList.begin(), end = strutList.end();
2074 for(; it != end; ++it) {
2076 if (strut->left > current_left)
2077 current_left = strut->left;
2078 if (strut->top > current_top)
2079 current_top = strut->top;
2080 if (strut->right > current_right)
2081 current_right = strut->right;
2082 if (strut->bottom > current_bottom)
2083 current_bottom = strut->bottom;
2086 usableArea.setPos(current_left, current_top);
2087 usableArea.setSize(usableArea.width() - (current_left + current_right),
2088 usableArea.height() - (current_top + current_bottom));
2090 if (old_area != usableArea) {
2091 BlackboxWindowList::iterator it = windowList.begin(),
2092 end = windowList.end();
2093 for (; it != end; ++it)
2094 if ((*it)->isMaximized()) (*it)->remaximize();
2101 Workspace* BScreen::getWorkspace(unsigned int index) {
2102 assert(index < workspacesList.size());
2103 return workspacesList[index];
2107 void BScreen::buttonPressEvent(const XButtonEvent *xbutton) {
2108 if (xbutton->button == 1) {
2109 if (! isRootColormapInstalled())
2110 image_control->installRootColormap();
2112 if (workspacemenu->isVisible())
2113 workspacemenu->hide();
2115 if (rootmenu->isVisible())
2117 } else if (xbutton->button == 2) {
2118 int mx = xbutton->x_root - (workspacemenu->getWidth() / 2);
2119 int my = xbutton->y_root - (workspacemenu->getTitleHeight() / 2);
2124 if (mx + workspacemenu->getWidth() > getWidth())
2125 mx = getWidth() - workspacemenu->getWidth() - getBorderWidth();
2127 if (my + workspacemenu->getHeight() > getHeight())
2128 my = getHeight() - workspacemenu->getHeight() - getBorderWidth();
2130 workspacemenu->move(mx, my);
2132 if (! workspacemenu->isVisible()) {
2133 workspacemenu->removeParent();
2134 workspacemenu->show();
2136 } else if (xbutton->button == 3) {
2137 int mx = xbutton->x_root - (rootmenu->getWidth() / 2);
2138 int my = xbutton->y_root - (rootmenu->getTitleHeight() / 2);
2143 if (mx + rootmenu->getWidth() > getWidth())
2144 mx = getWidth() - rootmenu->getWidth() - getBorderWidth();
2146 if (my + rootmenu->getHeight() > getHeight())
2147 my = getHeight() - rootmenu->getHeight() - getBorderWidth();
2149 rootmenu->move(mx, my);
2151 if (! rootmenu->isVisible()) {
2152 blackbox->checkMenu();
2156 } else if (xbutton->button == 4) {
2157 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2158 changeWorkspaceID(0);
2160 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2162 } else if (xbutton->button == 5) {
2163 if (getCurrentWorkspaceID() == 0)
2164 changeWorkspaceID(getWorkspaceCount() - 1);
2166 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2171 void BScreen::propertyNotifyEvent(const XPropertyEvent *pe) {
2172 if (pe->atom == xatom->getAtom(XAtom::net_desktop_names)) {
2173 // _NET_WM_DESKTOP_NAMES
2174 WorkspaceList::iterator it = workspacesList.begin();
2175 const WorkspaceList::iterator end = workspacesList.end();
2176 for (; it != end; ++it) {
2177 (*it)->readName(); // re-read its name from the window property
2178 workspacemenu->changeWorkspaceLabel((*it)->getID(), (*it)->getName());
2180 workspacemenu->update();
2181 toolbar->reconfigure();
2182 saveWorkspaceNames();
2187 void BScreen::toggleFocusModel(FocusModel model) {
2188 std::for_each(windowList.begin(), windowList.end(),
2189 std::mem_fun(&BlackboxWindow::ungrabButtons));
2191 if (model == SloppyFocus) {
2192 saveSloppyFocus(True);
2194 // we're cheating here to save writing the config file 3 times
2195 resource.auto_raise = False;
2196 resource.click_raise = False;
2197 saveSloppyFocus(False);
2200 std::for_each(windowList.begin(), windowList.end(),
2201 std::mem_fun(&BlackboxWindow::grabButtons));
2205 BTexture BScreen::readDatabaseTexture(const string &rname,
2206 const string &default_color,
2207 const Configuration &style) {
2211 if (style.getValue(rname, s))
2212 texture = BTexture(s);
2214 texture.setTexture(BTexture::Solid | BTexture::Flat);
2216 // associate this texture with this screen
2217 texture.setDisplay(getBaseDisplay(), getScreenNumber());
2218 texture.setImageControl(image_control);
2220 if (texture.texture() & BTexture::Solid) {
2221 texture.setColor(readDatabaseColor(rname + ".color",
2222 default_color, style));
2223 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2224 default_color, style));
2225 } else if (texture.texture() & BTexture::Gradient) {
2226 texture.setColor(readDatabaseColor(rname + ".color",
2227 default_color, style));
2228 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2229 default_color, style));
2236 BColor BScreen::readDatabaseColor(const string &rname,
2237 const string &default_color,
2238 const Configuration &style) {
2241 if (style.getValue(rname, s))
2242 color = BColor(s, getBaseDisplay(), getScreenNumber());
2244 color = BColor(default_color, getBaseDisplay(), getScreenNumber());
2249 BFont *BScreen::readDatabaseFont(const string &rbasename,
2250 const Configuration &style) {
2257 if (style.getValue(rbasename + "xft.font", s) &&
2258 style.getValue(rbasename + "xft.size", i)) {
2261 bool italic = False;
2262 if (style.getValue(rbasename + "xft.flags", s)) {
2263 if (s.find("bold") != string::npos)
2265 if (s.find("italic") != string::npos)
2269 BFont *b = new BFont(blackbox->getXDisplay(), this, family, i, bold,
2270 italic, resource.aa_fonts);
2274 delete b; // fall back to the normal X font stuff
2278 style.getValue(rbasename + "font", s);
2279 // if this fails, a blank string will be used, which will cause the fallback
2282 BFont *b = new BFont(blackbox->getXDisplay(), this, s);
2284 exit(2); // can't continue without a font