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>
37 #endif // HAVE_STDLIB_H
41 #endif // HAVE_STRING_H
45 #endif // HAVE_CTYPE_H
48 # include <sys/types.h>
50 #endif // HAVE_UNISTD_H
54 #endif // HAVE_DIRENT_H
58 #endif // HAVE_LOCALE_H
60 #ifdef HAVE_SYS_STAT_H
61 # include <sys/stat.h>
62 #endif // HAVE_SYS_STAT_H
66 #endif // HAVE_STDARG_H
77 #include "blackbox.hh"
78 #include "Clientmenu.hh"
80 #include "Iconmenu.hh"
84 #include "Rootmenu.hh"
88 #include "Workspace.hh"
89 #include "Workspacemenu.hh"
92 #ifndef FONT_ELEMENT_SIZE
93 #define FONT_ELEMENT_SIZE 50
94 #endif // FONT_ELEMENT_SIZE
97 static bool running = True;
99 static int anotherWMRunning(Display *display, XErrorEvent *) {
100 fprintf(stderr, i18n(ScreenSet, ScreenAnotherWMRunning,
101 "BScreen::BScreen: an error occured while querying the X server.\n"
102 " another window manager already running on display %s.\n"),
103 DisplayString(display));
111 BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
113 screenstr = (string)"session.screen" + itostring(scrn) + '.';
114 config = blackbox->getConfig();
115 xatom = blackbox->getXAtom();
117 event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
118 SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask;
120 XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
121 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask);
122 XSync(getBaseDisplay()->getXDisplay(), False);
123 XSetErrorHandler((XErrorHandler) old);
126 if (! managed) return;
128 fprintf(stderr, i18n(ScreenSet, ScreenManagingScreen,
129 "BScreen::BScreen: managing screen %d "
130 "using visual 0x%lx, depth %d\n"),
131 getScreenNumber(), XVisualIDFromVisual(getVisual()),
136 resource.mstyle.t_fontset = resource.mstyle.f_fontset =
137 resource.tstyle.fontset = resource.wstyle.fontset = (XFontSet) 0;
138 resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
139 resource.wstyle.font = (XFontStruct *) 0;
141 xatom->setSupported(this); // set-up netwm support
143 xatom->setValue(getRootWindow(), XAtom::blackbox_pid, XAtom::cardinal,
144 (unsigned long) getpid());
145 #endif // HAVE_GETPID
146 unsigned long geometry[] = { getWidth(),
148 xatom->setValue(getRootWindow(), XAtom::net_desktop_geometry,
149 XAtom::cardinal, geometry, 2);
150 unsigned long viewport[] = {0,0};
151 xatom->setValue(getRootWindow(), XAtom::net_desktop_viewport,
152 XAtom::cardinal, viewport, 2);
155 XDefineCursor(blackbox->getXDisplay(), getRootWindow(),
156 blackbox->getSessionCursor());
158 // start off full screen, top left.
159 usableArea.setSize(getWidth(), getHeight());
162 new BImageControl(blackbox, this, True, blackbox->getColorsPerChannel(),
163 blackbox->getCacheLife(), blackbox->getCacheMax());
164 image_control->installRootColormap();
165 root_colormap_installed = True;
171 unsigned long gc_value_mask = GCForeground;
172 if (! i18n.multibyte()) gc_value_mask |= GCFont;
174 gcv.foreground = WhitePixel(blackbox->getXDisplay(), getScreenNumber())
175 ^ BlackPixel(blackbox->getXDisplay(), getScreenNumber());
176 gcv.function = GXxor;
177 gcv.subwindow_mode = IncludeInferiors;
178 opGC = XCreateGC(blackbox->getXDisplay(), getRootWindow(),
179 GCForeground | GCFunction | GCSubwindowMode, &gcv);
181 const char *s = i18n(ScreenSet, ScreenPositionLength,
182 "0: 0000 x 0: 0000");
185 if (i18n.multibyte()) {
186 XRectangle ink, logical;
187 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
188 geom_w = logical.width;
190 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
192 geom_h = resource.wstyle.font->ascent +
193 resource.wstyle.font->descent;
195 geom_w = XTextWidth(resource.wstyle.font, s, l);
198 geom_w += (resource.bevel_width * 2);
199 geom_h += (resource.bevel_width * 2);
201 XSetWindowAttributes attrib;
202 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
203 attrib.border_pixel = getBorderColor()->pixel();
204 attrib.colormap = getColormap();
205 attrib.save_under = True;
207 geom_window = XCreateWindow(blackbox->getXDisplay(), getRootWindow(),
208 0, 0, geom_w, geom_h, resource.border_width,
209 getDepth(), InputOutput, getVisual(),
211 geom_visible = False;
213 BTexture* texture = &(resource.wstyle.l_focus);
214 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
215 if (geom_pixmap == ParentRelative) {
216 texture = &(resource.wstyle.t_focus);
217 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
220 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
221 texture->color().pixel());
223 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
224 geom_window, geom_pixmap);
226 workspacemenu = new Workspacemenu(this);
227 iconmenu = new Iconmenu(this);
228 configmenu = new Configmenu(this);
230 Workspace *wkspc = (Workspace *) 0;
231 if (resource.workspaces != 0) {
232 for (unsigned int i = 0; i < resource.workspaces; ++i) {
233 wkspc = new Workspace(this, workspacesList.size());
234 workspacesList.push_back(wkspc);
235 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
238 wkspc = new Workspace(this, workspacesList.size());
239 workspacesList.push_back(wkspc);
240 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
242 saveWorkspaceNames();
244 updateNetizenWorkspaceCount();
246 workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
247 workspacemenu->update();
249 current_workspace = workspacesList.front();
251 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
252 XAtom::cardinal, 0); //first workspace
254 workspacemenu->setItemSelected(2, True);
256 toolbar = new Toolbar(this);
258 slit = new Slit(this);
262 raiseWindows(0, 0); // this also initializes the empty stacking list
265 updateClientList(); // initialize the client list, which will be empty
266 updateAvailableArea();
268 changeWorkspaceID(0);
270 unsigned int i, j, nchild;
271 Window r, p, *children;
272 XQueryTree(blackbox->getXDisplay(), getRootWindow(), &r, &p,
275 // preen the window list of all icon windows... for better dockapp support
276 for (i = 0; i < nchild; i++) {
277 if (children[i] == None) continue;
279 XWMHints *wmhints = XGetWMHints(blackbox->getXDisplay(),
283 if ((wmhints->flags & IconWindowHint) &&
284 (wmhints->icon_window != children[i])) {
285 for (j = 0; j < nchild; j++) {
286 if (children[j] == wmhints->icon_window) {
297 // manage shown windows
298 for (i = 0; i < nchild; ++i) {
299 if (children[i] == None || (! blackbox->validateWindow(children[i])))
302 XWindowAttributes attrib;
303 if (XGetWindowAttributes(blackbox->getXDisplay(), children[i], &attrib)) {
304 if (attrib.override_redirect) continue;
306 if (attrib.map_state != IsUnmapped) {
307 manageWindow(children[i]);
314 // call this again just in case a window we found updates the Strut list
315 updateAvailableArea();
319 BScreen::~BScreen(void) {
320 if (! managed) return;
322 if (geom_pixmap != None)
323 image_control->removeImage(geom_pixmap);
325 if (geom_window != None)
326 XDestroyWindow(blackbox->getXDisplay(), geom_window);
328 std::for_each(workspacesList.begin(), workspacesList.end(),
331 std::for_each(iconList.begin(), iconList.end(), PointerAssassin());
333 std::for_each(netizenList.begin(), netizenList.end(), PointerAssassin());
336 delete workspacemenu;
341 delete image_control;
343 if (resource.wstyle.fontset)
344 XFreeFontSet(blackbox->getXDisplay(), resource.wstyle.fontset);
345 if (resource.mstyle.t_fontset)
346 XFreeFontSet(blackbox->getXDisplay(), resource.mstyle.t_fontset);
347 if (resource.mstyle.f_fontset)
348 XFreeFontSet(blackbox->getXDisplay(), resource.mstyle.f_fontset);
349 if (resource.tstyle.fontset)
350 XFreeFontSet(blackbox->getXDisplay(), resource.tstyle.fontset);
352 if (resource.wstyle.font)
353 XFreeFont(blackbox->getXDisplay(), resource.wstyle.font);
354 if (resource.mstyle.t_font)
355 XFreeFont(blackbox->getXDisplay(), resource.mstyle.t_font);
356 if (resource.mstyle.f_font)
357 XFreeFont(blackbox->getXDisplay(), resource.mstyle.f_font);
358 if (resource.tstyle.font)
359 XFreeFont(blackbox->getXDisplay(), resource.tstyle.font);
361 XFreeGC(blackbox->getXDisplay(), opGC);
365 void BScreen::saveSloppyFocus(bool s) {
366 resource.sloppy_focus = s;
369 if (resource.sloppy_focus) {
370 fmodel = "SloppyFocus";
371 if (resource.auto_raise) fmodel += " AutoRaise";
372 if (resource.click_raise) fmodel += " ClickRaise";
374 fmodel = "ClickToFocus";
376 config->setValue(screenstr + "focusModel", fmodel);
380 void BScreen::saveAutoRaise(bool a) {
381 resource.auto_raise = a;
382 saveSloppyFocus(resource.sloppy_focus);
386 void BScreen::saveClickRaise(bool c) {
387 resource.click_raise = c;
388 saveSloppyFocus(resource.sloppy_focus);
392 void BScreen::saveImageDither(bool d) {
393 image_control->setDither(d);
394 config->setValue(screenstr + "imageDither", doImageDither());
398 void BScreen::saveOpaqueMove(bool o) {
399 resource.opaque_move = o;
400 config->setValue(screenstr + "opaqueMove", resource.opaque_move);
404 void BScreen::saveFullMax(bool f) {
405 resource.full_max = f;
406 config->setValue(screenstr + "fullMaximization", resource.full_max);
410 void BScreen::saveFocusNew(bool f) {
411 resource.focus_new = f;
412 config->setValue(screenstr + "focusNewWindows", resource.focus_new);
416 void BScreen::saveFocusLast(bool f) {
417 resource.focus_last = f;
418 config->setValue(screenstr + "focusLastWindow", resource.focus_last);
422 void BScreen::saveHideToolbar(bool h) {
423 resource.hide_toolbar = h;
424 if (resource.hide_toolbar)
425 toolbar->unmapToolbar();
427 toolbar->mapToolbar();
428 config->setValue(screenstr + "hideToolbar", resource.hide_toolbar);
432 void BScreen::saveWindowToWindowSnap(bool s) {
433 resource.window_to_window_snap = s;
434 config->setValue(screenstr + "windowToWindowSnap",
435 resource.window_to_window_snap);
439 void BScreen::saveWindowCornerSnap(bool s) {
440 resource.window_corner_snap = s;
441 config->setValue(screenstr + "windowCornerSnap",
442 resource.window_corner_snap);
446 void BScreen::saveWorkspaces(unsigned int w) {
447 resource.workspaces = w;
448 config->setValue(screenstr + "workspaces", resource.workspaces);
452 void BScreen::savePlacementPolicy(int p) {
453 resource.placement_policy = p;
454 const char *placement;
455 switch (resource.placement_policy) {
456 case CascadePlacement: placement = "CascadePlacement"; break;
457 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
458 case RowSmartPlacement: default: placement = "RowSmartPlacement"; break;
460 config->setValue(screenstr + "windowPlacement", placement);
464 void BScreen::saveEdgeSnapThreshold(int t) {
465 resource.edge_snap_threshold = t;
466 config->setValue(screenstr + "edgeSnapThreshold",
467 resource.edge_snap_threshold);
471 void BScreen::saveRowPlacementDirection(int d) {
472 resource.row_direction = d;
473 config->setValue(screenstr + "rowPlacementDirection",
474 resource.row_direction == LeftRight ?
475 "LeftToRight" : "RightToLeft");
479 void BScreen::saveColPlacementDirection(int d) {
480 resource.col_direction = d;
481 config->setValue(screenstr + "colPlacementDirection",
482 resource.col_direction == TopBottom ?
483 "TopToBottom" : "BottomToTop");
488 void BScreen::saveStrftimeFormat(const std::string& format) {
489 resource.strftime_format = format;
490 config->setValue(screenstr + "strftimeFormat", resource.strftime_format);
493 #else // !HAVE_STRFTIME
495 void BScreen::saveDateFormat(int f) {
496 resource.date_format = f;
497 config->setValue(screenstr + "dateFormat",
498 resource.date_format == B_EuropeanDate ?
499 "European" : "American");
503 void BScreen::saveClock24Hour(Bool c) {
504 resource.clock24hour = c;
505 config->setValue(screenstr + "clockFormat", resource.clock24hour ? 24 : 12);
507 #endif // HAVE_STRFTIME
510 void BScreen::saveWorkspaceNames() {
511 XAtom::StringVect nameList;
512 unsigned long numnames = (unsigned) -1;
516 xatom->getValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
517 numnames, nameList)) {
518 for (unsigned int i = 0; i < nameList.size(); ++i) {
519 if (i > 0) names += ",";
520 names += nameList[i];
523 config->setValue(screenstr + "workspaceNames", names);
527 void BScreen::save_rc(void) {
528 saveSloppyFocus(resource.sloppy_focus);
529 saveAutoRaise(resource.auto_raise);
530 saveImageDither(doImageDither());
531 saveOpaqueMove(resource.opaque_move);
532 saveFullMax(resource.full_max);
533 saveFocusNew(resource.focus_new);
534 saveFocusLast(resource.focus_last);
535 saveHideToolbar(resource.hide_toolbar);
536 saveWindowToWindowSnap(resource.window_to_window_snap);
537 saveWindowCornerSnap(resource.window_corner_snap);
538 saveWorkspaces(resource.workspaces);
539 savePlacementPolicy(resource.placement_policy);
540 saveEdgeSnapThreshold(resource.edge_snap_threshold);
541 saveRowPlacementDirection(resource.row_direction);
542 saveColPlacementDirection(resource.col_direction);
544 saveStrftimeFormat(resource.strftime_format);
545 #else // !HAVE_STRFTIME
546 saveDateFormat(resource.date_format);
547 savwClock24Hour(resource.clock24hour);
548 #endif // HAVE_STRFTIME
555 void BScreen::load_rc(void) {
559 if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
560 resource.full_max = false;
562 if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
563 resource.focus_new = false;
565 if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
566 resource.focus_last = false;
568 if (! config->getValue(screenstr + "workspaces", resource.workspaces))
569 resource.workspaces = 1;
571 if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
572 resource.opaque_move = false;
574 if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
575 resource.hide_toolbar = false;
577 if (! config->getValue(screenstr + "windowToWindowSnap",
578 resource.window_to_window_snap))
579 resource.window_to_window_snap = true;
581 if (! config->getValue(screenstr + "windowCornerSnap",
582 resource.window_corner_snap))
583 resource.window_corner_snap = true;
585 if (! config->getValue(screenstr + "imageDither", b))
587 image_control->setDither(b);
589 if (! config->getValue(screenstr + "edgeSnapThreshold",
590 resource.edge_snap_threshold))
591 resource.edge_snap_threshold = 4;
593 if (config->getValue(screenstr + "rowPlacementDirection", s) &&
595 resource.row_direction = RightLeft;
597 resource.row_direction = LeftRight;
599 if (config->getValue(screenstr + "colPlacementDirection", s) &&
601 resource.col_direction = BottomTop;
603 resource.col_direction = TopBottom;
605 XAtom::StringVect workspaceNames;
606 if (config->getValue(screenstr + "workspaceNames", s)) {
607 string::const_iterator it = s.begin(), end = s.end();
609 string::const_iterator tmp = it; // current string.begin()
610 it = std::find(tmp, end, ','); // look for comma between tmp and end
611 workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
617 xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
620 resource.sloppy_focus = true;
621 resource.auto_raise = false;
622 resource.click_raise = false;
623 if (config->getValue(screenstr + "focusModel", s)) {
624 if (s.find("ClickToFocus") != string::npos) {
625 resource.sloppy_focus = false;
628 if (s.find("AutoRaise") != string::npos)
629 resource.auto_raise = true;
630 if (s.find("ClickRaise") != string::npos)
631 resource.click_raise = true;
635 if (config->getValue(screenstr + "windowPlacement", s)) {
636 if (s == "CascadePlacement")
637 resource.placement_policy = CascadePlacement;
638 else if (s == "ColSmartPlacement")
639 resource.placement_policy = ColSmartPlacement;
640 else //if (s == "RowSmartPlacement")
641 resource.placement_policy = RowSmartPlacement;
643 resource.placement_policy = RowSmartPlacement;
646 if (config->getValue(screenstr + "strftimeFormat", s))
647 resource.strftime_format = s;
649 resource.strftime_format = "%I:%M %p";
650 #else // !HAVE_STRFTIME
653 if (config->getValue(screenstr + "dateFormat", s) && s == "European")
654 resource.date_format = B_EuropeanDate;
656 resource.date_format = B_AmericanDate;
658 if (! config->getValue(screenstr + "clockFormat", l))
660 resource.clock24hour = l == 24;
661 #endif // HAVE_STRFTIME
665 void BScreen::reconfigure(void) {
672 unsigned long gc_value_mask = GCForeground;
673 if (! i18n.multibyte()) gc_value_mask |= GCFont;
675 gcv.foreground = WhitePixel(blackbox->getXDisplay(),
677 gcv.function = GXinvert;
678 gcv.subwindow_mode = IncludeInferiors;
679 XChangeGC(blackbox->getXDisplay(), opGC,
680 GCForeground | GCFunction | GCSubwindowMode, &gcv);
682 const char *s = i18n(ScreenSet, ScreenPositionLength,
683 "0: 0000 x 0: 0000");
686 if (i18n.multibyte()) {
687 XRectangle ink, logical;
688 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
689 geom_w = logical.width;
691 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
693 geom_w = XTextWidth(resource.wstyle.font, s, l);
695 geom_h = resource.wstyle.font->ascent + resource.wstyle.font->descent;
698 geom_w += (resource.bevel_width * 2);
699 geom_h += (resource.bevel_width * 2);
701 BTexture* texture = &(resource.wstyle.l_focus);
702 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
703 if (geom_pixmap == ParentRelative) {
704 texture = &(resource.wstyle.t_focus);
705 geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
708 XSetWindowBackground(blackbox->getXDisplay(), geom_window,
709 texture->color().pixel());
711 XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
712 geom_window, geom_pixmap);
714 XSetWindowBorderWidth(blackbox->getXDisplay(), geom_window,
715 resource.border_width);
716 XSetWindowBorder(blackbox->getXDisplay(), geom_window,
717 resource.border_color.pixel());
719 workspacemenu->reconfigure();
720 iconmenu->reconfigure();
722 typedef std::vector<int> SubList;
723 SubList remember_subs;
725 // save the current open menus
726 Basemenu *menu = rootmenu;
728 while ((submenu = menu->getCurrentSubmenu()) >= 0) {
729 remember_subs.push_back(submenu);
730 menu = menu->find(submenu)->submenu();
736 rootmenu->reconfigure();
738 // reopen the saved menus
740 const SubList::iterator subs_end = remember_subs.end();
741 for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
742 menu->drawSubmenu(*it);
743 menu = menu->find(*it)->submenu();
748 configmenu->reconfigure();
750 toolbar->reconfigure();
754 std::for_each(workspacesList.begin(), workspacesList.end(),
755 std::mem_fun(&Workspace::reconfigure));
757 BlackboxWindowList::iterator iit = iconList.begin();
758 for (; iit != iconList.end(); ++iit) {
759 BlackboxWindow *bw = *iit;
760 if (bw->validateClient())
764 image_control->timeout();
768 void BScreen::rereadMenu(void) {
772 rootmenu->reconfigure();
776 void BScreen::LoadStyle(void) {
779 const char *sfile = blackbox->getStyleFilename();
781 style.setFile(sfile);
782 if (! style.load()) {
783 style.setFile(DEFAULTSTYLE);
785 style.create(); // hardcoded default values will be used.
791 // load fonts/fontsets
792 if (resource.wstyle.fontset)
793 XFreeFontSet(blackbox->getXDisplay(), resource.wstyle.fontset);
794 if (resource.tstyle.fontset)
795 XFreeFontSet(blackbox->getXDisplay(), resource.tstyle.fontset);
796 if (resource.mstyle.f_fontset)
797 XFreeFontSet(blackbox->getXDisplay(), resource.mstyle.f_fontset);
798 if (resource.mstyle.t_fontset)
799 XFreeFontSet(blackbox->getXDisplay(), resource.mstyle.t_fontset);
800 resource.wstyle.fontset = 0;
801 resource.tstyle.fontset = 0;
802 resource.mstyle.f_fontset = 0;
803 resource.mstyle.t_fontset = 0;
804 if (resource.wstyle.font)
805 XFreeFont(blackbox->getXDisplay(), resource.wstyle.font);
806 if (resource.tstyle.font)
807 XFreeFont(blackbox->getXDisplay(), resource.tstyle.font);
808 if (resource.mstyle.f_font)
809 XFreeFont(blackbox->getXDisplay(), resource.mstyle.f_font);
810 if (resource.mstyle.t_font)
811 XFreeFont(blackbox->getXDisplay(), resource.mstyle.t_font);
812 resource.wstyle.font = 0;
813 resource.tstyle.font = 0;
814 resource.mstyle.f_font = 0;
815 resource.mstyle.t_font = 0;
817 if (i18n.multibyte()) {
818 resource.wstyle.fontset = readDatabaseFontSet("window.font", style);
819 resource.tstyle.fontset = readDatabaseFontSet("toolbar.font", style);
820 resource.mstyle.t_fontset = readDatabaseFontSet("menu.title.font", style);
821 resource.mstyle.f_fontset = readDatabaseFontSet("menu.frame.font", style);
823 resource.mstyle.t_fontset_extents =
824 XExtentsOfFontSet(resource.mstyle.t_fontset);
825 resource.mstyle.f_fontset_extents =
826 XExtentsOfFontSet(resource.mstyle.f_fontset);
827 resource.tstyle.fontset_extents =
828 XExtentsOfFontSet(resource.tstyle.fontset);
829 resource.wstyle.fontset_extents =
830 XExtentsOfFontSet(resource.wstyle.fontset);
832 resource.wstyle.font = readDatabaseFont("window.font", style);
833 resource.tstyle.font = readDatabaseFont("toolbar.font", style);
834 resource.mstyle.t_font = readDatabaseFont("menu.title.font", style);
835 resource.mstyle.f_font = readDatabaseFont("menu.frame.font", style);
838 // load window config
839 resource.wstyle.t_focus =
840 readDatabaseTexture("window.title.focus", "white", style);
841 resource.wstyle.t_unfocus =
842 readDatabaseTexture("window.title.unfocus", "black", style);
843 resource.wstyle.l_focus =
844 readDatabaseTexture("window.label.focus", "white", style);
845 resource.wstyle.l_unfocus =
846 readDatabaseTexture("window.label.unfocus", "black", style);
847 resource.wstyle.h_focus =
848 readDatabaseTexture("window.handle.focus", "white", style);
849 resource.wstyle.h_unfocus =
850 readDatabaseTexture("window.handle.unfocus", "black", style);
851 resource.wstyle.g_focus =
852 readDatabaseTexture("window.grip.focus", "white", style);
853 resource.wstyle.g_unfocus =
854 readDatabaseTexture("window.grip.unfocus", "black", style);
855 resource.wstyle.b_focus =
856 readDatabaseTexture("window.button.focus", "white", style);
857 resource.wstyle.b_unfocus =
858 readDatabaseTexture("window.button.unfocus", "black", style);
859 resource.wstyle.b_pressed =
860 readDatabaseTexture("window.button.pressed", "black", style);
861 resource.wstyle.f_focus =
862 readDatabaseColor("window.frame.focusColor", "white", style);
863 resource.wstyle.f_unfocus =
864 readDatabaseColor("window.frame.unfocusColor", "black", style);
865 resource.wstyle.l_text_focus =
866 readDatabaseColor("window.label.focus.textColor", "black", style);
867 resource.wstyle.l_text_unfocus =
868 readDatabaseColor("window.label.unfocus.textColor", "white", style);
869 resource.wstyle.b_pic_focus =
870 readDatabaseColor("window.button.focus.picColor", "black", style);
871 resource.wstyle.b_pic_unfocus =
872 readDatabaseColor("window.button.unfocus.picColor", "white", style);
874 resource.wstyle.justify = LeftJustify;
875 if (style.getValue("window.justify", s)) {
876 if (s == "right" || s == "Right")
877 resource.wstyle.justify = RightJustify;
878 else if (s == "center" || s == "Center")
879 resource.wstyle.justify = CenterJustify;
882 // load toolbar config
883 resource.tstyle.toolbar =
884 readDatabaseTexture("toolbar", "black", style);
885 resource.tstyle.label =
886 readDatabaseTexture("toolbar.label", "black", style);
887 resource.tstyle.window =
888 readDatabaseTexture("toolbar.windowLabel", "black", style);
889 resource.tstyle.button =
890 readDatabaseTexture("toolbar.button", "white", style);
891 resource.tstyle.pressed =
892 readDatabaseTexture("toolbar.button.pressed", "black", style);
893 resource.tstyle.clock =
894 readDatabaseTexture("toolbar.clock", "black", style);
895 resource.tstyle.l_text =
896 readDatabaseColor("toolbar.label.textColor", "white", style);
897 resource.tstyle.w_text =
898 readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
899 resource.tstyle.c_text =
900 readDatabaseColor("toolbar.clock.textColor", "white", style);
901 resource.tstyle.b_pic =
902 readDatabaseColor("toolbar.button.picColor", "black", style);
904 resource.tstyle.justify = LeftJustify;
905 if (style.getValue("toolbar.justify", s)) {
906 if (s == "right" || s == "Right")
907 resource.tstyle.justify = RightJustify;
908 else if (s == "center" || s == "Center")
909 resource.tstyle.justify = CenterJustify;
913 resource.mstyle.title =
914 readDatabaseTexture("menu.title", "white", style);
915 resource.mstyle.frame =
916 readDatabaseTexture("menu.frame", "black", style);
917 resource.mstyle.hilite =
918 readDatabaseTexture("menu.hilite", "white", style);
919 resource.mstyle.t_text =
920 readDatabaseColor("menu.title.textColor", "black", style);
921 resource.mstyle.f_text =
922 readDatabaseColor("menu.frame.textColor", "white", style);
923 resource.mstyle.d_text =
924 readDatabaseColor("menu.frame.disableColor", "black", style);
925 resource.mstyle.h_text =
926 readDatabaseColor("menu.hilite.textColor", "black", style);
928 resource.mstyle.t_justify = LeftJustify;
929 if (style.getValue("menu.title.justify", s)) {
930 if (s == "right" || s == "Right")
931 resource.mstyle.t_justify = RightJustify;
932 else if (s == "center" || s == "Center")
933 resource.mstyle.t_justify = CenterJustify;
936 resource.mstyle.f_justify = LeftJustify;
937 if (style.getValue("menu.frame.justify", s)) {
938 if (s == "right" || s == "Right")
939 resource.mstyle.f_justify = RightJustify;
940 else if (s == "center" || s == "Center")
941 resource.mstyle.f_justify = CenterJustify;
944 resource.mstyle.bullet = Basemenu::Triangle;
945 if (style.getValue("menu.bullet", s)) {
946 if (s == "empty" || s == "Empty")
947 resource.mstyle.bullet = Basemenu::Empty;
948 else if (s == "square" || s == "Square")
949 resource.mstyle.bullet = Basemenu::Square;
950 else if (s == "diamond" || s == "Diamond")
951 resource.mstyle.bullet = Basemenu::Diamond;
954 resource.mstyle.bullet_pos = Basemenu::Left;
955 if (style.getValue("menu.bullet.position", s)) {
956 if (s == "right" || s == "Right")
957 resource.mstyle.bullet_pos = Basemenu::Right;
960 resource.border_color =
961 readDatabaseColor("borderColor", "black", style);
963 // load bevel, border and handle widths
964 if (! style.getValue("handleWidth", resource.handle_width) ||
965 resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
966 resource.handle_width = 6;
968 if (! style.getValue("borderWidth", resource.border_width))
969 resource.border_width = 1;
971 if (! style.getValue("bevelWidth", resource.bevel_width) ||
972 resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
973 resource.bevel_width = 3;
975 if (! style.getValue("frameWidth", resource.frame_width) ||
976 resource.frame_width > (getWidth() / 2))
977 resource.frame_width = resource.bevel_width;
979 if (style.getValue("rootCommand", s))
980 bexec(s, displayString());
984 void BScreen::addIcon(BlackboxWindow *w) {
987 w->setWorkspace(BSENTINEL);
988 w->setWindowNumber(iconList.size());
990 iconList.push_back(w);
992 const char* title = w->getIconTitle();
993 iconmenu->insert(title);
998 void BScreen::removeIcon(BlackboxWindow *w) {
1003 iconmenu->remove(w->getWindowNumber());
1006 BlackboxWindowList::iterator it = iconList.begin(),
1007 end = iconList.end();
1008 for (int i = 0; it != end; ++it)
1009 (*it)->setWindowNumber(i++);
1013 BlackboxWindow *BScreen::getIcon(unsigned int index) {
1014 if (index < iconList.size()) {
1015 BlackboxWindowList::iterator it = iconList.begin();
1016 for (; index > 0; --index, ++it) ; /* increment to index */
1020 return (BlackboxWindow *) 0;
1024 unsigned int BScreen::addWorkspace(void) {
1025 Workspace *wkspc = new Workspace(this, workspacesList.size());
1026 workspacesList.push_back(wkspc);
1027 saveWorkspaces(getWorkspaceCount());
1029 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
1030 wkspc->getID() + 2);
1031 workspacemenu->update();
1033 toolbar->reconfigure();
1035 updateNetizenWorkspaceCount();
1037 return workspacesList.size();
1041 unsigned int BScreen::removeLastWorkspace(void) {
1042 if (workspacesList.size() == 1)
1045 Workspace *wkspc = workspacesList.back();
1047 if (current_workspace->getID() == wkspc->getID())
1048 changeWorkspaceID(current_workspace->getID() - 1);
1052 workspacemenu->remove(wkspc->getID() + 2);
1053 workspacemenu->update();
1055 workspacesList.pop_back();
1058 saveWorkspaces(getWorkspaceCount());
1060 toolbar->reconfigure();
1062 updateNetizenWorkspaceCount();
1064 return workspacesList.size();
1068 void BScreen::changeWorkspaceID(unsigned int id) {
1069 if (! current_workspace) return;
1071 if (id != current_workspace->getID()) {
1072 BlackboxWindow *focused = blackbox->getFocusedWindow();
1073 if (focused && focused->getScreen() == this && ! focused->isStuck()) {
1074 if (focused->getWorkspaceNumber() != current_workspace->getID()) {
1075 fprintf(stderr, "%s is on the wrong workspace, aborting\n",
1076 focused->getTitle());
1079 current_workspace->setLastFocusedWindow(focused);
1081 // if no window had focus, no need to store a last focus
1082 current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
1084 // when we switch workspaces, unfocus whatever was focused
1085 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1087 current_workspace->hideAll();
1088 workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1090 current_workspace = getWorkspace(id);
1092 xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
1093 XAtom::cardinal, id);
1095 workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1096 toolbar->redrawWorkspaceLabel(True);
1098 current_workspace->showAll();
1100 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1101 XSync(blackbox->getXDisplay(), False);
1102 current_workspace->getLastFocusedWindow()->setInputFocus();
1106 updateNetizenCurrentWorkspace();
1111 * Set the _NET_CLIENT_LIST root window property.
1113 void BScreen::updateClientList(void) {
1114 if (windowList.size() > 0) {
1115 Window *windows = new Window[windowList.size()];
1116 Window *win_it = windows;
1117 BlackboxWindowList::iterator it = windowList.begin();
1118 const BlackboxWindowList::iterator end = windowList.end();
1119 for (; it != end; ++it, ++win_it)
1120 *win_it = (*it)->getClientWindow();
1121 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1122 windows, windowList.size());
1125 xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
1131 * Set the _NET_CLIENT_LIST_STACKING root window property.
1133 void BScreen::updateStackingList(void) {
1135 BlackboxWindowList stack_order;
1138 * Get the atacking order from all of the workspaces.
1139 * We start with the current workspace so that the sticky windows will be
1140 * in the right order on the current workspace.
1141 * XXX: Do we need to have sticky windows in the list once for each workspace?
1143 getCurrentWorkspace()->appendStackOrder(stack_order);
1144 for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
1145 if (i != getCurrentWorkspaceID())
1146 getWorkspace(i)->appendStackOrder(stack_order);
1148 if (stack_order.size() > 0) {
1149 // set the client list atoms
1150 Window *windows = new Window[stack_order.size()];
1151 Window *win_it = windows;
1152 BlackboxWindowList::iterator it = stack_order.begin();
1153 const BlackboxWindowList::iterator end = stack_order.end();
1154 for (; it != end; ++it, ++win_it)
1155 *win_it = (*it)->getClientWindow();
1156 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1157 XAtom::window, windows, stack_order.size());
1160 xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
1161 XAtom::window, 0, 0);
1165 void BScreen::addSystrayWindow(Window window) {
1166 systrayWindowList.push_back(window);
1167 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1169 &systrayWindowList[0], systrayWindowList.size());
1170 blackbox->saveSystrayWindowSearch(window, this);
1174 void BScreen::removeSystrayWindow(Window window) {
1175 WindowList::iterator it = systrayWindowList.begin();
1176 const WindowList::iterator end = systrayWindowList.end();
1177 for (; it != end; ++it)
1178 if (*it == window) {
1179 systrayWindowList.erase(it);
1180 xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
1182 &systrayWindowList[0], systrayWindowList.size());
1183 blackbox->removeSystrayWindowSearch(window);
1189 void BScreen::addDesktopWindow(Window window) {
1190 desktopWindowList.push_back(window);
1191 XLowerWindow(blackbox->getXDisplay(), window);
1192 XSelectInput(blackbox->getXDisplay(), window, StructureNotifyMask);
1193 blackbox->saveDesktopWindowSearch(window, this);
1197 void BScreen::removeDesktopWindow(Window window) {
1198 WindowList::iterator it = desktopWindowList.begin();
1199 const WindowList::iterator end = desktopWindowList.end();
1200 for (; it != end; ++it)
1201 if (*it == window) {
1202 desktopWindowList.erase(it);
1203 XSelectInput(blackbox->getXDisplay(), window, None);
1204 blackbox->removeDesktopWindowSearch(window);
1210 void BScreen::manageWindow(Window w) {
1211 new BlackboxWindow(blackbox, w, this);
1213 BlackboxWindow *win = blackbox->searchWindow(w);
1216 if (win->isDesktop()) {
1217 // desktop windows cant do anything, so we remove all the normal window
1218 // stuff from them, they are only kept around so that we can keep them on
1219 // the bottom of the z-order
1221 addDesktopWindow(win->getClientWindow());
1226 windowList.push_back(win);
1229 XMapRequestEvent mre;
1231 if (blackbox->isStartup()) win->restoreAttributes();
1232 win->mapRequestEvent(&mre);
1236 void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
1239 if (w->getWorkspaceNumber() != BSENTINEL &&
1240 w->getWindowNumber() != BSENTINEL)
1241 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1242 else if (w->isIconic())
1245 windowList.remove(w);
1248 if (blackbox->getFocusedWindow() == w)
1249 blackbox->setFocusedWindow((BlackboxWindow *) 0);
1251 removeNetizen(w->getClientWindow());
1254 some managed windows can also be window group controllers. when
1255 unmanaging such windows, we should also delete the window group.
1257 BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
1264 void BScreen::addNetizen(Netizen *n) {
1265 netizenList.push_back(n);
1267 n->sendWorkspaceCount();
1268 n->sendCurrentWorkspace();
1270 WorkspaceList::iterator it = workspacesList.begin();
1271 const WorkspaceList::iterator end = workspacesList.end();
1272 for (; it != end; ++it)
1273 (*it)->sendWindowList(*n);
1275 Window f = ((blackbox->getFocusedWindow()) ?
1276 blackbox->getFocusedWindow()->getClientWindow() : None);
1277 n->sendWindowFocus(f);
1281 void BScreen::removeNetizen(Window w) {
1282 NetizenList::iterator it = netizenList.begin();
1283 for (; it != netizenList.end(); ++it) {
1284 if ((*it)->getWindowID() == w) {
1286 netizenList.erase(it);
1293 void BScreen::updateWorkArea(void) {
1294 if (workspacesList.size() > 0) {
1295 unsigned long *dims = new unsigned long[4 * workspacesList.size()];
1296 for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
1297 // XXX: this could be different for each workspace
1298 const Rect &area = availableArea();
1299 dims[(i * 4) + 0] = area.x();
1300 dims[(i * 4) + 1] = area.y();
1301 dims[(i * 4) + 2] = area.width();
1302 dims[(i * 4) + 3] = area.height();
1304 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1305 dims, 4 * workspacesList.size());
1308 xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
1313 void BScreen::updateNetizenCurrentWorkspace(void) {
1314 std::for_each(netizenList.begin(), netizenList.end(),
1315 std::mem_fun(&Netizen::sendCurrentWorkspace));
1319 void BScreen::updateNetizenWorkspaceCount(void) {
1320 xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
1321 XAtom::cardinal, workspacesList.size());
1325 std::for_each(netizenList.begin(), netizenList.end(),
1326 std::mem_fun(&Netizen::sendWorkspaceCount));
1330 void BScreen::updateNetizenWindowFocus(void) {
1331 Window f = ((blackbox->getFocusedWindow()) ?
1332 blackbox->getFocusedWindow()->getClientWindow() : None);
1334 xatom->setValue(getRootWindow(), XAtom::net_active_window,
1337 NetizenList::iterator it = netizenList.begin();
1338 for (; it != netizenList.end(); ++it)
1339 (*it)->sendWindowFocus(f);
1343 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1344 NetizenList::iterator it = netizenList.begin();
1345 for (; it != netizenList.end(); ++it) {
1346 (*it)->sendWindowAdd(w, p);
1351 void BScreen::updateNetizenWindowDel(Window w) {
1352 NetizenList::iterator it = netizenList.begin();
1353 for (; it != netizenList.end(); ++it)
1354 (*it)->sendWindowDel(w);
1358 void BScreen::updateNetizenWindowRaise(Window w) {
1359 NetizenList::iterator it = netizenList.begin();
1360 for (; it != netizenList.end(); ++it)
1361 (*it)->sendWindowRaise(w);
1365 void BScreen::updateNetizenWindowLower(Window w) {
1366 NetizenList::iterator it = netizenList.begin();
1367 for (; it != netizenList.end(); ++it)
1368 (*it)->sendWindowLower(w);
1372 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1373 NetizenList::iterator it = netizenList.begin();
1374 for (; it != netizenList.end(); ++it)
1375 (*it)->sendConfigNotify(e);
1379 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
1380 // the 13 represents the number of blackbox windows such as menus
1381 Window *session_stack = new
1382 Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
1383 unsigned int i = 0, k = num;
1385 XRaiseWindow(blackbox->getXDisplay(), iconmenu->getWindowID());
1386 *(session_stack + i++) = iconmenu->getWindowID();
1388 WorkspaceList::iterator wit = workspacesList.begin();
1389 const WorkspaceList::iterator w_end = workspacesList.end();
1390 for (; wit != w_end; ++wit)
1391 *(session_stack + i++) = (*wit)->getMenu()->getWindowID();
1393 *(session_stack + i++) = workspacemenu->getWindowID();
1395 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1396 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1397 *(session_stack + i++) = configmenu->getWindowID();
1399 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1400 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1401 *(session_stack + i++) = slit->getMenu()->getWindowID();
1403 *(session_stack + i++) =
1404 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1405 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1407 RootmenuList::iterator rit = rootmenuList.begin();
1408 for (; rit != rootmenuList.end(); ++rit)
1409 *(session_stack + i++) = (*rit)->getWindowID();
1410 *(session_stack + i++) = rootmenu->getWindowID();
1412 if (toolbar->isOnTop())
1413 *(session_stack + i++) = toolbar->getWindowID();
1415 if (slit->isOnTop())
1416 *(session_stack + i++) = slit->getWindowID();
1419 *(session_stack + i++) = *(workspace_stack + k);
1421 XRestackWindows(blackbox->getXDisplay(), session_stack, i);
1423 delete [] session_stack;
1425 updateStackingList();
1429 void BScreen::lowerDesktops(void) {
1430 if (desktopWindowList.empty()) return;
1432 XLowerWindow(blackbox->getXDisplay(), desktopWindowList[0]);
1433 if (desktopWindowList.size() > 1)
1434 XRestackWindows(blackbox->getXDisplay(), &desktopWindowList[0],
1435 desktopWindowList.size());
1439 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
1440 bool ignore_sticky) {
1443 if (wkspc_id == BSENTINEL)
1444 wkspc_id = current_workspace->getID();
1446 if (w->getWorkspaceNumber() == wkspc_id)
1449 if (w->isIconic()) {
1451 getWorkspace(wkspc_id)->addWindow(w);
1452 } else if (ignore_sticky || ! w->isStuck()) {
1453 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1454 getWorkspace(wkspc_id)->addWindow(w);
1459 void BScreen::propagateWindowName(const BlackboxWindow *bw) {
1460 if (bw->isIconic()) {
1461 iconmenu->changeItemLabel(bw->getWindowNumber(), bw->getIconTitle());
1465 Clientmenu *clientmenu = getWorkspace(bw->getWorkspaceNumber())->getMenu();
1466 clientmenu->changeItemLabel(bw->getWindowNumber(), bw->getTitle());
1467 clientmenu->update();
1469 if (blackbox->getFocusedWindow() == bw)
1470 toolbar->redrawWindowLabel(True);
1475 void BScreen::nextFocus(void) {
1476 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1480 // if window is not on this screen, ignore it
1481 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1482 focused = (BlackboxWindow*) 0;
1485 if (focused && current_workspace->getCount() > 1) {
1486 // next is the next window to recieve focus, current is a place holder
1487 BlackboxWindow *current;
1490 next = current_workspace->getNextWindowInList(current);
1491 } while(! next->setInputFocus() && next != focused);
1493 if (next != focused)
1494 current_workspace->raiseWindow(next);
1495 } else if (current_workspace->getCount() >= 1) {
1496 next = current_workspace->getTopWindowOnStack();
1498 current_workspace->raiseWindow(next);
1499 next->setInputFocus();
1504 void BScreen::prevFocus(void) {
1505 BlackboxWindow *focused = blackbox->getFocusedWindow(),
1509 // if window is not on this screen, ignore it
1510 if (focused->getScreen()->getScreenNumber() != getScreenNumber())
1511 focused = (BlackboxWindow*) 0;
1514 if (focused && current_workspace->getCount() > 1) {
1515 // next is the next window to recieve focus, current is a place holder
1516 BlackboxWindow *current;
1519 next = current_workspace->getPrevWindowInList(current);
1520 } while(! next->setInputFocus() && next != focused);
1522 if (next != focused)
1523 current_workspace->raiseWindow(next);
1524 } else if (current_workspace->getCount() >= 1) {
1525 next = current_workspace->getTopWindowOnStack();
1527 current_workspace->raiseWindow(next);
1528 next->setInputFocus();
1533 void BScreen::raiseFocus(void) {
1534 BlackboxWindow *focused = blackbox->getFocusedWindow();
1538 // if on this Screen, raise it
1539 if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
1540 Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
1541 workspace->raiseWindow(focused);
1546 void BScreen::InitMenu(void) {
1548 rootmenuList.clear();
1550 while (rootmenu->getCount())
1551 rootmenu->remove(0);
1553 rootmenu = new Rootmenu(this);
1555 bool defaultMenu = True;
1557 FILE *menu_file = (FILE *) 0;
1558 const char *menu_filename = blackbox->getMenuFilename();
1561 if (! (menu_file = fopen(menu_filename, "r")))
1562 perror(menu_filename);
1563 if (! menu_file) { // opening the menu file failed, try the default menu
1564 menu_filename = DEFAULTMENU;
1565 if (! (menu_file = fopen(menu_filename, "r")))
1566 perror(menu_filename);
1570 if (feof(menu_file)) {
1571 fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
1572 "%s: Empty menu file"),
1575 char line[1024], label[1024];
1576 memset(line, 0, 1024);
1577 memset(label, 0, 1024);
1579 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
1580 if (line[0] != '#') {
1581 int i, key = 0, index = -1, len = strlen(line);
1583 for (i = 0; i < len; i++) {
1584 if (line[i] == '[') index = 0;
1585 else if (line[i] == ']') break;
1586 else if (line[i] != ' ')
1588 key += tolower(line[i]);
1591 if (key == 517) { // [begin]
1593 for (i = index; i < len; i++) {
1594 if (line[i] == '(') index = 0;
1595 else if (line[i] == ')') break;
1596 else if (index++ >= 0) {
1597 if (line[i] == '\\' && i < len - 1) i++;
1598 label[index - 1] = line[i];
1602 if (index == -1) index = 0;
1603 label[index] = '\0';
1605 rootmenu->setLabel(label);
1606 defaultMenu = parseMenuFile(menu_file, rootmenu);
1608 blackbox->addMenuTimestamp(menu_filename);
1618 rootmenu->setInternalMenu();
1619 rootmenu->insert(i18n(ScreenSet, Screenxterm, "xterm"),
1621 i18n(ScreenSet, Screenxterm, "xterm"));
1622 rootmenu->insert(i18n(ScreenSet, ScreenRestart, "Restart"),
1624 rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
1626 rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
1632 bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
1633 char line[1024], label[1024], command[1024];
1635 while (! feof(file)) {
1636 memset(line, 0, 1024);
1637 memset(label, 0, 1024);
1638 memset(command, 0, 1024);
1640 if (fgets(line, 1024, file)) {
1641 if (line[0] != '#') {
1642 int i, key = 0, parse = 0, index = -1, line_length = strlen(line);
1644 // determine the keyword
1645 for (i = 0; i < line_length; i++) {
1646 if (line[i] == '[') parse = 1;
1647 else if (line[i] == ']') break;
1648 else if (line[i] != ' ')
1650 key += tolower(line[i]);
1653 // get the label enclosed in ()'s
1656 for (i = 0; i < line_length; i++) {
1657 if (line[i] == '(') {
1660 } else if (line[i] == ')') break;
1661 else if (index++ >= 0) {
1662 if (line[i] == '\\' && i < line_length - 1) i++;
1663 label[index - 1] = line[i];
1668 label[index] = '\0';
1673 // get the command enclosed in {}'s
1676 for (i = 0; i < line_length; i++) {
1677 if (line[i] == '{') {
1680 } else if (line[i] == '}') break;
1681 else if (index++ >= 0) {
1682 if (line[i] == '\\' && i < line_length - 1) i++;
1683 command[index - 1] = line[i];
1688 command[index] = '\0';
1695 return ((menu->getCount() == 0) ? True : False);
1702 menu->insert(label);
1707 if ((! *label) && (! *command)) {
1708 fprintf(stderr, i18n(ScreenSet, ScreenEXECError,
1709 "BScreen::parseMenuFile: [exec] error, "
1710 "no menu label and/or command defined\n"));
1714 menu->insert(label, BScreen::Execute, command);
1720 fprintf(stderr, i18n(ScreenSet, ScreenEXITError,
1721 "BScreen::parseMenuFile: [exit] error, "
1722 "no menu label defined\n"));
1726 menu->insert(label, BScreen::Exit);
1732 if ((! *label) || (! *command)) {
1734 i18n(ScreenSet, ScreenSTYLEError,
1735 "BScreen::parseMenuFile: [style] error, "
1736 "no menu label and/or filename defined\n"));
1740 string style = expandTilde(command);
1742 menu->insert(label, BScreen::SetStyle, style.c_str());
1749 fprintf(stderr, i18n(ScreenSet, ScreenCONFIGError,
1750 "BScreen::parseMenufile: [config] error, "
1751 "no label defined"));
1755 menu->insert(label, configmenu);
1759 case 740: // include
1762 fprintf(stderr, i18n(ScreenSet, ScreenINCLUDEError,
1763 "BScreen::parseMenuFile: [include] error, "
1764 "no filename defined\n"));
1768 string newfile = expandTilde(label);
1769 FILE *submenufile = fopen(newfile.c_str(), "r");
1773 if (fstat(fileno(submenufile), &buf) ||
1774 (! S_ISREG(buf.st_mode))) {
1776 i18n(ScreenSet, ScreenINCLUDEErrorReg,
1777 "BScreen::parseMenuFile: [include] error: "
1778 "'%s' is not a regular file\n"), newfile.c_str());
1782 if (! feof(submenufile)) {
1783 if (! parseMenuFile(submenufile, menu))
1784 blackbox->addMenuTimestamp(newfile);
1786 fclose(submenufile);
1789 perror(newfile.c_str());
1795 case 767: // submenu
1798 fprintf(stderr, i18n(ScreenSet, ScreenSUBMENUError,
1799 "BScreen::parseMenuFile: [submenu] error, "
1800 "no menu label defined\n"));
1804 Rootmenu *submenu = new Rootmenu(this);
1807 submenu->setLabel(command);
1809 submenu->setLabel(label);
1811 parseMenuFile(file, submenu);
1813 menu->insert(label, submenu);
1814 rootmenuList.push_back(submenu);
1819 case 773: // restart
1822 fprintf(stderr, i18n(ScreenSet, ScreenRESTARTError,
1823 "BScreen::parseMenuFile: [restart] error, "
1824 "no menu label defined\n"));
1829 menu->insert(label, BScreen::RestartOther, command);
1831 menu->insert(label, BScreen::Restart);
1836 case 845: // reconfig
1840 i18n(ScreenSet, ScreenRECONFIGError,
1841 "BScreen::parseMenuFile: [reconfig] error, "
1842 "no menu label defined\n"));
1846 menu->insert(label, BScreen::Reconfigure);
1851 case 995: // stylesdir
1852 case 1113: // stylesmenu
1854 bool newmenu = ((key == 1113) ? True : False);
1856 if ((! *label) || ((! *command) && newmenu)) {
1858 i18n(ScreenSet, ScreenSTYLESDIRError,
1859 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1860 " error, no directory defined\n"));
1864 char *directory = ((newmenu) ? command : label);
1866 string stylesdir = expandTilde(directory);
1868 struct stat statbuf;
1870 if (! stat(stylesdir.c_str(), &statbuf)) {
1871 if (S_ISDIR(statbuf.st_mode)) {
1872 Rootmenu *stylesmenu;
1875 stylesmenu = new Rootmenu(this);
1879 DIR *d = opendir(stylesdir.c_str());
1881 std::vector<string> ls;
1883 while((p = readdir(d)))
1884 ls.push_back(p->d_name);
1888 std::sort(ls.begin(), ls.end());
1890 std::vector<string>::iterator it = ls.begin(),
1892 for (; it != end; ++it) {
1893 const string& fname = *it;
1895 if (fname[fname.size()-1] == '~')
1898 string style = stylesdir;
1902 if ((! stat(style.c_str(), &statbuf)) &&
1903 S_ISREG(statbuf.st_mode))
1904 stylesmenu->insert(fname, BScreen::SetStyle, style);
1907 stylesmenu->update();
1910 stylesmenu->setLabel(label);
1911 menu->insert(label, stylesmenu);
1912 rootmenuList.push_back(stylesmenu);
1915 blackbox->addMenuTimestamp(stylesdir);
1918 i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
1919 "BScreen::parseMenuFile:"
1920 " [stylesdir/stylesmenu] error, %s is not a"
1921 " directory\n"), stylesdir.c_str());
1925 i18n(ScreenSet, ScreenSTYLESDIRErrorNoExist,
1926 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1927 " error, %s does not exist\n"), stylesdir.c_str());
1932 case 1090: // workspaces
1936 i18n(ScreenSet, ScreenWORKSPACESError,
1937 "BScreen:parseMenuFile: [workspaces] error, "
1938 "no menu label defined\n"));
1942 menu->insert(label, workspacemenu);
1951 return ((menu->getCount() == 0) ? True : False);
1955 void BScreen::shutdown(void) {
1956 XSelectInput(blackbox->getXDisplay(), getRootWindow(), NoEventMask);
1957 XSync(blackbox->getXDisplay(), False);
1959 while(! windowList.empty())
1960 unmanageWindow(windowList.front(), True);
1966 void BScreen::showPosition(int x, int y) {
1967 if (! geom_visible) {
1968 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
1969 (getWidth() - geom_w) / 2,
1970 (getHeight() - geom_h) / 2, geom_w, geom_h);
1971 XMapWindow(blackbox->getXDisplay(), geom_window);
1972 XRaiseWindow(blackbox->getXDisplay(), geom_window);
1974 geom_visible = True;
1979 sprintf(label, i18n(ScreenSet, ScreenPositionFormat,
1980 "X: %4d x Y: %4d"), x, y);
1982 XClearWindow(blackbox->getXDisplay(), geom_window);
1984 BPen pen(resource.wstyle.l_text_focus, resource.wstyle.font);
1985 if (i18n.multibyte()) {
1986 XmbDrawString(blackbox->getXDisplay(), geom_window,
1987 resource.wstyle.fontset, pen.gc(),
1988 resource.bevel_width, resource.bevel_width -
1989 resource.wstyle.fontset_extents->max_ink_extent.y,
1990 label, strlen(label));
1992 XDrawString(blackbox->getXDisplay(), geom_window,
1993 pen.gc(), resource.bevel_width,
1994 resource.wstyle.font->ascent + resource.bevel_width,
1995 label, strlen(label));
2000 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
2001 if (! geom_visible) {
2002 XMoveResizeWindow(blackbox->getXDisplay(), geom_window,
2003 (getWidth() - geom_w) / 2,
2004 (getHeight() - geom_h) / 2, geom_w, geom_h);
2005 XMapWindow(blackbox->getXDisplay(), geom_window);
2006 XRaiseWindow(blackbox->getXDisplay(), geom_window);
2008 geom_visible = True;
2013 sprintf(label, i18n(ScreenSet, ScreenGeometryFormat,
2014 "W: %4d x H: %4d"), gx, gy);
2016 XClearWindow(blackbox->getXDisplay(), geom_window);
2018 BPen pen(resource.wstyle.l_text_focus, resource.wstyle.font);
2019 if (i18n.multibyte()) {
2020 XmbDrawString(blackbox->getXDisplay(), geom_window,
2021 resource.wstyle.fontset, pen.gc(),
2022 resource.bevel_width, resource.bevel_width -
2023 resource.wstyle.fontset_extents->max_ink_extent.y,
2024 label, strlen(label));
2026 XDrawString(blackbox->getXDisplay(), geom_window,
2027 pen.gc(), resource.bevel_width,
2028 resource.wstyle.font->ascent +
2029 resource.bevel_width, label, strlen(label));
2034 void BScreen::hideGeometry(void) {
2036 XUnmapWindow(blackbox->getXDisplay(), geom_window);
2037 geom_visible = False;
2042 void BScreen::addStrut(Strut *strut) {
2043 strutList.push_back(strut);
2047 void BScreen::removeStrut(Strut *strut) {
2048 strutList.remove(strut);
2052 const Rect& BScreen::availableArea(void) const {
2054 return getRect(); // return the full screen
2059 void BScreen::updateAvailableArea(void) {
2060 Rect old_area = usableArea;
2061 usableArea = getRect(); // reset to full screen
2063 /* these values represent offsets from the screen edge
2064 * we look for the biggest offset on each edge and then apply them
2066 * do not be confused by the similarity to the names of Rect's members
2068 unsigned int current_left = 0, current_right = 0, current_top = 0,
2071 StrutList::const_iterator it = strutList.begin(), end = strutList.end();
2073 for(; it != end; ++it) {
2075 if (strut->left > current_left)
2076 current_left = strut->left;
2077 if (strut->top > current_top)
2078 current_top = strut->top;
2079 if (strut->right > current_right)
2080 current_right = strut->right;
2081 if (strut->bottom > current_bottom)
2082 current_bottom = strut->bottom;
2085 usableArea.setPos(current_left, current_top);
2086 usableArea.setSize(usableArea.width() - (current_left + current_right),
2087 usableArea.height() - (current_top + current_bottom));
2089 if (old_area != usableArea) {
2090 BlackboxWindowList::iterator it = windowList.begin(),
2091 end = windowList.end();
2092 for (; it != end; ++it)
2093 if ((*it)->isMaximized()) (*it)->remaximize();
2100 Workspace* BScreen::getWorkspace(unsigned int index) {
2101 assert(index < workspacesList.size());
2102 return workspacesList[index];
2106 void BScreen::buttonPressEvent(XButtonEvent *xbutton) {
2107 if (xbutton->button == 1) {
2108 if (! isRootColormapInstalled())
2109 image_control->installRootColormap();
2111 if (workspacemenu->isVisible())
2112 workspacemenu->hide();
2114 if (rootmenu->isVisible())
2116 } else if (xbutton->button == 2) {
2117 int mx = xbutton->x_root - (workspacemenu->getWidth() / 2);
2118 int my = xbutton->y_root - (workspacemenu->getTitleHeight() / 2);
2123 if (mx + workspacemenu->getWidth() > getWidth())
2124 mx = getWidth() - workspacemenu->getWidth() - getBorderWidth();
2126 if (my + workspacemenu->getHeight() > getHeight())
2127 my = getHeight() - workspacemenu->getHeight() - getBorderWidth();
2129 workspacemenu->move(mx, my);
2131 if (! workspacemenu->isVisible()) {
2132 workspacemenu->removeParent();
2133 workspacemenu->show();
2135 } else if (xbutton->button == 3) {
2136 int mx = xbutton->x_root - (rootmenu->getWidth() / 2);
2137 int my = xbutton->y_root - (rootmenu->getTitleHeight() / 2);
2142 if (mx + rootmenu->getWidth() > getWidth())
2143 mx = getWidth() - rootmenu->getWidth() - getBorderWidth();
2145 if (my + rootmenu->getHeight() > getHeight())
2146 my = getHeight() - rootmenu->getHeight() - getBorderWidth();
2148 rootmenu->move(mx, my);
2150 if (! rootmenu->isVisible()) {
2151 blackbox->checkMenu();
2155 } else if (xbutton->button == 4) {
2156 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2157 changeWorkspaceID(0);
2159 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2161 } else if (xbutton->button == 5) {
2162 if (getCurrentWorkspaceID() == 0)
2163 changeWorkspaceID(getWorkspaceCount() - 1);
2165 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2170 void BScreen::toggleFocusModel(FocusModel model) {
2171 if (model == SloppyFocus) {
2172 saveSloppyFocus(True);
2174 // we're cheating here to save writing the config file 3 times
2175 resource.auto_raise = False;
2176 resource.click_raise = False;
2177 saveSloppyFocus(False);
2184 void BScreen::updateFocusModel()
2186 std::for_each(workspacesList.begin(), workspacesList.end(),
2187 std::mem_fun(&Workspace::updateFocusModel));
2191 BTexture BScreen::readDatabaseTexture(const string &rname,
2192 const string &default_color,
2193 Configuration &style) {
2197 if (style.getValue(rname, s))
2198 texture = BTexture(s);
2200 texture.setTexture(BTexture::Solid | BTexture::Flat);
2202 // associate this texture with this screen
2203 texture.setDisplay(getBaseDisplay(), getScreenNumber());
2204 texture.setImageControl(image_control);
2206 if (texture.texture() & BTexture::Solid) {
2207 texture.setColor(readDatabaseColor(rname + ".color",
2208 default_color, style));
2209 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2210 default_color, style));
2211 } else if (texture.texture() & BTexture::Gradient) {
2212 texture.setColor(readDatabaseColor(rname + ".color",
2213 default_color, style));
2214 texture.setColorTo(readDatabaseColor(rname + ".colorTo",
2215 default_color, style));
2222 BColor BScreen::readDatabaseColor(const string &rname,
2223 const string &default_color,
2224 Configuration &style) {
2227 if (style.getValue(rname, s))
2228 color = BColor(s, getBaseDisplay(), getScreenNumber());
2230 color = BColor(default_color, getBaseDisplay(), getScreenNumber());
2235 XFontSet BScreen::readDatabaseFontSet(const string &rname,
2236 Configuration &style) {
2237 char *defaultFont = "fixed";
2239 bool load_default = True;
2241 XFontSet fontset = 0;
2242 if (style.getValue(rname, s) && (fontset = createFontSet(s)))
2243 load_default = False;
2246 fontset = createFontSet(defaultFont);
2250 i18n(ScreenSet, ScreenDefaultFontLoadFail,
2251 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2260 XFontStruct *BScreen::readDatabaseFont(const string &rname,
2261 Configuration &style) {
2262 char *defaultFont = "fixed";
2264 bool load_default = False;
2266 XFontStruct *font = 0;
2267 if (style.getValue(rname, s)) {
2268 if ((font = XLoadQueryFont(blackbox->getXDisplay(), s.c_str())) == NULL) {
2270 i18n(ScreenSet, ScreenFontLoadFail,
2271 "BScreen::setCurrentStyle(): couldn't load font '%s'\n"),
2274 load_default = True;
2277 load_default = True;
2281 font = XLoadQueryFont(blackbox->getXDisplay(), defaultFont);
2284 i18n(ScreenSet, ScreenDefaultFontLoadFail,
2285 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2294 #ifndef HAVE_STRCASESTR
2295 static const char * strcasestr(const char *str, const char *ptn) {
2296 const char *s2, *p2;
2297 for(; *str; str++) {
2298 for(s2=str,p2=ptn; ; s2++,p2++) {
2299 if (! *p2) return str;
2300 if (toupper(*s2) != toupper(*p2)) break;
2305 #endif // HAVE_STRCASESTR
2308 static const char *getFontElement(const char *pattern, char *buf,
2314 va_start(va, bufsiz);
2316 buf[bufsiz-2] = '*';
2317 while((v = va_arg(va, char *)) != NULL) {
2318 p = strcasestr(pattern, v);
2320 strncpy(buf, p+1, bufsiz-2);
2321 p2 = strchr(buf, '-');
2328 strncpy(buf, "*", bufsiz);
2333 static const char *getFontSize(const char *pattern, int *size) {
2335 const char *p2=NULL;
2338 for (p=pattern; 1; p++) {
2340 if (p2!=NULL && n>1 && n<72) {
2341 *size = n; return p2+1;
2343 *size = 16; return NULL;
2345 } else if (*p=='-') {
2346 if (n>1 && n<72 && p2!=NULL) {
2351 } else if (*p>='0' && *p<='9' && p2!=NULL) {
2361 XFontSet BScreen::createFontSet(const string &fontname) {
2363 char **missing, *def = "-";
2364 int nmissing, pixel_size = 0, buf_size = 0;
2365 char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE];
2367 fs = XCreateFontSet(blackbox->getXDisplay(),
2368 fontname.c_str(), &missing, &nmissing, &def);
2369 if (fs && (! nmissing))
2372 const char *nfontname = fontname.c_str();
2373 #ifdef HAVE_SETLOCALE
2375 if (nmissing) XFreeStringList(missing);
2377 setlocale(LC_CTYPE, "C");
2378 fs = XCreateFontSet(blackbox->getXDisplay(), fontname.c_str(),
2379 &missing, &nmissing, &def);
2380 setlocale(LC_CTYPE, "");
2382 #endif // HAVE_SETLOCALE
2385 XFontStruct **fontstructs;
2387 XFontsOfFontSet(fs, &fontstructs, &fontnames);
2388 nfontname = fontnames[0];
2391 getFontElement(nfontname, weight, FONT_ELEMENT_SIZE,
2392 "-medium-", "-bold-", "-demibold-", "-regular-", NULL);
2393 getFontElement(nfontname, slant, FONT_ELEMENT_SIZE,
2394 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);
2395 getFontSize(nfontname, &pixel_size);
2397 if (! strcmp(weight, "*"))
2398 strncpy(weight, "medium", FONT_ELEMENT_SIZE);
2399 if (! strcmp(slant, "*"))
2400 strncpy(slant, "r", FONT_ELEMENT_SIZE);
2403 else if (pixel_size > 97)
2406 buf_size = strlen(nfontname) + (FONT_ELEMENT_SIZE * 2) + 64;
2407 char *pattern2 = new char[buf_size];
2410 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
2411 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
2412 nfontname, weight, slant, pixel_size, pixel_size);
2413 nfontname = pattern2;
2416 XFreeStringList(missing);
2418 XFreeFontSet(blackbox->getXDisplay(), fs);
2420 fs = XCreateFontSet(blackbox->getXDisplay(), nfontname, &missing,