1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Screen.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
24 #include "../config.h"
27 #include <X11/Xatom.h>
28 #include <X11/keysym.h>
32 #endif // HAVE_STDLIB_H
36 #endif // HAVE_STRING_H
40 #endif // HAVE_CTYPE_H
43 # include <sys/types.h>
45 #endif // HAVE_UNISTD_H
49 #endif // HAVE_DIRENT_H
53 #endif // HAVE_LOCALE_H
55 #ifdef HAVE_SYS_STAT_H
56 # include <sys/stat.h>
57 #endif // HAVE_SYS_STAT_H
61 #endif // HAVE_STDARG_H
72 #include "blackbox.hh"
73 #include "Clientmenu.hh"
76 #include "Iconmenu.hh"
80 #include "Rootmenu.hh"
84 #include "Workspace.hh"
85 #include "Workspacemenu.hh"
88 #ifndef FONT_ELEMENT_SIZE
89 #define FONT_ELEMENT_SIZE 50
90 #endif // FONT_ELEMENT_SIZE
93 static bool running
= True
;
95 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
96 fprintf(stderr
, i18n(ScreenSet
, ScreenAnotherWMRunning
,
97 "BScreen::BScreen: an error occured while querying the X server.\n"
98 " another window manager already running on display %s.\n"),
99 DisplayString(display
));
107 BScreen::BScreen(Blackbox
*bb
, unsigned int scrn
) : ScreenInfo(bb
, scrn
) {
109 screenstr
= "session.screen" + itostring(scrn
) + '.';
110 config
= blackbox
->getConfig();
111 xatom
= blackbox
->getXAtom();
113 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
114 SubstructureRedirectMask
| ButtonPressMask
| ButtonReleaseMask
;
116 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
117 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask
);
118 XSync(getBaseDisplay()->getXDisplay(), False
);
119 XSetErrorHandler((XErrorHandler
) old
);
122 if (! managed
) return;
124 fprintf(stderr
, i18n(ScreenSet
, ScreenManagingScreen
,
125 "BScreen::BScreen: managing screen %d "
126 "using visual 0x%lx, depth %d\n"),
127 getScreenNumber(), XVisualIDFromVisual(getVisual()),
132 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
133 resource
.wstyle
.font
= (BFont
*) 0;
137 xatom
->setSupported(this); // set-up netwm support
139 xatom
->setValue(getRootWindow(), XAtom::blackbox_pid
, XAtom::cardinal
,
140 (unsigned long) getpid());
141 #endif // HAVE_GETPID
142 unsigned long geometry
[] = { getWidth(),
144 xatom
->setValue(getRootWindow(), XAtom::net_desktop_geometry
,
145 XAtom::cardinal
, geometry
, 2);
146 unsigned long viewport
[] = {0,0};
147 xatom
->setValue(getRootWindow(), XAtom::net_desktop_viewport
,
148 XAtom::cardinal
, viewport
, 2);
151 XDefineCursor(blackbox
->getXDisplay(), getRootWindow(),
152 blackbox
->getSessionCursor());
154 // start off full screen, top left.
155 usableArea
.setSize(getWidth(), getHeight());
158 new BImageControl(blackbox
, this, True
, blackbox
->getColorsPerChannel(),
159 blackbox
->getCacheLife(), blackbox
->getCacheMax());
160 image_control
->installRootColormap();
161 root_colormap_installed
= True
;
167 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(), getScreenNumber())
168 ^ BlackPixel(blackbox
->getXDisplay(), getScreenNumber());
169 gcv
.function
= GXxor
;
170 gcv
.subwindow_mode
= IncludeInferiors
;
171 opGC
= XCreateGC(blackbox
->getXDisplay(), getRootWindow(),
172 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
174 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
175 "0: 0000 x 0: 0000");
176 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
177 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
179 XSetWindowAttributes attrib
;
180 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
181 attrib
.border_pixel
= getBorderColor()->pixel();
182 attrib
.colormap
= getColormap();
183 attrib
.save_under
= True
;
185 geom_window
= XCreateWindow(blackbox
->getXDisplay(), getRootWindow(),
186 0, 0, geom_w
, geom_h
, resource
.border_width
,
187 getDepth(), InputOutput
, getVisual(),
189 geom_visible
= False
;
191 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
192 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
193 if (geom_pixmap
== ParentRelative
) {
194 texture
= &(resource
.wstyle
.t_focus
);
195 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
198 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
199 texture
->color().pixel());
201 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
202 geom_window
, geom_pixmap
);
204 workspacemenu
= new Workspacemenu(this);
205 iconmenu
= new Iconmenu(this);
206 configmenu
= new Configmenu(this);
208 if (resource
.workspaces
!= 0) {
209 for (unsigned int i
= 0; i
< resource
.workspaces
; ++i
) {
210 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
211 workspacesList
.push_back(wkspc
);
212 workspacemenu
->insertWorkspace(wkspc
);
213 workspacemenu
->update();
217 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
218 workspacesList
.push_back(wkspc
);
219 workspacemenu
->insertWorkspace(wkspc
);
220 workspacemenu
->update();
222 saveWorkspaceNames();
224 updateNetizenWorkspaceCount();
226 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
227 workspacemenu
->update();
229 current_workspace
= workspacesList
.front();
231 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
232 XAtom::cardinal
, 0); //first workspace
234 //workspacemenu->setItemSelected(2, True);
236 toolbar
= new Toolbar(this);
238 slit
= new Slit(this);
242 raiseWindows(0, 0); // this also initializes the empty stacking list
245 updateClientList(); // initialize the client lists, which will be empty
246 updateAvailableArea();
248 changeWorkspaceID(0);
250 unsigned int i
, j
, nchild
;
251 Window r
, p
, *children
;
252 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
255 // preen the window list of all icon windows... for better dockapp support
256 for (i
= 0; i
< nchild
; i
++) {
257 if (children
[i
] == None
) continue;
259 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
263 if ((wmhints
->flags
& IconWindowHint
) &&
264 (wmhints
->icon_window
!= children
[i
])) {
265 for (j
= 0; j
< nchild
; j
++) {
266 if (children
[j
] == wmhints
->icon_window
) {
277 // manage shown windows
278 for (i
= 0; i
< nchild
; ++i
) {
279 if (children
[i
] == None
|| (! blackbox
->validateWindow(children
[i
])))
282 XWindowAttributes attrib
;
283 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
284 if (attrib
.override_redirect
) continue;
286 if (attrib
.map_state
!= IsUnmapped
) {
287 manageWindow(children
[i
]);
294 // call this again just in case a window we found updates the Strut list
295 updateAvailableArea();
299 BScreen::~BScreen(void) {
300 if (! managed
) return;
302 if (geom_pixmap
!= None
)
303 image_control
->removeImage(geom_pixmap
);
305 if (geom_window
!= None
)
306 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
308 std::for_each(workspacesList
.begin(), workspacesList
.end(),
311 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
313 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
315 while (! systrayWindowList
.empty())
316 removeSystrayWindow(systrayWindowList
[0]);
319 delete workspacemenu
;
324 delete image_control
;
326 if (resource
.wstyle
.font
)
327 delete resource
.wstyle
.font
;
328 if (resource
.mstyle
.t_font
)
329 delete resource
.mstyle
.t_font
;
330 if (resource
.mstyle
.f_font
)
331 delete resource
.mstyle
.f_font
;
332 if (resource
.tstyle
.font
)
333 delete resource
.tstyle
.font
;
335 XFreeGC(blackbox
->getXDisplay(), opGC
);
339 void BScreen::saveSloppyFocus(bool s
) {
340 resource
.sloppy_focus
= s
;
343 if (resource
.sloppy_focus
) {
344 fmodel
= "SloppyFocus";
345 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
346 if (resource
.click_raise
) fmodel
+= " ClickRaise";
348 fmodel
= "ClickToFocus";
350 config
->setValue(screenstr
+ "focusModel", fmodel
);
354 void BScreen::saveAutoRaise(bool a
) {
355 resource
.auto_raise
= a
;
356 saveSloppyFocus(resource
.sloppy_focus
);
360 void BScreen::saveClickRaise(bool c
) {
361 resource
.click_raise
= c
;
362 saveSloppyFocus(resource
.sloppy_focus
);
366 void BScreen::saveImageDither(bool d
) {
367 image_control
->setDither(d
);
368 config
->setValue(screenstr
+ "imageDither", doImageDither());
372 void BScreen::saveOpaqueMove(bool o
) {
373 resource
.opaque_move
= o
;
374 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
378 void BScreen::saveFullMax(bool f
) {
379 resource
.full_max
= f
;
380 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
384 void BScreen::saveFocusNew(bool f
) {
385 resource
.focus_new
= f
;
386 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
390 void BScreen::saveFocusLast(bool f
) {
391 resource
.focus_last
= f
;
392 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
396 void BScreen::saveAAFonts(bool f
) {
397 resource
.aa_fonts
= f
;
399 config
->setValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
);
403 void BScreen::saveHideToolbar(bool h
) {
404 resource
.hide_toolbar
= h
;
405 if (resource
.hide_toolbar
)
406 toolbar
->unmapToolbar();
408 toolbar
->mapToolbar();
409 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
413 void BScreen::saveWindowToWindowSnap(bool s
) {
414 resource
.window_to_window_snap
= s
;
415 config
->setValue(screenstr
+ "windowToWindowSnap",
416 resource
.window_to_window_snap
);
420 void BScreen::saveResizeZones(unsigned int z
) {
421 resource
.resize_zones
= z
;
422 config
->setValue(screenstr
+ "resizeZones", resource
.resize_zones
);
426 void BScreen::saveWindowCornerSnap(bool s
) {
427 resource
.window_corner_snap
= s
;
428 config
->setValue(screenstr
+ "windowCornerSnap",
429 resource
.window_corner_snap
);
433 void BScreen::saveWorkspaces(unsigned int w
) {
434 resource
.workspaces
= w
;
435 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
439 void BScreen::savePlacementPolicy(int p
) {
440 resource
.placement_policy
= p
;
441 const char *placement
;
442 switch (resource
.placement_policy
) {
443 case CascadePlacement
: placement
= "CascadePlacement"; break;
444 case UnderMousePlacement
: placement
= "UnderMousePlacement"; break;
445 case ClickMousePlacement
: placement
= "ClickMousePlacement"; break;
446 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
447 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
449 config
->setValue(screenstr
+ "windowPlacement", placement
);
453 void BScreen::saveEdgeSnapThreshold(int t
) {
454 resource
.edge_snap_threshold
= t
;
455 config
->setValue(screenstr
+ "edgeSnapThreshold",
456 resource
.edge_snap_threshold
);
460 void BScreen::saveRowPlacementDirection(int d
) {
461 resource
.row_direction
= d
;
462 config
->setValue(screenstr
+ "rowPlacementDirection",
463 resource
.row_direction
== LeftRight
?
464 "LeftToRight" : "RightToLeft");
468 void BScreen::saveColPlacementDirection(int d
) {
469 resource
.col_direction
= d
;
470 config
->setValue(screenstr
+ "colPlacementDirection",
471 resource
.col_direction
== TopBottom
?
472 "TopToBottom" : "BottomToTop");
477 void BScreen::saveStrftimeFormat(const std::string
& format
) {
478 resource
.strftime_format
= format
;
479 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
482 #else // !HAVE_STRFTIME
484 void BScreen::saveDateFormat(int f
) {
485 resource
.date_format
= f
;
486 config
->setValue(screenstr
+ "dateFormat",
487 resource
.date_format
== B_EuropeanDate
?
488 "European" : "American");
492 void BScreen::saveClock24Hour(bool c
) {
493 resource
.clock24hour
= c
;
494 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
496 #endif // HAVE_STRFTIME
499 void BScreen::saveWorkspaceNames() {
502 for (unsigned int i
= 0; i
< workspacesList
.size(); ++i
) {
503 names
+= workspacesList
[i
]->getName();
504 if (i
< workspacesList
.size() - 1)
508 config
->setValue(screenstr
+ "workspaceNames", names
);
512 void BScreen::savePlaceIgnoreShaded(bool i
) {
513 resource
.ignore_shaded
= i
;
514 config
->setValue(screenstr
+ "placementIgnoreShaded",
515 resource
.ignore_shaded
);
519 void BScreen::savePlaceIgnoreMaximized(bool i
) {
520 resource
.ignore_maximized
= i
;
521 config
->setValue(screenstr
+ "placementIgnoreMaximized",
522 resource
.ignore_maximized
);
526 void BScreen::save_rc(void) {
527 saveSloppyFocus(resource
.sloppy_focus
);
528 saveAutoRaise(resource
.auto_raise
);
529 saveImageDither(doImageDither());
530 saveAAFonts(resource
.aa_fonts
);
531 saveResizeZones(resource
.resize_zones
);
532 saveOpaqueMove(resource
.opaque_move
);
533 saveFullMax(resource
.full_max
);
534 saveFocusNew(resource
.focus_new
);
535 saveFocusLast(resource
.focus_last
);
536 saveHideToolbar(resource
.hide_toolbar
);
537 saveWindowToWindowSnap(resource
.window_to_window_snap
);
538 saveWindowCornerSnap(resource
.window_corner_snap
);
539 saveWorkspaces(resource
.workspaces
);
540 savePlacementPolicy(resource
.placement_policy
);
541 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
542 saveRowPlacementDirection(resource
.row_direction
);
543 saveColPlacementDirection(resource
.col_direction
);
545 saveStrftimeFormat(resource
.strftime_format
);
546 #else // !HAVE_STRFTIME
547 saveDateFormat(resource
.date_format
);
548 savwClock24Hour(resource
.clock24hour
);
549 #endif // HAVE_STRFTIME
550 savePlaceIgnoreShaded(resource
.ignore_shaded
);
551 savePlaceIgnoreMaximized(resource
.ignore_maximized
);
558 void BScreen::load_rc(void) {
562 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
563 resource
.full_max
= false;
565 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
566 resource
.focus_new
= false;
568 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
569 resource
.focus_last
= false;
571 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
572 resource
.workspaces
= 1;
574 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
575 resource
.opaque_move
= false;
577 if (! config
->getValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
))
578 resource
.aa_fonts
= true;
580 if (! config
->getValue(screenstr
+ "resizeZones", resource
.resize_zones
) ||
581 (resource
.resize_zones
!= 1 && resource
.resize_zones
!= 2 &&
582 resource
.resize_zones
!= 4))
583 resource
.resize_zones
= 4;
585 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
586 resource
.hide_toolbar
= false;
588 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
589 resource
.window_to_window_snap
))
590 resource
.window_to_window_snap
= true;
592 if (! config
->getValue(screenstr
+ "windowCornerSnap",
593 resource
.window_corner_snap
))
594 resource
.window_corner_snap
= true;
596 if (! config
->getValue(screenstr
+ "imageDither", b
))
598 image_control
->setDither(b
);
600 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
601 resource
.edge_snap_threshold
))
602 resource
.edge_snap_threshold
= 4;
604 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
606 resource
.row_direction
= RightLeft
;
608 resource
.row_direction
= LeftRight
;
610 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
612 resource
.col_direction
= BottomTop
;
614 resource
.col_direction
= TopBottom
;
616 XAtom::StringVect workspaceNames
;
617 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
618 string::const_iterator it
= s
.begin(), end
= s
.end();
620 string::const_iterator tmp
= it
; // current string.begin()
621 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
622 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
628 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
631 resource
.sloppy_focus
= true;
632 resource
.auto_raise
= false;
633 resource
.click_raise
= false;
634 if (config
->getValue(screenstr
+ "focusModel", s
)) {
635 if (s
.find("ClickToFocus") != string::npos
) {
636 resource
.sloppy_focus
= false;
639 if (s
.find("AutoRaise") != string::npos
)
640 resource
.auto_raise
= true;
641 if (s
.find("ClickRaise") != string::npos
)
642 resource
.click_raise
= true;
646 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
647 if (s
== "CascadePlacement")
648 resource
.placement_policy
= CascadePlacement
;
649 else if (s
== "UnderMousePlacement")
650 resource
.placement_policy
= UnderMousePlacement
;
651 else if (s
== "ClickMousePlacement")
652 resource
.placement_policy
= ClickMousePlacement
;
653 else if (s
== "ColSmartPlacement")
654 resource
.placement_policy
= ColSmartPlacement
;
655 else //if (s == "RowSmartPlacement")
656 resource
.placement_policy
= RowSmartPlacement
;
658 resource
.placement_policy
= RowSmartPlacement
;
661 if (! config
->getValue(screenstr
+ "strftimeFormat",
662 resource
.strftime_format
))
663 resource
.strftime_format
= "%I:%M %p";
664 #else // !HAVE_STRFTIME
667 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
668 resource
.date_format
= B_EuropeanDate
;
670 resource
.date_format
= B_AmericanDate
;
672 if (! config
->getValue(screenstr
+ "clockFormat", l
))
674 resource
.clock24hour
= l
== 24;
675 #endif // HAVE_STRFTIME
677 if (! config
->getValue(screenstr
+ "placementIgnoreShaded",
678 resource
.ignore_shaded
))
679 resource
.ignore_shaded
= true;
681 if (! config
->getValue(screenstr
+ "placementIgnoreMaximized",
682 resource
.ignore_maximized
))
683 resource
.ignore_maximized
= true;
687 void BScreen::reconfigure(void) {
694 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
696 gcv
.function
= GXinvert
;
697 gcv
.subwindow_mode
= IncludeInferiors
;
698 XChangeGC(blackbox
->getXDisplay(), opGC
,
699 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
701 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
702 "0: 0000 x 0: 0000");
704 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
705 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
707 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
708 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
709 if (geom_pixmap
== ParentRelative
) {
710 texture
= &(resource
.wstyle
.t_focus
);
711 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
714 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
715 texture
->color().pixel());
717 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
718 geom_window
, geom_pixmap
);
720 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
721 resource
.border_width
);
722 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
723 resource
.border_color
.pixel());
725 workspacemenu
->reconfigure();
726 iconmenu
->reconfigure();
728 typedef std::vector
<int> SubList
;
729 SubList remember_subs
;
731 // save the current open menus
732 Basemenu
*menu
= rootmenu
;
734 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
735 remember_subs
.push_back(submenu
);
736 menu
= menu
->find(submenu
)->submenu();
742 rootmenu
->reconfigure();
744 // reopen the saved menus
746 const SubList::iterator subs_end
= remember_subs
.end();
747 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
748 menu
->drawSubmenu(*it
);
749 menu
= menu
->find(*it
)->submenu();
754 configmenu
->reconfigure();
756 toolbar
->reconfigure();
760 std::for_each(workspacesList
.begin(), workspacesList
.end(),
761 std::mem_fun(&Workspace::reconfigure
));
763 BlackboxWindowList::iterator iit
= iconList
.begin();
764 for (; iit
!= iconList
.end(); ++iit
) {
765 BlackboxWindow
*bw
= *iit
;
766 if (bw
->validateClient())
770 image_control
->timeout();
774 void BScreen::rereadMenu(void) {
778 rootmenu
->reconfigure();
782 void BScreen::LoadStyle(void) {
783 Configuration
style(False
);
785 const char *sfile
= blackbox
->getStyleFilename();
787 style
.setFile(sfile
);
788 if (! style
.load()) {
789 style
.setFile(DEFAULTSTYLE
);
791 style
.create(); // hardcoded default values will be used.
795 // merge in the rc file
796 style
.merge(config
->file(), True
);
800 // load fonts/fontsets
801 if (resource
.wstyle
.font
)
802 delete resource
.wstyle
.font
;
803 if (resource
.tstyle
.font
)
804 delete resource
.tstyle
.font
;
805 if (resource
.mstyle
.f_font
)
806 delete resource
.mstyle
.f_font
;
807 if (resource
.mstyle
.t_font
)
808 delete resource
.mstyle
.t_font
;
809 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
810 resource
.mstyle
.t_font
= (BFont
*) 0;
812 resource
.wstyle
.font
= readDatabaseFont("window.", style
);
813 resource
.tstyle
.font
= readDatabaseFont("toolbar.", style
);
814 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.", style
);
815 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.", style
);
817 // load window config
818 resource
.wstyle
.t_focus
=
819 readDatabaseTexture("window.title.focus", "white", style
);
820 resource
.wstyle
.t_unfocus
=
821 readDatabaseTexture("window.title.unfocus", "black", style
);
822 resource
.wstyle
.l_focus
=
823 readDatabaseTexture("window.label.focus", "white", style
);
824 resource
.wstyle
.l_unfocus
=
825 readDatabaseTexture("window.label.unfocus", "black", style
);
826 resource
.wstyle
.h_focus
=
827 readDatabaseTexture("window.handle.focus", "white", style
);
828 resource
.wstyle
.h_unfocus
=
829 readDatabaseTexture("window.handle.unfocus", "black", style
);
830 resource
.wstyle
.g_focus
=
831 readDatabaseTexture("window.grip.focus", "white", style
);
832 resource
.wstyle
.g_unfocus
=
833 readDatabaseTexture("window.grip.unfocus", "black", style
);
834 resource
.wstyle
.b_focus
=
835 readDatabaseTexture("window.button.focus", "white", style
);
836 resource
.wstyle
.b_unfocus
=
837 readDatabaseTexture("window.button.unfocus", "black", style
);
838 resource
.wstyle
.b_pressed
=
839 readDatabaseTexture("window.button.pressed", "black", style
);
840 resource
.wstyle
.f_focus
=
841 readDatabaseColor("window.frame.focusColor", "white", style
);
842 resource
.wstyle
.f_unfocus
=
843 readDatabaseColor("window.frame.unfocusColor", "black", style
);
844 resource
.wstyle
.l_text_focus
=
845 readDatabaseColor("window.label.focus.textColor", "black", style
);
846 resource
.wstyle
.l_text_unfocus
=
847 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
848 resource
.wstyle
.b_pic_focus
=
849 readDatabaseColor("window.button.focus.picColor", "black", style
);
850 resource
.wstyle
.b_pic_unfocus
=
851 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
853 resource
.wstyle
.justify
= LeftJustify
;
854 if (style
.getValue("window.justify", s
)) {
855 if (s
== "right" || s
== "Right")
856 resource
.wstyle
.justify
= RightJustify
;
857 else if (s
== "center" || s
== "Center")
858 resource
.wstyle
.justify
= CenterJustify
;
861 // load toolbar config
862 resource
.tstyle
.toolbar
=
863 readDatabaseTexture("toolbar", "black", style
);
864 resource
.tstyle
.label
=
865 readDatabaseTexture("toolbar.label", "black", style
);
866 resource
.tstyle
.window
=
867 readDatabaseTexture("toolbar.windowLabel", "black", style
);
868 resource
.tstyle
.button
=
869 readDatabaseTexture("toolbar.button", "white", style
);
870 resource
.tstyle
.pressed
=
871 readDatabaseTexture("toolbar.button.pressed", "black", style
);
872 resource
.tstyle
.clock
=
873 readDatabaseTexture("toolbar.clock", "black", style
);
874 resource
.tstyle
.l_text
=
875 readDatabaseColor("toolbar.label.textColor", "white", style
);
876 resource
.tstyle
.w_text
=
877 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
878 resource
.tstyle
.c_text
=
879 readDatabaseColor("toolbar.clock.textColor", "white", style
);
880 resource
.tstyle
.b_pic
=
881 readDatabaseColor("toolbar.button.picColor", "black", style
);
883 resource
.tstyle
.justify
= LeftJustify
;
884 if (style
.getValue("toolbar.justify", s
)) {
885 if (s
== "right" || s
== "Right")
886 resource
.tstyle
.justify
= RightJustify
;
887 else if (s
== "center" || s
== "Center")
888 resource
.tstyle
.justify
= CenterJustify
;
892 resource
.mstyle
.title
=
893 readDatabaseTexture("menu.title", "white", style
);
894 resource
.mstyle
.frame
=
895 readDatabaseTexture("menu.frame", "black", style
);
896 resource
.mstyle
.hilite
=
897 readDatabaseTexture("menu.hilite", "white", style
);
898 resource
.mstyle
.t_text
=
899 readDatabaseColor("menu.title.textColor", "black", style
);
900 resource
.mstyle
.f_text
=
901 readDatabaseColor("menu.frame.textColor", "white", style
);
902 resource
.mstyle
.d_text
=
903 readDatabaseColor("menu.frame.disableColor", "black", style
);
904 resource
.mstyle
.h_text
=
905 readDatabaseColor("menu.hilite.textColor", "black", style
);
907 resource
.mstyle
.t_justify
= LeftJustify
;
908 if (style
.getValue("menu.title.justify", s
)) {
909 if (s
== "right" || s
== "Right")
910 resource
.mstyle
.t_justify
= RightJustify
;
911 else if (s
== "center" || s
== "Center")
912 resource
.mstyle
.t_justify
= CenterJustify
;
915 resource
.mstyle
.f_justify
= LeftJustify
;
916 if (style
.getValue("menu.frame.justify", s
)) {
917 if (s
== "right" || s
== "Right")
918 resource
.mstyle
.f_justify
= RightJustify
;
919 else if (s
== "center" || s
== "Center")
920 resource
.mstyle
.f_justify
= CenterJustify
;
923 resource
.mstyle
.bullet
= Basemenu::Triangle
;
924 if (style
.getValue("menu.bullet", s
)) {
925 if (s
== "empty" || s
== "Empty")
926 resource
.mstyle
.bullet
= Basemenu::Empty
;
927 else if (s
== "square" || s
== "Square")
928 resource
.mstyle
.bullet
= Basemenu::Square
;
929 else if (s
== "diamond" || s
== "Diamond")
930 resource
.mstyle
.bullet
= Basemenu::Diamond
;
933 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
934 if (style
.getValue("menu.bullet.position", s
)) {
935 if (s
== "right" || s
== "Right")
936 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
939 resource
.border_color
=
940 readDatabaseColor("borderColor", "black", style
);
942 // load bevel, border and handle widths
943 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
944 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
945 resource
.handle_width
= 6;
947 if (! style
.getValue("borderWidth", resource
.border_width
))
948 resource
.border_width
= 1;
950 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
951 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
952 resource
.bevel_width
= 3;
954 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
955 resource
.frame_width
> (getWidth() / 2))
956 resource
.frame_width
= resource
.bevel_width
;
958 if (style
.getValue("rootCommand", s
))
959 bexec(s
, displayString());
963 void BScreen::addIcon(BlackboxWindow
*w
) {
966 w
->setWorkspace(BSENTINEL
);
967 w
->setWindowNumber(iconList
.size());
969 iconList
.push_back(w
);
971 const char* title
= w
->getIconTitle();
972 iconmenu
->insert(title
);
977 void BScreen::removeIcon(BlackboxWindow
*w
) {
982 iconmenu
->remove(w
->getWindowNumber());
985 BlackboxWindowList::iterator it
= iconList
.begin(),
986 end
= iconList
.end();
987 for (int i
= 0; it
!= end
; ++it
)
988 (*it
)->setWindowNumber(i
++);
992 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
993 if (index
< iconList
.size()) {
994 BlackboxWindowList::iterator it
= iconList
.begin();
995 for (; index
> 0; --index
, ++it
) ; /* increment to index */
999 return (BlackboxWindow
*) 0;
1003 unsigned int BScreen::addWorkspace(void) {
1004 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
1005 workspacesList
.push_back(wkspc
);
1006 saveWorkspaces(getWorkspaceCount());
1007 saveWorkspaceNames();
1009 workspacemenu
->insertWorkspace(wkspc
);
1010 workspacemenu
->update();
1012 toolbar
->reconfigure();
1014 updateNetizenWorkspaceCount();
1016 return workspacesList
.size();
1020 unsigned int BScreen::removeLastWorkspace(void) {
1021 if (workspacesList
.size() == 1)
1024 Workspace
*wkspc
= workspacesList
.back();
1026 if (current_workspace
->getID() == wkspc
->getID())
1027 changeWorkspaceID(current_workspace
->getID() - 1);
1031 workspacemenu
->removeWorkspace(wkspc
);
1032 workspacemenu
->update();
1034 workspacesList
.pop_back();
1037 saveWorkspaces(getWorkspaceCount());
1038 saveWorkspaceNames();
1040 toolbar
->reconfigure();
1042 updateNetizenWorkspaceCount();
1044 return workspacesList
.size();
1048 void BScreen::changeWorkspaceID(unsigned int id
) {
1049 if (! current_workspace
|| id
== current_workspace
->getID()) return;
1051 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1052 if (focused
&& focused
->getScreen() == this) {
1053 assert(focused
->isStuck() ||
1054 focused
->getWorkspaceNumber() == current_workspace
->getID());
1056 current_workspace
->setLastFocusedWindow(focused
);
1058 // if no window had focus, no need to store a last focus
1059 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1062 // when we switch workspaces, unfocus whatever was focused
1063 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1065 current_workspace
->hideAll();
1066 //workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
1068 current_workspace
= getWorkspace(id
);
1070 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1071 XAtom::cardinal
, id
);
1073 //workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
1074 toolbar
->redrawWorkspaceLabel(True
);
1076 current_workspace
->showAll();
1078 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1079 XSync(blackbox
->getXDisplay(), False
);
1080 current_workspace
->getLastFocusedWindow()->setInputFocus();
1083 updateNetizenCurrentWorkspace();
1088 * Set the _NET_CLIENT_LIST root window property.
1090 void BScreen::updateClientList(void) {
1091 if (windowList
.size() > 0) {
1092 Window
*windows
= new Window
[windowList
.size()];
1093 Window
*win_it
= windows
;
1094 BlackboxWindowList::iterator it
= windowList
.begin();
1095 const BlackboxWindowList::iterator end
= windowList
.end();
1096 for (; it
!= end
; ++it
, ++win_it
)
1097 *win_it
= (*it
)->getClientWindow();
1098 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1099 windows
, windowList
.size());
1102 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1105 updateStackingList();
1110 * Set the _NET_CLIENT_LIST_STACKING root window property.
1112 void BScreen::updateStackingList(void) {
1114 BlackboxWindowList stack_order
;
1117 * Get the stacking order from all of the workspaces.
1118 * We start with the current workspace so that the sticky windows will be
1119 * in the right order on the current workspace.
1120 * XXX: Do we need to have sticky windows in the list once for each workspace?
1122 getCurrentWorkspace()->appendStackOrder(stack_order
);
1123 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1124 if (i
!= getCurrentWorkspaceID())
1125 getWorkspace(i
)->appendStackOrder(stack_order
);
1127 if (stack_order
.size() > 0) {
1128 // set the client list atoms
1129 Window
*windows
= new Window
[stack_order
.size()];
1130 Window
*win_it
= windows
;
1131 BlackboxWindowList::iterator it
= stack_order
.begin(),
1132 end
= stack_order
.end();
1133 for (; it
!= end
; ++it
, ++win_it
)
1134 *win_it
= (*it
)->getClientWindow();
1135 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1136 XAtom::window
, windows
, stack_order
.size());
1139 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1140 XAtom::window
, 0, 0);
1144 void BScreen::addSystrayWindow(Window window
) {
1145 systrayWindowList
.push_back(window
);
1146 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1148 &systrayWindowList
[0], systrayWindowList
.size());
1149 blackbox
->saveSystrayWindowSearch(window
, this);
1153 void BScreen::removeSystrayWindow(Window window
) {
1154 WindowList::iterator it
= systrayWindowList
.begin();
1155 const WindowList::iterator end
= systrayWindowList
.end();
1156 for (; it
!= end
; ++it
)
1157 if (*it
== window
) {
1158 systrayWindowList
.erase(it
);
1159 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1161 &systrayWindowList
[0], systrayWindowList
.size());
1162 blackbox
->removeSystrayWindowSearch(window
);
1168 void BScreen::manageWindow(Window w
) {
1169 // is the window a KDE systray window?
1171 if (xatom
->getValue(w
, XAtom::kde_net_wm_system_tray_window_for
,
1172 XAtom::window
, systray
) && systray
) {
1173 addSystrayWindow(w
);
1177 new BlackboxWindow(blackbox
, w
, this);
1179 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1184 if (win
->isNormal()) {
1185 // don't list non-normal windows as managed windows
1186 windowList
.push_back(win
);
1188 } else if (win
->isDesktop()) {
1189 desktopWindowList
.push_back(win
->getFrameWindow());
1192 XMapRequestEvent mre
;
1194 if (blackbox
->isStartup() && win
->isNormal()) win
->restoreAttributes();
1195 win
->mapRequestEvent(&mre
);
1199 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1202 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1203 w
->getWindowNumber() != BSENTINEL
)
1204 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1205 else if (w
->isIconic())
1208 if (w
->isNormal()) {
1209 // we don't list non-normal windows as managed windows
1210 windowList
.remove(w
);
1212 } else if (w
->isDesktop()) {
1213 WindowList::iterator it
= desktopWindowList
.begin();
1214 const WindowList::iterator end
= desktopWindowList
.end();
1215 for (; it
!= end
; ++it
)
1216 if (*it
== w
->getFrameWindow()) {
1217 desktopWindowList
.erase(it
);
1220 assert(it
!= end
); // the window wasnt a desktop window?
1223 if (blackbox
->getFocusedWindow() == w
)
1224 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1226 removeNetizen(w
->getClientWindow());
1229 some managed windows can also be window group controllers. when
1230 unmanaging such windows, we should also delete the window group.
1232 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1239 void BScreen::addNetizen(Netizen
*n
) {
1240 netizenList
.push_back(n
);
1242 n
->sendWorkspaceCount();
1243 n
->sendCurrentWorkspace();
1245 WorkspaceList::iterator it
= workspacesList
.begin();
1246 const WorkspaceList::iterator end
= workspacesList
.end();
1247 for (; it
!= end
; ++it
)
1248 (*it
)->sendWindowList(*n
);
1250 Window f
= ((blackbox
->getFocusedWindow()) ?
1251 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1252 n
->sendWindowFocus(f
);
1256 void BScreen::removeNetizen(Window w
) {
1257 NetizenList::iterator it
= netizenList
.begin();
1258 for (; it
!= netizenList
.end(); ++it
) {
1259 if ((*it
)->getWindowID() == w
) {
1261 netizenList
.erase(it
);
1268 void BScreen::updateWorkArea(void) {
1269 if (workspacesList
.size() > 0) {
1270 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1271 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1272 // XXX: this could be different for each workspace
1273 const Rect
&area
= availableArea();
1274 dims
[(i
* 4) + 0] = area
.x();
1275 dims
[(i
* 4) + 1] = area
.y();
1276 dims
[(i
* 4) + 2] = area
.width();
1277 dims
[(i
* 4) + 3] = area
.height();
1279 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1280 dims
, 4 * workspacesList
.size());
1283 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1288 void BScreen::updateNetizenCurrentWorkspace(void) {
1289 std::for_each(netizenList
.begin(), netizenList
.end(),
1290 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1294 void BScreen::updateNetizenWorkspaceCount(void) {
1295 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1296 XAtom::cardinal
, workspacesList
.size());
1300 std::for_each(netizenList
.begin(), netizenList
.end(),
1301 std::mem_fun(&Netizen::sendWorkspaceCount
));
1305 void BScreen::updateNetizenWindowFocus(void) {
1306 Window f
= ((blackbox
->getFocusedWindow()) ?
1307 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1309 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1312 NetizenList::iterator it
= netizenList
.begin();
1313 for (; it
!= netizenList
.end(); ++it
)
1314 (*it
)->sendWindowFocus(f
);
1318 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1319 NetizenList::iterator it
= netizenList
.begin();
1320 for (; it
!= netizenList
.end(); ++it
) {
1321 (*it
)->sendWindowAdd(w
, p
);
1326 void BScreen::updateNetizenWindowDel(Window w
) {
1327 NetizenList::iterator it
= netizenList
.begin();
1328 for (; it
!= netizenList
.end(); ++it
)
1329 (*it
)->sendWindowDel(w
);
1333 void BScreen::updateNetizenWindowRaise(Window w
) {
1334 NetizenList::iterator it
= netizenList
.begin();
1335 for (; it
!= netizenList
.end(); ++it
)
1336 (*it
)->sendWindowRaise(w
);
1340 void BScreen::updateNetizenWindowLower(Window w
) {
1341 NetizenList::iterator it
= netizenList
.begin();
1342 for (; it
!= netizenList
.end(); ++it
)
1343 (*it
)->sendWindowLower(w
);
1347 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1348 NetizenList::iterator it
= netizenList
.begin();
1349 for (; it
!= netizenList
.end(); ++it
)
1350 (*it
)->sendConfigNotify(e
);
1354 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1355 // the 13 represents the number of blackbox windows such as menus
1356 Window
*session_stack
= new
1357 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1358 unsigned int i
= 0, k
= num
;
1360 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1361 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1363 WorkspaceList::iterator wit
= workspacesList
.begin();
1364 const WorkspaceList::iterator w_end
= workspacesList
.end();
1365 for (; wit
!= w_end
; ++wit
)
1366 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1368 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1370 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1371 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1372 *(session_stack
+ i
++) = configmenu
->getWindowID();
1374 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1375 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1376 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1378 *(session_stack
+ i
++) =
1379 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1380 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1382 RootmenuList::iterator rit
= rootmenuList
.begin();
1383 for (; rit
!= rootmenuList
.end(); ++rit
)
1384 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1385 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1387 if (toolbar
->isOnTop())
1388 *(session_stack
+ i
++) = toolbar
->getWindowID();
1390 if (slit
->isOnTop())
1391 *(session_stack
+ i
++) = slit
->getWindowID();
1394 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1396 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1398 delete [] session_stack
;
1400 updateStackingList();
1404 void BScreen::lowerWindows(Window
*workspace_stack
, unsigned int num
) {
1405 assert(num
> 0); // this would cause trouble in the XRaiseWindow call
1407 Window
*session_stack
= new Window
[(num
+ desktopWindowList
.size())];
1408 unsigned int i
= 0, k
= num
;
1410 XLowerWindow(blackbox
->getXDisplay(), workspace_stack
[0]);
1413 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1415 WindowList::iterator dit
= desktopWindowList
.begin();
1416 const WindowList::iterator d_end
= desktopWindowList
.end();
1417 for (; dit
!= d_end
; ++dit
)
1418 *(session_stack
+ i
++) = *dit
;
1420 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1422 delete [] session_stack
;
1424 updateStackingList();
1428 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1429 bool ignore_sticky
) {
1432 if (wkspc_id
== BSENTINEL
)
1433 wkspc_id
= current_workspace
->getID();
1435 if (w
->getWorkspaceNumber() == wkspc_id
)
1438 if (w
->isIconic()) {
1440 getWorkspace(wkspc_id
)->addWindow(w
);
1441 } else if (ignore_sticky
|| ! w
->isStuck()) {
1442 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1443 getWorkspace(wkspc_id
)->addWindow(w
);
1445 updateStackingList();
1449 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1450 if (bw
->isIconic()) {
1451 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1455 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1456 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1457 clientmenu
->update();
1459 if (blackbox
->getFocusedWindow() == bw
)
1460 toolbar
->redrawWindowLabel(True
);
1465 void BScreen::nextFocus(void) {
1466 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1470 // if window is not on this screen, ignore it
1471 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1472 focused
= (BlackboxWindow
*) 0;
1475 if (focused
&& current_workspace
->getCount() > 1) {
1476 // next is the next window to recieve focus, current is a place holder
1477 BlackboxWindow
*current
;
1480 next
= current_workspace
->getNextWindowInList(current
);
1481 } while(! next
->setInputFocus() && next
!= focused
);
1483 if (next
!= focused
)
1484 current_workspace
->raiseWindow(next
);
1485 } else if (current_workspace
->getCount() >= 1) {
1486 next
= current_workspace
->getTopWindowOnStack();
1488 current_workspace
->raiseWindow(next
);
1489 next
->setInputFocus();
1494 void BScreen::prevFocus(void) {
1495 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1499 // if window is not on this screen, ignore it
1500 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1501 focused
= (BlackboxWindow
*) 0;
1504 if (focused
&& current_workspace
->getCount() > 1) {
1505 // next is the next window to recieve focus, current is a place holder
1506 BlackboxWindow
*current
;
1509 next
= current_workspace
->getPrevWindowInList(current
);
1510 } while(! next
->setInputFocus() && next
!= focused
);
1512 if (next
!= focused
)
1513 current_workspace
->raiseWindow(next
);
1514 } else if (current_workspace
->getCount() >= 1) {
1515 next
= current_workspace
->getTopWindowOnStack();
1517 current_workspace
->raiseWindow(next
);
1518 next
->setInputFocus();
1523 void BScreen::raiseFocus(void) {
1524 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1528 // if on this Screen, raise it
1529 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1530 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1531 workspace
->raiseWindow(focused
);
1536 void BScreen::InitMenu(void) {
1538 rootmenuList
.clear();
1540 while (rootmenu
->getCount())
1541 rootmenu
->remove(0);
1543 rootmenu
= new Rootmenu(this);
1545 bool defaultMenu
= True
;
1547 FILE *menu_file
= (FILE *) 0;
1548 const char *menu_filename
= blackbox
->getMenuFilename();
1551 if (! (menu_file
= fopen(menu_filename
, "r")))
1552 perror(menu_filename
);
1553 if (! menu_file
) { // opening the menu file failed, try the default menu
1554 menu_filename
= DEFAULTMENU
;
1555 if (! (menu_file
= fopen(menu_filename
, "r")))
1556 perror(menu_filename
);
1560 if (feof(menu_file
)) {
1561 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1562 "%s: Empty menu file"),
1565 char line
[1024], label
[1024];
1566 memset(line
, 0, 1024);
1567 memset(label
, 0, 1024);
1569 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1570 if (line
[0] != '#') {
1571 int i
, key
= 0, index
= -1, len
= strlen(line
);
1573 for (i
= 0; i
< len
; i
++) {
1574 if (line
[i
] == '[') index
= 0;
1575 else if (line
[i
] == ']') break;
1576 else if (line
[i
] != ' ')
1578 key
+= tolower(line
[i
]);
1581 if (key
== 517) { // [begin]
1583 for (i
= index
; i
< len
; i
++) {
1584 if (line
[i
] == '(') index
= 0;
1585 else if (line
[i
] == ')') break;
1586 else if (index
++ >= 0) {
1587 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1588 label
[index
- 1] = line
[i
];
1592 if (index
== -1) index
= 0;
1593 label
[index
] = '\0';
1595 rootmenu
->setLabel(label
);
1596 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1598 blackbox
->addMenuTimestamp(menu_filename
);
1608 rootmenu
->setInternalMenu();
1609 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1611 i18n(ScreenSet
, Screenxterm
, "xterm"));
1612 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1614 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1616 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1622 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1623 char line
[1024], label
[1024], command
[1024];
1625 while (! feof(file
)) {
1626 memset(line
, 0, 1024);
1627 memset(label
, 0, 1024);
1628 memset(command
, 0, 1024);
1630 if (fgets(line
, 1024, file
)) {
1631 if (line
[0] != '#') {
1632 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1634 // determine the keyword
1635 for (i
= 0; i
< line_length
; i
++) {
1636 if (line
[i
] == '[') parse
= 1;
1637 else if (line
[i
] == ']') break;
1638 else if (line
[i
] != ' ')
1640 key
+= tolower(line
[i
]);
1643 // get the label enclosed in ()'s
1646 for (i
= 0; i
< line_length
; i
++) {
1647 if (line
[i
] == '(') {
1650 } else if (line
[i
] == ')') break;
1651 else if (index
++ >= 0) {
1652 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1653 label
[index
- 1] = line
[i
];
1658 label
[index
] = '\0';
1663 // get the command enclosed in {}'s
1666 for (i
= 0; i
< line_length
; i
++) {
1667 if (line
[i
] == '{') {
1670 } else if (line
[i
] == '}') break;
1671 else if (index
++ >= 0) {
1672 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1673 command
[index
- 1] = line
[i
];
1678 command
[index
] = '\0';
1685 return ((menu
->getCount() == 0) ? True
: False
);
1692 menu
->insert(label
);
1697 if ((! *label
) && (! *command
)) {
1698 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1699 "BScreen::parseMenuFile: [exec] error, "
1700 "no menu label and/or command defined\n"));
1704 menu
->insert(label
, BScreen::Execute
, command
);
1710 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1711 "BScreen::parseMenuFile: [exit] error, "
1712 "no menu label defined\n"));
1716 menu
->insert(label
, BScreen::Exit
);
1722 if ((! *label
) || (! *command
)) {
1724 i18n(ScreenSet
, ScreenSTYLEError
,
1725 "BScreen::parseMenuFile: [style] error, "
1726 "no menu label and/or filename defined\n"));
1730 string style
= expandTilde(command
);
1732 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1739 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1740 "BScreen::parseMenufile: [config] error, "
1741 "no label defined"));
1745 menu
->insert(label
, configmenu
);
1749 case 740: // include
1752 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1753 "BScreen::parseMenuFile: [include] error, "
1754 "no filename defined\n"));
1758 string newfile
= expandTilde(label
);
1759 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1763 if (fstat(fileno(submenufile
), &buf
) ||
1764 (! S_ISREG(buf
.st_mode
))) {
1766 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1767 "BScreen::parseMenuFile: [include] error: "
1768 "'%s' is not a regular file\n"), newfile
.c_str());
1772 if (! feof(submenufile
)) {
1773 if (! parseMenuFile(submenufile
, menu
))
1774 blackbox
->addMenuTimestamp(newfile
);
1776 fclose(submenufile
);
1779 perror(newfile
.c_str());
1785 case 767: // submenu
1788 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1789 "BScreen::parseMenuFile: [submenu] error, "
1790 "no menu label defined\n"));
1794 Rootmenu
*submenu
= new Rootmenu(this);
1797 submenu
->setLabel(command
);
1799 submenu
->setLabel(label
);
1801 parseMenuFile(file
, submenu
);
1803 menu
->insert(label
, submenu
);
1804 rootmenuList
.push_back(submenu
);
1809 case 773: // restart
1812 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1813 "BScreen::parseMenuFile: [restart] error, "
1814 "no menu label defined\n"));
1819 menu
->insert(label
, BScreen::RestartOther
, command
);
1821 menu
->insert(label
, BScreen::Restart
);
1826 case 845: // reconfig
1830 i18n(ScreenSet
, ScreenRECONFIGError
,
1831 "BScreen::parseMenuFile: [reconfig] error, "
1832 "no menu label defined\n"));
1836 menu
->insert(label
, BScreen::Reconfigure
);
1841 case 995: // stylesdir
1842 case 1113: // stylesmenu
1844 bool newmenu
= ((key
== 1113) ? True
: False
);
1846 if ((! *label
) || ((! *command
) && newmenu
)) {
1848 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1849 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1850 " error, no directory defined\n"));
1854 char *directory
= ((newmenu
) ? command
: label
);
1856 string stylesdir
= expandTilde(directory
);
1858 struct stat statbuf
;
1860 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1861 if (S_ISDIR(statbuf
.st_mode
)) {
1862 Rootmenu
*stylesmenu
;
1865 stylesmenu
= new Rootmenu(this);
1869 DIR *d
= opendir(stylesdir
.c_str());
1871 std::vector
<string
> ls
;
1873 while((p
= readdir(d
)))
1874 ls
.push_back(p
->d_name
);
1878 std::sort(ls
.begin(), ls
.end());
1880 std::vector
<string
>::iterator it
= ls
.begin(),
1882 for (; it
!= end
; ++it
) {
1883 const string
& fname
= *it
;
1885 if (fname
[fname
.size()-1] == '~')
1888 string style
= stylesdir
;
1892 if ((! stat(style
.c_str(), &statbuf
)) &&
1893 S_ISREG(statbuf
.st_mode
))
1894 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1897 stylesmenu
->update();
1900 stylesmenu
->setLabel(label
);
1901 menu
->insert(label
, stylesmenu
);
1902 rootmenuList
.push_back(stylesmenu
);
1905 blackbox
->addMenuTimestamp(stylesdir
);
1908 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1909 "BScreen::parseMenuFile:"
1910 " [stylesdir/stylesmenu] error, %s is not a"
1911 " directory\n"), stylesdir
.c_str());
1915 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1916 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1917 " error, %s does not exist\n"), stylesdir
.c_str());
1922 case 1090: // workspaces
1926 i18n(ScreenSet
, ScreenWORKSPACESError
,
1927 "BScreen:parseMenuFile: [workspaces] error, "
1928 "no menu label defined\n"));
1932 menu
->insert(label
, workspacemenu
);
1941 return ((menu
->getCount() == 0) ? True
: False
);
1945 void BScreen::shutdown(void) {
1946 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1947 XSync(blackbox
->getXDisplay(), False
);
1949 while(! windowList
.empty())
1950 unmanageWindow(windowList
.front(), True
);
1956 void BScreen::showPosition(int x
, int y
) {
1957 if (! geom_visible
) {
1958 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1959 (getWidth() - geom_w
) / 2,
1960 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1961 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1962 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1964 geom_visible
= True
;
1969 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1970 "X: %4d x Y: %4d"), x
, y
);
1972 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1974 resource
.wstyle
.font
->drawString(geom_window
,
1975 resource
.bevel_width
, resource
.bevel_width
,
1976 resource
.wstyle
.l_text_focus
,
1981 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1982 if (! geom_visible
) {
1983 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1984 (getWidth() - geom_w
) / 2,
1985 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1986 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1987 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1989 geom_visible
= True
;
1994 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1995 "W: %4d x H: %4d"), gx
, gy
);
1997 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1999 resource
.wstyle
.font
->drawString(geom_window
,
2000 resource
.bevel_width
, resource
.bevel_width
,
2001 resource
.wstyle
.l_text_focus
,
2006 void BScreen::hideGeometry(void) {
2008 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
2009 geom_visible
= False
;
2014 void BScreen::addStrut(Strut
*strut
) {
2015 strutList
.push_back(strut
);
2019 void BScreen::removeStrut(Strut
*strut
) {
2020 strutList
.remove(strut
);
2024 const Rect
& BScreen::availableArea(void) const {
2026 return getRect(); // return the full screen
2031 void BScreen::updateAvailableArea(void) {
2032 Rect old_area
= usableArea
;
2033 usableArea
= getRect(); // reset to full screen
2035 /* these values represent offsets from the screen edge
2036 * we look for the biggest offset on each edge and then apply them
2038 * do not be confused by the similarity to the names of Rect's members
2040 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
2043 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
2045 for(; it
!= end
; ++it
) {
2047 if (strut
->left
> current_left
)
2048 current_left
= strut
->left
;
2049 if (strut
->top
> current_top
)
2050 current_top
= strut
->top
;
2051 if (strut
->right
> current_right
)
2052 current_right
= strut
->right
;
2053 if (strut
->bottom
> current_bottom
)
2054 current_bottom
= strut
->bottom
;
2057 usableArea
.setPos(current_left
, current_top
);
2058 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2059 usableArea
.height() - (current_top
+ current_bottom
));
2061 if (old_area
!= usableArea
) {
2062 BlackboxWindowList::iterator it
= windowList
.begin(),
2063 end
= windowList
.end();
2064 for (; it
!= end
; ++it
)
2065 if ((*it
)->isMaximized()) (*it
)->remaximize();
2072 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2073 assert(index
< workspacesList
.size());
2074 return workspacesList
[index
];
2078 void BScreen::buttonPressEvent(const XButtonEvent
*xbutton
) {
2079 if (xbutton
->button
== 1) {
2080 if (! isRootColormapInstalled())
2081 image_control
->installRootColormap();
2083 if (workspacemenu
->isVisible())
2084 workspacemenu
->hide();
2086 if (rootmenu
->isVisible())
2088 } else if (xbutton
->button
== 2) {
2089 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2090 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2095 if (mx
+ workspacemenu
->getWidth() > getWidth())
2096 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2098 if (my
+ workspacemenu
->getHeight() > getHeight())
2099 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2101 workspacemenu
->move(mx
, my
);
2103 if (! workspacemenu
->isVisible()) {
2104 workspacemenu
->removeParent();
2105 workspacemenu
->show();
2107 } else if (xbutton
->button
== 3) {
2108 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2109 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2114 if (mx
+ rootmenu
->getWidth() > getWidth())
2115 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2117 if (my
+ rootmenu
->getHeight() > getHeight())
2118 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2120 rootmenu
->move(mx
, my
);
2122 if (! rootmenu
->isVisible()) {
2123 blackbox
->checkMenu();
2127 } else if (xbutton
->button
== 4) {
2128 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2129 changeWorkspaceID(0);
2131 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2133 } else if (xbutton
->button
== 5) {
2134 if (getCurrentWorkspaceID() == 0)
2135 changeWorkspaceID(getWorkspaceCount() - 1);
2137 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2142 void BScreen::propertyNotifyEvent(const XPropertyEvent
*pe
) {
2143 if (pe
->atom
== xatom
->getAtom(XAtom::net_desktop_names
)) {
2144 // _NET_WM_DESKTOP_NAMES
2145 WorkspaceList::iterator it
= workspacesList
.begin();
2146 const WorkspaceList::iterator end
= workspacesList
.end();
2147 for (; it
!= end
; ++it
) {
2148 (*it
)->readName(); // re-read its name from the window property
2149 workspacemenu
->changeWorkspaceLabel((*it
)->getID(), (*it
)->getName());
2151 workspacemenu
->update();
2152 toolbar
->reconfigure();
2153 saveWorkspaceNames();
2158 void BScreen::toggleFocusModel(FocusModel model
) {
2159 std::for_each(windowList
.begin(), windowList
.end(),
2160 std::mem_fun(&BlackboxWindow::ungrabButtons
));
2162 if (model
== SloppyFocus
) {
2163 saveSloppyFocus(True
);
2165 // we're cheating here to save writing the config file 3 times
2166 resource
.auto_raise
= False
;
2167 resource
.click_raise
= False
;
2168 saveSloppyFocus(False
);
2171 std::for_each(windowList
.begin(), windowList
.end(),
2172 std::mem_fun(&BlackboxWindow::grabButtons
));
2176 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2177 const string
&default_color
,
2178 const Configuration
&style
) {
2182 if (style
.getValue(rname
, s
))
2183 texture
= BTexture(s
);
2185 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2187 // associate this texture with this screen
2188 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2189 texture
.setImageControl(image_control
);
2191 if (texture
.texture() & BTexture::Solid
) {
2192 texture
.setColor(readDatabaseColor(rname
+ ".color",
2193 default_color
, style
));
2194 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2195 default_color
, style
));
2196 } else if (texture
.texture() & BTexture::Gradient
) {
2197 texture
.setColor(readDatabaseColor(rname
+ ".color",
2198 default_color
, style
));
2199 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2200 default_color
, style
));
2207 BColor
BScreen::readDatabaseColor(const string
&rname
,
2208 const string
&default_color
,
2209 const Configuration
&style
) {
2212 if (style
.getValue(rname
, s
))
2213 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2215 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2220 BFont
*BScreen::readDatabaseFont(const string
&rbasename
,
2221 const Configuration
&style
) {
2228 if (style
.getValue(rbasename
+ "xft.font", s
) &&
2229 style
.getValue(rbasename
+ "xft.size", i
)) {
2232 bool italic
= False
;
2233 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
2234 if (s
.find("bold") != string::npos
)
2236 if (s
.find("italic") != string::npos
)
2240 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, family
, i
, bold
,
2241 italic
, resource
.aa_fonts
);
2245 delete b
; // fall back to the normal X font stuff
2249 style
.getValue(rbasename
+ "font", s
);
2250 // if this fails, a blank string will be used, which will cause the fallback
2253 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2255 exit(2); // can't continue without a font