1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Screen.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
25 #include "../config.h"
26 #endif // HAVE_CONFIG_H
29 #include <X11/Xatom.h>
30 #include <X11/keysym.h>
33 # include <X11/Xlib.h>
34 # include <X11/extensions/Xinerama.h>
39 #endif // HAVE_STDLIB_H
43 #endif // HAVE_STRING_H
47 #endif // HAVE_CTYPE_H
50 # include <sys/types.h>
52 #endif // HAVE_UNISTD_H
56 #endif // HAVE_DIRENT_H
60 #endif // HAVE_LOCALE_H
62 #ifdef HAVE_SYS_STAT_H
63 # include <sys/stat.h>
64 #endif // HAVE_SYS_STAT_H
68 #endif // HAVE_STDARG_H
79 #include "blackbox.hh"
80 #include "Clientmenu.hh"
83 #include "Iconmenu.hh"
87 #include "Rootmenu.hh"
91 #include "Workspace.hh"
92 #include "Workspacemenu.hh"
96 #ifndef FONT_ELEMENT_SIZE
97 #define FONT_ELEMENT_SIZE 50
98 #endif // FONT_ELEMENT_SIZE
101 static bool running
= True
;
103 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
104 fprintf(stderr
, i18n(ScreenSet
, ScreenAnotherWMRunning
,
105 "BScreen::BScreen: an error occured while querying the X server.\n"
106 " another window manager already running on display %s.\n"),
107 DisplayString(display
));
115 BScreen::BScreen(Blackbox
*bb
, unsigned int scrn
) : ScreenInfo(bb
, scrn
) {
117 screenstr
= "session.screen" + itostring(scrn
) + '.';
118 config
= blackbox
->getConfig();
119 xatom
= blackbox
->getXAtom();
121 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
122 SubstructureRedirectMask
| ButtonPressMask
| ButtonReleaseMask
;
124 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
125 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask
);
126 XSync(getBaseDisplay()->getXDisplay(), False
);
127 XSetErrorHandler((XErrorHandler
) old
);
130 if (! managed
) return;
132 fprintf(stderr
, i18n(ScreenSet
, ScreenManagingScreen
,
133 "BScreen::BScreen: managing screen %d "
134 "using visual 0x%lx, depth %d\n"),
135 getScreenNumber(), XVisualIDFromVisual(getVisual()),
140 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
141 resource
.wstyle
.font
= (BFont
*) 0;
145 xatom
->setSupported(this); // set-up netwm support
147 xatom
->setValue(getRootWindow(), XAtom::blackbox_pid
, XAtom::cardinal
,
148 (unsigned long) getpid());
149 #endif // HAVE_GETPID
150 unsigned long geometry
[] = { getWidth(),
152 xatom
->setValue(getRootWindow(), XAtom::net_desktop_geometry
,
153 XAtom::cardinal
, geometry
, 2);
154 unsigned long viewport
[] = {0,0};
155 xatom
->setValue(getRootWindow(), XAtom::net_desktop_viewport
,
156 XAtom::cardinal
, viewport
, 2);
159 XDefineCursor(blackbox
->getXDisplay(), getRootWindow(),
160 blackbox
->getSessionCursor());
162 updateAvailableArea();
165 new BImageControl(blackbox
, this, True
, blackbox
->getColorsPerChannel(),
166 blackbox
->getCacheLife(), blackbox
->getCacheMax());
167 image_control
->installRootColormap();
168 root_colormap_installed
= True
;
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");
183 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
184 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
186 XSetWindowAttributes attrib
;
187 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
188 attrib
.border_pixel
= getBorderColor()->pixel();
189 attrib
.colormap
= getColormap();
190 attrib
.save_under
= True
;
192 geom_window
= XCreateWindow(blackbox
->getXDisplay(), getRootWindow(),
193 0, 0, geom_w
, geom_h
, resource
.border_width
,
194 getDepth(), InputOutput
, getVisual(),
196 geom_visible
= False
;
198 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
199 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
200 if (geom_pixmap
== ParentRelative
) {
201 texture
= &(resource
.wstyle
.t_focus
);
202 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
205 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
206 texture
->color().pixel());
208 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
209 geom_window
, geom_pixmap
);
211 workspacemenu
= new Workspacemenu(this);
212 iconmenu
= new Iconmenu(this);
213 configmenu
= new Configmenu(this);
215 if (resource
.workspaces
> 0) {
216 for (unsigned int i
= 0; i
< resource
.workspaces
; ++i
) {
217 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
218 workspacesList
.push_back(wkspc
);
219 workspacemenu
->insertWorkspace(wkspc
);
220 workspacemenu
->update();
224 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
225 workspacesList
.push_back(wkspc
);
226 workspacemenu
->insertWorkspace(wkspc
);
227 workspacemenu
->update();
229 saveWorkspaceNames();
231 updateNetizenWorkspaceCount();
233 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
234 workspacemenu
->update();
236 current_workspace
= workspacesList
.front();
238 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
239 XAtom::cardinal
, 0); //first workspace
241 workspacemenu
->setItemSelected(2, True
);
243 toolbar
= new Toolbar(this);
245 slit
= new Slit(this);
249 raiseWindows(0, 0); // this also initializes the empty stacking list
252 updateClientList(); // initialize the client lists, which will be empty
253 updateAvailableArea();
255 changeWorkspaceID(0);
257 unsigned int i
, j
, nchild
;
258 Window r
, p
, *children
;
259 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
262 // preen the window list of all icon windows... for better dockapp support
263 for (i
= 0; i
< nchild
; i
++) {
264 if (children
[i
] == None
) continue;
266 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
270 if ((wmhints
->flags
& IconWindowHint
) &&
271 (wmhints
->icon_window
!= children
[i
])) {
272 for (j
= 0; j
< nchild
; j
++) {
273 if (children
[j
] == wmhints
->icon_window
) {
284 // manage shown windows
285 for (i
= 0; i
< nchild
; ++i
) {
286 if (children
[i
] == None
|| ! blackbox
->validateWindow(children
[i
]))
289 XWindowAttributes attrib
;
290 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
291 if (attrib
.override_redirect
) continue;
293 if (attrib
.map_state
!= IsUnmapped
) {
294 manageWindow(children
[i
]);
301 // call this again just in case a window we found updates the Strut list
302 updateAvailableArea();
306 BScreen::~BScreen(void) {
307 if (! managed
) return;
309 if (geom_pixmap
!= None
)
310 image_control
->removeImage(geom_pixmap
);
312 if (geom_window
!= None
)
313 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
315 std::for_each(workspacesList
.begin(), workspacesList
.end(),
318 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
320 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
322 while (! systrayWindowList
.empty())
323 removeSystrayWindow(systrayWindowList
[0]);
326 delete workspacemenu
;
331 delete image_control
;
333 if (resource
.wstyle
.font
)
334 delete resource
.wstyle
.font
;
335 if (resource
.mstyle
.t_font
)
336 delete resource
.mstyle
.t_font
;
337 if (resource
.mstyle
.f_font
)
338 delete resource
.mstyle
.f_font
;
339 if (resource
.tstyle
.font
)
340 delete resource
.tstyle
.font
;
342 XFreeGC(blackbox
->getXDisplay(), opGC
);
346 void BScreen::saveSloppyFocus(bool s
) {
347 resource
.sloppy_focus
= s
;
350 if (resource
.sloppy_focus
) {
351 fmodel
= "SloppyFocus";
352 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
353 if (resource
.click_raise
) fmodel
+= " ClickRaise";
355 fmodel
= "ClickToFocus";
357 config
->setValue(screenstr
+ "focusModel", fmodel
);
361 void BScreen::saveAutoRaise(bool a
) {
362 resource
.auto_raise
= a
;
363 saveSloppyFocus(resource
.sloppy_focus
);
367 void BScreen::saveClickRaise(bool c
) {
368 resource
.click_raise
= c
;
369 saveSloppyFocus(resource
.sloppy_focus
);
373 void BScreen::saveImageDither(bool d
) {
374 image_control
->setDither(d
);
375 config
->setValue(screenstr
+ "imageDither", doImageDither());
379 void BScreen::saveOpaqueMove(bool o
) {
380 resource
.opaque_move
= o
;
381 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
385 void BScreen::saveFullMax(bool f
) {
386 resource
.full_max
= f
;
387 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
391 void BScreen::saveFocusNew(bool f
) {
392 resource
.focus_new
= f
;
393 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
397 void BScreen::saveFocusLast(bool f
) {
398 resource
.focus_last
= f
;
399 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
403 void BScreen::saveAAFonts(bool f
) {
404 resource
.aa_fonts
= f
;
406 config
->setValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
);
410 void BScreen::saveHideToolbar(bool h
) {
411 resource
.hide_toolbar
= h
;
412 if (resource
.hide_toolbar
)
413 toolbar
->unmapToolbar();
415 toolbar
->mapToolbar();
416 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
420 void BScreen::saveWindowToWindowSnap(bool s
) {
421 resource
.window_to_window_snap
= s
;
422 config
->setValue(screenstr
+ "windowToWindowSnap",
423 resource
.window_to_window_snap
);
427 void BScreen::saveResizeZones(unsigned int z
) {
428 resource
.resize_zones
= z
;
429 config
->setValue(screenstr
+ "resizeZones", resource
.resize_zones
);
433 void BScreen::saveWindowCornerSnap(bool s
) {
434 resource
.window_corner_snap
= s
;
435 config
->setValue(screenstr
+ "windowCornerSnap",
436 resource
.window_corner_snap
);
440 void BScreen::saveWorkspaces(unsigned int w
) {
441 resource
.workspaces
= w
;
442 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
446 void BScreen::savePlacementPolicy(int p
) {
447 resource
.placement_policy
= p
;
448 const char *placement
;
449 switch (resource
.placement_policy
) {
450 case CascadePlacement
: placement
= "CascadePlacement"; break;
451 case UnderMousePlacement
: placement
= "UnderMousePlacement"; break;
452 case ClickMousePlacement
: placement
= "ClickMousePlacement"; break;
453 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
454 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
456 config
->setValue(screenstr
+ "windowPlacement", placement
);
460 void BScreen::saveEdgeSnapThreshold(int t
) {
461 resource
.edge_snap_threshold
= t
;
462 config
->setValue(screenstr
+ "edgeSnapThreshold",
463 resource
.edge_snap_threshold
);
467 void BScreen::saveRowPlacementDirection(int d
) {
468 resource
.row_direction
= d
;
469 config
->setValue(screenstr
+ "rowPlacementDirection",
470 resource
.row_direction
== LeftRight
?
471 "LeftToRight" : "RightToLeft");
475 void BScreen::saveColPlacementDirection(int d
) {
476 resource
.col_direction
= d
;
477 config
->setValue(screenstr
+ "colPlacementDirection",
478 resource
.col_direction
== TopBottom
?
479 "TopToBottom" : "BottomToTop");
484 void BScreen::saveStrftimeFormat(const std::string
& format
) {
485 resource
.strftime_format
= format
;
486 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
489 #else // !HAVE_STRFTIME
491 void BScreen::saveDateFormat(int f
) {
492 resource
.date_format
= f
;
493 config
->setValue(screenstr
+ "dateFormat",
494 resource
.date_format
== B_EuropeanDate
?
495 "European" : "American");
499 void BScreen::saveClock24Hour(bool c
) {
500 resource
.clock24hour
= c
;
501 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
503 #endif // HAVE_STRFTIME
506 void BScreen::saveWorkspaceNames() {
509 for (unsigned int i
= 0; i
< workspacesList
.size(); ++i
) {
510 names
+= workspacesList
[i
]->getName();
511 if (i
< workspacesList
.size() - 1)
515 config
->setValue(screenstr
+ "workspaceNames", names
);
519 void BScreen::savePlaceIgnoreShaded(bool i
) {
520 resource
.ignore_shaded
= i
;
521 config
->setValue(screenstr
+ "placementIgnoreShaded",
522 resource
.ignore_shaded
);
526 void BScreen::savePlaceIgnoreMaximized(bool i
) {
527 resource
.ignore_maximized
= i
;
528 config
->setValue(screenstr
+ "placementIgnoreMaximized",
529 resource
.ignore_maximized
);
533 void BScreen::saveAllowScrollLock(bool a
) {
534 resource
.allow_scroll_lock
= a
;
535 config
->setValue(screenstr
+ "disableBindingsWithScrollLock",
536 resource
.allow_scroll_lock
);
540 void BScreen::saveWorkspaceWarping(bool w
) {
541 resource
.workspace_warping
= w
;
542 config
->setValue(screenstr
+ "workspaceWarping",
543 resource
.workspace_warping
);
547 void BScreen::save_rc(void) {
548 saveSloppyFocus(resource
.sloppy_focus
);
549 saveAutoRaise(resource
.auto_raise
);
550 saveImageDither(doImageDither());
551 saveAAFonts(resource
.aa_fonts
);
552 saveResizeZones(resource
.resize_zones
);
553 saveOpaqueMove(resource
.opaque_move
);
554 saveFullMax(resource
.full_max
);
555 saveFocusNew(resource
.focus_new
);
556 saveFocusLast(resource
.focus_last
);
557 saveHideToolbar(resource
.hide_toolbar
);
558 saveWindowToWindowSnap(resource
.window_to_window_snap
);
559 saveWindowCornerSnap(resource
.window_corner_snap
);
560 saveWorkspaces(resource
.workspaces
);
561 savePlacementPolicy(resource
.placement_policy
);
562 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
563 saveRowPlacementDirection(resource
.row_direction
);
564 saveColPlacementDirection(resource
.col_direction
);
566 saveStrftimeFormat(resource
.strftime_format
);
567 #else // !HAVE_STRFTIME
568 saveDateFormat(resource
.date_format
);
569 savwClock24Hour(resource
.clock24hour
);
570 #endif // HAVE_STRFTIME
571 savePlaceIgnoreShaded(resource
.ignore_shaded
);
572 savePlaceIgnoreMaximized(resource
.ignore_maximized
);
573 saveAllowScrollLock(resource
.allow_scroll_lock
);
574 saveWorkspaceWarping(resource
.workspace_warping
);
581 void BScreen::load_rc(void) {
585 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
586 resource
.full_max
= false;
588 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
589 resource
.focus_new
= false;
591 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
592 resource
.focus_last
= false;
594 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
595 resource
.workspaces
= 1;
597 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
598 resource
.opaque_move
= false;
600 if (! config
->getValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
))
601 resource
.aa_fonts
= true;
603 if (! config
->getValue(screenstr
+ "resizeZones", resource
.resize_zones
) ||
604 (resource
.resize_zones
!= 1 && resource
.resize_zones
!= 2 &&
605 resource
.resize_zones
!= 4))
606 resource
.resize_zones
= 4;
608 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
609 resource
.hide_toolbar
= false;
611 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
612 resource
.window_to_window_snap
))
613 resource
.window_to_window_snap
= true;
615 if (! config
->getValue(screenstr
+ "windowCornerSnap",
616 resource
.window_corner_snap
))
617 resource
.window_corner_snap
= true;
619 if (! config
->getValue(screenstr
+ "imageDither", b
))
621 image_control
->setDither(b
);
623 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
624 resource
.edge_snap_threshold
))
625 resource
.edge_snap_threshold
= 4;
627 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
629 resource
.row_direction
= RightLeft
;
631 resource
.row_direction
= LeftRight
;
633 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
635 resource
.col_direction
= BottomTop
;
637 resource
.col_direction
= TopBottom
;
639 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
640 XAtom::StringVect workspaceNames
;
642 string::const_iterator it
= s
.begin(), end
= s
.end();
644 string::const_iterator tmp
= it
; // current string.begin()
645 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
646 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
652 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
656 resource
.sloppy_focus
= true;
657 resource
.auto_raise
= false;
658 resource
.click_raise
= false;
659 if (config
->getValue(screenstr
+ "focusModel", s
)) {
660 if (s
.find("ClickToFocus") != string::npos
) {
661 resource
.sloppy_focus
= false;
664 if (s
.find("AutoRaise") != string::npos
)
665 resource
.auto_raise
= true;
666 if (s
.find("ClickRaise") != string::npos
)
667 resource
.click_raise
= true;
671 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
672 if (s
== "CascadePlacement")
673 resource
.placement_policy
= CascadePlacement
;
674 else if (s
== "UnderMousePlacement")
675 resource
.placement_policy
= UnderMousePlacement
;
676 else if (s
== "ClickMousePlacement")
677 resource
.placement_policy
= ClickMousePlacement
;
678 else if (s
== "ColSmartPlacement")
679 resource
.placement_policy
= ColSmartPlacement
;
680 else //if (s == "RowSmartPlacement")
681 resource
.placement_policy
= RowSmartPlacement
;
683 resource
.placement_policy
= RowSmartPlacement
;
686 if (! config
->getValue(screenstr
+ "strftimeFormat",
687 resource
.strftime_format
))
688 resource
.strftime_format
= "%I:%M %p";
689 #else // !HAVE_STRFTIME
692 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
693 resource
.date_format
= B_EuropeanDate
;
695 resource
.date_format
= B_AmericanDate
;
697 if (! config
->getValue(screenstr
+ "clockFormat", l
))
699 resource
.clock24hour
= l
== 24;
700 #endif // HAVE_STRFTIME
702 if (! config
->getValue(screenstr
+ "placementIgnoreShaded",
703 resource
.ignore_shaded
))
704 resource
.ignore_shaded
= true;
706 if (! config
->getValue(screenstr
+ "placementIgnoreMaximized",
707 resource
.ignore_maximized
))
708 resource
.ignore_maximized
= true;
710 if (! config
->getValue(screenstr
+ "disableBindingsWithScrollLock",
711 resource
.allow_scroll_lock
))
712 resource
.allow_scroll_lock
= false;
714 if (! config
->getValue(screenstr
+ "workspaceWarping",
715 resource
.workspace_warping
))
716 resource
.workspace_warping
= false;
720 void BScreen::changeWorkspaceCount(unsigned int new_count
) {
721 assert(new_count
> 0);
723 if (new_count
< workspacesList
.size()) {
725 for (unsigned int i
= workspacesList
.size(); i
> new_count
; --i
)
726 removeLastWorkspace();
727 // removeLast already sets the current workspace to the
728 // last available one.
729 } else if (new_count
> workspacesList
.size()) {
731 for(unsigned int i
= workspacesList
.size(); i
< new_count
; ++i
)
737 void BScreen::reconfigure(void) {
738 // don't reconfigure while saving the initial rc file, it's a waste and it
739 // breaks somethings (workspace names)
740 if (blackbox
->isStartup()) return;
747 // we need to do this explicitly, because just loading this value from the rc
749 changeWorkspaceCount(resource
.workspaces
);
752 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
754 gcv
.function
= GXinvert
;
755 gcv
.subwindow_mode
= IncludeInferiors
;
756 XChangeGC(blackbox
->getXDisplay(), opGC
,
757 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
759 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
760 "0: 0000 x 0: 0000");
762 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
763 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
765 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
766 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
767 if (geom_pixmap
== ParentRelative
) {
768 texture
= &(resource
.wstyle
.t_focus
);
769 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
772 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
773 texture
->color().pixel());
775 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
776 geom_window
, geom_pixmap
);
778 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
779 resource
.border_width
);
780 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
781 resource
.border_color
.pixel());
783 workspacemenu
->reconfigure();
784 iconmenu
->reconfigure();
786 typedef std::vector
<int> SubList
;
787 SubList remember_subs
;
789 // save the current open menus
790 Basemenu
*menu
= rootmenu
;
792 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
793 remember_subs
.push_back(submenu
);
794 menu
= menu
->find(submenu
)->submenu();
800 rootmenu
->reconfigure();
802 // reopen the saved menus
804 const SubList::iterator subs_end
= remember_subs
.end();
805 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
806 menu
->drawSubmenu(*it
);
807 menu
= menu
->find(*it
)->submenu();
812 configmenu
->reconfigure();
814 toolbar
->reconfigure();
818 std::for_each(workspacesList
.begin(), workspacesList
.end(),
819 std::mem_fun(&Workspace::reconfigure
));
821 BlackboxWindowList::iterator iit
= iconList
.begin();
822 for (; iit
!= iconList
.end(); ++iit
) {
823 BlackboxWindow
*bw
= *iit
;
824 if (bw
->validateClient())
828 image_control
->timeout();
832 void BScreen::rereadMenu(void) {
836 rootmenu
->reconfigure();
840 void BScreen::LoadStyle(void) {
841 Configuration
style(False
);
843 const char *sfile
= blackbox
->getStyleFilename();
845 style
.setFile(sfile
);
846 if (! style
.load()) {
847 style
.setFile(DEFAULTSTYLE
);
849 style
.create(); // hardcoded default values will be used.
853 // merge in the rc file
854 style
.merge(config
->file(), True
);
858 // load fonts/fontsets
859 if (resource
.wstyle
.font
)
860 delete resource
.wstyle
.font
;
861 if (resource
.tstyle
.font
)
862 delete resource
.tstyle
.font
;
863 if (resource
.mstyle
.f_font
)
864 delete resource
.mstyle
.f_font
;
865 if (resource
.mstyle
.t_font
)
866 delete resource
.mstyle
.t_font
;
867 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
868 resource
.mstyle
.t_font
= (BFont
*) 0;
870 resource
.wstyle
.font
= readDatabaseFont("window.", style
);
871 resource
.tstyle
.font
= readDatabaseFont("toolbar.", style
);
872 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.", style
);
873 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.", style
);
875 // load window config
876 resource
.wstyle
.t_focus
=
877 readDatabaseTexture("window.title.focus", "white", style
);
878 resource
.wstyle
.t_unfocus
=
879 readDatabaseTexture("window.title.unfocus", "black", style
);
880 resource
.wstyle
.l_focus
=
881 readDatabaseTexture("window.label.focus", "white", style
);
882 resource
.wstyle
.l_unfocus
=
883 readDatabaseTexture("window.label.unfocus", "black", style
);
884 resource
.wstyle
.h_focus
=
885 readDatabaseTexture("window.handle.focus", "white", style
);
886 resource
.wstyle
.h_unfocus
=
887 readDatabaseTexture("window.handle.unfocus", "black", style
);
888 resource
.wstyle
.g_focus
=
889 readDatabaseTexture("window.grip.focus", "white", style
);
890 resource
.wstyle
.g_unfocus
=
891 readDatabaseTexture("window.grip.unfocus", "black", style
);
892 resource
.wstyle
.b_focus
=
893 readDatabaseTexture("window.button.focus", "white", style
);
894 resource
.wstyle
.b_unfocus
=
895 readDatabaseTexture("window.button.unfocus", "black", style
);
896 resource
.wstyle
.b_pressed
=
897 readDatabaseTexture("window.button.pressed", "black", style
);
898 resource
.wstyle
.f_focus
=
899 readDatabaseColor("window.frame.focusColor", "white", style
);
900 resource
.wstyle
.f_unfocus
=
901 readDatabaseColor("window.frame.unfocusColor", "black", style
);
902 resource
.wstyle
.l_text_focus
=
903 readDatabaseColor("window.label.focus.textColor", "black", style
);
904 resource
.wstyle
.l_text_unfocus
=
905 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
906 resource
.wstyle
.b_pic_focus
=
907 readDatabaseColor("window.button.focus.picColor", "black", style
);
908 resource
.wstyle
.b_pic_unfocus
=
909 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
911 resource
.wstyle
.justify
= LeftJustify
;
912 if (style
.getValue("window.justify", s
)) {
913 if (s
== "right" || s
== "Right")
914 resource
.wstyle
.justify
= RightJustify
;
915 else if (s
== "center" || s
== "Center")
916 resource
.wstyle
.justify
= CenterJustify
;
919 // load toolbar config
920 resource
.tstyle
.toolbar
=
921 readDatabaseTexture("toolbar", "black", style
);
922 resource
.tstyle
.label
=
923 readDatabaseTexture("toolbar.label", "black", style
);
924 resource
.tstyle
.window
=
925 readDatabaseTexture("toolbar.windowLabel", "black", style
);
926 resource
.tstyle
.button
=
927 readDatabaseTexture("toolbar.button", "white", style
);
928 resource
.tstyle
.pressed
=
929 readDatabaseTexture("toolbar.button.pressed", "black", style
);
930 resource
.tstyle
.clock
=
931 readDatabaseTexture("toolbar.clock", "black", style
);
932 resource
.tstyle
.l_text
=
933 readDatabaseColor("toolbar.label.textColor", "white", style
);
934 resource
.tstyle
.w_text
=
935 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
936 resource
.tstyle
.c_text
=
937 readDatabaseColor("toolbar.clock.textColor", "white", style
);
938 resource
.tstyle
.b_pic
=
939 readDatabaseColor("toolbar.button.picColor", "black", style
);
941 resource
.tstyle
.justify
= LeftJustify
;
942 if (style
.getValue("toolbar.justify", s
)) {
943 if (s
== "right" || s
== "Right")
944 resource
.tstyle
.justify
= RightJustify
;
945 else if (s
== "center" || s
== "Center")
946 resource
.tstyle
.justify
= CenterJustify
;
950 resource
.mstyle
.title
=
951 readDatabaseTexture("menu.title", "white", style
);
952 resource
.mstyle
.frame
=
953 readDatabaseTexture("menu.frame", "black", style
);
954 resource
.mstyle
.hilite
=
955 readDatabaseTexture("menu.hilite", "white", style
);
956 resource
.mstyle
.t_text
=
957 readDatabaseColor("menu.title.textColor", "black", style
);
958 resource
.mstyle
.f_text
=
959 readDatabaseColor("menu.frame.textColor", "white", style
);
960 resource
.mstyle
.d_text
=
961 readDatabaseColor("menu.frame.disableColor", "black", style
);
962 resource
.mstyle
.h_text
=
963 readDatabaseColor("menu.hilite.textColor", "black", style
);
965 resource
.mstyle
.t_justify
= LeftJustify
;
966 if (style
.getValue("menu.title.justify", s
)) {
967 if (s
== "right" || s
== "Right")
968 resource
.mstyle
.t_justify
= RightJustify
;
969 else if (s
== "center" || s
== "Center")
970 resource
.mstyle
.t_justify
= CenterJustify
;
973 resource
.mstyle
.f_justify
= LeftJustify
;
974 if (style
.getValue("menu.frame.justify", s
)) {
975 if (s
== "right" || s
== "Right")
976 resource
.mstyle
.f_justify
= RightJustify
;
977 else if (s
== "center" || s
== "Center")
978 resource
.mstyle
.f_justify
= CenterJustify
;
981 resource
.mstyle
.bullet
= Basemenu::Triangle
;
982 if (style
.getValue("menu.bullet", s
)) {
983 if (s
== "empty" || s
== "Empty")
984 resource
.mstyle
.bullet
= Basemenu::Empty
;
985 else if (s
== "square" || s
== "Square")
986 resource
.mstyle
.bullet
= Basemenu::Square
;
987 else if (s
== "diamond" || s
== "Diamond")
988 resource
.mstyle
.bullet
= Basemenu::Diamond
;
991 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
992 if (style
.getValue("menu.bullet.position", s
)) {
993 if (s
== "right" || s
== "Right")
994 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
997 resource
.border_color
=
998 readDatabaseColor("borderColor", "black", style
);
1000 // load bevel, border and handle widths
1001 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
1002 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
1003 resource
.handle_width
= 6;
1005 if (! style
.getValue("borderWidth", resource
.border_width
))
1006 resource
.border_width
= 1;
1008 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
1009 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
1010 resource
.bevel_width
= 3;
1012 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
1013 resource
.frame_width
> (getWidth() / 2))
1014 resource
.frame_width
= resource
.bevel_width
;
1016 if (style
.getValue("rootCommand", s
))
1017 bexec(s
, displayString());
1021 void BScreen::addIcon(BlackboxWindow
*w
) {
1024 w
->setWorkspace(BSENTINEL
);
1025 w
->setWindowNumber(iconList
.size());
1027 iconList
.push_back(w
);
1029 const char* title
= w
->getIconTitle();
1030 iconmenu
->insert(title
);
1035 void BScreen::removeIcon(BlackboxWindow
*w
) {
1040 iconmenu
->remove(w
->getWindowNumber());
1043 BlackboxWindowList::iterator it
= iconList
.begin(),
1044 end
= iconList
.end();
1045 for (int i
= 0; it
!= end
; ++it
)
1046 (*it
)->setWindowNumber(i
++);
1050 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
1051 if (index
< iconList
.size()) {
1052 BlackboxWindowList::iterator it
= iconList
.begin();
1053 for (; index
> 0; --index
, ++it
) ; /* increment to index */
1057 return (BlackboxWindow
*) 0;
1061 unsigned int BScreen::addWorkspace(void) {
1062 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
1063 workspacesList
.push_back(wkspc
);
1064 saveWorkspaces(getWorkspaceCount());
1065 saveWorkspaceNames();
1067 workspacemenu
->insertWorkspace(wkspc
);
1068 workspacemenu
->update();
1070 toolbar
->reconfigure();
1072 updateNetizenWorkspaceCount();
1074 return workspacesList
.size();
1078 unsigned int BScreen::removeLastWorkspace(void) {
1079 if (workspacesList
.size() == 1)
1082 Workspace
*wkspc
= workspacesList
.back();
1084 if (current_workspace
->getID() == wkspc
->getID())
1085 changeWorkspaceID(current_workspace
->getID() - 1);
1089 workspacemenu
->removeWorkspace(wkspc
);
1090 workspacemenu
->update();
1092 workspacesList
.pop_back();
1095 saveWorkspaces(getWorkspaceCount());
1096 saveWorkspaceNames();
1098 toolbar
->reconfigure();
1100 updateNetizenWorkspaceCount();
1102 return workspacesList
.size();
1106 void BScreen::changeWorkspaceID(unsigned int id
) {
1107 if (! current_workspace
|| id
== current_workspace
->getID()) return;
1109 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1110 if (focused
&& focused
->getScreen() == this) {
1111 assert(focused
->isStuck() ||
1112 focused
->getWorkspaceNumber() == current_workspace
->getID());
1114 current_workspace
->setLastFocusedWindow(focused
);
1116 // if no window had focus, no need to store a last focus
1117 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1120 // when we switch workspaces, unfocus whatever was focused
1121 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1123 current_workspace
->hideAll();
1124 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1126 current_workspace
= getWorkspace(id
);
1128 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1129 XAtom::cardinal
, id
);
1131 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1132 toolbar
->redrawWorkspaceLabel(True
);
1134 current_workspace
->showAll();
1136 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1137 XSync(blackbox
->getXDisplay(), False
);
1138 current_workspace
->getLastFocusedWindow()->setInputFocus();
1141 updateNetizenCurrentWorkspace();
1146 * Set the _NET_CLIENT_LIST root window property.
1148 void BScreen::updateClientList(void) {
1149 if (windowList
.size() > 0) {
1150 Window
*windows
= new Window
[windowList
.size()];
1151 Window
*win_it
= windows
;
1152 BlackboxWindowList::iterator it
= windowList
.begin();
1153 const BlackboxWindowList::iterator end
= windowList
.end();
1154 for (; it
!= end
; ++it
, ++win_it
)
1155 *win_it
= (*it
)->getClientWindow();
1156 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1157 windows
, windowList
.size());
1160 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1163 updateStackingList();
1168 * Set the _NET_CLIENT_LIST_STACKING root window property.
1170 void BScreen::updateStackingList(void) {
1172 BlackboxWindowList stack_order
;
1175 * Get the stacking order from all of the workspaces.
1176 * We start with the current workspace so that the sticky windows will be
1177 * in the right order on the current workspace.
1178 * XXX: Do we need to have sticky windows in the list once for each workspace?
1180 getCurrentWorkspace()->appendStackOrder(stack_order
);
1181 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1182 if (i
!= getCurrentWorkspaceID())
1183 getWorkspace(i
)->appendStackOrder(stack_order
);
1185 if (stack_order
.size() > 0) {
1186 // set the client list atoms
1187 Window
*windows
= new Window
[stack_order
.size()];
1188 Window
*win_it
= windows
;
1189 BlackboxWindowList::iterator it
= stack_order
.begin(),
1190 end
= stack_order
.end();
1191 for (; it
!= end
; ++it
, ++win_it
)
1192 *win_it
= (*it
)->getClientWindow();
1193 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1194 XAtom::window
, windows
, stack_order
.size());
1197 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1198 XAtom::window
, 0, 0);
1202 void BScreen::addSystrayWindow(Window window
) {
1203 systrayWindowList
.push_back(window
);
1204 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1206 &systrayWindowList
[0], systrayWindowList
.size());
1207 blackbox
->saveSystrayWindowSearch(window
, this);
1211 void BScreen::removeSystrayWindow(Window window
) {
1212 WindowList::iterator it
= systrayWindowList
.begin();
1213 const WindowList::iterator end
= systrayWindowList
.end();
1214 for (; it
!= end
; ++it
)
1215 if (*it
== window
) {
1216 systrayWindowList
.erase(it
);
1217 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1219 &systrayWindowList
[0], systrayWindowList
.size());
1220 blackbox
->removeSystrayWindowSearch(window
);
1226 void BScreen::manageWindow(Window w
) {
1227 // is the window a KDE systray window?
1229 if (xatom
->getValue(w
, XAtom::kde_net_wm_system_tray_window_for
,
1230 XAtom::window
, systray
) && systray
) {
1231 addSystrayWindow(w
);
1235 // is the window a docking app
1236 XWMHints
*wmhint
= XGetWMHints(blackbox
->getXDisplay(), w
);
1237 if (wmhint
&& (wmhint
->flags
& StateHint
) &&
1238 wmhint
->initial_state
== WithdrawnState
) {
1243 new BlackboxWindow(blackbox
, w
, this);
1245 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1250 if (win
->isNormal()) {
1251 // don't list non-normal windows as managed windows
1252 windowList
.push_back(win
);
1254 } else if (win
->isDesktop()) {
1255 desktopWindowList
.push_back(win
->getFrameWindow());
1258 XMapRequestEvent mre
;
1260 if (blackbox
->isStartup() && win
->isNormal()) win
->restoreAttributes();
1261 win
->mapRequestEvent(&mre
);
1265 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1268 // Remove the modality so that its parent won't try to re-focus the window
1269 if (w
->isModal()) w
->setModal(False
);
1271 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1272 w
->getWindowNumber() != BSENTINEL
)
1273 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1274 else if (w
->isIconic())
1277 if (w
->isNormal()) {
1278 // we don't list non-normal windows as managed windows
1279 windowList
.remove(w
);
1281 } else if (w
->isDesktop()) {
1282 WindowList::iterator it
= desktopWindowList
.begin();
1283 const WindowList::iterator end
= desktopWindowList
.end();
1284 for (; it
!= end
; ++it
)
1285 if (*it
== w
->getFrameWindow()) {
1286 desktopWindowList
.erase(it
);
1289 assert(it
!= end
); // the window wasnt a desktop window?
1292 if (blackbox
->getFocusedWindow() == w
)
1293 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1295 removeNetizen(w
->getClientWindow());
1298 some managed windows can also be window group controllers. when
1299 unmanaging such windows, we should also delete the window group.
1301 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1308 void BScreen::addNetizen(Netizen
*n
) {
1309 netizenList
.push_back(n
);
1311 n
->sendWorkspaceCount();
1312 n
->sendCurrentWorkspace();
1314 WorkspaceList::iterator it
= workspacesList
.begin();
1315 const WorkspaceList::iterator end
= workspacesList
.end();
1316 for (; it
!= end
; ++it
)
1317 (*it
)->sendWindowList(*n
);
1319 Window f
= ((blackbox
->getFocusedWindow()) ?
1320 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1321 n
->sendWindowFocus(f
);
1325 void BScreen::removeNetizen(Window w
) {
1326 NetizenList::iterator it
= netizenList
.begin();
1327 for (; it
!= netizenList
.end(); ++it
) {
1328 if ((*it
)->getWindowID() == w
) {
1330 netizenList
.erase(it
);
1337 void BScreen::updateWorkArea(void) {
1338 if (workspacesList
.size() > 0) {
1339 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1340 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1341 // XXX: this could be different for each workspace
1342 const Rect
&area
= availableArea();
1343 dims
[(i
* 4) + 0] = area
.x();
1344 dims
[(i
* 4) + 1] = area
.y();
1345 dims
[(i
* 4) + 2] = area
.width();
1346 dims
[(i
* 4) + 3] = area
.height();
1348 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1349 dims
, 4 * workspacesList
.size());
1352 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1357 void BScreen::updateNetizenCurrentWorkspace(void) {
1358 std::for_each(netizenList
.begin(), netizenList
.end(),
1359 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1363 void BScreen::updateNetizenWorkspaceCount(void) {
1364 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1365 XAtom::cardinal
, workspacesList
.size());
1369 std::for_each(netizenList
.begin(), netizenList
.end(),
1370 std::mem_fun(&Netizen::sendWorkspaceCount
));
1374 void BScreen::updateNetizenWindowFocus(void) {
1375 Window f
= ((blackbox
->getFocusedWindow()) ?
1376 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1378 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1381 NetizenList::iterator it
= netizenList
.begin();
1382 for (; it
!= netizenList
.end(); ++it
)
1383 (*it
)->sendWindowFocus(f
);
1387 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1388 NetizenList::iterator it
= netizenList
.begin();
1389 for (; it
!= netizenList
.end(); ++it
) {
1390 (*it
)->sendWindowAdd(w
, p
);
1395 void BScreen::updateNetizenWindowDel(Window w
) {
1396 NetizenList::iterator it
= netizenList
.begin();
1397 for (; it
!= netizenList
.end(); ++it
)
1398 (*it
)->sendWindowDel(w
);
1402 void BScreen::updateNetizenWindowRaise(Window w
) {
1403 NetizenList::iterator it
= netizenList
.begin();
1404 for (; it
!= netizenList
.end(); ++it
)
1405 (*it
)->sendWindowRaise(w
);
1409 void BScreen::updateNetizenWindowLower(Window w
) {
1410 NetizenList::iterator it
= netizenList
.begin();
1411 for (; it
!= netizenList
.end(); ++it
)
1412 (*it
)->sendWindowLower(w
);
1416 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1417 NetizenList::iterator it
= netizenList
.begin();
1418 for (; it
!= netizenList
.end(); ++it
)
1419 (*it
)->sendConfigNotify(e
);
1423 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1424 // the 13 represents the number of blackbox windows such as menus
1430 Window
*session_stack
= new
1431 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + bbwins
)];
1432 unsigned int i
= 0, k
= num
;
1434 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1435 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1437 WorkspaceList::iterator wit
= workspacesList
.begin();
1438 const WorkspaceList::iterator w_end
= workspacesList
.end();
1439 for (; wit
!= w_end
; ++wit
)
1440 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1442 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1444 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1445 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1447 *(session_stack
+ i
++) = configmenu
->getXineramamenu()->getWindowID();
1449 *(session_stack
+ i
++) = configmenu
->getWindowID();
1451 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1452 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1453 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1455 *(session_stack
+ i
++) =
1456 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1457 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1459 RootmenuList::iterator rit
= rootmenuList
.begin();
1460 for (; rit
!= rootmenuList
.end(); ++rit
)
1461 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1462 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1464 if (toolbar
->isOnTop())
1465 *(session_stack
+ i
++) = toolbar
->getWindowID();
1467 if (slit
->isOnTop())
1468 *(session_stack
+ i
++) = slit
->getWindowID();
1471 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1473 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1475 delete [] session_stack
;
1477 updateStackingList();
1481 void BScreen::lowerWindows(Window
*workspace_stack
, unsigned int num
) {
1482 assert(num
> 0); // this would cause trouble in the XRaiseWindow call
1484 Window
*session_stack
= new Window
[(num
+ desktopWindowList
.size())];
1485 unsigned int i
= 0, k
= num
;
1487 XLowerWindow(blackbox
->getXDisplay(), workspace_stack
[0]);
1490 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1492 WindowList::iterator dit
= desktopWindowList
.begin();
1493 const WindowList::iterator d_end
= desktopWindowList
.end();
1494 for (; dit
!= d_end
; ++dit
)
1495 *(session_stack
+ i
++) = *dit
;
1497 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1499 delete [] session_stack
;
1501 updateStackingList();
1505 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1506 bool ignore_sticky
) {
1509 if (wkspc_id
== BSENTINEL
)
1510 wkspc_id
= current_workspace
->getID();
1512 if (w
->getWorkspaceNumber() == wkspc_id
)
1515 if (w
->isIconic()) {
1517 getWorkspace(wkspc_id
)->addWindow(w
);
1518 } else if (ignore_sticky
|| ! w
->isStuck()) {
1521 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1522 getWorkspace(wkspc_id
)->addWindow(w
);
1524 updateStackingList();
1528 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1529 if (bw
->isIconic()) {
1530 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1534 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1535 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1536 clientmenu
->update();
1538 if (blackbox
->getFocusedWindow() == bw
)
1539 toolbar
->redrawWindowLabel(True
);
1544 void BScreen::nextFocus(void) {
1545 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1549 // if window is not on this screen, ignore it
1550 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1551 focused
= (BlackboxWindow
*) 0;
1554 if (focused
&& current_workspace
->getCount() > 1) {
1555 // next is the next window to recieve focus, current is a place holder
1556 BlackboxWindow
*current
;
1559 next
= current_workspace
->getNextWindowInList(current
);
1560 } while(! next
->setInputFocus() && next
!= focused
);
1562 if (next
!= focused
)
1563 current_workspace
->raiseWindow(next
);
1564 } else if (current_workspace
->getCount() >= 1) {
1565 next
= current_workspace
->getTopWindowOnStack();
1567 current_workspace
->raiseWindow(next
);
1568 next
->setInputFocus();
1573 void BScreen::prevFocus(void) {
1574 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1578 // if window is not on this screen, ignore it
1579 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1580 focused
= (BlackboxWindow
*) 0;
1583 if (focused
&& current_workspace
->getCount() > 1) {
1584 // next is the next window to recieve focus, current is a place holder
1585 BlackboxWindow
*current
;
1588 next
= current_workspace
->getPrevWindowInList(current
);
1589 } while(! next
->setInputFocus() && next
!= focused
);
1591 if (next
!= focused
)
1592 current_workspace
->raiseWindow(next
);
1593 } else if (current_workspace
->getCount() >= 1) {
1594 next
= current_workspace
->getTopWindowOnStack();
1596 current_workspace
->raiseWindow(next
);
1597 next
->setInputFocus();
1602 void BScreen::raiseFocus(void) {
1603 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1607 // if on this Screen, raise it
1608 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1609 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1610 workspace
->raiseWindow(focused
);
1615 void BScreen::InitMenu(void) {
1617 rootmenuList
.clear();
1619 while (rootmenu
->getCount())
1620 rootmenu
->remove(0);
1622 rootmenu
= new Rootmenu(this);
1624 bool defaultMenu
= True
;
1626 FILE *menu_file
= (FILE *) 0;
1627 const char *menu_filename
= blackbox
->getMenuFilename();
1630 if (! (menu_file
= fopen(menu_filename
, "r")))
1631 perror(menu_filename
);
1632 if (! menu_file
) { // opening the menu file failed, try the default menu
1633 menu_filename
= DEFAULTMENU
;
1634 if (! (menu_file
= fopen(menu_filename
, "r")))
1635 perror(menu_filename
);
1639 if (feof(menu_file
)) {
1640 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1641 "%s: Empty menu file"),
1644 char line
[1024], label
[1024];
1645 memset(line
, 0, 1024);
1646 memset(label
, 0, 1024);
1648 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1649 if (line
[0] != '#') {
1650 int i
, key
= 0, index
= -1, len
= strlen(line
);
1652 for (i
= 0; i
< len
; i
++) {
1653 if (line
[i
] == '[') index
= 0;
1654 else if (line
[i
] == ']') break;
1655 else if (line
[i
] != ' ')
1657 key
+= tolower(line
[i
]);
1660 if (key
== 517) { // [begin]
1662 for (i
= index
; i
< len
; i
++) {
1663 if (line
[i
] == '(') index
= 0;
1664 else if (line
[i
] == ')') break;
1665 else if (index
++ >= 0) {
1666 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1667 label
[index
- 1] = line
[i
];
1671 if (index
== -1) index
= 0;
1672 label
[index
] = '\0';
1674 rootmenu
->setLabel(label
);
1675 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1677 blackbox
->addMenuTimestamp(menu_filename
);
1687 rootmenu
->setInternalMenu();
1688 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1690 i18n(ScreenSet
, Screenxterm
, "xterm"));
1691 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1693 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1695 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1701 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1702 char line
[1024], label
[1024], command
[1024];
1704 while (! feof(file
)) {
1705 memset(line
, 0, 1024);
1706 memset(label
, 0, 1024);
1707 memset(command
, 0, 1024);
1709 if (fgets(line
, 1024, file
)) {
1710 if (line
[0] != '#') {
1711 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1713 // determine the keyword
1714 for (i
= 0; i
< line_length
; i
++) {
1715 if (line
[i
] == '[') parse
= 1;
1716 else if (line
[i
] == ']') break;
1717 else if (line
[i
] != ' ')
1719 key
+= tolower(line
[i
]);
1722 // get the label enclosed in ()'s
1725 for (i
= 0; i
< line_length
; i
++) {
1726 if (line
[i
] == '(') {
1729 } else if (line
[i
] == ')') break;
1730 else if (index
++ >= 0) {
1731 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1732 label
[index
- 1] = line
[i
];
1737 label
[index
] = '\0';
1742 // get the command enclosed in {}'s
1745 for (i
= 0; i
< line_length
; i
++) {
1746 if (line
[i
] == '{') {
1749 } else if (line
[i
] == '}') break;
1750 else if (index
++ >= 0) {
1751 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1752 command
[index
- 1] = line
[i
];
1757 command
[index
] = '\0';
1764 return ((menu
->getCount() == 0) ? True
: False
);
1771 menu
->insert(label
);
1776 if (! (*label
&& *command
)) {
1777 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1778 "BScreen::parseMenuFile: [exec] error, "
1779 "no menu label and/or command defined\n"));
1783 menu
->insert(label
, BScreen::Execute
, command
);
1789 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1790 "BScreen::parseMenuFile: [exit] error, "
1791 "no menu label defined\n"));
1795 menu
->insert(label
, BScreen::Exit
);
1799 case 561: { // style
1800 if (! (*label
&& *command
)) {
1802 i18n(ScreenSet
, ScreenSTYLEError
,
1803 "BScreen::parseMenuFile: [style] error, "
1804 "no menu label and/or filename defined\n"));
1808 string style
= expandTilde(command
);
1810 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1816 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1817 "BScreen::parseMenufile: [config] error, "
1818 "no label defined"));
1822 menu
->insert(label
, configmenu
);
1826 case 740: // include
1829 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1830 "BScreen::parseMenuFile: [include] error, "
1831 "no filename defined\n"));
1835 string newfile
= expandTilde(label
);
1836 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1840 if (fstat(fileno(submenufile
), &buf
) ||
1841 ! S_ISREG(buf
.st_mode
)) {
1843 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1844 "BScreen::parseMenuFile: [include] error: "
1845 "'%s' is not a regular file\n"), newfile
.c_str());
1849 if (! feof(submenufile
)) {
1850 if (! parseMenuFile(submenufile
, menu
))
1851 blackbox
->addMenuTimestamp(newfile
);
1853 fclose(submenufile
);
1856 perror(newfile
.c_str());
1862 case 767: // submenu
1865 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1866 "BScreen::parseMenuFile: [submenu] error, "
1867 "no menu label defined\n"));
1871 Rootmenu
*submenu
= new Rootmenu(this);
1874 submenu
->setLabel(command
);
1876 submenu
->setLabel(label
);
1878 parseMenuFile(file
, submenu
);
1880 menu
->insert(label
, submenu
);
1881 rootmenuList
.push_back(submenu
);
1886 case 773: // restart
1889 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1890 "BScreen::parseMenuFile: [restart] error, "
1891 "no menu label defined\n"));
1896 menu
->insert(label
, BScreen::RestartOther
, command
);
1898 menu
->insert(label
, BScreen::Restart
);
1903 case 845: // reconfig
1907 i18n(ScreenSet
, ScreenRECONFIGError
,
1908 "BScreen::parseMenuFile: [reconfig] error, "
1909 "no menu label defined\n"));
1913 menu
->insert(label
, BScreen::Reconfigure
);
1918 case 995: // stylesdir
1919 case 1113: // stylesmenu
1921 bool newmenu
= ((key
== 1113) ? True
: False
);
1923 if (! *label
|| (! *command
&& newmenu
)) {
1925 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1926 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1927 " error, no directory defined\n"));
1931 char *directory
= ((newmenu
) ? command
: label
);
1933 string stylesdir
= expandTilde(directory
);
1935 struct stat statbuf
;
1937 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1938 if (S_ISDIR(statbuf
.st_mode
)) {
1939 Rootmenu
*stylesmenu
;
1942 stylesmenu
= new Rootmenu(this);
1946 DIR *d
= opendir(stylesdir
.c_str());
1948 std::vector
<string
> ls
;
1950 while((p
= readdir(d
)))
1951 ls
.push_back(p
->d_name
);
1955 std::sort(ls
.begin(), ls
.end());
1957 std::vector
<string
>::iterator it
= ls
.begin(),
1959 for (; it
!= end
; ++it
) {
1960 const string
& fname
= *it
;
1962 if (fname
[fname
.size()-1] == '~')
1965 string style
= stylesdir
;
1969 if (! stat(style
.c_str(), &statbuf
) &&
1970 S_ISREG(statbuf
.st_mode
))
1971 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1974 stylesmenu
->update();
1977 stylesmenu
->setLabel(label
);
1978 menu
->insert(label
, stylesmenu
);
1979 rootmenuList
.push_back(stylesmenu
);
1982 blackbox
->addMenuTimestamp(stylesdir
);
1985 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1986 "BScreen::parseMenuFile:"
1987 " [stylesdir/stylesmenu] error, %s is not a"
1988 " directory\n"), stylesdir
.c_str());
1992 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1993 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1994 " error, %s does not exist\n"), stylesdir
.c_str());
1999 case 1090: // workspaces
2003 i18n(ScreenSet
, ScreenWORKSPACESError
,
2004 "BScreen:parseMenuFile: [workspaces] error, "
2005 "no menu label defined\n"));
2009 menu
->insert(label
, workspacemenu
);
2018 return ((menu
->getCount() == 0) ? True
: False
);
2022 void BScreen::shutdown(void) {
2023 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
2024 XSync(blackbox
->getXDisplay(), False
);
2026 while(! windowList
.empty())
2027 unmanageWindow(windowList
.front(), True
);
2033 void BScreen::showPosition(int x
, int y
) {
2034 if (! geom_visible
) {
2035 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
2036 (getWidth() - geom_w
) / 2,
2037 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
2038 XMapWindow(blackbox
->getXDisplay(), geom_window
);
2039 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
2041 geom_visible
= True
;
2046 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
2047 "X: %4d x Y: %4d"), x
, y
);
2049 XClearWindow(blackbox
->getXDisplay(), geom_window
);
2051 resource
.wstyle
.font
->drawString(geom_window
,
2052 resource
.bevel_width
, resource
.bevel_width
,
2053 resource
.wstyle
.l_text_focus
,
2058 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
2059 if (! geom_visible
) {
2060 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
2061 (getWidth() - geom_w
) / 2,
2062 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
2063 XMapWindow(blackbox
->getXDisplay(), geom_window
);
2064 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
2066 geom_visible
= True
;
2071 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
2072 "W: %4d x H: %4d"), gx
, gy
);
2074 XClearWindow(blackbox
->getXDisplay(), geom_window
);
2076 resource
.wstyle
.font
->drawString(geom_window
,
2077 resource
.bevel_width
, resource
.bevel_width
,
2078 resource
.wstyle
.l_text_focus
,
2083 void BScreen::hideGeometry(void) {
2085 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
2086 geom_visible
= False
;
2091 void BScreen::addStrut(Strut
*strut
) {
2092 strutList
.push_back(strut
);
2096 void BScreen::removeStrut(Strut
*strut
) {
2097 strutList
.remove(strut
);
2101 const Rect
& BScreen::availableArea(void) const {
2103 return getRect(); // return the full screen
2109 const RectList
& BScreen::allAvailableAreas(void) const {
2110 assert(isXineramaActive());
2111 assert(xineramaUsableArea
.size() > 0);
2112 fprintf(stderr
, "1found x %d y %d w %d h %d\n",
2113 xineramaUsableArea
[0].x(), xineramaUsableArea
[0].y(),
2114 xineramaUsableArea
[0].width(), xineramaUsableArea
[0].height());
2115 return xineramaUsableArea
;
2120 void BScreen::updateAvailableArea(void) {
2121 Rect old_area
= usableArea
;
2122 usableArea
= getRect(); // reset to full screen
2125 // reset to the full areas
2126 if (isXineramaActive())
2127 xineramaUsableArea
= getXineramaAreas();
2130 /* these values represent offsets from the screen edge
2131 * we look for the biggest offset on each edge and then apply them
2133 * do not be confused by the similarity to the names of Rect's members
2135 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
2138 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
2140 for(; it
!= end
; ++it
) {
2142 if (strut
->left
> current_left
)
2143 current_left
= strut
->left
;
2144 if (strut
->top
> current_top
)
2145 current_top
= strut
->top
;
2146 if (strut
->right
> current_right
)
2147 current_right
= strut
->right
;
2148 if (strut
->bottom
> current_bottom
)
2149 current_bottom
= strut
->bottom
;
2152 usableArea
.setPos(current_left
, current_top
);
2153 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2154 usableArea
.height() - (current_top
+ current_bottom
));
2157 if (isXineramaActive()) {
2158 // keep each of the ximerama-defined areas inside the strut
2159 RectList::iterator xit
, xend
= xineramaUsableArea
.end();
2160 for (xit
= xineramaUsableArea
.begin(); xit
!= xend
; ++xit
) {
2161 if (xit
->x() < usableArea
.x()) {
2162 xit
->setX(usableArea
.x());
2163 xit
->setWidth(xit
->width() - usableArea
.x());
2165 if (xit
->y() < usableArea
.y()) {
2166 xit
->setY(usableArea
.y());
2167 xit
->setHeight(xit
->height() - usableArea
.y());
2169 if (xit
->x() + xit
->width() > usableArea
.width())
2170 xit
->setWidth(usableArea
.width() - xit
->x());
2171 if (xit
->y() + xit
->height() > usableArea
.height())
2172 xit
->setHeight(usableArea
.height() - xit
->y());
2177 if (old_area
!= usableArea
) {
2178 BlackboxWindowList::iterator it
= windowList
.begin(),
2179 end
= windowList
.end();
2180 for (; it
!= end
; ++it
)
2181 if ((*it
)->isMaximized()) (*it
)->remaximize();
2188 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2189 assert(index
< workspacesList
.size());
2190 return workspacesList
[index
];
2194 void BScreen::buttonPressEvent(const XButtonEvent
*xbutton
) {
2195 if (xbutton
->button
== 1) {
2196 if (! isRootColormapInstalled())
2197 image_control
->installRootColormap();
2199 if (workspacemenu
->isVisible())
2200 workspacemenu
->hide();
2202 if (rootmenu
->isVisible())
2204 } else if (xbutton
->button
== 2) {
2205 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2206 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2211 if (mx
+ workspacemenu
->getWidth() > getWidth())
2212 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2214 if (my
+ workspacemenu
->getHeight() > getHeight())
2215 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2217 workspacemenu
->move(mx
, my
);
2219 if (! workspacemenu
->isVisible()) {
2220 workspacemenu
->removeParent();
2221 workspacemenu
->show();
2223 } else if (xbutton
->button
== 3) {
2224 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2225 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2230 if (mx
+ rootmenu
->getWidth() > getWidth())
2231 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2233 if (my
+ rootmenu
->getHeight() > getHeight())
2234 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2236 rootmenu
->move(mx
, my
);
2238 if (! rootmenu
->isVisible()) {
2239 blackbox
->checkMenu();
2243 } else if (xbutton
->button
== 4) {
2244 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2245 changeWorkspaceID(0);
2247 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2249 } else if (xbutton
->button
== 5) {
2250 if (getCurrentWorkspaceID() == 0)
2251 changeWorkspaceID(getWorkspaceCount() - 1);
2253 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2258 void BScreen::propertyNotifyEvent(const XPropertyEvent
*pe
) {
2259 if (pe
->atom
== xatom
->getAtom(XAtom::net_desktop_names
)) {
2260 // _NET_WM_DESKTOP_NAMES
2261 WorkspaceList::iterator it
= workspacesList
.begin();
2262 const WorkspaceList::iterator end
= workspacesList
.end();
2263 for (; it
!= end
; ++it
) {
2264 (*it
)->readName(); // re-read its name from the window property
2265 workspacemenu
->changeWorkspaceLabel((*it
)->getID(), (*it
)->getName());
2267 workspacemenu
->update();
2268 toolbar
->reconfigure();
2269 saveWorkspaceNames();
2274 void BScreen::toggleFocusModel(FocusModel model
) {
2275 std::for_each(windowList
.begin(), windowList
.end(),
2276 std::mem_fun(&BlackboxWindow::ungrabButtons
));
2278 if (model
== SloppyFocus
) {
2279 saveSloppyFocus(True
);
2281 // we're cheating here to save writing the config file 3 times
2282 resource
.auto_raise
= False
;
2283 resource
.click_raise
= False
;
2284 saveSloppyFocus(False
);
2287 std::for_each(windowList
.begin(), windowList
.end(),
2288 std::mem_fun(&BlackboxWindow::grabButtons
));
2292 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2293 const string
&default_color
,
2294 const Configuration
&style
) {
2298 if (style
.getValue(rname
, s
))
2299 texture
= BTexture(s
);
2301 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2303 // associate this texture with this screen
2304 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2305 texture
.setImageControl(image_control
);
2307 if (texture
.texture() & BTexture::Solid
) {
2308 texture
.setColor(readDatabaseColor(rname
+ ".color",
2309 default_color
, style
));
2310 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2311 default_color
, style
));
2312 } else if (texture
.texture() & BTexture::Gradient
) {
2313 texture
.setColor(readDatabaseColor(rname
+ ".color",
2314 default_color
, style
));
2315 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2316 default_color
, style
));
2323 BColor
BScreen::readDatabaseColor(const string
&rname
,
2324 const string
&default_color
,
2325 const Configuration
&style
) {
2328 if (style
.getValue(rname
, s
))
2329 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2331 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2336 BFont
*BScreen::readDatabaseFont(const string
&rbasename
,
2337 const Configuration
&style
) {
2344 if (style
.getValue(rbasename
+ "xft.font", s
) &&
2345 style
.getValue(rbasename
+ "xft.size", i
)) {
2348 bool italic
= False
;
2349 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
2350 if (s
.find("bold") != string::npos
)
2352 if (s
.find("italic") != string::npos
)
2356 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, family
, i
, bold
,
2357 italic
, resource
.aa_fonts
);
2361 delete b
; // fall back to the normal X font stuff
2365 style
.getValue(rbasename
+ "font", s
);
2366 // if this fails, a blank string will be used, which will cause the fallback
2369 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2371 exit(2); // can't continue without a font