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.
24 #include "../config.h"
27 #include <X11/Xatom.h>
28 #include <X11/keysym.h>
32 #endif // HAVE_STDLIB_H
36 #endif // HAVE_STRING_H
40 #endif // HAVE_CTYPE_H
43 # include <sys/types.h>
45 #endif // HAVE_UNISTD_H
49 #endif // HAVE_DIRENT_H
53 #endif // HAVE_LOCALE_H
55 #ifdef HAVE_SYS_STAT_H
56 # include <sys/stat.h>
57 #endif // HAVE_SYS_STAT_H
61 #endif // HAVE_STDARG_H
72 #include "blackbox.hh"
73 #include "Clientmenu.hh"
76 #include "Iconmenu.hh"
80 #include "Rootmenu.hh"
84 #include "Workspace.hh"
85 #include "Workspacemenu.hh"
88 #ifndef FONT_ELEMENT_SIZE
89 #define FONT_ELEMENT_SIZE 50
90 #endif // FONT_ELEMENT_SIZE
93 static bool running = True;
95 static int anotherWMRunning(Display *display, XErrorEvent *) {
96 fprintf(stderr, i18n(ScreenSet, ScreenAnotherWMRunning,
97 "BScreen::BScreen: an error occured while querying the X server.\n"
98 " another window manager already running on display %s.\n"),
99 DisplayString(display));
107 BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
109 screenstr = "session.screen" + itostring(scrn) + '.';
110 config = blackbox->getConfig();
111 xatom = blackbox->getXAtom();
113 event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
114 SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask;
116 XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
117 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask);
118 XSync(getBaseDisplay()->getXDisplay(), False);
119 XSetErrorHandler((XErrorHandler) old);
122 if (! managed) return;
124 fprintf(stderr, i18n(ScreenSet, ScreenManagingScreen,
125 "BScreen::BScreen: managing screen %d "
126 "using visual 0x%lx, depth %d\n"),
127 getScreenNumber(), XVisualIDFromVisual(getVisual()),
132 resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
133 resource.wstyle.font = (BFont *) 0;
137 xatom->setSupported(this); // set-up netwm support
139 xatom->setValue(getRootWindow(), XAtom::blackbox_pid, XAtom::cardinal,
140 (unsigned long) getpid());
141 #endif // HAVE_GETPID
142 unsigned long geometry[] = { getWidth(),
144 xatom->setValue(getRootWindow(), XAtom::net_desktop_geometry,
145 XAtom::cardinal, geometry, 2);
146 unsigned long viewport[] = {0,0};
147 xatom->setValue(getRootWindow(), XAtom::net_desktop_viewport,
148 XAtom::cardinal, viewport, 2);
151 XDefineCursor(blackbox->getXDisplay(), getRootWindow(),
152 blackbox->getSessionCursor());
154 // start off full screen, top left.
155 usableArea.setSize(getWidth(), getHeight());
158 new BImageControl(blackbox, this, True, blackbox->getColorsPerChannel(),
159 blackbox->getCacheLife(), blackbox->getCacheMax());
160 image_control->installRootColormap();
161 root_colormap_installed = True;
167 gcv.foreground = WhitePixel(blackbox->getXDisplay(), getScreenNumber())
168 ^ BlackPixel(blackbox->getXDisplay(), getScreenNumber());
169 gcv.function = GXxor;
170 gcv.subwindow_mode = IncludeInferiors;
171 opGC = XCreateGC(blackbox->getXDisplay(), getRootWindow(),
172 GCForeground | GCFunction | GCSubwindowMode, &gcv);
174 const char *s = i18n(ScreenSet, ScreenPositionLength,
175 "0: 0000 x 0: 0000");
176 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
177 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
179 XSetWindowAttributes attrib;
180 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
181 attrib.border_pixel = getBorderColor()->pixel();
182 attrib.colormap = getColormap();
183 attrib.save_under = True;
185 geom_window = XCreateWindow(blackbox->getXDisplay(), getRootWindow(),
186 0, 0, geom_w, geom_h, resource.border_width,
187 getDepth(), InputOutput, getVisual(),
189 geom_visible = False;
191 BTexture* texture = &(resource.wstyle.l_focus);
192 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
193 if (geom_pixmap == ParentRelative) {
194 texture = &(resource.wstyle.t_focus);
195 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
198 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
199 texture->color().pixel());
201 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
202 geom_window, geom_pixmap);
204 workspacemenu = new Workspacemenu(this);
205 iconmenu = new Iconmenu(this);
206 configmenu = new Configmenu(this);
208 Workspace *wkspc = (Workspace *) 0;
209 if (resource.workspaces != 0) {
210 for (unsigned int i = 0; i < resource.workspaces; ++i) {
211 wkspc = new Workspace(this, workspacesList.size());
212 workspacesList.push_back(wkspc);
213 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
216 wkspc = new Workspace(this, workspacesList.size());
217 workspacesList.push_back(wkspc);
218 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
220 saveWorkspaceNames();
222 updateNetizenWorkspaceCount();
224 workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
225 workspacemenu->update();
227 current_workspace = workspacesList.front();
229 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
230 XAtom::cardinal, 0); //first workspace
232 workspacemenu->setItemSelected(2, True);
234 toolbar = new Toolbar(this);
236 slit = new Slit(this);
240 raiseWindows(0, 0); // this also initializes the empty stacking list
243 updateClientList(); // initialize the client lists, which will be empty
244 updateAvailableArea();
246 changeWorkspaceID(0);
248 unsigned int i, j, nchild;
249 Window r, p, *children;
250 XQueryTree(blackbox->getXDisplay(), getRootWindow(), &r, &p,
253 // preen the window list of all icon windows... for better dockapp support
254 for (i = 0; i < nchild; i++) {
255 if (children[i] == None) continue;
257 XWMHints *wmhints = XGetWMHints(blackbox->getXDisplay(),
261 if ((wmhints->flags & IconWindowHint) &&
262 (wmhints->icon_window != children[i])) {
263 for (j = 0; j < nchild; j++) {
264 if (children[j] == wmhints->icon_window) {
275 // manage shown windows
276 for (i = 0; i < nchild; ++i) {
277 if (children[i] == None || (! blackbox->validateWindow(children[i])))
280 XWindowAttributes attrib;
281 if (XGetWindowAttributes(blackbox->getXDisplay(), children[i], &attrib)) {
282 if (attrib.override_redirect) continue;
284 if (attrib.map_state != IsUnmapped) {
285 manageWindow(children[i]);
292 // call this again just in case a window we found updates the Strut list
293 updateAvailableArea();
297 BScreen::~BScreen(void) {
298 if (! managed) return;
300 if (geom_pixmap != None)
301 image_control->removeImage(geom_pixmap);
303 if (geom_window != None)
304 XDestroyWindow(blackbox->getXDisplay(), geom_window);
306 std::for_each(workspacesList.begin(), workspacesList.end(),
309 std::for_each(iconList.begin(), iconList.end(), PointerAssassin());
311 std::for_each(netizenList.begin(), netizenList.end(), PointerAssassin());
314 delete workspacemenu;
319 delete image_control;
321 if (resource.wstyle.font)
322 delete resource.wstyle.font;
323 if (resource.mstyle.t_font)
324 delete resource.mstyle.t_font;
325 if (resource.mstyle.f_font)
326 delete resource.mstyle.f_font;
327 if (resource.tstyle.font)
328 delete resource.tstyle.font;
330 XFreeGC(blackbox->getXDisplay(), opGC);
334 void BScreen::saveSloppyFocus(bool s) {
335 resource.sloppy_focus = s;
338 if (resource.sloppy_focus) {
339 fmodel = "SloppyFocus";
340 if (resource.auto_raise) fmodel += " AutoRaise";
341 if (resource.click_raise) fmodel += " ClickRaise";
343 fmodel = "ClickToFocus";
345 config->setValue(screenstr + "focusModel", fmodel);
349 void BScreen::saveAutoRaise(bool a) {
350 resource.auto_raise = a;
351 saveSloppyFocus(resource.sloppy_focus);
355 void BScreen::saveClickRaise(bool c) {
356 resource.click_raise = c;
357 saveSloppyFocus(resource.sloppy_focus);
361 void BScreen::saveImageDither(bool d) {
362 image_control->setDither(d);
363 config->setValue(screenstr + "imageDither", doImageDither());
367 void BScreen::saveOpaqueMove(bool o) {
368 resource.opaque_move = o;
369 config->setValue(screenstr + "opaqueMove", resource.opaque_move);
373 void BScreen::saveFullMax(bool f) {
374 resource.full_max = f;
375 config->setValue(screenstr + "fullMaximization", resource.full_max);
379 void BScreen::saveFocusNew(bool f) {
380 resource.focus_new = f;
381 config->setValue(screenstr + "focusNewWindows", resource.focus_new);
385 void BScreen::saveFocusLast(bool f) {
386 resource.focus_last = f;
387 config->setValue(screenstr + "focusLastWindow", resource.focus_last);
391 void BScreen::saveAAFonts(bool f) {
392 resource.aa_fonts = f;
394 config->setValue(screenstr + "antialiasFonts", resource.aa_fonts);
398 void BScreen::saveHideToolbar(bool h) {
399 resource.hide_toolbar = h;
400 if (resource.hide_toolbar)
401 toolbar->unmapToolbar();
403 toolbar->mapToolbar();
404 config->setValue(screenstr + "hideToolbar", resource.hide_toolbar);
408 void BScreen::saveWindowToWindowSnap(bool s) {
409 resource.window_to_window_snap = s;
410 config->setValue(screenstr + "windowToWindowSnap",
411 resource.window_to_window_snap);
415 void BScreen::saveResizeZones(unsigned int z) {
416 resource.resize_zones = z;
417 config->setValue(screenstr + "resizeZones", resource.resize_zones);
421 void BScreen::saveWindowCornerSnap(bool s) {
422 resource.window_corner_snap = s;
423 config->setValue(screenstr + "windowCornerSnap",
424 resource.window_corner_snap);
428 void BScreen::saveWorkspaces(unsigned int w) {
429 resource.workspaces = w;
430 config->setValue(screenstr + "workspaces", resource.workspaces);
434 void BScreen::savePlacementPolicy(int p) {
435 resource.placement_policy = p;
436 const char *placement;
437 switch (resource.placement_policy) {
438 case CascadePlacement: placement = "CascadePlacement"; break;
439 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
440 case RowSmartPlacement: default: placement = "RowSmartPlacement"; break;
442 config->setValue(screenstr + "windowPlacement", placement);
446 void BScreen::saveEdgeSnapThreshold(int t) {
447 resource.edge_snap_threshold = t;
448 config->setValue(screenstr + "edgeSnapThreshold",
449 resource.edge_snap_threshold);
453 void BScreen::saveRowPlacementDirection(int d) {
454 resource.row_direction = d;
455 config->setValue(screenstr + "rowPlacementDirection",
456 resource.row_direction == LeftRight ?
457 "LeftToRight" : "RightToLeft");
461 void BScreen::saveColPlacementDirection(int d) {
462 resource.col_direction = d;
463 config->setValue(screenstr + "colPlacementDirection",
464 resource.col_direction == TopBottom ?
465 "TopToBottom" : "BottomToTop");
470 void BScreen::saveStrftimeFormat(const std::string& format) {
471 resource.strftime_format = format;
472 config->setValue(screenstr + "strftimeFormat", resource.strftime_format);
475 #else // !HAVE_STRFTIME
477 void BScreen::saveDateFormat(int f) {
478 resource.date_format = f;
479 config->setValue(screenstr + "dateFormat",
480 resource.date_format == B_EuropeanDate ?
481 "European" : "American");
485 void BScreen::saveClock24Hour(Bool c) {
486 resource.clock24hour = c;
487 config->setValue(screenstr + "clockFormat", resource.clock24hour ? 24 : 12);
489 #endif // HAVE_STRFTIME
492 void BScreen::saveWorkspaceNames() {
493 XAtom::StringVect nameList;
494 unsigned long numnames = (unsigned) -1;
498 xatom->getValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
499 numnames, nameList)) {
500 for (unsigned int i = 0; i < nameList.size(); ++i) {
501 if (i > 0) names += ",";
502 names += nameList[i];
505 config->setValue(screenstr + "workspaceNames", names);
509 void BScreen::save_rc(void) {
510 saveSloppyFocus(resource.sloppy_focus);
511 saveAutoRaise(resource.auto_raise);
512 saveImageDither(doImageDither());
513 saveAAFonts(resource.aa_fonts);
514 saveResizeZones(resource.resize_zones);
515 saveOpaqueMove(resource.opaque_move);
516 saveFullMax(resource.full_max);
517 saveFocusNew(resource.focus_new);
518 saveFocusLast(resource.focus_last);
519 saveHideToolbar(resource.hide_toolbar);
520 saveWindowToWindowSnap(resource.window_to_window_snap);
521 saveWindowCornerSnap(resource.window_corner_snap);
522 saveWorkspaces(resource.workspaces);
523 savePlacementPolicy(resource.placement_policy);
524 saveEdgeSnapThreshold(resource.edge_snap_threshold);
525 saveRowPlacementDirection(resource.row_direction);
526 saveColPlacementDirection(resource.col_direction);
528 saveStrftimeFormat(resource.strftime_format);
529 #else // !HAVE_STRFTIME
530 saveDateFormat(resource.date_format);
531 savwClock24Hour(resource.clock24hour);
532 #endif // HAVE_STRFTIME
539 void BScreen::load_rc(void) {
543 if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
544 resource.full_max = false;
546 if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
547 resource.focus_new = false;
549 if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
550 resource.focus_last = false;
552 if (! config->getValue(screenstr + "workspaces", resource.workspaces))
553 resource.workspaces = 1;
555 if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
556 resource.opaque_move = false;
558 if (! config->getValue(screenstr + "antialiasFonts", resource.aa_fonts))
559 resource.aa_fonts = true;
561 if (! config->getValue(screenstr + "resizeZones", resource.resize_zones) ||
562 (resource.resize_zones != 1 && resource.resize_zones != 2 &&
563 resource.resize_zones != 4))
564 resource.resize_zones = 4;
566 if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
567 resource.hide_toolbar = false;
569 if (! config->getValue(screenstr + "windowToWindowSnap",
570 resource.window_to_window_snap))
571 resource.window_to_window_snap = true;
573 if (! config->getValue(screenstr + "windowCornerSnap",
574 resource.window_corner_snap))
575 resource.window_corner_snap = true;
577 if (! config->getValue(screenstr + "imageDither", b))
579 image_control->setDither(b);
581 if (! config->getValue(screenstr + "edgeSnapThreshold",
582 resource.edge_snap_threshold))
583 resource.edge_snap_threshold = 4;
585 if (config->getValue(screenstr + "rowPlacementDirection", s) &&
587 resource.row_direction = RightLeft;
589 resource.row_direction = LeftRight;
591 if (config->getValue(screenstr + "colPlacementDirection", s) &&
593 resource.col_direction = BottomTop;
595 resource.col_direction = TopBottom;
597 XAtom::StringVect workspaceNames;
598 if (config->getValue(screenstr + "workspaceNames", s)) {
599 string::const_iterator it = s.begin(), end = s.end();
601 string::const_iterator tmp = it; // current string.begin()
602 it = std::find(tmp, end, ','); // look for comma between tmp and end
603 workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
609 xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
612 resource.sloppy_focus = true;
613 resource.auto_raise = false;
614 resource.click_raise = false;
615 if (config->getValue(screenstr + "focusModel", s)) {
616 if (s.find("ClickToFocus") != string::npos) {
617 resource.sloppy_focus = false;
620 if (s.find("AutoRaise") != string::npos)
621 resource.auto_raise = true;
622 if (s.find("ClickRaise") != string::npos)
623 resource.click_raise = true;
627 if (config->getValue(screenstr + "windowPlacement", s)) {
628 if (s == "CascadePlacement")
629 resource.placement_policy = CascadePlacement;
630 else if (s == "ColSmartPlacement")
631 resource.placement_policy = ColSmartPlacement;
632 else //if (s == "RowSmartPlacement")
633 resource.placement_policy = RowSmartPlacement;
635 resource.placement_policy = RowSmartPlacement;
638 if (config->getValue(screenstr + "strftimeFormat", s))
639 resource.strftime_format = s;
641 resource.strftime_format = "%I:%M %p";
642 #else // !HAVE_STRFTIME
645 if (config->getValue(screenstr + "dateFormat", s) && s == "European")
646 resource.date_format = B_EuropeanDate;
648 resource.date_format = B_AmericanDate;
650 if (! config->getValue(screenstr + "clockFormat", l))
652 resource.clock24hour = l == 24;
653 #endif // HAVE_STRFTIME
657 void BScreen::reconfigure(void) {
664 gcv.foreground = WhitePixel(blackbox->getXDisplay(),
666 gcv.function = GXinvert;
667 gcv.subwindow_mode = IncludeInferiors;
668 XChangeGC(blackbox->getXDisplay(), opGC,
669 GCForeground | GCFunction | GCSubwindowMode, &gcv);
671 const char *s = i18n(ScreenSet, ScreenPositionLength,
672 "0: 0000 x 0: 0000");
674 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
675 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
677 BTexture* texture = &(resource.wstyle.l_focus);
678 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
679 if (geom_pixmap == ParentRelative) {
680 texture = &(resource.wstyle.t_focus);
681 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
684 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
685 texture->color().pixel());
687 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
688 geom_window, geom_pixmap);
690 XSetWindowBorderWidth(blackbox->getXDisplay(), geom_window,
691 resource.border_width);
692 XSetWindowBorder(blackbox->getXDisplay(), geom_window,
693 resource.border_color.pixel());
695 workspacemenu->reconfigure();
696 iconmenu->reconfigure();
698 typedef std::vector<int> SubList;
699 SubList remember_subs;
701 // save the current open menus
702 Basemenu *menu = rootmenu;
704 while ((submenu = menu->getCurrentSubmenu()) >= 0) {
705 remember_subs.push_back(submenu);
706 menu = menu->find(submenu)->submenu();
712 rootmenu->reconfigure();
714 // reopen the saved menus
716 const SubList::iterator subs_end = remember_subs.end();
717 for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
718 menu->drawSubmenu(*it);
719 menu = menu->find(*it)->submenu();
724 configmenu->reconfigure();
726 toolbar->reconfigure();
730 std::for_each(workspacesList.begin(), workspacesList.end(),
731 std::mem_fun(&Workspace::reconfigure));
733 BlackboxWindowList::iterator iit = iconList.begin();
734 for (; iit != iconList.end(); ++iit) {
735 BlackboxWindow *bw = *iit;
736 if (bw->validateClient())
740 image_control->timeout();
744 void BScreen::rereadMenu(void) {
748 rootmenu->reconfigure();
752 void BScreen::LoadStyle(void) {
753 Configuration style(False);
755 const char *sfile = blackbox->getStyleFilename();
757 style.setFile(sfile);
758 if (! style.load()) {
759 style.setFile(DEFAULTSTYLE);
761 style.create(); // hardcoded default values will be used.
765 // merge in the rc file
766 style.merge(config->file(), True);
770 // load fonts/fontsets
771 if (resource.wstyle.font)
772 delete resource.wstyle.font;
773 if (resource.tstyle.font)
774 delete resource.tstyle.font;
775 if (resource.mstyle.f_font)
776 delete resource.mstyle.f_font;
777 if (resource.mstyle.t_font)
778 delete resource.mstyle.t_font;
779 resource.wstyle.font = resource.tstyle.font = resource.mstyle.f_font =
780 resource.mstyle.t_font = (BFont *) 0;
782 resource.wstyle.font = readDatabaseFont("window.", style);
783 resource.tstyle.font = readDatabaseFont("toolbar.", style);
784 resource.mstyle.t_font = readDatabaseFont("menu.title.", style);
785 resource.mstyle.f_font = readDatabaseFont("menu.frame.", style);
787 // load window config
788 resource.wstyle.t_focus =
789 readDatabaseTexture("window.title.focus", "white", style);
790 resource.wstyle.t_unfocus =
791 readDatabaseTexture("window.title.unfocus", "black", style);
792 resource.wstyle.l_focus =
793 readDatabaseTexture("window.label.focus", "white", style);
794 resource.wstyle.l_unfocus =
795 readDatabaseTexture("window.label.unfocus", "black", style);
796 resource.wstyle.h_focus =
797 readDatabaseTexture("window.handle.focus", "white", style);
798 resource.wstyle.h_unfocus =
799 readDatabaseTexture("window.handle.unfocus", "black", style);
800 resource.wstyle.g_focus =
801 readDatabaseTexture("window.grip.focus", "white", style);
802 resource.wstyle.g_unfocus =
803 readDatabaseTexture("window.grip.unfocus", "black", style);
804 resource.wstyle.b_focus =
805 readDatabaseTexture("window.button.focus", "white", style);
806 resource.wstyle.b_unfocus =
807 readDatabaseTexture("window.button.unfocus", "black", style);
808 resource.wstyle.b_pressed =
809 readDatabaseTexture("window.button.pressed", "black", style);
810 resource.wstyle.f_focus =
811 readDatabaseColor("window.frame.focusColor", "white", style);
812 resource.wstyle.f_unfocus =
813 readDatabaseColor("window.frame.unfocusColor", "black", style);
814 resource.wstyle.l_text_focus =
815 readDatabaseColor("window.label.focus.textColor", "black", style);
816 resource.wstyle.l_text_unfocus =
817 readDatabaseColor("window.label.unfocus.textColor", "white", style);
818 resource.wstyle.b_pic_focus =
819 readDatabaseColor("window.button.focus.picColor", "black", style);
820 resource.wstyle.b_pic_unfocus =
821 readDatabaseColor("window.button.unfocus.picColor", "white", style);
823 resource.wstyle.justify = LeftJustify;
824 if (style.getValue("window.justify", s)) {
825 if (s == "right" || s == "Right")
826 resource.wstyle.justify = RightJustify;
827 else if (s == "center" || s == "Center")
828 resource.wstyle.justify = CenterJustify;
831 // load toolbar config
832 resource.tstyle.toolbar =
833 readDatabaseTexture("toolbar", "black", style);
834 resource.tstyle.label =
835 readDatabaseTexture("toolbar.label", "black", style);
836 resource.tstyle.window =
837 readDatabaseTexture("toolbar.windowLabel", "black", style);
838 resource.tstyle.button =
839 readDatabaseTexture("toolbar.button", "white", style);
840 resource.tstyle.pressed =
841 readDatabaseTexture("toolbar.button.pressed", "black", style);
842 resource.tstyle.clock =
843 readDatabaseTexture("toolbar.clock", "black", style);
844 resource.tstyle.l_text =
845 readDatabaseColor("toolbar.label.textColor", "white", style);
846 resource.tstyle.w_text =
847 readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
848 resource.tstyle.c_text =
849 readDatabaseColor("toolbar.clock.textColor", "white", style);
850 resource.tstyle.b_pic =
851 readDatabaseColor("toolbar.button.picColor", "black", style);
853 resource.tstyle.justify = LeftJustify;
854 if (style.getValue("toolbar.justify", s)) {
855 if (s == "right" || s == "Right")
856 resource.tstyle.justify = RightJustify;
857 else if (s == "center" || s == "Center")
858 resource.tstyle.justify = CenterJustify;
862 resource.mstyle.title =
863 readDatabaseTexture("menu.title", "white", style);
864 resource.mstyle.frame =
865 readDatabaseTexture("menu.frame", "black", style);
866 resource.mstyle.hilite =
867 readDatabaseTexture("menu.hilite", "white", style);
868 resource.mstyle.t_text =
869 readDatabaseColor("menu.title.textColor", "black", style);
870 resource.mstyle.f_text =
871 readDatabaseColor("menu.frame.textColor", "white", style);
872 resource.mstyle.d_text =
873 readDatabaseColor("menu.frame.disableColor", "black", style);
874 resource.mstyle.h_text =
875 readDatabaseColor("menu.hilite.textColor", "black", style);
877 resource.mstyle.t_justify = LeftJustify;
878 if (style.getValue("menu.title.justify", s)) {
879 if (s == "right" || s == "Right")
880 resource.mstyle.t_justify = RightJustify;
881 else if (s == "center" || s == "Center")
882 resource.mstyle.t_justify = CenterJustify;
885 resource.mstyle.f_justify = LeftJustify;
886 if (style.getValue("menu.frame.justify", s)) {
887 if (s == "right" || s == "Right")
888 resource.mstyle.f_justify = RightJustify;
889 else if (s == "center" || s == "Center")
890 resource.mstyle.f_justify = CenterJustify;
893 resource.mstyle.bullet = Basemenu::Triangle;
894 if (style.getValue("menu.bullet", s)) {
895 if (s == "empty" || s == "Empty")
896 resource.mstyle.bullet = Basemenu::Empty;
897 else if (s == "square" || s == "Square")
898 resource.mstyle.bullet = Basemenu::Square;
899 else if (s == "diamond" || s == "Diamond")
900 resource.mstyle.bullet = Basemenu::Diamond;
903 resource.mstyle.bullet_pos = Basemenu::Left;
904 if (style.getValue("menu.bullet.position", s)) {
905 if (s == "right" || s == "Right")
906 resource.mstyle.bullet_pos = Basemenu::Right;
909 resource.border_color =
910 readDatabaseColor("borderColor", "black", style);
912 // load bevel, border and handle widths
913 if (! style.getValue("handleWidth", resource.handle_width) ||
914 resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
915 resource.handle_width = 6;
917 if (! style.getValue("borderWidth", resource.border_width))
918 resource.border_width = 1;
920 if (! style.getValue("bevelWidth", resource.bevel_width) ||
921 resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
922 resource.bevel_width = 3;
924 if (! style.getValue("frameWidth", resource.frame_width) ||
925 resource.frame_width > (getWidth() / 2))
926 resource.frame_width = resource.bevel_width;
928 if (style.getValue("rootCommand", s))
929 bexec(s, displayString());
933 void BScreen::addIcon(BlackboxWindow *w) {
936 w->setWorkspace(BSENTINEL);
937 w->setWindowNumber(iconList.size());
939 iconList.push_back(w);
941 const char* title = w->getIconTitle();
942 iconmenu->insert(title);
947 void BScreen::removeIcon(BlackboxWindow *w) {
952 iconmenu->remove(w->getWindowNumber());
955 BlackboxWindowList::iterator it = iconList.begin(),
956 end = iconList.end();
957 for (int i = 0; it != end; ++it)
958 (*it)->setWindowNumber(i++);
962 BlackboxWindow *BScreen::getIcon(unsigned int index) {
963 if (index < iconList.size()) {
964 BlackboxWindowList::iterator it = iconList.begin();
965 for (; index > 0; --index, ++it) ; /* increment to index */
969 return (BlackboxWindow *) 0;
973 unsigned int BScreen::addWorkspace(void) {
974 Workspace *wkspc = new Workspace(this, workspacesList.size());
975 workspacesList.push_back(wkspc);
976 saveWorkspaces(getWorkspaceCount());
978 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
980 workspacemenu->update();
982 toolbar->reconfigure();
984 updateNetizenWorkspaceCount();
986 return workspacesList.size();
990 unsigned int BScreen::removeLastWorkspace(void) {
991 if (workspacesList.size() == 1)
994 Workspace *wkspc = workspacesList.back();
996 if (current_workspace->getID() == wkspc->getID())
997 changeWorkspaceID(current_workspace->getID() - 1);
1001 workspacemenu->remove(wkspc->getID() + 2);
1002 workspacemenu->update();
1004 workspacesList.pop_back();
1007 saveWorkspaces(getWorkspaceCount());
1009 toolbar->reconfigure();
1011 updateNetizenWorkspaceCount();
1013 return workspacesList.size();
1017 void BScreen::changeWorkspaceID(unsigned int id) {
1018 if (! current_workspace) return;
1020 if (id != current_workspace->getID()) {
1021 BlackboxWindow *focused = blackbox->getFocusedWindow();
1022 if (focused && focused->getScreen() == this && ! focused->isStuck()) {
1023 if (focused->getWorkspaceNumber() != current_workspace->getID()) {
1024 fprintf(stderr, "%s is on the wrong workspace, aborting\n",
1025 focused->getTitle());
1028 current_workspace->setLastFocusedWindow(focused);
1030 // if no window had focus, no need to store a last focus
1031 current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
1033 // when we switch workspaces, unfocus whatever was focused
1034 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1036 current_workspace->hideAll();
1037 workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1039 current_workspace = getWorkspace(id);
1041 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
1042 XAtom::cardinal, id);
1044 workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1045 toolbar->redrawWorkspaceLabel(True);
1047 current_workspace->showAll();
1049 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1050 XSync(blackbox->getXDisplay(), False);
1051 current_workspace->getLastFocusedWindow()->setInputFocus();
1055 updateNetizenCurrentWorkspace();
1060 * Set the _NET_CLIENT_LIST root window property.
1062 void BScreen::updateClientList(void) {
1063 if (windowList.size() > 0) {
1064 Window *windows = new Window[windowList.size()];
1065 Window *win_it = windows;
1066 BlackboxWindowList::iterator it = windowList.begin();
1067 const BlackboxWindowList::iterator end = windowList.end();
1068 for (; it != end; ++it, ++win_it)
1069 *win_it = (*it)->getClientWindow();
1070 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1071 windows, windowList.size());
1074 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1077 updateStackingList();
1082 * Set the _NET_CLIENT_LIST_STACKING root window property.
1084 void BScreen::updateStackingList(void) {
1086 BlackboxWindowList stack_order;
1089 * Get the stacking order from all of the workspaces.
1090 * We start with the current workspace so that the sticky windows will be
1091 * in the right order on the current workspace.
1092 * XXX: Do we need to have sticky windows in the list once for each workspace?
1094 getCurrentWorkspace()->appendStackOrder(stack_order);
1095 for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
1096 if (i != getCurrentWorkspaceID())
1097 getWorkspace(i)->appendStackOrder(stack_order);
1099 if (stack_order.size() > 0) {
1100 // set the client list atoms
1101 Window *windows = new Window[stack_order.size()];
1102 Window *win_it = windows;
1103 BlackboxWindowList::iterator it = stack_order.begin(),
1104 end = stack_order.end();
1105 for (; it != end; ++it, ++win_it)
1106 *win_it = (*it)->getClientWindow();
1107 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1108 XAtom::window, windows, stack_order.size());
1111 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1112 XAtom::window, 0, 0);
1116 void BScreen::addSystrayWindow(Window window) {
1117 systrayWindowList.push_back(window);
1118 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1120 &systrayWindowList[0], systrayWindowList.size());
1121 blackbox->saveSystrayWindowSearch(window, this);
1125 void BScreen::removeSystrayWindow(Window window) {
1126 WindowList::iterator it = systrayWindowList.begin();
1127 const WindowList::iterator end = systrayWindowList.end();
1128 for (; it != end; ++it)
1129 if (*it == window) {
1130 systrayWindowList.erase(it);
1131 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1133 &systrayWindowList[0], systrayWindowList.size());
1134 blackbox->removeSystrayWindowSearch(window);
1140 void BScreen::addDesktopWindow(Window window) {
1141 desktopWindowList.push_back(window);
1142 XLowerWindow(blackbox->getXDisplay(), window);
1143 XSelectInput(blackbox->getXDisplay(), window, StructureNotifyMask);
1144 blackbox->saveDesktopWindowSearch(window, this);
1148 void BScreen::removeDesktopWindow(Window window) {
1149 WindowList::iterator it = desktopWindowList.begin();
1150 const WindowList::iterator end = desktopWindowList.end();
1151 for (; it != end; ++it)
1152 if (*it == window) {
1153 desktopWindowList.erase(it);
1154 XSelectInput(blackbox->getXDisplay(), window, None);
1155 blackbox->removeDesktopWindowSearch(window);
1161 void BScreen::manageWindow(Window w) {
1162 new BlackboxWindow(blackbox, w, this);
1164 BlackboxWindow *win = blackbox->searchWindow(w);
1167 if (win->isDesktop()) {
1168 // desktop windows cant do anything, so we remove all the normal window
1169 // stuff from them, they are only kept around so that we can keep them on
1170 // the bottom of the z-order
1172 addDesktopWindow(win->getClientWindow());
1177 windowList.push_back(win);
1180 XMapRequestEvent mre;
1182 if (blackbox->isStartup()) win->restoreAttributes();
1183 win->mapRequestEvent(&mre);
1187 void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
1190 if (w->getWorkspaceNumber() != BSENTINEL &&
1191 w->getWindowNumber() != BSENTINEL)
1192 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1193 else if (w->isIconic())
1196 windowList.remove(w);
1199 if (blackbox->getFocusedWindow() == w)
1200 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1202 removeNetizen(w->getClientWindow());
1205 some managed windows can also be window group controllers. when
1206 unmanaging such windows, we should also delete the window group.
1208 BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
1215 void BScreen::addNetizen(Netizen *n) {
1216 netizenList.push_back(n);
1218 n->sendWorkspaceCount();
1219 n->sendCurrentWorkspace();
1221 WorkspaceList::iterator it = workspacesList.begin();
1222 const WorkspaceList::iterator end = workspacesList.end();
1223 for (; it != end; ++it)
1224 (*it)->sendWindowList(*n);
1226 Window f = ((blackbox->getFocusedWindow()) ?
1227 blackbox->getFocusedWindow()->getClientWindow() : None);
1228 n->sendWindowFocus(f);
1232 void BScreen::removeNetizen(Window w) {
1233 NetizenList::iterator it = netizenList.begin();
1234 for (; it != netizenList.end(); ++it) {
1235 if ((*it)->getWindowID() == w) {
1237 netizenList.erase(it);
1244 void BScreen::updateWorkArea(void) {
1245 if (workspacesList.size() > 0) {
1246 unsigned long *dims = new unsigned long[4 * workspacesList.size()];
1247 for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
1248 // XXX: this could be different for each workspace
1249 const Rect &area = availableArea();
1250 dims[(i * 4) + 0] = area.x();
1251 dims[(i * 4) + 1] = area.y();
1252 dims[(i * 4) + 2] = area.width();
1253 dims[(i * 4) + 3] = area.height();
1255 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1256 dims, 4 * workspacesList.size());
1259 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1264 void BScreen::updateNetizenCurrentWorkspace(void) {
1265 std::for_each(netizenList.begin(), netizenList.end(),
1266 std::mem_fun(&Netizen::sendCurrentWorkspace));
1270 void BScreen::updateNetizenWorkspaceCount(void) {
1271 xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
1272 XAtom::cardinal, workspacesList.size());
1276 std::for_each(netizenList.begin(), netizenList.end(),
1277 std::mem_fun(&Netizen::sendWorkspaceCount));
1281 void BScreen::updateNetizenWindowFocus(void) {
1282 Window f = ((blackbox->getFocusedWindow()) ?
1283 blackbox->getFocusedWindow()->getClientWindow() : None);
1285 xatom->setValue(getRootWindow(), XAtom::net_active_window,
1288 NetizenList::iterator it = netizenList.begin();
1289 for (; it != netizenList.end(); ++it)
1290 (*it)->sendWindowFocus(f);
1294 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1295 NetizenList::iterator it = netizenList.begin();
1296 for (; it != netizenList.end(); ++it) {
1297 (*it)->sendWindowAdd(w, p);
1302 void BScreen::updateNetizenWindowDel(Window w) {
1303 NetizenList::iterator it = netizenList.begin();
1304 for (; it != netizenList.end(); ++it)
1305 (*it)->sendWindowDel(w);
1309 void BScreen::updateNetizenWindowRaise(Window w) {
1310 NetizenList::iterator it = netizenList.begin();
1311 for (; it != netizenList.end(); ++it)
1312 (*it)->sendWindowRaise(w);
1316 void BScreen::updateNetizenWindowLower(Window w) {
1317 NetizenList::iterator it = netizenList.begin();
1318 for (; it != netizenList.end(); ++it)
1319 (*it)->sendWindowLower(w);
1323 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1324 NetizenList::iterator it = netizenList.begin();
1325 for (; it != netizenList.end(); ++it)
1326 (*it)->sendConfigNotify(e);
1330 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
1331 // the 13 represents the number of blackbox windows such as menus
1332 Window *session_stack = new
1333 Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
1334 unsigned int i = 0, k = num;
1336 XRaiseWindow(blackbox->getXDisplay(), iconmenu->getWindowID());
1337 *(session_stack + i++) = iconmenu->getWindowID();
1339 WorkspaceList::iterator wit = workspacesList.begin();
1340 const WorkspaceList::iterator w_end = workspacesList.end();
1341 for (; wit != w_end; ++wit)
1342 *(session_stack + i++) = (*wit)->getMenu()->getWindowID();
1344 *(session_stack + i++) = workspacemenu->getWindowID();
1346 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1347 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1348 *(session_stack + i++) = configmenu->getWindowID();
1350 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1351 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1352 *(session_stack + i++) = slit->getMenu()->getWindowID();
1354 *(session_stack + i++) =
1355 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1356 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1358 RootmenuList::iterator rit = rootmenuList.begin();
1359 for (; rit != rootmenuList.end(); ++rit)
1360 *(session_stack + i++) = (*rit)->getWindowID();
1361 *(session_stack + i++) = rootmenu->getWindowID();
1363 if (toolbar->isOnTop())
1364 *(session_stack + i++) = toolbar->getWindowID();
1366 if (slit->isOnTop())
1367 *(session_stack + i++) = slit->getWindowID();
1370 *(session_stack + i++) = *(workspace_stack + k);
1372 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1374 delete [] session_stack;
1376 updateStackingList();
1380 void BScreen::lowerDesktops(void) {
1381 if (desktopWindowList.empty()) return;
1383 XLowerWindow(blackbox->getXDisplay(), desktopWindowList[0]);
1384 if (desktopWindowList.size() > 1)
1385 XRestackWindows(blackbox->getXDisplay(), &desktopWindowList[0],
1386 desktopWindowList.size());
1390 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
1391 bool ignore_sticky) {
1394 if (wkspc_id == BSENTINEL)
1395 wkspc_id = current_workspace->getID();
1397 if (w->getWorkspaceNumber() == wkspc_id)
1400 if (w->isIconic()) {
1402 getWorkspace(wkspc_id)->addWindow(w);
1403 } else if (ignore_sticky || ! w->isStuck()) {
1404 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1405 getWorkspace(wkspc_id)->addWindow(w);
1407 updateStackingList();
1411 void BScreen::propagateWindowName(const BlackboxWindow *bw) {
1412 if (bw->isIconic()) {
1413 iconmenu->changeItemLabel(bw->getWindowNumber(), bw->getIconTitle());
1417 Clientmenu *clientmenu = getWorkspace(bw->getWorkspaceNumber())->getMenu();
1418 clientmenu->changeItemLabel(bw->getWindowNumber(), bw->getTitle());
1419 clientmenu->update();
1421 if (blackbox->getFocusedWindow() == bw)
1422 toolbar->redrawWindowLabel(True);
1427 void BScreen::nextFocus(void) {
1428 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1432 // if window is not on this screen, ignore it
1433 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1434 focused = (BlackboxWindow*) 0;
1437 if (focused && current_workspace->getCount() > 1) {
1438 // next is the next window to recieve focus, current is a place holder
1439 BlackboxWindow *current;
1442 next = current_workspace->getNextWindowInList(current);
1443 } while(! next->setInputFocus() && next != focused);
1445 if (next != focused)
1446 current_workspace->raiseWindow(next);
1447 } else if (current_workspace->getCount() >= 1) {
1448 next = current_workspace->getTopWindowOnStack();
1450 current_workspace->raiseWindow(next);
1451 next->setInputFocus();
1456 void BScreen::prevFocus(void) {
1457 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1461 // if window is not on this screen, ignore it
1462 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1463 focused = (BlackboxWindow*) 0;
1466 if (focused && current_workspace->getCount() > 1) {
1467 // next is the next window to recieve focus, current is a place holder
1468 BlackboxWindow *current;
1471 next = current_workspace->getPrevWindowInList(current);
1472 } while(! next->setInputFocus() && next != focused);
1474 if (next != focused)
1475 current_workspace->raiseWindow(next);
1476 } else if (current_workspace->getCount() >= 1) {
1477 next = current_workspace->getTopWindowOnStack();
1479 current_workspace->raiseWindow(next);
1480 next->setInputFocus();
1485 void BScreen::raiseFocus(void) {
1486 BlackboxWindow *focused = blackbox->getFocusedWindow();
1490 // if on this Screen, raise it
1491 if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
1492 Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
1493 workspace->raiseWindow(focused);
1498 void BScreen::InitMenu(void) {
1500 rootmenuList.clear();
1502 while (rootmenu->getCount())
1503 rootmenu->remove(0);
1505 rootmenu = new Rootmenu(this);
1507 bool defaultMenu = True;
1509 FILE *menu_file = (FILE *) 0;
1510 const char *menu_filename = blackbox->getMenuFilename();
1513 if (! (menu_file = fopen(menu_filename, "r")))
1514 perror(menu_filename);
1515 if (! menu_file) { // opening the menu file failed, try the default menu
1516 menu_filename = DEFAULTMENU;
1517 if (! (menu_file = fopen(menu_filename, "r")))
1518 perror(menu_filename);
1522 if (feof(menu_file)) {
1523 fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
1524 "%s: Empty menu file"),
1527 char line[1024], label[1024];
1528 memset(line, 0, 1024);
1529 memset(label, 0, 1024);
1531 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
1532 if (line[0] != '#') {
1533 int i, key = 0, index = -1, len = strlen(line);
1535 for (i = 0; i < len; i++) {
1536 if (line[i] == '[') index = 0;
1537 else if (line[i] == ']') break;
1538 else if (line[i] != ' ')
1540 key += tolower(line[i]);
1543 if (key == 517) { // [begin]
1545 for (i = index; i < len; i++) {
1546 if (line[i] == '(') index = 0;
1547 else if (line[i] == ')') break;
1548 else if (index++ >= 0) {
1549 if (line[i] == '\\' && i < len - 1) i++;
1550 label[index - 1] = line[i];
1554 if (index == -1) index = 0;
1555 label[index] = '\0';
1557 rootmenu->setLabel(label);
1558 defaultMenu = parseMenuFile(menu_file, rootmenu);
1560 blackbox->addMenuTimestamp(menu_filename);
1570 rootmenu->setInternalMenu();
1571 rootmenu->insert(i18n(ScreenSet, Screenxterm, "xterm"),
1573 i18n(ScreenSet, Screenxterm, "xterm"));
1574 rootmenu->insert(i18n(ScreenSet, ScreenRestart, "Restart"),
1576 rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
1578 rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
1584 bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
1585 char line[1024], label[1024], command[1024];
1587 while (! feof(file)) {
1588 memset(line, 0, 1024);
1589 memset(label, 0, 1024);
1590 memset(command, 0, 1024);
1592 if (fgets(line, 1024, file)) {
1593 if (line[0] != '#') {
1594 int i, key = 0, parse = 0, index = -1, line_length = strlen(line);
1596 // determine the keyword
1597 for (i = 0; i < line_length; i++) {
1598 if (line[i] == '[') parse = 1;
1599 else if (line[i] == ']') break;
1600 else if (line[i] != ' ')
1602 key += tolower(line[i]);
1605 // get the label enclosed in ()'s
1608 for (i = 0; i < line_length; i++) {
1609 if (line[i] == '(') {
1612 } else if (line[i] == ')') break;
1613 else if (index++ >= 0) {
1614 if (line[i] == '\\' && i < line_length - 1) i++;
1615 label[index - 1] = line[i];
1620 label[index] = '\0';
1625 // get the command enclosed in {}'s
1628 for (i = 0; i < line_length; i++) {
1629 if (line[i] == '{') {
1632 } else if (line[i] == '}') break;
1633 else if (index++ >= 0) {
1634 if (line[i] == '\\' && i < line_length - 1) i++;
1635 command[index - 1] = line[i];
1640 command[index] = '\0';
1647 return ((menu->getCount() == 0) ? True : False);
1654 menu->insert(label);
1659 if ((! *label) && (! *command)) {
1660 fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
1661 "BScreen::parseMenuFile: [exec] error, "
1662 "no menu label and/or command defined\n"));
1666 menu->insert(label, BScreen::Execute, command);
1672 fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
1673 "BScreen::parseMenuFile: [exit] error, "
1674 "no menu label defined\n"));
1678 menu->insert(label, BScreen::Exit);
1684 if ((! *label) || (! *command)) {
1686 i18n(ScreenSet, ScreenSTYLEError,
1687 "BScreen::parseMenuFile: [style] error, "
1688 "no menu label and/or filename defined\n"));
1692 string style = expandTilde(command);
1694 menu->insert(label, BScreen::SetStyle, style.c_str());
1701 fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
1702 "BScreen::parseMenufile: [config] error, "
1703 "no label defined"));
1707 menu->insert(label, configmenu);
1711 case 740: // include
1714 fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
1715 "BScreen::parseMenuFile: [include] error, "
1716 "no filename defined\n"));
1720 string newfile = expandTilde(label);
1721 FILE *submenufile = fopen(newfile.c_str(), "r");
1725 if (fstat(fileno(submenufile), &buf) ||
1726 (! S_ISREG(buf.st_mode))) {
1728 i18n(ScreenSet, ScreenINCLUDEErrorReg,
1729 "BScreen::parseMenuFile: [include] error: "
1730 "'%s' is not a regular file\n"), newfile.c_str());
1734 if (! feof(submenufile)) {
1735 if (! parseMenuFile(submenufile, menu))
1736 blackbox->addMenuTimestamp(newfile);
1738 fclose(submenufile);
1741 perror(newfile.c_str());
1747 case 767: // submenu
1750 fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
1751 "BScreen::parseMenuFile: [submenu] error, "
1752 "no menu label defined\n"));
1756 Rootmenu *submenu = new Rootmenu(this);
1759 submenu->setLabel(command);
1761 submenu->setLabel(label);
1763 parseMenuFile(file, submenu);
1765 menu->insert(label, submenu);
1766 rootmenuList.push_back(submenu);
1771 case 773: // restart
1774 fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
1775 "BScreen::parseMenuFile: [restart] error, "
1776 "no menu label defined\n"));
1781 menu->insert(label, BScreen::RestartOther, command);
1783 menu->insert(label, BScreen::Restart);
1788 case 845: // reconfig
1792 i18n(ScreenSet, ScreenRECONFIGError,
1793 "BScreen::parseMenuFile: [reconfig] error, "
1794 "no menu label defined\n"));
1798 menu->insert(label, BScreen::Reconfigure);
1803 case 995: // stylesdir
1804 case 1113: // stylesmenu
1806 bool newmenu = ((key == 1113) ? True : False);
1808 if ((! *label) || ((! *command) && newmenu)) {
1810 i18n(ScreenSet, ScreenSTYLESDIRError,
1811 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1812 " error, no directory defined\n"));
1816 char *directory = ((newmenu) ? command : label);
1818 string stylesdir = expandTilde(directory);
1820 struct stat statbuf;
1822 if (! stat(stylesdir.c_str(), &statbuf)) {
1823 if (S_ISDIR(statbuf.st_mode)) {
1824 Rootmenu *stylesmenu;
1827 stylesmenu = new Rootmenu(this);
1831 DIR *d = opendir(stylesdir.c_str());
1833 std::vector<string> ls;
1835 while((p = readdir(d)))
1836 ls.push_back(p->d_name);
1840 std::sort(ls.begin(), ls.end());
1842 std::vector<string>::iterator it = ls.begin(),
1844 for (; it != end; ++it) {
1845 const string& fname = *it;
1847 if (fname[fname.size()-1] == '~')
1850 string style = stylesdir;
1854 if ((! stat(style.c_str(), &statbuf)) &&
1855 S_ISREG(statbuf.st_mode))
1856 stylesmenu->insert(fname, BScreen::SetStyle, style);
1859 stylesmenu->update();
1862 stylesmenu->setLabel(label);
1863 menu->insert(label, stylesmenu);
1864 rootmenuList.push_back(stylesmenu);
1867 blackbox->addMenuTimestamp(stylesdir);
1870 i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
1871 "BScreen::parseMenuFile:"
1872 " [stylesdir/stylesmenu] error, %s is not a"
1873 " directory\n"), stylesdir.c_str());
1877 i18n(ScreenSet, ScreenSTYLESDIRErrorNoExist,
1878 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1879 " error, %s does not exist\n"), stylesdir.c_str());
1884 case 1090: // workspaces
1888 i18n(ScreenSet, ScreenWORKSPACESError,
1889 "BScreen:parseMenuFile: [workspaces] error, "
1890 "no menu label defined\n"));
1894 menu->insert(label, workspacemenu);
1903 return ((menu->getCount() == 0) ? True : False);
1907 void BScreen::shutdown(void) {
1908 XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
1909 XSync(blackbox->getXDisplay(), False);
1911 while(! windowList.empty())
1912 unmanageWindow(windowList.front(), True);
1918 void BScreen::showPosition(int x, int y) {
1919 if (! geom_visible) {
1920 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1921 (getWidth() - geom_w) / 2,
1922 (getHeight() - geom_h) / 2, geom_w, geom_h);
1923 XMapWindow(blackbox->getXDisplay(), geom_window);
1924 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1926 geom_visible = True;
1931 sprintf(label, i18n(ScreenSet, ScreenPositionFormat,
1932 "X: %4d x Y: %4d"), x, y);
1934 XClearWindow(blackbox->getXDisplay(), geom_window);
1936 resource.wstyle.font->drawString(geom_window,
1937 resource.bevel_width, resource.bevel_width,
1938 resource.wstyle.l_text_focus,
1943 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
1944 if (! geom_visible) {
1945 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1946 (getWidth() - geom_w) / 2,
1947 (getHeight() - geom_h) / 2, geom_w, geom_h);
1948 XMapWindow(blackbox->getXDisplay(), geom_window);
1949 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1951 geom_visible = True;
1956 sprintf(label, i18n(ScreenSet, ScreenGeometryFormat,
1957 "W: %4d x H: %4d"), gx, gy);
1959 XClearWindow(blackbox->getXDisplay(), geom_window);
1961 resource.wstyle.font->drawString(geom_window,
1962 resource.bevel_width, resource.bevel_width,
1963 resource.wstyle.l_text_focus,
1968 void BScreen::hideGeometry(void) {
1970 XUnmapWindow(blackbox->getXDisplay(), geom_window);
1971 geom_visible = False;
1976 void BScreen::addStrut(Strut *strut) {
1977 strutList.push_back(strut);
1981 void BScreen::removeStrut(Strut *strut) {
1982 strutList.remove(strut);
1986 const Rect& BScreen::availableArea(void) const {
1988 return getRect(); // return the full screen
1993 void BScreen::updateAvailableArea(void) {
1994 Rect old_area = usableArea;
1995 usableArea = getRect(); // reset to full screen
1997 /* these values represent offsets from the screen edge
1998 * we look for the biggest offset on each edge and then apply them
2000 * do not be confused by the similarity to the names of Rect's members
2002 unsigned int current_left = 0, current_right = 0, current_top = 0,
2005 StrutList::const_iterator it = strutList.begin(), end = strutList.end();
2007 for(; it != end; ++it) {
2009 if (strut->left > current_left)
2010 current_left = strut->left;
2011 if (strut->top > current_top)
2012 current_top = strut->top;
2013 if (strut->right > current_right)
2014 current_right = strut->right;
2015 if (strut->bottom > current_bottom)
2016 current_bottom = strut->bottom;
2019 usableArea.setPos(current_left, current_top);
2020 usableArea.setSize(usableArea.width() - (current_left + current_right),
2021 usableArea.height() - (current_top + current_bottom));
2023 if (old_area != usableArea) {
2024 BlackboxWindowList::iterator it = windowList.begin(),
2025 end = windowList.end();
2026 for (; it != end; ++it)
2027 if ((*it)->isMaximized()) (*it)->remaximize();
2034 Workspace* BScreen::getWorkspace(unsigned int index) {
2035 assert(index < workspacesList.size());
2036 return workspacesList[index];
2040 void BScreen::buttonPressEvent(const XButtonEvent *xbutton) {
2041 if (xbutton->button == 1) {
2042 if (! isRootColormapInstalled())
2043 image_control->installRootColormap();
2045 if (workspacemenu->isVisible())
2046 workspacemenu->hide();
2048 if (rootmenu->isVisible())
2050 } else if (xbutton->button == 2) {
2051 int mx = xbutton->x_root - (workspacemenu->getWidth() / 2);
2052 int my = xbutton->y_root - (workspacemenu->getTitleHeight() / 2);
2057 if (mx + workspacemenu->getWidth() > getWidth())
2058 mx = getWidth() - workspacemenu->getWidth() - getBorderWidth();
2060 if (my + workspacemenu->getHeight() > getHeight())
2061 my = getHeight() - workspacemenu->getHeight() - getBorderWidth();
2063 workspacemenu->move(mx, my);
2065 if (! workspacemenu->isVisible()) {
2066 workspacemenu->removeParent();
2067 workspacemenu->show();
2069 } else if (xbutton->button == 3) {
2070 int mx = xbutton->x_root - (rootmenu->getWidth() / 2);
2071 int my = xbutton->y_root - (rootmenu->getTitleHeight() / 2);
2076 if (mx + rootmenu->getWidth() > getWidth())
2077 mx = getWidth() - rootmenu->getWidth() - getBorderWidth();
2079 if (my + rootmenu->getHeight() > getHeight())
2080 my = getHeight() - rootmenu->getHeight() - getBorderWidth();
2082 rootmenu->move(mx, my);
2084 if (! rootmenu->isVisible()) {
2085 blackbox->checkMenu();
2089 } else if (xbutton->button == 4) {
2090 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2091 changeWorkspaceID(0);
2093 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2095 } else if (xbutton->button == 5) {
2096 if (getCurrentWorkspaceID() == 0)
2097 changeWorkspaceID(getWorkspaceCount() - 1);
2099 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2104 void BScreen::toggleFocusModel(FocusModel model) {
2105 std::for_each(windowList.begin(), windowList.end(),
2106 std::mem_fun(&BlackboxWindow::ungrabButtons));
2108 if (model == SloppyFocus) {
2109 saveSloppyFocus(True);
2111 // we're cheating here to save writing the config file 3 times
2112 resource.auto_raise = False;
2113 resource.click_raise = False;
2114 saveSloppyFocus(False);
2117 std::for_each(windowList.begin(), windowList.end(),
2118 std::mem_fun(&BlackboxWindow::grabButtons));
2122 BTexture BScreen::readDatabaseTexture(const string &rname,
2123 const string &default_color,
2124 const Configuration &style) {
2128 if (style.getValue(rname, s))
2129 texture = BTexture(s);
2131 texture.setTexture(BTexture::Solid | BTexture::Flat);
2133 // associate this texture with this screen
2134 texture.setDisplay(getBaseDisplay(), getScreenNumber());
2135 texture.setImageControl(image_control);
2137 if (texture.texture() & BTexture::Solid) {
2138 texture.setColor(readDatabaseColor(rname + ".color",
2139 default_color, style));
2140 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2141 default_color, style));
2142 } else if (texture.texture() & BTexture::Gradient) {
2143 texture.setColor(readDatabaseColor(rname + ".color",
2144 default_color, style));
2145 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2146 default_color, style));
2153 BColor BScreen::readDatabaseColor(const string &rname,
2154 const string &default_color,
2155 const Configuration &style) {
2158 if (style.getValue(rname, s))
2159 color = BColor(s, getBaseDisplay(), getScreenNumber());
2161 color = BColor(default_color, getBaseDisplay(), getScreenNumber());
2166 BFont *BScreen::readDatabaseFont(const string &rbasename,
2167 const Configuration &style) {
2174 if (style.getValue(rbasename + "xft.font", s) &&
2175 style.getValue(rbasename + "xft.size", i)) {
2178 bool italic = False;
2179 if (style.getValue(rbasename + "xft.flags", s)) {
2180 if (s.find("bold") != string::npos)
2182 if (s.find("italic") != string::npos)
2186 BFont *b = new BFont(blackbox->getXDisplay(), this, family, i, bold,
2187 italic, resource.aa_fonts);
2191 delete b; // fall back to the normal X font stuff
2195 style.getValue(rbasename + "font", s);
2196 // if this fails, a blank string will be used, which will cause the fallback
2199 BFont *b = new BFont(blackbox->getXDisplay(), this, s);
2201 exit(2); // can't continue without a font