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 (! desktopWindowList
.empty())
316 removeDesktopWindow(desktopWindowList
[0]);
318 while (! systrayWindowList
.empty())
319 removeSystrayWindow(systrayWindowList
[0]);
322 delete workspacemenu
;
327 delete image_control
;
329 if (resource
.wstyle
.font
)
330 delete resource
.wstyle
.font
;
331 if (resource
.mstyle
.t_font
)
332 delete resource
.mstyle
.t_font
;
333 if (resource
.mstyle
.f_font
)
334 delete resource
.mstyle
.f_font
;
335 if (resource
.tstyle
.font
)
336 delete resource
.tstyle
.font
;
338 XFreeGC(blackbox
->getXDisplay(), opGC
);
342 void BScreen::saveSloppyFocus(bool s
) {
343 resource
.sloppy_focus
= s
;
346 if (resource
.sloppy_focus
) {
347 fmodel
= "SloppyFocus";
348 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
349 if (resource
.click_raise
) fmodel
+= " ClickRaise";
351 fmodel
= "ClickToFocus";
353 config
->setValue(screenstr
+ "focusModel", fmodel
);
357 void BScreen::saveAutoRaise(bool a
) {
358 resource
.auto_raise
= a
;
359 saveSloppyFocus(resource
.sloppy_focus
);
363 void BScreen::saveClickRaise(bool c
) {
364 resource
.click_raise
= c
;
365 saveSloppyFocus(resource
.sloppy_focus
);
369 void BScreen::saveImageDither(bool d
) {
370 image_control
->setDither(d
);
371 config
->setValue(screenstr
+ "imageDither", doImageDither());
375 void BScreen::saveOpaqueMove(bool o
) {
376 resource
.opaque_move
= o
;
377 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
381 void BScreen::saveFullMax(bool f
) {
382 resource
.full_max
= f
;
383 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
387 void BScreen::saveFocusNew(bool f
) {
388 resource
.focus_new
= f
;
389 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
393 void BScreen::saveFocusLast(bool f
) {
394 resource
.focus_last
= f
;
395 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
399 void BScreen::saveAAFonts(bool f
) {
400 resource
.aa_fonts
= f
;
402 config
->setValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
);
406 void BScreen::saveHideToolbar(bool h
) {
407 resource
.hide_toolbar
= h
;
408 if (resource
.hide_toolbar
)
409 toolbar
->unmapToolbar();
411 toolbar
->mapToolbar();
412 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
416 void BScreen::saveWindowToWindowSnap(bool s
) {
417 resource
.window_to_window_snap
= s
;
418 config
->setValue(screenstr
+ "windowToWindowSnap",
419 resource
.window_to_window_snap
);
423 void BScreen::saveResizeZones(unsigned int z
) {
424 resource
.resize_zones
= z
;
425 config
->setValue(screenstr
+ "resizeZones", resource
.resize_zones
);
429 void BScreen::saveWindowCornerSnap(bool s
) {
430 resource
.window_corner_snap
= s
;
431 config
->setValue(screenstr
+ "windowCornerSnap",
432 resource
.window_corner_snap
);
436 void BScreen::saveWorkspaces(unsigned int w
) {
437 resource
.workspaces
= w
;
438 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
442 void BScreen::savePlacementPolicy(int p
) {
443 resource
.placement_policy
= p
;
444 const char *placement
;
445 switch (resource
.placement_policy
) {
446 case CascadePlacement
: placement
= "CascadePlacement"; break;
447 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
448 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
450 config
->setValue(screenstr
+ "windowPlacement", placement
);
454 void BScreen::saveEdgeSnapThreshold(int t
) {
455 resource
.edge_snap_threshold
= t
;
456 config
->setValue(screenstr
+ "edgeSnapThreshold",
457 resource
.edge_snap_threshold
);
461 void BScreen::saveRowPlacementDirection(int d
) {
462 resource
.row_direction
= d
;
463 config
->setValue(screenstr
+ "rowPlacementDirection",
464 resource
.row_direction
== LeftRight
?
465 "LeftToRight" : "RightToLeft");
469 void BScreen::saveColPlacementDirection(int d
) {
470 resource
.col_direction
= d
;
471 config
->setValue(screenstr
+ "colPlacementDirection",
472 resource
.col_direction
== TopBottom
?
473 "TopToBottom" : "BottomToTop");
478 void BScreen::saveStrftimeFormat(const std::string
& format
) {
479 resource
.strftime_format
= format
;
480 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
483 #else // !HAVE_STRFTIME
485 void BScreen::saveDateFormat(int f
) {
486 resource
.date_format
= f
;
487 config
->setValue(screenstr
+ "dateFormat",
488 resource
.date_format
== B_EuropeanDate
?
489 "European" : "American");
493 void BScreen::saveClock24Hour(bool c
) {
494 resource
.clock24hour
= c
;
495 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
497 #endif // HAVE_STRFTIME
500 void BScreen::saveWorkspaceNames() {
503 for (unsigned int i
= 0; i
< workspacesList
.size(); ++i
) {
504 names
+= workspacesList
[i
]->getName();
505 if (i
< workspacesList
.size() - 1)
509 config
->setValue(screenstr
+ "workspaceNames", names
);
513 void BScreen::savePlaceIgnoreShaded(bool i
) {
514 resource
.ignore_shaded
= i
;
515 config
->setValue(screenstr
+ "placementIgnoreShaded",
516 resource
.ignore_shaded
);
520 void BScreen::savePlaceIgnoreMaximized(bool i
) {
521 resource
.ignore_maximized
= i
;
522 config
->setValue(screenstr
+ "placementIgnoreMaximized",
523 resource
.ignore_maximized
);
527 void BScreen::save_rc(void) {
528 saveSloppyFocus(resource
.sloppy_focus
);
529 saveAutoRaise(resource
.auto_raise
);
530 saveImageDither(doImageDither());
531 saveAAFonts(resource
.aa_fonts
);
532 saveResizeZones(resource
.resize_zones
);
533 saveOpaqueMove(resource
.opaque_move
);
534 saveFullMax(resource
.full_max
);
535 saveFocusNew(resource
.focus_new
);
536 saveFocusLast(resource
.focus_last
);
537 saveHideToolbar(resource
.hide_toolbar
);
538 saveWindowToWindowSnap(resource
.window_to_window_snap
);
539 saveWindowCornerSnap(resource
.window_corner_snap
);
540 saveWorkspaces(resource
.workspaces
);
541 savePlacementPolicy(resource
.placement_policy
);
542 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
543 saveRowPlacementDirection(resource
.row_direction
);
544 saveColPlacementDirection(resource
.col_direction
);
546 saveStrftimeFormat(resource
.strftime_format
);
547 #else // !HAVE_STRFTIME
548 saveDateFormat(resource
.date_format
);
549 savwClock24Hour(resource
.clock24hour
);
550 #endif // HAVE_STRFTIME
551 savePlaceIgnoreShaded(resource
.ignore_shaded
);
552 savePlaceIgnoreMaximized(resource
.ignore_maximized
);
559 void BScreen::load_rc(void) {
563 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
564 resource
.full_max
= false;
566 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
567 resource
.focus_new
= false;
569 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
570 resource
.focus_last
= false;
572 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
573 resource
.workspaces
= 1;
575 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
576 resource
.opaque_move
= false;
578 if (! config
->getValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
))
579 resource
.aa_fonts
= true;
581 if (! config
->getValue(screenstr
+ "resizeZones", resource
.resize_zones
) ||
582 (resource
.resize_zones
!= 1 && resource
.resize_zones
!= 2 &&
583 resource
.resize_zones
!= 4))
584 resource
.resize_zones
= 4;
586 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
587 resource
.hide_toolbar
= false;
589 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
590 resource
.window_to_window_snap
))
591 resource
.window_to_window_snap
= true;
593 if (! config
->getValue(screenstr
+ "windowCornerSnap",
594 resource
.window_corner_snap
))
595 resource
.window_corner_snap
= true;
597 if (! config
->getValue(screenstr
+ "imageDither", b
))
599 image_control
->setDither(b
);
601 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
602 resource
.edge_snap_threshold
))
603 resource
.edge_snap_threshold
= 4;
605 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
607 resource
.row_direction
= RightLeft
;
609 resource
.row_direction
= LeftRight
;
611 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
613 resource
.col_direction
= BottomTop
;
615 resource
.col_direction
= TopBottom
;
617 XAtom::StringVect workspaceNames
;
618 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
619 string::const_iterator it
= s
.begin(), end
= s
.end();
621 string::const_iterator tmp
= it
; // current string.begin()
622 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
623 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
629 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
632 resource
.sloppy_focus
= true;
633 resource
.auto_raise
= false;
634 resource
.click_raise
= false;
635 if (config
->getValue(screenstr
+ "focusModel", s
)) {
636 if (s
.find("ClickToFocus") != string::npos
) {
637 resource
.sloppy_focus
= false;
640 if (s
.find("AutoRaise") != string::npos
)
641 resource
.auto_raise
= true;
642 if (s
.find("ClickRaise") != string::npos
)
643 resource
.click_raise
= true;
647 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
648 if (s
== "CascadePlacement")
649 resource
.placement_policy
= CascadePlacement
;
650 else if (s
== "ColSmartPlacement")
651 resource
.placement_policy
= ColSmartPlacement
;
652 else //if (s == "RowSmartPlacement")
653 resource
.placement_policy
= RowSmartPlacement
;
655 resource
.placement_policy
= RowSmartPlacement
;
658 if (! config
->getValue(screenstr
+ "strftimeFormat",
659 resource
.strftime_format
))
660 resource
.strftime_format
= "%I:%M %p";
661 #else // !HAVE_STRFTIME
664 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
665 resource
.date_format
= B_EuropeanDate
;
667 resource
.date_format
= B_AmericanDate
;
669 if (! config
->getValue(screenstr
+ "clockFormat", l
))
671 resource
.clock24hour
= l
== 24;
672 #endif // HAVE_STRFTIME
674 if (! config
->getValue(screenstr
+ "placementIgnoreShaded",
675 resource
.ignore_shaded
))
676 resource
.ignore_shaded
= true;
678 if (! config
->getValue(screenstr
+ "placementIgnoreMaximized",
679 resource
.ignore_maximized
))
680 resource
.ignore_maximized
= true;
684 void BScreen::reconfigure(void) {
691 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
693 gcv
.function
= GXinvert
;
694 gcv
.subwindow_mode
= IncludeInferiors
;
695 XChangeGC(blackbox
->getXDisplay(), opGC
,
696 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
698 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
699 "0: 0000 x 0: 0000");
701 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
702 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
704 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
705 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
706 if (geom_pixmap
== ParentRelative
) {
707 texture
= &(resource
.wstyle
.t_focus
);
708 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
711 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
712 texture
->color().pixel());
714 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
715 geom_window
, geom_pixmap
);
717 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
718 resource
.border_width
);
719 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
720 resource
.border_color
.pixel());
722 workspacemenu
->reconfigure();
723 iconmenu
->reconfigure();
725 typedef std::vector
<int> SubList
;
726 SubList remember_subs
;
728 // save the current open menus
729 Basemenu
*menu
= rootmenu
;
731 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
732 remember_subs
.push_back(submenu
);
733 menu
= menu
->find(submenu
)->submenu();
739 rootmenu
->reconfigure();
741 // reopen the saved menus
743 const SubList::iterator subs_end
= remember_subs
.end();
744 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
745 menu
->drawSubmenu(*it
);
746 menu
= menu
->find(*it
)->submenu();
751 configmenu
->reconfigure();
753 toolbar
->reconfigure();
757 std::for_each(workspacesList
.begin(), workspacesList
.end(),
758 std::mem_fun(&Workspace::reconfigure
));
760 BlackboxWindowList::iterator iit
= iconList
.begin();
761 for (; iit
!= iconList
.end(); ++iit
) {
762 BlackboxWindow
*bw
= *iit
;
763 if (bw
->validateClient())
767 image_control
->timeout();
771 void BScreen::rereadMenu(void) {
775 rootmenu
->reconfigure();
779 void BScreen::LoadStyle(void) {
780 Configuration
style(False
);
782 const char *sfile
= blackbox
->getStyleFilename();
784 style
.setFile(sfile
);
785 if (! style
.load()) {
786 style
.setFile(DEFAULTSTYLE
);
788 style
.create(); // hardcoded default values will be used.
792 // merge in the rc file
793 style
.merge(config
->file(), True
);
797 // load fonts/fontsets
798 if (resource
.wstyle
.font
)
799 delete resource
.wstyle
.font
;
800 if (resource
.tstyle
.font
)
801 delete resource
.tstyle
.font
;
802 if (resource
.mstyle
.f_font
)
803 delete resource
.mstyle
.f_font
;
804 if (resource
.mstyle
.t_font
)
805 delete resource
.mstyle
.t_font
;
806 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
807 resource
.mstyle
.t_font
= (BFont
*) 0;
809 resource
.wstyle
.font
= readDatabaseFont("window.", style
);
810 resource
.tstyle
.font
= readDatabaseFont("toolbar.", style
);
811 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.", style
);
812 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.", style
);
814 // load window config
815 resource
.wstyle
.t_focus
=
816 readDatabaseTexture("window.title.focus", "white", style
);
817 resource
.wstyle
.t_unfocus
=
818 readDatabaseTexture("window.title.unfocus", "black", style
);
819 resource
.wstyle
.l_focus
=
820 readDatabaseTexture("window.label.focus", "white", style
);
821 resource
.wstyle
.l_unfocus
=
822 readDatabaseTexture("window.label.unfocus", "black", style
);
823 resource
.wstyle
.h_focus
=
824 readDatabaseTexture("window.handle.focus", "white", style
);
825 resource
.wstyle
.h_unfocus
=
826 readDatabaseTexture("window.handle.unfocus", "black", style
);
827 resource
.wstyle
.g_focus
=
828 readDatabaseTexture("window.grip.focus", "white", style
);
829 resource
.wstyle
.g_unfocus
=
830 readDatabaseTexture("window.grip.unfocus", "black", style
);
831 resource
.wstyle
.b_focus
=
832 readDatabaseTexture("window.button.focus", "white", style
);
833 resource
.wstyle
.b_unfocus
=
834 readDatabaseTexture("window.button.unfocus", "black", style
);
835 resource
.wstyle
.b_pressed
=
836 readDatabaseTexture("window.button.pressed", "black", style
);
837 resource
.wstyle
.f_focus
=
838 readDatabaseColor("window.frame.focusColor", "white", style
);
839 resource
.wstyle
.f_unfocus
=
840 readDatabaseColor("window.frame.unfocusColor", "black", style
);
841 resource
.wstyle
.l_text_focus
=
842 readDatabaseColor("window.label.focus.textColor", "black", style
);
843 resource
.wstyle
.l_text_unfocus
=
844 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
845 resource
.wstyle
.b_pic_focus
=
846 readDatabaseColor("window.button.focus.picColor", "black", style
);
847 resource
.wstyle
.b_pic_unfocus
=
848 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
850 resource
.wstyle
.justify
= LeftJustify
;
851 if (style
.getValue("window.justify", s
)) {
852 if (s
== "right" || s
== "Right")
853 resource
.wstyle
.justify
= RightJustify
;
854 else if (s
== "center" || s
== "Center")
855 resource
.wstyle
.justify
= CenterJustify
;
858 // load toolbar config
859 resource
.tstyle
.toolbar
=
860 readDatabaseTexture("toolbar", "black", style
);
861 resource
.tstyle
.label
=
862 readDatabaseTexture("toolbar.label", "black", style
);
863 resource
.tstyle
.window
=
864 readDatabaseTexture("toolbar.windowLabel", "black", style
);
865 resource
.tstyle
.button
=
866 readDatabaseTexture("toolbar.button", "white", style
);
867 resource
.tstyle
.pressed
=
868 readDatabaseTexture("toolbar.button.pressed", "black", style
);
869 resource
.tstyle
.clock
=
870 readDatabaseTexture("toolbar.clock", "black", style
);
871 resource
.tstyle
.l_text
=
872 readDatabaseColor("toolbar.label.textColor", "white", style
);
873 resource
.tstyle
.w_text
=
874 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
875 resource
.tstyle
.c_text
=
876 readDatabaseColor("toolbar.clock.textColor", "white", style
);
877 resource
.tstyle
.b_pic
=
878 readDatabaseColor("toolbar.button.picColor", "black", style
);
880 resource
.tstyle
.justify
= LeftJustify
;
881 if (style
.getValue("toolbar.justify", s
)) {
882 if (s
== "right" || s
== "Right")
883 resource
.tstyle
.justify
= RightJustify
;
884 else if (s
== "center" || s
== "Center")
885 resource
.tstyle
.justify
= CenterJustify
;
889 resource
.mstyle
.title
=
890 readDatabaseTexture("menu.title", "white", style
);
891 resource
.mstyle
.frame
=
892 readDatabaseTexture("menu.frame", "black", style
);
893 resource
.mstyle
.hilite
=
894 readDatabaseTexture("menu.hilite", "white", style
);
895 resource
.mstyle
.t_text
=
896 readDatabaseColor("menu.title.textColor", "black", style
);
897 resource
.mstyle
.f_text
=
898 readDatabaseColor("menu.frame.textColor", "white", style
);
899 resource
.mstyle
.d_text
=
900 readDatabaseColor("menu.frame.disableColor", "black", style
);
901 resource
.mstyle
.h_text
=
902 readDatabaseColor("menu.hilite.textColor", "black", style
);
904 resource
.mstyle
.t_justify
= LeftJustify
;
905 if (style
.getValue("menu.title.justify", s
)) {
906 if (s
== "right" || s
== "Right")
907 resource
.mstyle
.t_justify
= RightJustify
;
908 else if (s
== "center" || s
== "Center")
909 resource
.mstyle
.t_justify
= CenterJustify
;
912 resource
.mstyle
.f_justify
= LeftJustify
;
913 if (style
.getValue("menu.frame.justify", s
)) {
914 if (s
== "right" || s
== "Right")
915 resource
.mstyle
.f_justify
= RightJustify
;
916 else if (s
== "center" || s
== "Center")
917 resource
.mstyle
.f_justify
= CenterJustify
;
920 resource
.mstyle
.bullet
= Basemenu::Triangle
;
921 if (style
.getValue("menu.bullet", s
)) {
922 if (s
== "empty" || s
== "Empty")
923 resource
.mstyle
.bullet
= Basemenu::Empty
;
924 else if (s
== "square" || s
== "Square")
925 resource
.mstyle
.bullet
= Basemenu::Square
;
926 else if (s
== "diamond" || s
== "Diamond")
927 resource
.mstyle
.bullet
= Basemenu::Diamond
;
930 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
931 if (style
.getValue("menu.bullet.position", s
)) {
932 if (s
== "right" || s
== "Right")
933 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
936 resource
.border_color
=
937 readDatabaseColor("borderColor", "black", style
);
939 // load bevel, border and handle widths
940 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
941 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
942 resource
.handle_width
= 6;
944 if (! style
.getValue("borderWidth", resource
.border_width
))
945 resource
.border_width
= 1;
947 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
948 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
949 resource
.bevel_width
= 3;
951 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
952 resource
.frame_width
> (getWidth() / 2))
953 resource
.frame_width
= resource
.bevel_width
;
955 if (style
.getValue("rootCommand", s
))
956 bexec(s
, displayString());
960 void BScreen::addIcon(BlackboxWindow
*w
) {
963 w
->setWorkspace(BSENTINEL
);
964 w
->setWindowNumber(iconList
.size());
966 iconList
.push_back(w
);
968 const char* title
= w
->getIconTitle();
969 iconmenu
->insert(title
);
974 void BScreen::removeIcon(BlackboxWindow
*w
) {
979 iconmenu
->remove(w
->getWindowNumber());
982 BlackboxWindowList::iterator it
= iconList
.begin(),
983 end
= iconList
.end();
984 for (int i
= 0; it
!= end
; ++it
)
985 (*it
)->setWindowNumber(i
++);
989 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
990 if (index
< iconList
.size()) {
991 BlackboxWindowList::iterator it
= iconList
.begin();
992 for (; index
> 0; --index
, ++it
) ; /* increment to index */
996 return (BlackboxWindow
*) 0;
1000 unsigned int BScreen::addWorkspace(void) {
1001 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
1002 workspacesList
.push_back(wkspc
);
1003 saveWorkspaces(getWorkspaceCount());
1004 saveWorkspaceNames();
1006 workspacemenu
->insertWorkspace(wkspc
);
1007 workspacemenu
->update();
1009 toolbar
->reconfigure();
1011 updateNetizenWorkspaceCount();
1013 return workspacesList
.size();
1017 unsigned int BScreen::removeLastWorkspace(void) {
1018 if (workspacesList
.size() == 1)
1021 Workspace
*wkspc
= workspacesList
.back();
1023 if (current_workspace
->getID() == wkspc
->getID())
1024 changeWorkspaceID(current_workspace
->getID() - 1);
1028 workspacemenu
->removeWorkspace(wkspc
);
1029 workspacemenu
->update();
1031 workspacesList
.pop_back();
1034 saveWorkspaces(getWorkspaceCount());
1035 saveWorkspaceNames();
1037 toolbar
->reconfigure();
1039 updateNetizenWorkspaceCount();
1041 return workspacesList
.size();
1045 void BScreen::changeWorkspaceID(unsigned int id
) {
1046 if (! current_workspace
|| id
== current_workspace
->getID()) return;
1048 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1049 if (focused
&& focused
->getScreen() == this) {
1050 assert(focused
->isStuck() ||
1051 focused
->getWorkspaceNumber() == current_workspace
->getID());
1053 current_workspace
->setLastFocusedWindow(focused
);
1055 // if no window had focus, no need to store a last focus
1056 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1059 // when we switch workspaces, unfocus whatever was focused
1060 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1062 current_workspace
->hideAll();
1063 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1065 current_workspace
= getWorkspace(id
);
1067 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1068 XAtom::cardinal
, id
);
1070 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1071 toolbar
->redrawWorkspaceLabel(True
);
1073 current_workspace
->showAll();
1075 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1076 XSync(blackbox
->getXDisplay(), False
);
1077 current_workspace
->getLastFocusedWindow()->setInputFocus();
1080 updateNetizenCurrentWorkspace();
1085 * Set the _NET_CLIENT_LIST root window property.
1087 void BScreen::updateClientList(void) {
1088 if (windowList
.size() > 0) {
1089 Window
*windows
= new Window
[windowList
.size()];
1090 Window
*win_it
= windows
;
1091 BlackboxWindowList::iterator it
= windowList
.begin();
1092 const BlackboxWindowList::iterator end
= windowList
.end();
1093 for (; it
!= end
; ++it
, ++win_it
)
1094 *win_it
= (*it
)->getClientWindow();
1095 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1096 windows
, windowList
.size());
1099 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1102 updateStackingList();
1107 * Set the _NET_CLIENT_LIST_STACKING root window property.
1109 void BScreen::updateStackingList(void) {
1111 BlackboxWindowList stack_order
;
1114 * Get the stacking order from all of the workspaces.
1115 * We start with the current workspace so that the sticky windows will be
1116 * in the right order on the current workspace.
1117 * XXX: Do we need to have sticky windows in the list once for each workspace?
1119 getCurrentWorkspace()->appendStackOrder(stack_order
);
1120 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1121 if (i
!= getCurrentWorkspaceID())
1122 getWorkspace(i
)->appendStackOrder(stack_order
);
1124 if (stack_order
.size() > 0) {
1125 // set the client list atoms
1126 Window
*windows
= new Window
[stack_order
.size()];
1127 Window
*win_it
= windows
;
1128 BlackboxWindowList::iterator it
= stack_order
.begin(),
1129 end
= stack_order
.end();
1130 for (; it
!= end
; ++it
, ++win_it
)
1131 *win_it
= (*it
)->getClientWindow();
1132 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1133 XAtom::window
, windows
, stack_order
.size());
1136 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1137 XAtom::window
, 0, 0);
1141 void BScreen::addSystrayWindow(Window window
) {
1142 systrayWindowList
.push_back(window
);
1143 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1145 &systrayWindowList
[0], systrayWindowList
.size());
1146 blackbox
->saveSystrayWindowSearch(window
, this);
1150 void BScreen::removeSystrayWindow(Window window
) {
1151 WindowList::iterator it
= systrayWindowList
.begin();
1152 const WindowList::iterator end
= systrayWindowList
.end();
1153 for (; it
!= end
; ++it
)
1154 if (*it
== window
) {
1155 systrayWindowList
.erase(it
);
1156 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1158 &systrayWindowList
[0], systrayWindowList
.size());
1159 blackbox
->removeSystrayWindowSearch(window
);
1165 void BScreen::addDesktopWindow(Window window
) {
1166 desktopWindowList
.push_back(window
);
1167 XLowerWindow(blackbox
->getXDisplay(), window
);
1168 XSelectInput(blackbox
->getXDisplay(), window
, StructureNotifyMask
);
1169 blackbox
->saveDesktopWindowSearch(window
, this);
1173 void BScreen::removeDesktopWindow(Window window
) {
1174 WindowList::iterator it
= desktopWindowList
.begin();
1175 const WindowList::iterator end
= desktopWindowList
.end();
1176 for (; it
!= end
; ++it
)
1177 if (*it
== window
) {
1178 desktopWindowList
.erase(it
);
1179 XSelectInput(blackbox
->getXDisplay(), window
, None
);
1180 blackbox
->removeDesktopWindowSearch(window
);
1186 void BScreen::manageWindow(Window w
) {
1187 new BlackboxWindow(blackbox
, w
, this);
1189 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1192 if (win
->isDesktop()) {
1193 // desktop windows cant do anything, so we remove all the normal window
1194 // stuff from them, they are only kept around so that we can keep them on
1195 // the bottom of the z-order
1197 addDesktopWindow(win
->getClientWindow());
1202 windowList
.push_back(win
);
1205 XMapRequestEvent mre
;
1207 if (blackbox
->isStartup()) win
->restoreAttributes();
1208 win
->mapRequestEvent(&mre
);
1212 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1215 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1216 w
->getWindowNumber() != BSENTINEL
)
1217 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1218 else if (w
->isIconic())
1221 windowList
.remove(w
);
1224 if (blackbox
->getFocusedWindow() == w
)
1225 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1227 removeNetizen(w
->getClientWindow());
1230 some managed windows can also be window group controllers. when
1231 unmanaging such windows, we should also delete the window group.
1233 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1240 void BScreen::addNetizen(Netizen
*n
) {
1241 netizenList
.push_back(n
);
1243 n
->sendWorkspaceCount();
1244 n
->sendCurrentWorkspace();
1246 WorkspaceList::iterator it
= workspacesList
.begin();
1247 const WorkspaceList::iterator end
= workspacesList
.end();
1248 for (; it
!= end
; ++it
)
1249 (*it
)->sendWindowList(*n
);
1251 Window f
= ((blackbox
->getFocusedWindow()) ?
1252 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1253 n
->sendWindowFocus(f
);
1257 void BScreen::removeNetizen(Window w
) {
1258 NetizenList::iterator it
= netizenList
.begin();
1259 for (; it
!= netizenList
.end(); ++it
) {
1260 if ((*it
)->getWindowID() == w
) {
1262 netizenList
.erase(it
);
1269 void BScreen::updateWorkArea(void) {
1270 if (workspacesList
.size() > 0) {
1271 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1272 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1273 // XXX: this could be different for each workspace
1274 const Rect
&area
= availableArea();
1275 dims
[(i
* 4) + 0] = area
.x();
1276 dims
[(i
* 4) + 1] = area
.y();
1277 dims
[(i
* 4) + 2] = area
.width();
1278 dims
[(i
* 4) + 3] = area
.height();
1280 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1281 dims
, 4 * workspacesList
.size());
1284 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1289 void BScreen::updateNetizenCurrentWorkspace(void) {
1290 std::for_each(netizenList
.begin(), netizenList
.end(),
1291 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1295 void BScreen::updateNetizenWorkspaceCount(void) {
1296 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1297 XAtom::cardinal
, workspacesList
.size());
1301 std::for_each(netizenList
.begin(), netizenList
.end(),
1302 std::mem_fun(&Netizen::sendWorkspaceCount
));
1306 void BScreen::updateNetizenWindowFocus(void) {
1307 Window f
= ((blackbox
->getFocusedWindow()) ?
1308 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1310 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1313 NetizenList::iterator it
= netizenList
.begin();
1314 for (; it
!= netizenList
.end(); ++it
)
1315 (*it
)->sendWindowFocus(f
);
1319 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1320 NetizenList::iterator it
= netizenList
.begin();
1321 for (; it
!= netizenList
.end(); ++it
) {
1322 (*it
)->sendWindowAdd(w
, p
);
1327 void BScreen::updateNetizenWindowDel(Window w
) {
1328 NetizenList::iterator it
= netizenList
.begin();
1329 for (; it
!= netizenList
.end(); ++it
)
1330 (*it
)->sendWindowDel(w
);
1334 void BScreen::updateNetizenWindowRaise(Window w
) {
1335 NetizenList::iterator it
= netizenList
.begin();
1336 for (; it
!= netizenList
.end(); ++it
)
1337 (*it
)->sendWindowRaise(w
);
1341 void BScreen::updateNetizenWindowLower(Window w
) {
1342 NetizenList::iterator it
= netizenList
.begin();
1343 for (; it
!= netizenList
.end(); ++it
)
1344 (*it
)->sendWindowLower(w
);
1348 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1349 NetizenList::iterator it
= netizenList
.begin();
1350 for (; it
!= netizenList
.end(); ++it
)
1351 (*it
)->sendConfigNotify(e
);
1355 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1356 // the 13 represents the number of blackbox windows such as menus
1357 Window
*session_stack
= new
1358 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1359 unsigned int i
= 0, k
= num
;
1361 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1362 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1364 WorkspaceList::iterator wit
= workspacesList
.begin();
1365 const WorkspaceList::iterator w_end
= workspacesList
.end();
1366 for (; wit
!= w_end
; ++wit
)
1367 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1369 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1371 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1372 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1373 *(session_stack
+ i
++) = configmenu
->getWindowID();
1375 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1376 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1377 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1379 *(session_stack
+ i
++) =
1380 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1381 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1383 RootmenuList::iterator rit
= rootmenuList
.begin();
1384 for (; rit
!= rootmenuList
.end(); ++rit
)
1385 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1386 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1388 if (toolbar
->isOnTop())
1389 *(session_stack
+ i
++) = toolbar
->getWindowID();
1391 if (slit
->isOnTop())
1392 *(session_stack
+ i
++) = slit
->getWindowID();
1395 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1397 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1399 delete [] session_stack
;
1401 updateStackingList();
1405 void BScreen::lowerWindows(Window
*workspace_stack
, unsigned int num
) {
1406 assert(num
> 0); // this would cause trouble in the XRaiseWindow call
1408 Window
*session_stack
= new Window
[(num
+ desktopWindowList
.size())];
1409 unsigned int i
= 0, k
= num
;
1411 XLowerWindow(blackbox
->getXDisplay(), workspace_stack
[0]);
1414 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1416 WindowList::iterator dit
= desktopWindowList
.begin();
1417 const WindowList::iterator d_end
= desktopWindowList
.end();
1418 for (; dit
!= d_end
; ++dit
)
1419 *(session_stack
+ i
++) = *dit
;
1421 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1423 delete [] session_stack
;
1425 updateStackingList();
1429 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1430 bool ignore_sticky
) {
1433 if (wkspc_id
== BSENTINEL
)
1434 wkspc_id
= current_workspace
->getID();
1436 if (w
->getWorkspaceNumber() == wkspc_id
)
1439 if (w
->isIconic()) {
1441 getWorkspace(wkspc_id
)->addWindow(w
);
1442 } else if (ignore_sticky
|| ! w
->isStuck()) {
1443 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1444 getWorkspace(wkspc_id
)->addWindow(w
);
1446 updateStackingList();
1450 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1451 if (bw
->isIconic()) {
1452 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1456 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1457 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1458 clientmenu
->update();
1460 if (blackbox
->getFocusedWindow() == bw
)
1461 toolbar
->redrawWindowLabel(True
);
1466 void BScreen::nextFocus(void) {
1467 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1471 // if window is not on this screen, ignore it
1472 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1473 focused
= (BlackboxWindow
*) 0;
1476 if (focused
&& current_workspace
->getCount() > 1) {
1477 // next is the next window to recieve focus, current is a place holder
1478 BlackboxWindow
*current
;
1481 next
= current_workspace
->getNextWindowInList(current
);
1482 } while(! next
->setInputFocus() && next
!= focused
);
1484 if (next
!= focused
)
1485 current_workspace
->raiseWindow(next
);
1486 } else if (current_workspace
->getCount() >= 1) {
1487 next
= current_workspace
->getTopWindowOnStack();
1489 current_workspace
->raiseWindow(next
);
1490 next
->setInputFocus();
1495 void BScreen::prevFocus(void) {
1496 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1500 // if window is not on this screen, ignore it
1501 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1502 focused
= (BlackboxWindow
*) 0;
1505 if (focused
&& current_workspace
->getCount() > 1) {
1506 // next is the next window to recieve focus, current is a place holder
1507 BlackboxWindow
*current
;
1510 next
= current_workspace
->getPrevWindowInList(current
);
1511 } while(! next
->setInputFocus() && next
!= focused
);
1513 if (next
!= focused
)
1514 current_workspace
->raiseWindow(next
);
1515 } else if (current_workspace
->getCount() >= 1) {
1516 next
= current_workspace
->getTopWindowOnStack();
1518 current_workspace
->raiseWindow(next
);
1519 next
->setInputFocus();
1524 void BScreen::raiseFocus(void) {
1525 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1529 // if on this Screen, raise it
1530 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1531 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1532 workspace
->raiseWindow(focused
);
1537 void BScreen::InitMenu(void) {
1539 rootmenuList
.clear();
1541 while (rootmenu
->getCount())
1542 rootmenu
->remove(0);
1544 rootmenu
= new Rootmenu(this);
1546 bool defaultMenu
= True
;
1548 FILE *menu_file
= (FILE *) 0;
1549 const char *menu_filename
= blackbox
->getMenuFilename();
1552 if (! (menu_file
= fopen(menu_filename
, "r")))
1553 perror(menu_filename
);
1554 if (! menu_file
) { // opening the menu file failed, try the default menu
1555 menu_filename
= DEFAULTMENU
;
1556 if (! (menu_file
= fopen(menu_filename
, "r")))
1557 perror(menu_filename
);
1561 if (feof(menu_file
)) {
1562 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1563 "%s: Empty menu file"),
1566 char line
[1024], label
[1024];
1567 memset(line
, 0, 1024);
1568 memset(label
, 0, 1024);
1570 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1571 if (line
[0] != '#') {
1572 int i
, key
= 0, index
= -1, len
= strlen(line
);
1574 for (i
= 0; i
< len
; i
++) {
1575 if (line
[i
] == '[') index
= 0;
1576 else if (line
[i
] == ']') break;
1577 else if (line
[i
] != ' ')
1579 key
+= tolower(line
[i
]);
1582 if (key
== 517) { // [begin]
1584 for (i
= index
; i
< len
; i
++) {
1585 if (line
[i
] == '(') index
= 0;
1586 else if (line
[i
] == ')') break;
1587 else if (index
++ >= 0) {
1588 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1589 label
[index
- 1] = line
[i
];
1593 if (index
== -1) index
= 0;
1594 label
[index
] = '\0';
1596 rootmenu
->setLabel(label
);
1597 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1599 blackbox
->addMenuTimestamp(menu_filename
);
1609 rootmenu
->setInternalMenu();
1610 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1612 i18n(ScreenSet
, Screenxterm
, "xterm"));
1613 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1615 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1617 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1623 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1624 char line
[1024], label
[1024], command
[1024];
1626 while (! feof(file
)) {
1627 memset(line
, 0, 1024);
1628 memset(label
, 0, 1024);
1629 memset(command
, 0, 1024);
1631 if (fgets(line
, 1024, file
)) {
1632 if (line
[0] != '#') {
1633 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1635 // determine the keyword
1636 for (i
= 0; i
< line_length
; i
++) {
1637 if (line
[i
] == '[') parse
= 1;
1638 else if (line
[i
] == ']') break;
1639 else if (line
[i
] != ' ')
1641 key
+= tolower(line
[i
]);
1644 // get the label enclosed in ()'s
1647 for (i
= 0; i
< line_length
; i
++) {
1648 if (line
[i
] == '(') {
1651 } else if (line
[i
] == ')') break;
1652 else if (index
++ >= 0) {
1653 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1654 label
[index
- 1] = line
[i
];
1659 label
[index
] = '\0';
1664 // get the command enclosed in {}'s
1667 for (i
= 0; i
< line_length
; i
++) {
1668 if (line
[i
] == '{') {
1671 } else if (line
[i
] == '}') break;
1672 else if (index
++ >= 0) {
1673 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1674 command
[index
- 1] = line
[i
];
1679 command
[index
] = '\0';
1686 return ((menu
->getCount() == 0) ? True
: False
);
1693 menu
->insert(label
);
1698 if ((! *label
) && (! *command
)) {
1699 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1700 "BScreen::parseMenuFile: [exec] error, "
1701 "no menu label and/or command defined\n"));
1705 menu
->insert(label
, BScreen::Execute
, command
);
1711 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1712 "BScreen::parseMenuFile: [exit] error, "
1713 "no menu label defined\n"));
1717 menu
->insert(label
, BScreen::Exit
);
1723 if ((! *label
) || (! *command
)) {
1725 i18n(ScreenSet
, ScreenSTYLEError
,
1726 "BScreen::parseMenuFile: [style] error, "
1727 "no menu label and/or filename defined\n"));
1731 string style
= expandTilde(command
);
1733 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1740 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1741 "BScreen::parseMenufile: [config] error, "
1742 "no label defined"));
1746 menu
->insert(label
, configmenu
);
1750 case 740: // include
1753 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1754 "BScreen::parseMenuFile: [include] error, "
1755 "no filename defined\n"));
1759 string newfile
= expandTilde(label
);
1760 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1764 if (fstat(fileno(submenufile
), &buf
) ||
1765 (! S_ISREG(buf
.st_mode
))) {
1767 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1768 "BScreen::parseMenuFile: [include] error: "
1769 "'%s' is not a regular file\n"), newfile
.c_str());
1773 if (! feof(submenufile
)) {
1774 if (! parseMenuFile(submenufile
, menu
))
1775 blackbox
->addMenuTimestamp(newfile
);
1777 fclose(submenufile
);
1780 perror(newfile
.c_str());
1786 case 767: // submenu
1789 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1790 "BScreen::parseMenuFile: [submenu] error, "
1791 "no menu label defined\n"));
1795 Rootmenu
*submenu
= new Rootmenu(this);
1798 submenu
->setLabel(command
);
1800 submenu
->setLabel(label
);
1802 parseMenuFile(file
, submenu
);
1804 menu
->insert(label
, submenu
);
1805 rootmenuList
.push_back(submenu
);
1810 case 773: // restart
1813 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1814 "BScreen::parseMenuFile: [restart] error, "
1815 "no menu label defined\n"));
1820 menu
->insert(label
, BScreen::RestartOther
, command
);
1822 menu
->insert(label
, BScreen::Restart
);
1827 case 845: // reconfig
1831 i18n(ScreenSet
, ScreenRECONFIGError
,
1832 "BScreen::parseMenuFile: [reconfig] error, "
1833 "no menu label defined\n"));
1837 menu
->insert(label
, BScreen::Reconfigure
);
1842 case 995: // stylesdir
1843 case 1113: // stylesmenu
1845 bool newmenu
= ((key
== 1113) ? True
: False
);
1847 if ((! *label
) || ((! *command
) && newmenu
)) {
1849 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1850 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1851 " error, no directory defined\n"));
1855 char *directory
= ((newmenu
) ? command
: label
);
1857 string stylesdir
= expandTilde(directory
);
1859 struct stat statbuf
;
1861 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1862 if (S_ISDIR(statbuf
.st_mode
)) {
1863 Rootmenu
*stylesmenu
;
1866 stylesmenu
= new Rootmenu(this);
1870 DIR *d
= opendir(stylesdir
.c_str());
1872 std::vector
<string
> ls
;
1874 while((p
= readdir(d
)))
1875 ls
.push_back(p
->d_name
);
1879 std::sort(ls
.begin(), ls
.end());
1881 std::vector
<string
>::iterator it
= ls
.begin(),
1883 for (; it
!= end
; ++it
) {
1884 const string
& fname
= *it
;
1886 if (fname
[fname
.size()-1] == '~')
1889 string style
= stylesdir
;
1893 if ((! stat(style
.c_str(), &statbuf
)) &&
1894 S_ISREG(statbuf
.st_mode
))
1895 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1898 stylesmenu
->update();
1901 stylesmenu
->setLabel(label
);
1902 menu
->insert(label
, stylesmenu
);
1903 rootmenuList
.push_back(stylesmenu
);
1906 blackbox
->addMenuTimestamp(stylesdir
);
1909 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1910 "BScreen::parseMenuFile:"
1911 " [stylesdir/stylesmenu] error, %s is not a"
1912 " directory\n"), stylesdir
.c_str());
1916 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1917 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1918 " error, %s does not exist\n"), stylesdir
.c_str());
1923 case 1090: // workspaces
1927 i18n(ScreenSet
, ScreenWORKSPACESError
,
1928 "BScreen:parseMenuFile: [workspaces] error, "
1929 "no menu label defined\n"));
1933 menu
->insert(label
, workspacemenu
);
1942 return ((menu
->getCount() == 0) ? True
: False
);
1946 void BScreen::shutdown(void) {
1947 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1948 XSync(blackbox
->getXDisplay(), False
);
1950 while(! windowList
.empty())
1951 unmanageWindow(windowList
.front(), True
);
1957 void BScreen::showPosition(int x
, int y
) {
1958 if (! geom_visible
) {
1959 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1960 (getWidth() - geom_w
) / 2,
1961 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1962 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1963 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1965 geom_visible
= True
;
1970 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1971 "X: %4d x Y: %4d"), x
, y
);
1973 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1975 resource
.wstyle
.font
->drawString(geom_window
,
1976 resource
.bevel_width
, resource
.bevel_width
,
1977 resource
.wstyle
.l_text_focus
,
1982 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1983 if (! geom_visible
) {
1984 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1985 (getWidth() - geom_w
) / 2,
1986 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1987 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1988 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1990 geom_visible
= True
;
1995 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1996 "W: %4d x H: %4d"), gx
, gy
);
1998 XClearWindow(blackbox
->getXDisplay(), geom_window
);
2000 resource
.wstyle
.font
->drawString(geom_window
,
2001 resource
.bevel_width
, resource
.bevel_width
,
2002 resource
.wstyle
.l_text_focus
,
2007 void BScreen::hideGeometry(void) {
2009 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
2010 geom_visible
= False
;
2015 void BScreen::addStrut(Strut
*strut
) {
2016 strutList
.push_back(strut
);
2020 void BScreen::removeStrut(Strut
*strut
) {
2021 strutList
.remove(strut
);
2025 const Rect
& BScreen::availableArea(void) const {
2027 return getRect(); // return the full screen
2032 void BScreen::updateAvailableArea(void) {
2033 Rect old_area
= usableArea
;
2034 usableArea
= getRect(); // reset to full screen
2036 /* these values represent offsets from the screen edge
2037 * we look for the biggest offset on each edge and then apply them
2039 * do not be confused by the similarity to the names of Rect's members
2041 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
2044 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
2046 for(; it
!= end
; ++it
) {
2048 if (strut
->left
> current_left
)
2049 current_left
= strut
->left
;
2050 if (strut
->top
> current_top
)
2051 current_top
= strut
->top
;
2052 if (strut
->right
> current_right
)
2053 current_right
= strut
->right
;
2054 if (strut
->bottom
> current_bottom
)
2055 current_bottom
= strut
->bottom
;
2058 usableArea
.setPos(current_left
, current_top
);
2059 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2060 usableArea
.height() - (current_top
+ current_bottom
));
2062 if (old_area
!= usableArea
) {
2063 BlackboxWindowList::iterator it
= windowList
.begin(),
2064 end
= windowList
.end();
2065 for (; it
!= end
; ++it
)
2066 if ((*it
)->isMaximized()) (*it
)->remaximize();
2073 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2074 assert(index
< workspacesList
.size());
2075 return workspacesList
[index
];
2079 void BScreen::buttonPressEvent(const XButtonEvent
*xbutton
) {
2080 if (xbutton
->button
== 1) {
2081 if (! isRootColormapInstalled())
2082 image_control
->installRootColormap();
2084 if (workspacemenu
->isVisible())
2085 workspacemenu
->hide();
2087 if (rootmenu
->isVisible())
2089 } else if (xbutton
->button
== 2) {
2090 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2091 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2096 if (mx
+ workspacemenu
->getWidth() > getWidth())
2097 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2099 if (my
+ workspacemenu
->getHeight() > getHeight())
2100 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2102 workspacemenu
->move(mx
, my
);
2104 if (! workspacemenu
->isVisible()) {
2105 workspacemenu
->removeParent();
2106 workspacemenu
->show();
2108 } else if (xbutton
->button
== 3) {
2109 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2110 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2115 if (mx
+ rootmenu
->getWidth() > getWidth())
2116 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2118 if (my
+ rootmenu
->getHeight() > getHeight())
2119 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2121 rootmenu
->move(mx
, my
);
2123 if (! rootmenu
->isVisible()) {
2124 blackbox
->checkMenu();
2128 } else if (xbutton
->button
== 4) {
2129 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2130 changeWorkspaceID(0);
2132 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2134 } else if (xbutton
->button
== 5) {
2135 if (getCurrentWorkspaceID() == 0)
2136 changeWorkspaceID(getWorkspaceCount() - 1);
2138 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2143 void BScreen::propertyNotifyEvent(const XPropertyEvent
*pe
) {
2144 if (pe
->atom
== xatom
->getAtom(XAtom::net_desktop_names
)) {
2145 // _NET_WM_DESKTOP_NAMES
2146 fprintf(stderr
, "UPDATING WORKSPACE NAMES\n");
2147 WorkspaceList::iterator it
= workspacesList
.begin();
2148 const WorkspaceList::iterator end
= workspacesList
.end();
2149 for (; it
!= end
; ++it
) {
2150 (*it
)->readName(); // re-read its name from the window property
2151 workspacemenu
->changeWorkspaceLabel((*it
)->getID(), (*it
)->getName());
2153 workspacemenu
->update();
2154 toolbar
->reconfigure();
2155 saveWorkspaceNames();
2160 void BScreen::toggleFocusModel(FocusModel model
) {
2161 std::for_each(windowList
.begin(), windowList
.end(),
2162 std::mem_fun(&BlackboxWindow::ungrabButtons
));
2164 if (model
== SloppyFocus
) {
2165 saveSloppyFocus(True
);
2167 // we're cheating here to save writing the config file 3 times
2168 resource
.auto_raise
= False
;
2169 resource
.click_raise
= False
;
2170 saveSloppyFocus(False
);
2173 std::for_each(windowList
.begin(), windowList
.end(),
2174 std::mem_fun(&BlackboxWindow::grabButtons
));
2178 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2179 const string
&default_color
,
2180 const Configuration
&style
) {
2184 if (style
.getValue(rname
, s
))
2185 texture
= BTexture(s
);
2187 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2189 // associate this texture with this screen
2190 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2191 texture
.setImageControl(image_control
);
2193 if (texture
.texture() & BTexture::Solid
) {
2194 texture
.setColor(readDatabaseColor(rname
+ ".color",
2195 default_color
, style
));
2196 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2197 default_color
, style
));
2198 } else if (texture
.texture() & BTexture::Gradient
) {
2199 texture
.setColor(readDatabaseColor(rname
+ ".color",
2200 default_color
, style
));
2201 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2202 default_color
, style
));
2209 BColor
BScreen::readDatabaseColor(const string
&rname
,
2210 const string
&default_color
,
2211 const Configuration
&style
) {
2214 if (style
.getValue(rname
, s
))
2215 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2217 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2222 BFont
*BScreen::readDatabaseFont(const string
&rbasename
,
2223 const Configuration
&style
) {
2230 if (style
.getValue(rbasename
+ "xft.font", s
) &&
2231 style
.getValue(rbasename
+ "xft.size", i
)) {
2234 bool italic
= False
;
2235 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
2236 if (s
.find("bold") != string::npos
)
2238 if (s
.find("italic") != string::npos
)
2242 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, family
, i
, bold
,
2243 italic
, resource
.aa_fonts
);
2247 delete b
; // fall back to the normal X font stuff
2251 style
.getValue(rbasename
+ "font", s
);
2252 // if this fails, a blank string will be used, which will cause the fallback
2255 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2257 exit(2); // can't continue without a font