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 list, 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::saveHideToolbar(bool h) {
392 resource.hide_toolbar = h;
393 if (resource.hide_toolbar)
394 toolbar->unmapToolbar();
396 toolbar->mapToolbar();
397 config->setValue(screenstr + "hideToolbar", resource.hide_toolbar);
401 void BScreen::saveWindowToWindowSnap(bool s) {
402 resource.window_to_window_snap = s;
403 config->setValue(screenstr + "windowToWindowSnap",
404 resource.window_to_window_snap);
408 void BScreen::saveWindowCornerSnap(bool s) {
409 resource.window_corner_snap = s;
410 config->setValue(screenstr + "windowCornerSnap",
411 resource.window_corner_snap);
415 void BScreen::saveWorkspaces(unsigned int w) {
416 resource.workspaces = w;
417 config->setValue(screenstr + "workspaces", resource.workspaces);
421 void BScreen::savePlacementPolicy(int p) {
422 resource.placement_policy = p;
423 const char *placement;
424 switch (resource.placement_policy) {
425 case CascadePlacement: placement = "CascadePlacement"; break;
426 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
427 case RowSmartPlacement: default: placement = "RowSmartPlacement"; break;
429 config->setValue(screenstr + "windowPlacement", placement);
433 void BScreen::saveEdgeSnapThreshold(int t) {
434 resource.edge_snap_threshold = t;
435 config->setValue(screenstr + "edgeSnapThreshold",
436 resource.edge_snap_threshold);
440 void BScreen::saveRowPlacementDirection(int d) {
441 resource.row_direction = d;
442 config->setValue(screenstr + "rowPlacementDirection",
443 resource.row_direction == LeftRight ?
444 "LeftToRight" : "RightToLeft");
448 void BScreen::saveColPlacementDirection(int d) {
449 resource.col_direction = d;
450 config->setValue(screenstr + "colPlacementDirection",
451 resource.col_direction == TopBottom ?
452 "TopToBottom" : "BottomToTop");
457 void BScreen::saveStrftimeFormat(const std::string& format) {
458 resource.strftime_format = format;
459 config->setValue(screenstr + "strftimeFormat", resource.strftime_format);
462 #else // !HAVE_STRFTIME
464 void BScreen::saveDateFormat(int f) {
465 resource.date_format = f;
466 config->setValue(screenstr + "dateFormat",
467 resource.date_format == B_EuropeanDate ?
468 "European" : "American");
472 void BScreen::saveClock24Hour(Bool c) {
473 resource.clock24hour = c;
474 config->setValue(screenstr + "clockFormat", resource.clock24hour ? 24 : 12);
476 #endif // HAVE_STRFTIME
479 void BScreen::saveWorkspaceNames() {
480 XAtom::StringVect nameList;
481 unsigned long numnames = (unsigned) -1;
485 xatom->getValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
486 numnames, nameList)) {
487 for (unsigned int i = 0; i < nameList.size(); ++i) {
488 if (i > 0) names += ",";
489 names += nameList[i];
492 config->setValue(screenstr + "workspaceNames", names);
496 void BScreen::save_rc(void) {
497 saveSloppyFocus(resource.sloppy_focus);
498 saveAutoRaise(resource.auto_raise);
499 saveImageDither(doImageDither());
500 saveOpaqueMove(resource.opaque_move);
501 saveFullMax(resource.full_max);
502 saveFocusNew(resource.focus_new);
503 saveFocusLast(resource.focus_last);
504 saveHideToolbar(resource.hide_toolbar);
505 saveWindowToWindowSnap(resource.window_to_window_snap);
506 saveWindowCornerSnap(resource.window_corner_snap);
507 saveWorkspaces(resource.workspaces);
508 savePlacementPolicy(resource.placement_policy);
509 saveEdgeSnapThreshold(resource.edge_snap_threshold);
510 saveRowPlacementDirection(resource.row_direction);
511 saveColPlacementDirection(resource.col_direction);
513 saveStrftimeFormat(resource.strftime_format);
514 #else // !HAVE_STRFTIME
515 saveDateFormat(resource.date_format);
516 savwClock24Hour(resource.clock24hour);
517 #endif // HAVE_STRFTIME
524 void BScreen::load_rc(void) {
528 if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
529 resource.full_max = false;
531 if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
532 resource.focus_new = false;
534 if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
535 resource.focus_last = false;
537 if (! config->getValue(screenstr + "workspaces", resource.workspaces))
538 resource.workspaces = 1;
540 if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
541 resource.opaque_move = false;
543 if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
544 resource.hide_toolbar = false;
546 if (! config->getValue(screenstr + "windowToWindowSnap",
547 resource.window_to_window_snap))
548 resource.window_to_window_snap = true;
550 if (! config->getValue(screenstr + "windowCornerSnap",
551 resource.window_corner_snap))
552 resource.window_corner_snap = true;
554 if (! config->getValue(screenstr + "imageDither", b))
556 image_control->setDither(b);
558 if (! config->getValue(screenstr + "edgeSnapThreshold",
559 resource.edge_snap_threshold))
560 resource.edge_snap_threshold = 4;
562 if (config->getValue(screenstr + "rowPlacementDirection", s) &&
564 resource.row_direction = RightLeft;
566 resource.row_direction = LeftRight;
568 if (config->getValue(screenstr + "colPlacementDirection", s) &&
570 resource.col_direction = BottomTop;
572 resource.col_direction = TopBottom;
574 XAtom::StringVect workspaceNames;
575 if (config->getValue(screenstr + "workspaceNames", s)) {
576 string::const_iterator it = s.begin(), end = s.end();
578 string::const_iterator tmp = it; // current string.begin()
579 it = std::find(tmp, end, ','); // look for comma between tmp and end
580 workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
586 xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
589 resource.sloppy_focus = true;
590 resource.auto_raise = false;
591 resource.click_raise = false;
592 if (config->getValue(screenstr + "focusModel", s)) {
593 if (s.find("ClickToFocus") != string::npos) {
594 resource.sloppy_focus = false;
597 if (s.find("AutoRaise") != string::npos)
598 resource.auto_raise = true;
599 if (s.find("ClickRaise") != string::npos)
600 resource.click_raise = true;
604 if (config->getValue(screenstr + "windowPlacement", s)) {
605 if (s == "CascadePlacement")
606 resource.placement_policy = CascadePlacement;
607 else if (s == "ColSmartPlacement")
608 resource.placement_policy = ColSmartPlacement;
609 else //if (s == "RowSmartPlacement")
610 resource.placement_policy = RowSmartPlacement;
612 resource.placement_policy = RowSmartPlacement;
615 if (config->getValue(screenstr + "strftimeFormat", s))
616 resource.strftime_format = s;
618 resource.strftime_format = "%I:%M %p";
619 #else // !HAVE_STRFTIME
622 if (config->getValue(screenstr + "dateFormat", s) && s == "European")
623 resource.date_format = B_EuropeanDate;
625 resource.date_format = B_AmericanDate;
627 if (! config->getValue(screenstr + "clockFormat", l))
629 resource.clock24hour = l == 24;
630 #endif // HAVE_STRFTIME
634 void BScreen::reconfigure(void) {
641 gcv.foreground = WhitePixel(blackbox->getXDisplay(),
643 gcv.function = GXinvert;
644 gcv.subwindow_mode = IncludeInferiors;
645 XChangeGC(blackbox->getXDisplay(), opGC,
646 GCForeground | GCFunction | GCSubwindowMode, &gcv);
648 const char *s = i18n(ScreenSet, ScreenPositionLength,
649 "0: 0000 x 0: 0000");
651 geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
652 geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
654 BTexture* texture = &(resource.wstyle.l_focus);
655 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
656 if (geom_pixmap == ParentRelative) {
657 texture = &(resource.wstyle.t_focus);
658 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
661 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
662 texture->color().pixel());
664 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
665 geom_window, geom_pixmap);
667 XSetWindowBorderWidth(blackbox->getXDisplay(), geom_window,
668 resource.border_width);
669 XSetWindowBorder(blackbox->getXDisplay(), geom_window,
670 resource.border_color.pixel());
672 workspacemenu->reconfigure();
673 iconmenu->reconfigure();
675 typedef std::vector<int> SubList;
676 SubList remember_subs;
678 // save the current open menus
679 Basemenu *menu = rootmenu;
681 while ((submenu = menu->getCurrentSubmenu()) >= 0) {
682 remember_subs.push_back(submenu);
683 menu = menu->find(submenu)->submenu();
689 rootmenu->reconfigure();
691 // reopen the saved menus
693 const SubList::iterator subs_end = remember_subs.end();
694 for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
695 menu->drawSubmenu(*it);
696 menu = menu->find(*it)->submenu();
701 configmenu->reconfigure();
703 toolbar->reconfigure();
707 std::for_each(workspacesList.begin(), workspacesList.end(),
708 std::mem_fun(&Workspace::reconfigure));
710 BlackboxWindowList::iterator iit = iconList.begin();
711 for (; iit != iconList.end(); ++iit) {
712 BlackboxWindow *bw = *iit;
713 if (bw->validateClient())
717 image_control->timeout();
721 void BScreen::rereadMenu(void) {
725 rootmenu->reconfigure();
729 void BScreen::LoadStyle(void) {
730 Configuration style(False);
732 const char *sfile = blackbox->getStyleFilename();
734 style.setFile(sfile);
735 if (! style.load()) {
736 style.setFile(DEFAULTSTYLE);
738 style.create(); // hardcoded default values will be used.
742 // merge in the rc file
743 style.merge(config->file(), True);
747 // load fonts/fontsets
748 if (resource.wstyle.font)
749 delete resource.wstyle.font;
750 if (resource.tstyle.font)
751 delete resource.tstyle.font;
752 if (resource.mstyle.f_font)
753 delete resource.mstyle.f_font;
754 if (resource.mstyle.t_font)
755 delete resource.mstyle.t_font;
756 resource.wstyle.font = resource.tstyle.font = resource.mstyle.f_font =
757 resource.mstyle.t_font = (BFont *) 0;
759 resource.wstyle.font = readDatabaseFont("window.", style);
760 resource.tstyle.font = readDatabaseFont("toolbar.", style);
761 resource.mstyle.t_font = readDatabaseFont("menu.title.", style);
762 resource.mstyle.f_font = readDatabaseFont("menu.frame.", style);
764 // load window config
765 resource.wstyle.t_focus =
766 readDatabaseTexture("window.title.focus", "white", style);
767 resource.wstyle.t_unfocus =
768 readDatabaseTexture("window.title.unfocus", "black", style);
769 resource.wstyle.l_focus =
770 readDatabaseTexture("window.label.focus", "white", style);
771 resource.wstyle.l_unfocus =
772 readDatabaseTexture("window.label.unfocus", "black", style);
773 resource.wstyle.h_focus =
774 readDatabaseTexture("window.handle.focus", "white", style);
775 resource.wstyle.h_unfocus =
776 readDatabaseTexture("window.handle.unfocus", "black", style);
777 resource.wstyle.g_focus =
778 readDatabaseTexture("window.grip.focus", "white", style);
779 resource.wstyle.g_unfocus =
780 readDatabaseTexture("window.grip.unfocus", "black", style);
781 resource.wstyle.b_focus =
782 readDatabaseTexture("window.button.focus", "white", style);
783 resource.wstyle.b_unfocus =
784 readDatabaseTexture("window.button.unfocus", "black", style);
785 resource.wstyle.b_pressed =
786 readDatabaseTexture("window.button.pressed", "black", style);
787 resource.wstyle.f_focus =
788 readDatabaseColor("window.frame.focusColor", "white", style);
789 resource.wstyle.f_unfocus =
790 readDatabaseColor("window.frame.unfocusColor", "black", style);
791 resource.wstyle.l_text_focus =
792 readDatabaseColor("window.label.focus.textColor", "black", style);
793 resource.wstyle.l_text_unfocus =
794 readDatabaseColor("window.label.unfocus.textColor", "white", style);
795 resource.wstyle.b_pic_focus =
796 readDatabaseColor("window.button.focus.picColor", "black", style);
797 resource.wstyle.b_pic_unfocus =
798 readDatabaseColor("window.button.unfocus.picColor", "white", style);
800 resource.wstyle.justify = LeftJustify;
801 if (style.getValue("window.justify", s)) {
802 if (s == "right" || s == "Right")
803 resource.wstyle.justify = RightJustify;
804 else if (s == "center" || s == "Center")
805 resource.wstyle.justify = CenterJustify;
808 // load toolbar config
809 resource.tstyle.toolbar =
810 readDatabaseTexture("toolbar", "black", style);
811 resource.tstyle.label =
812 readDatabaseTexture("toolbar.label", "black", style);
813 resource.tstyle.window =
814 readDatabaseTexture("toolbar.windowLabel", "black", style);
815 resource.tstyle.button =
816 readDatabaseTexture("toolbar.button", "white", style);
817 resource.tstyle.pressed =
818 readDatabaseTexture("toolbar.button.pressed", "black", style);
819 resource.tstyle.clock =
820 readDatabaseTexture("toolbar.clock", "black", style);
821 resource.tstyle.l_text =
822 readDatabaseColor("toolbar.label.textColor", "white", style);
823 resource.tstyle.w_text =
824 readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
825 resource.tstyle.c_text =
826 readDatabaseColor("toolbar.clock.textColor", "white", style);
827 resource.tstyle.b_pic =
828 readDatabaseColor("toolbar.button.picColor", "black", style);
830 resource.tstyle.justify = LeftJustify;
831 if (style.getValue("toolbar.justify", s)) {
832 if (s == "right" || s == "Right")
833 resource.tstyle.justify = RightJustify;
834 else if (s == "center" || s == "Center")
835 resource.tstyle.justify = CenterJustify;
839 resource.mstyle.title =
840 readDatabaseTexture("menu.title", "white", style);
841 resource.mstyle.frame =
842 readDatabaseTexture("menu.frame", "black", style);
843 resource.mstyle.hilite =
844 readDatabaseTexture("menu.hilite", "white", style);
845 resource.mstyle.t_text =
846 readDatabaseColor("menu.title.textColor", "black", style);
847 resource.mstyle.f_text =
848 readDatabaseColor("menu.frame.textColor", "white", style);
849 resource.mstyle.d_text =
850 readDatabaseColor("menu.frame.disableColor", "black", style);
851 resource.mstyle.h_text =
852 readDatabaseColor("menu.hilite.textColor", "black", style);
854 resource.mstyle.t_justify = LeftJustify;
855 if (style.getValue("menu.title.justify", s)) {
856 if (s == "right" || s == "Right")
857 resource.mstyle.t_justify = RightJustify;
858 else if (s == "center" || s == "Center")
859 resource.mstyle.t_justify = CenterJustify;
862 resource.mstyle.f_justify = LeftJustify;
863 if (style.getValue("menu.frame.justify", s)) {
864 if (s == "right" || s == "Right")
865 resource.mstyle.f_justify = RightJustify;
866 else if (s == "center" || s == "Center")
867 resource.mstyle.f_justify = CenterJustify;
870 resource.mstyle.bullet = Basemenu::Triangle;
871 if (style.getValue("menu.bullet", s)) {
872 if (s == "empty" || s == "Empty")
873 resource.mstyle.bullet = Basemenu::Empty;
874 else if (s == "square" || s == "Square")
875 resource.mstyle.bullet = Basemenu::Square;
876 else if (s == "diamond" || s == "Diamond")
877 resource.mstyle.bullet = Basemenu::Diamond;
880 resource.mstyle.bullet_pos = Basemenu::Left;
881 if (style.getValue("menu.bullet.position", s)) {
882 if (s == "right" || s == "Right")
883 resource.mstyle.bullet_pos = Basemenu::Right;
886 resource.border_color =
887 readDatabaseColor("borderColor", "black", style);
889 // load bevel, border and handle widths
890 if (! style.getValue("handleWidth", resource.handle_width) ||
891 resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
892 resource.handle_width = 6;
894 if (! style.getValue("borderWidth", resource.border_width))
895 resource.border_width = 1;
897 if (! style.getValue("bevelWidth", resource.bevel_width) ||
898 resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
899 resource.bevel_width = 3;
901 if (! style.getValue("frameWidth", resource.frame_width) ||
902 resource.frame_width > (getWidth() / 2))
903 resource.frame_width = resource.bevel_width;
905 if (style.getValue("rootCommand", s))
906 bexec(s, displayString());
910 void BScreen::addIcon(BlackboxWindow *w) {
913 w->setWorkspace(BSENTINEL);
914 w->setWindowNumber(iconList.size());
916 iconList.push_back(w);
918 const char* title = w->getIconTitle();
919 iconmenu->insert(title);
924 void BScreen::removeIcon(BlackboxWindow *w) {
929 iconmenu->remove(w->getWindowNumber());
932 BlackboxWindowList::iterator it = iconList.begin(),
933 end = iconList.end();
934 for (int i = 0; it != end; ++it)
935 (*it)->setWindowNumber(i++);
939 BlackboxWindow *BScreen::getIcon(unsigned int index) {
940 if (index < iconList.size()) {
941 BlackboxWindowList::iterator it = iconList.begin();
942 for (; index > 0; --index, ++it) ; /* increment to index */
946 return (BlackboxWindow *) 0;
950 unsigned int BScreen::addWorkspace(void) {
951 Workspace *wkspc = new Workspace(this, workspacesList.size());
952 workspacesList.push_back(wkspc);
953 saveWorkspaces(getWorkspaceCount());
955 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
957 workspacemenu->update();
959 toolbar->reconfigure();
961 updateNetizenWorkspaceCount();
963 return workspacesList.size();
967 unsigned int BScreen::removeLastWorkspace(void) {
968 if (workspacesList.size() == 1)
971 Workspace *wkspc = workspacesList.back();
973 if (current_workspace->getID() == wkspc->getID())
974 changeWorkspaceID(current_workspace->getID() - 1);
978 workspacemenu->remove(wkspc->getID() + 2);
979 workspacemenu->update();
981 workspacesList.pop_back();
984 saveWorkspaces(getWorkspaceCount());
986 toolbar->reconfigure();
988 updateNetizenWorkspaceCount();
990 return workspacesList.size();
994 void BScreen::changeWorkspaceID(unsigned int id) {
995 if (! current_workspace) return;
997 if (id != current_workspace->getID()) {
998 BlackboxWindow *focused = blackbox->getFocusedWindow();
999 if (focused && focused->getScreen() == this && ! focused->isStuck()) {
1000 if (focused->getWorkspaceNumber() != current_workspace->getID()) {
1001 fprintf(stderr, "%s is on the wrong workspace, aborting\n",
1002 focused->getTitle());
1005 current_workspace->setLastFocusedWindow(focused);
1007 // if no window had focus, no need to store a last focus
1008 current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
1010 // when we switch workspaces, unfocus whatever was focused
1011 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1013 current_workspace->hideAll();
1014 workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1016 current_workspace = getWorkspace(id);
1018 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
1019 XAtom::cardinal, id);
1021 workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1022 toolbar->redrawWorkspaceLabel(True);
1024 current_workspace->showAll();
1026 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1027 XSync(blackbox->getXDisplay(), False);
1028 current_workspace->getLastFocusedWindow()->setInputFocus();
1032 updateNetizenCurrentWorkspace();
1037 * Set the _NET_CLIENT_LIST root window property.
1039 void BScreen::updateClientList(void) {
1040 if (windowList.size() > 0) {
1041 Window *windows = new Window[windowList.size()];
1042 Window *win_it = windows;
1043 BlackboxWindowList::iterator it = windowList.begin();
1044 const BlackboxWindowList::iterator end = windowList.end();
1045 for (; it != end; ++it, ++win_it)
1046 *win_it = (*it)->getClientWindow();
1047 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1048 windows, windowList.size());
1051 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1057 * Set the _NET_CLIENT_LIST_STACKING root window property.
1059 void BScreen::updateStackingList(void) {
1061 BlackboxWindowList stack_order;
1064 * Get the atacking order from all of the workspaces.
1065 * We start with the current workspace so that the sticky windows will be
1066 * in the right order on the current workspace.
1067 * XXX: Do we need to have sticky windows in the list once for each workspace?
1069 getCurrentWorkspace()->appendStackOrder(stack_order);
1070 for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
1071 if (i != getCurrentWorkspaceID())
1072 getWorkspace(i)->appendStackOrder(stack_order);
1074 if (stack_order.size() > 0) {
1075 // set the client list atoms
1076 Window *windows = new Window[stack_order.size()];
1077 Window *win_it = windows;
1078 BlackboxWindowList::iterator it = stack_order.begin();
1079 const BlackboxWindowList::iterator end = stack_order.end();
1080 for (; it != end; ++it, ++win_it)
1081 *win_it = (*it)->getClientWindow();
1082 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1083 XAtom::window, windows, stack_order.size());
1086 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1087 XAtom::window, 0, 0);
1091 void BScreen::addSystrayWindow(Window window) {
1092 systrayWindowList.push_back(window);
1093 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1095 &systrayWindowList[0], systrayWindowList.size());
1096 blackbox->saveSystrayWindowSearch(window, this);
1100 void BScreen::removeSystrayWindow(Window window) {
1101 WindowList::iterator it = systrayWindowList.begin();
1102 const WindowList::iterator end = systrayWindowList.end();
1103 for (; it != end; ++it)
1104 if (*it == window) {
1105 systrayWindowList.erase(it);
1106 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1108 &systrayWindowList[0], systrayWindowList.size());
1109 blackbox->removeSystrayWindowSearch(window);
1115 void BScreen::addDesktopWindow(Window window) {
1116 desktopWindowList.push_back(window);
1117 XLowerWindow(blackbox->getXDisplay(), window);
1118 XSelectInput(blackbox->getXDisplay(), window, StructureNotifyMask);
1119 blackbox->saveDesktopWindowSearch(window, this);
1123 void BScreen::removeDesktopWindow(Window window) {
1124 WindowList::iterator it = desktopWindowList.begin();
1125 const WindowList::iterator end = desktopWindowList.end();
1126 for (; it != end; ++it)
1127 if (*it == window) {
1128 desktopWindowList.erase(it);
1129 XSelectInput(blackbox->getXDisplay(), window, None);
1130 blackbox->removeDesktopWindowSearch(window);
1136 void BScreen::manageWindow(Window w) {
1137 new BlackboxWindow(blackbox, w, this);
1139 BlackboxWindow *win = blackbox->searchWindow(w);
1142 if (win->isDesktop()) {
1143 // desktop windows cant do anything, so we remove all the normal window
1144 // stuff from them, they are only kept around so that we can keep them on
1145 // the bottom of the z-order
1147 addDesktopWindow(win->getClientWindow());
1152 windowList.push_back(win);
1155 XMapRequestEvent mre;
1157 if (blackbox->isStartup()) win->restoreAttributes();
1158 win->mapRequestEvent(&mre);
1162 void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
1165 if (w->getWorkspaceNumber() != BSENTINEL &&
1166 w->getWindowNumber() != BSENTINEL)
1167 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1168 else if (w->isIconic())
1171 windowList.remove(w);
1174 if (blackbox->getFocusedWindow() == w)
1175 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1177 removeNetizen(w->getClientWindow());
1180 some managed windows can also be window group controllers. when
1181 unmanaging such windows, we should also delete the window group.
1183 BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
1190 void BScreen::addNetizen(Netizen *n) {
1191 netizenList.push_back(n);
1193 n->sendWorkspaceCount();
1194 n->sendCurrentWorkspace();
1196 WorkspaceList::iterator it = workspacesList.begin();
1197 const WorkspaceList::iterator end = workspacesList.end();
1198 for (; it != end; ++it)
1199 (*it)->sendWindowList(*n);
1201 Window f = ((blackbox->getFocusedWindow()) ?
1202 blackbox->getFocusedWindow()->getClientWindow() : None);
1203 n->sendWindowFocus(f);
1207 void BScreen::removeNetizen(Window w) {
1208 NetizenList::iterator it = netizenList.begin();
1209 for (; it != netizenList.end(); ++it) {
1210 if ((*it)->getWindowID() == w) {
1212 netizenList.erase(it);
1219 void BScreen::updateWorkArea(void) {
1220 if (workspacesList.size() > 0) {
1221 unsigned long *dims = new unsigned long[4 * workspacesList.size()];
1222 for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
1223 // XXX: this could be different for each workspace
1224 const Rect &area = availableArea();
1225 dims[(i * 4) + 0] = area.x();
1226 dims[(i * 4) + 1] = area.y();
1227 dims[(i * 4) + 2] = area.width();
1228 dims[(i * 4) + 3] = area.height();
1230 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1231 dims, 4 * workspacesList.size());
1234 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1239 void BScreen::updateNetizenCurrentWorkspace(void) {
1240 std::for_each(netizenList.begin(), netizenList.end(),
1241 std::mem_fun(&Netizen::sendCurrentWorkspace));
1245 void BScreen::updateNetizenWorkspaceCount(void) {
1246 xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
1247 XAtom::cardinal, workspacesList.size());
1251 std::for_each(netizenList.begin(), netizenList.end(),
1252 std::mem_fun(&Netizen::sendWorkspaceCount));
1256 void BScreen::updateNetizenWindowFocus(void) {
1257 Window f = ((blackbox->getFocusedWindow()) ?
1258 blackbox->getFocusedWindow()->getClientWindow() : None);
1260 xatom->setValue(getRootWindow(), XAtom::net_active_window,
1263 NetizenList::iterator it = netizenList.begin();
1264 for (; it != netizenList.end(); ++it)
1265 (*it)->sendWindowFocus(f);
1269 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1270 NetizenList::iterator it = netizenList.begin();
1271 for (; it != netizenList.end(); ++it) {
1272 (*it)->sendWindowAdd(w, p);
1277 void BScreen::updateNetizenWindowDel(Window w) {
1278 NetizenList::iterator it = netizenList.begin();
1279 for (; it != netizenList.end(); ++it)
1280 (*it)->sendWindowDel(w);
1284 void BScreen::updateNetizenWindowRaise(Window w) {
1285 NetizenList::iterator it = netizenList.begin();
1286 for (; it != netizenList.end(); ++it)
1287 (*it)->sendWindowRaise(w);
1291 void BScreen::updateNetizenWindowLower(Window w) {
1292 NetizenList::iterator it = netizenList.begin();
1293 for (; it != netizenList.end(); ++it)
1294 (*it)->sendWindowLower(w);
1298 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1299 NetizenList::iterator it = netizenList.begin();
1300 for (; it != netizenList.end(); ++it)
1301 (*it)->sendConfigNotify(e);
1305 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
1306 // the 13 represents the number of blackbox windows such as menus
1307 Window *session_stack = new
1308 Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
1309 unsigned int i = 0, k = num;
1311 XRaiseWindow(blackbox->getXDisplay(), iconmenu->getWindowID());
1312 *(session_stack + i++) = iconmenu->getWindowID();
1314 WorkspaceList::iterator wit = workspacesList.begin();
1315 const WorkspaceList::iterator w_end = workspacesList.end();
1316 for (; wit != w_end; ++wit)
1317 *(session_stack + i++) = (*wit)->getMenu()->getWindowID();
1319 *(session_stack + i++) = workspacemenu->getWindowID();
1321 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1322 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1323 *(session_stack + i++) = configmenu->getWindowID();
1325 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1326 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1327 *(session_stack + i++) = slit->getMenu()->getWindowID();
1329 *(session_stack + i++) =
1330 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1331 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1333 RootmenuList::iterator rit = rootmenuList.begin();
1334 for (; rit != rootmenuList.end(); ++rit)
1335 *(session_stack + i++) = (*rit)->getWindowID();
1336 *(session_stack + i++) = rootmenu->getWindowID();
1338 if (toolbar->isOnTop())
1339 *(session_stack + i++) = toolbar->getWindowID();
1341 if (slit->isOnTop())
1342 *(session_stack + i++) = slit->getWindowID();
1345 *(session_stack + i++) = *(workspace_stack + k);
1347 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1349 delete [] session_stack;
1351 updateStackingList();
1355 void BScreen::lowerDesktops(void) {
1356 if (desktopWindowList.empty()) return;
1358 XLowerWindow(blackbox->getXDisplay(), desktopWindowList[0]);
1359 if (desktopWindowList.size() > 1)
1360 XRestackWindows(blackbox->getXDisplay(), &desktopWindowList[0],
1361 desktopWindowList.size());
1365 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
1366 bool ignore_sticky) {
1369 if (wkspc_id == BSENTINEL)
1370 wkspc_id = current_workspace->getID();
1372 if (w->getWorkspaceNumber() == wkspc_id)
1375 if (w->isIconic()) {
1377 getWorkspace(wkspc_id)->addWindow(w);
1378 } else if (ignore_sticky || ! w->isStuck()) {
1379 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1380 getWorkspace(wkspc_id)->addWindow(w);
1385 void BScreen::propagateWindowName(const BlackboxWindow *bw) {
1386 if (bw->isIconic()) {
1387 iconmenu->changeItemLabel(bw->getWindowNumber(), bw->getIconTitle());
1391 Clientmenu *clientmenu = getWorkspace(bw->getWorkspaceNumber())->getMenu();
1392 clientmenu->changeItemLabel(bw->getWindowNumber(), bw->getTitle());
1393 clientmenu->update();
1395 if (blackbox->getFocusedWindow() == bw)
1396 toolbar->redrawWindowLabel(True);
1401 void BScreen::nextFocus(void) {
1402 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1406 // if window is not on this screen, ignore it
1407 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1408 focused = (BlackboxWindow*) 0;
1411 if (focused && current_workspace->getCount() > 1) {
1412 // next is the next window to recieve focus, current is a place holder
1413 BlackboxWindow *current;
1416 next = current_workspace->getNextWindowInList(current);
1417 } while(! next->setInputFocus() && next != focused);
1419 if (next != focused)
1420 current_workspace->raiseWindow(next);
1421 } else if (current_workspace->getCount() >= 1) {
1422 next = current_workspace->getTopWindowOnStack();
1424 current_workspace->raiseWindow(next);
1425 next->setInputFocus();
1430 void BScreen::prevFocus(void) {
1431 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1435 // if window is not on this screen, ignore it
1436 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1437 focused = (BlackboxWindow*) 0;
1440 if (focused && current_workspace->getCount() > 1) {
1441 // next is the next window to recieve focus, current is a place holder
1442 BlackboxWindow *current;
1445 next = current_workspace->getPrevWindowInList(current);
1446 } while(! next->setInputFocus() && next != focused);
1448 if (next != focused)
1449 current_workspace->raiseWindow(next);
1450 } else if (current_workspace->getCount() >= 1) {
1451 next = current_workspace->getTopWindowOnStack();
1453 current_workspace->raiseWindow(next);
1454 next->setInputFocus();
1459 void BScreen::raiseFocus(void) {
1460 BlackboxWindow *focused = blackbox->getFocusedWindow();
1464 // if on this Screen, raise it
1465 if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
1466 Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
1467 workspace->raiseWindow(focused);
1472 void BScreen::InitMenu(void) {
1474 rootmenuList.clear();
1476 while (rootmenu->getCount())
1477 rootmenu->remove(0);
1479 rootmenu = new Rootmenu(this);
1481 bool defaultMenu = True;
1483 FILE *menu_file = (FILE *) 0;
1484 const char *menu_filename = blackbox->getMenuFilename();
1487 if (! (menu_file = fopen(menu_filename, "r")))
1488 perror(menu_filename);
1489 if (! menu_file) { // opening the menu file failed, try the default menu
1490 menu_filename = DEFAULTMENU;
1491 if (! (menu_file = fopen(menu_filename, "r")))
1492 perror(menu_filename);
1496 if (feof(menu_file)) {
1497 fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
1498 "%s: Empty menu file"),
1501 char line[1024], label[1024];
1502 memset(line, 0, 1024);
1503 memset(label, 0, 1024);
1505 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
1506 if (line[0] != '#') {
1507 int i, key = 0, index = -1, len = strlen(line);
1509 for (i = 0; i < len; i++) {
1510 if (line[i] == '[') index = 0;
1511 else if (line[i] == ']') break;
1512 else if (line[i] != ' ')
1514 key += tolower(line[i]);
1517 if (key == 517) { // [begin]
1519 for (i = index; i < len; i++) {
1520 if (line[i] == '(') index = 0;
1521 else if (line[i] == ')') break;
1522 else if (index++ >= 0) {
1523 if (line[i] == '\\' && i < len - 1) i++;
1524 label[index - 1] = line[i];
1528 if (index == -1) index = 0;
1529 label[index] = '\0';
1531 rootmenu->setLabel(label);
1532 defaultMenu = parseMenuFile(menu_file, rootmenu);
1534 blackbox->addMenuTimestamp(menu_filename);
1544 rootmenu->setInternalMenu();
1545 rootmenu->insert(i18n(ScreenSet, Screenxterm, "xterm"),
1547 i18n(ScreenSet, Screenxterm, "xterm"));
1548 rootmenu->insert(i18n(ScreenSet, ScreenRestart, "Restart"),
1550 rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
1552 rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
1558 bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
1559 char line[1024], label[1024], command[1024];
1561 while (! feof(file)) {
1562 memset(line, 0, 1024);
1563 memset(label, 0, 1024);
1564 memset(command, 0, 1024);
1566 if (fgets(line, 1024, file)) {
1567 if (line[0] != '#') {
1568 int i, key = 0, parse = 0, index = -1, line_length = strlen(line);
1570 // determine the keyword
1571 for (i = 0; i < line_length; i++) {
1572 if (line[i] == '[') parse = 1;
1573 else if (line[i] == ']') break;
1574 else if (line[i] != ' ')
1576 key += tolower(line[i]);
1579 // get the label enclosed in ()'s
1582 for (i = 0; i < line_length; i++) {
1583 if (line[i] == '(') {
1586 } else if (line[i] == ')') break;
1587 else if (index++ >= 0) {
1588 if (line[i] == '\\' && i < line_length - 1) i++;
1589 label[index - 1] = line[i];
1594 label[index] = '\0';
1599 // get the command enclosed in {}'s
1602 for (i = 0; i < line_length; i++) {
1603 if (line[i] == '{') {
1606 } else if (line[i] == '}') break;
1607 else if (index++ >= 0) {
1608 if (line[i] == '\\' && i < line_length - 1) i++;
1609 command[index - 1] = line[i];
1614 command[index] = '\0';
1621 return ((menu->getCount() == 0) ? True : False);
1628 menu->insert(label);
1633 if ((! *label) && (! *command)) {
1634 fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
1635 "BScreen::parseMenuFile: [exec] error, "
1636 "no menu label and/or command defined\n"));
1640 menu->insert(label, BScreen::Execute, command);
1646 fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
1647 "BScreen::parseMenuFile: [exit] error, "
1648 "no menu label defined\n"));
1652 menu->insert(label, BScreen::Exit);
1658 if ((! *label) || (! *command)) {
1660 i18n(ScreenSet, ScreenSTYLEError,
1661 "BScreen::parseMenuFile: [style] error, "
1662 "no menu label and/or filename defined\n"));
1666 string style = expandTilde(command);
1668 menu->insert(label, BScreen::SetStyle, style.c_str());
1675 fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
1676 "BScreen::parseMenufile: [config] error, "
1677 "no label defined"));
1681 menu->insert(label, configmenu);
1685 case 740: // include
1688 fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
1689 "BScreen::parseMenuFile: [include] error, "
1690 "no filename defined\n"));
1694 string newfile = expandTilde(label);
1695 FILE *submenufile = fopen(newfile.c_str(), "r");
1699 if (fstat(fileno(submenufile), &buf) ||
1700 (! S_ISREG(buf.st_mode))) {
1702 i18n(ScreenSet, ScreenINCLUDEErrorReg,
1703 "BScreen::parseMenuFile: [include] error: "
1704 "'%s' is not a regular file\n"), newfile.c_str());
1708 if (! feof(submenufile)) {
1709 if (! parseMenuFile(submenufile, menu))
1710 blackbox->addMenuTimestamp(newfile);
1712 fclose(submenufile);
1715 perror(newfile.c_str());
1721 case 767: // submenu
1724 fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
1725 "BScreen::parseMenuFile: [submenu] error, "
1726 "no menu label defined\n"));
1730 Rootmenu *submenu = new Rootmenu(this);
1733 submenu->setLabel(command);
1735 submenu->setLabel(label);
1737 parseMenuFile(file, submenu);
1739 menu->insert(label, submenu);
1740 rootmenuList.push_back(submenu);
1745 case 773: // restart
1748 fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
1749 "BScreen::parseMenuFile: [restart] error, "
1750 "no menu label defined\n"));
1755 menu->insert(label, BScreen::RestartOther, command);
1757 menu->insert(label, BScreen::Restart);
1762 case 845: // reconfig
1766 i18n(ScreenSet, ScreenRECONFIGError,
1767 "BScreen::parseMenuFile: [reconfig] error, "
1768 "no menu label defined\n"));
1772 menu->insert(label, BScreen::Reconfigure);
1777 case 995: // stylesdir
1778 case 1113: // stylesmenu
1780 bool newmenu = ((key == 1113) ? True : False);
1782 if ((! *label) || ((! *command) && newmenu)) {
1784 i18n(ScreenSet, ScreenSTYLESDIRError,
1785 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1786 " error, no directory defined\n"));
1790 char *directory = ((newmenu) ? command : label);
1792 string stylesdir = expandTilde(directory);
1794 struct stat statbuf;
1796 if (! stat(stylesdir.c_str(), &statbuf)) {
1797 if (S_ISDIR(statbuf.st_mode)) {
1798 Rootmenu *stylesmenu;
1801 stylesmenu = new Rootmenu(this);
1805 DIR *d = opendir(stylesdir.c_str());
1807 std::vector<string> ls;
1809 while((p = readdir(d)))
1810 ls.push_back(p->d_name);
1814 std::sort(ls.begin(), ls.end());
1816 std::vector<string>::iterator it = ls.begin(),
1818 for (; it != end; ++it) {
1819 const string& fname = *it;
1821 if (fname[fname.size()-1] == '~')
1824 string style = stylesdir;
1828 if ((! stat(style.c_str(), &statbuf)) &&
1829 S_ISREG(statbuf.st_mode))
1830 stylesmenu->insert(fname, BScreen::SetStyle, style);
1833 stylesmenu->update();
1836 stylesmenu->setLabel(label);
1837 menu->insert(label, stylesmenu);
1838 rootmenuList.push_back(stylesmenu);
1841 blackbox->addMenuTimestamp(stylesdir);
1844 i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
1845 "BScreen::parseMenuFile:"
1846 " [stylesdir/stylesmenu] error, %s is not a"
1847 " directory\n"), stylesdir.c_str());
1851 i18n(ScreenSet, ScreenSTYLESDIRErrorNoExist,
1852 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1853 " error, %s does not exist\n"), stylesdir.c_str());
1858 case 1090: // workspaces
1862 i18n(ScreenSet, ScreenWORKSPACESError,
1863 "BScreen:parseMenuFile: [workspaces] error, "
1864 "no menu label defined\n"));
1868 menu->insert(label, workspacemenu);
1877 return ((menu->getCount() == 0) ? True : False);
1881 void BScreen::shutdown(void) {
1882 XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
1883 XSync(blackbox->getXDisplay(), False);
1885 while(! windowList.empty())
1886 unmanageWindow(windowList.front(), True);
1892 void BScreen::showPosition(int x, int y) {
1893 if (! geom_visible) {
1894 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1895 (getWidth() - geom_w) / 2,
1896 (getHeight() - geom_h) / 2, geom_w, geom_h);
1897 XMapWindow(blackbox->getXDisplay(), geom_window);
1898 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1900 geom_visible = True;
1905 sprintf(label, i18n(ScreenSet, ScreenPositionFormat,
1906 "X: %4d x Y: %4d"), x, y);
1908 XClearWindow(blackbox->getXDisplay(), geom_window);
1910 resource.wstyle.font->drawString(geom_window,
1911 resource.bevel_width, resource.bevel_width,
1912 resource.wstyle.l_text_focus,
1917 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
1918 if (! geom_visible) {
1919 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1920 (getWidth() - geom_w) / 2,
1921 (getHeight() - geom_h) / 2, geom_w, geom_h);
1922 XMapWindow(blackbox->getXDisplay(), geom_window);
1923 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1925 geom_visible = True;
1930 sprintf(label, i18n(ScreenSet, ScreenGeometryFormat,
1931 "W: %4d x H: %4d"), gx, gy);
1933 XClearWindow(blackbox->getXDisplay(), geom_window);
1935 resource.wstyle.font->drawString(geom_window,
1936 resource.bevel_width, resource.bevel_width,
1937 resource.wstyle.l_text_focus,
1942 void BScreen::hideGeometry(void) {
1944 XUnmapWindow(blackbox->getXDisplay(), geom_window);
1945 geom_visible = False;
1950 void BScreen::addStrut(Strut *strut) {
1951 strutList.push_back(strut);
1955 void BScreen::removeStrut(Strut *strut) {
1956 strutList.remove(strut);
1960 const Rect& BScreen::availableArea(void) const {
1962 return getRect(); // return the full screen
1967 void BScreen::updateAvailableArea(void) {
1968 Rect old_area = usableArea;
1969 usableArea = getRect(); // reset to full screen
1971 /* these values represent offsets from the screen edge
1972 * we look for the biggest offset on each edge and then apply them
1974 * do not be confused by the similarity to the names of Rect's members
1976 unsigned int current_left = 0, current_right = 0, current_top = 0,
1979 StrutList::const_iterator it = strutList.begin(), end = strutList.end();
1981 for(; it != end; ++it) {
1983 if (strut->left > current_left)
1984 current_left = strut->left;
1985 if (strut->top > current_top)
1986 current_top = strut->top;
1987 if (strut->right > current_right)
1988 current_right = strut->right;
1989 if (strut->bottom > current_bottom)
1990 current_bottom = strut->bottom;
1993 usableArea.setPos(current_left, current_top);
1994 usableArea.setSize(usableArea.width() - (current_left + current_right),
1995 usableArea.height() - (current_top + current_bottom));
1997 if (old_area != usableArea) {
1998 BlackboxWindowList::iterator it = windowList.begin(),
1999 end = windowList.end();
2000 for (; it != end; ++it)
2001 if ((*it)->isMaximized()) (*it)->remaximize();
2008 Workspace* BScreen::getWorkspace(unsigned int index) {
2009 assert(index < workspacesList.size());
2010 return workspacesList[index];
2014 void BScreen::buttonPressEvent(const XButtonEvent *xbutton) {
2015 if (xbutton->button == 1) {
2016 if (! isRootColormapInstalled())
2017 image_control->installRootColormap();
2019 if (workspacemenu->isVisible())
2020 workspacemenu->hide();
2022 if (rootmenu->isVisible())
2024 } else if (xbutton->button == 2) {
2025 int mx = xbutton->x_root - (workspacemenu->getWidth() / 2);
2026 int my = xbutton->y_root - (workspacemenu->getTitleHeight() / 2);
2031 if (mx + workspacemenu->getWidth() > getWidth())
2032 mx = getWidth() - workspacemenu->getWidth() - getBorderWidth();
2034 if (my + workspacemenu->getHeight() > getHeight())
2035 my = getHeight() - workspacemenu->getHeight() - getBorderWidth();
2037 workspacemenu->move(mx, my);
2039 if (! workspacemenu->isVisible()) {
2040 workspacemenu->removeParent();
2041 workspacemenu->show();
2043 } else if (xbutton->button == 3) {
2044 int mx = xbutton->x_root - (rootmenu->getWidth() / 2);
2045 int my = xbutton->y_root - (rootmenu->getTitleHeight() / 2);
2050 if (mx + rootmenu->getWidth() > getWidth())
2051 mx = getWidth() - rootmenu->getWidth() - getBorderWidth();
2053 if (my + rootmenu->getHeight() > getHeight())
2054 my = getHeight() - rootmenu->getHeight() - getBorderWidth();
2056 rootmenu->move(mx, my);
2058 if (! rootmenu->isVisible()) {
2059 blackbox->checkMenu();
2063 } else if (xbutton->button == 4) {
2064 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2065 changeWorkspaceID(0);
2067 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2069 } else if (xbutton->button == 5) {
2070 if (getCurrentWorkspaceID() == 0)
2071 changeWorkspaceID(getWorkspaceCount() - 1);
2073 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2078 void BScreen::toggleFocusModel(FocusModel model) {
2079 std::for_each(windowList.begin(), windowList.end(),
2080 std::mem_fun(&BlackboxWindow::ungrabButtons));
2082 if (model == SloppyFocus) {
2083 saveSloppyFocus(True);
2085 // we're cheating here to save writing the config file 3 times
2086 resource.auto_raise = False;
2087 resource.click_raise = False;
2088 saveSloppyFocus(False);
2091 std::for_each(windowList.begin(), windowList.end(),
2092 std::mem_fun(&BlackboxWindow::grabButtons));
2096 BTexture BScreen::readDatabaseTexture(const string &rname,
2097 const string &default_color,
2098 const Configuration &style) {
2102 if (style.getValue(rname, s))
2103 texture = BTexture(s);
2105 texture.setTexture(BTexture::Solid | BTexture::Flat);
2107 // associate this texture with this screen
2108 texture.setDisplay(getBaseDisplay(), getScreenNumber());
2109 texture.setImageControl(image_control);
2111 if (texture.texture() & BTexture::Solid) {
2112 texture.setColor(readDatabaseColor(rname + ".color",
2113 default_color, style));
2114 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2115 default_color, style));
2116 } else if (texture.texture() & BTexture::Gradient) {
2117 texture.setColor(readDatabaseColor(rname + ".color",
2118 default_color, style));
2119 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2120 default_color, style));
2127 BColor BScreen::readDatabaseColor(const string &rname,
2128 const string &default_color,
2129 const Configuration &style) {
2132 if (style.getValue(rname, s))
2133 color = BColor(s, getBaseDisplay(), getScreenNumber());
2135 color = BColor(default_color, getBaseDisplay(), getScreenNumber());
2140 BFont *BScreen::readDatabaseFont(const string &rbasename,
2141 const Configuration &style) {
2148 if (style.getValue(rbasename + "xft.font", s) &&
2149 style.getValue(rbasename + "xft.size", i)) {
2152 bool italic = False;
2153 if (style.getValue(rbasename + "xft.flags", s)) {
2154 if (s.find("bold") != string::npos)
2156 if (s.find("italic") != string::npos)
2160 BFont *b = new BFont(blackbox->getXDisplay(), this, family, i, bold,
2165 delete b; // fall back to the normal X font stuff
2169 style.getValue(rbasename + "font", s);
2170 // if this fails, a blank string will be used, which will cause the fallback
2173 BFont *b = new BFont(blackbox->getXDisplay(), this, s);
2175 exit(2); // can't continue without a font