1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // blackbox.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
25 # include "../config.h"
26 #endif // HAVE_CONFIG_H
30 #include <X11/Xutil.h>
31 #include <X11/Xatom.h>
32 #include <X11/cursorfont.h>
33 #include <X11/keysym.h>
36 #include <X11/extensions/shape.h>
41 #endif // HAVE_STDIO_H
45 #endif // HAVE_STDLIB_H
49 #endif // HAVE_STRING_H
52 # include <sys/types.h>
54 #endif // HAVE_UNISTD_H
56 #ifdef HAVE_SYS_PARAM_H
57 # include <sys/param.h>
58 #endif // HAVE_SYS_PARAM_H
60 #ifdef HAVE_SYS_SELECT_H
61 # include <sys/select.h>
62 #endif // HAVE_SYS_SELECT_H
66 #endif // HAVE_SIGNAL_H
68 #ifdef HAVE_SYS_SIGNAL_H
69 # include <sys/signal.h>
70 #endif // HAVE_SYS_SIGNAL_H
72 #ifdef HAVE_SYS_STAT_H
73 # include <sys/types.h>
74 # include <sys/stat.h>
75 #endif // HAVE_SYS_STAT_H
77 #ifdef TIME_WITH_SYS_TIME
78 # include <sys/time.h>
80 #else // !TIME_WITH_SYS_TIME
81 # ifdef HAVE_SYS_TIME_H
82 # include <sys/time.h>
83 # else // !HAVE_SYS_TIME_H
85 # endif // HAVE_SYS_TIME_H
86 #endif // TIME_WITH_SYS_TIME
90 #endif // HAVE_LIBGEN_H
100 #include "blackbox.hh"
101 #include "Basemenu.hh"
102 #include "Clientmenu.hh"
103 #include "GCCache.hh"
105 #include "Rootmenu.hh"
108 #include "Toolbar.hh"
111 #include "Workspace.hh"
112 #include "Workspacemenu.hh"
115 // X event scanner for enter/leave notifies - adapted from twm
118 bool leave
, inferior
, enter
;
121 static Bool
queueScanner(Display
*, XEvent
*e
, char *args
) {
122 scanargs
*scan
= (scanargs
*) args
;
123 if ((e
->type
== LeaveNotify
) &&
124 (e
->xcrossing
.window
== scan
->w
) &&
125 (e
->xcrossing
.mode
== NotifyNormal
)) {
127 scan
->inferior
= (e
->xcrossing
.detail
== NotifyInferior
);
128 } else if ((e
->type
== EnterNotify
) && (e
->xcrossing
.mode
== NotifyUngrab
)) {
138 Blackbox::Blackbox(char **m_argv
, char *dpy_name
, char *rc
, char *menu
)
139 : BaseDisplay(m_argv
[0], dpy_name
) {
140 if (! XSupportsLocale())
141 fprintf(stderr
, "X server does not support locale\n");
143 if (XSetLocaleModifiers("") == NULL
)
144 fprintf(stderr
, "cannot set locale modifiers\n");
148 if (! rc
) rc
= "~/.openbox/rc";
149 rc_file
= expandTilde(rc
);
150 config
.setFile(rc_file
);
151 if (! menu
) menu
= "~/.openbox/menu";
152 menu_file
= expandTilde(menu
);
156 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
= 0;
159 focused_window
= (BlackboxWindow
*) 0;
164 xatom
= new XAtom(this);
166 cursor
.session
= XCreateFontCursor(getXDisplay(), XC_left_ptr
);
167 cursor
.move
= XCreateFontCursor(getXDisplay(), XC_fleur
);
168 cursor
.ll_angle
= XCreateFontCursor(getXDisplay(), XC_ll_angle
);
169 cursor
.lr_angle
= XCreateFontCursor(getXDisplay(), XC_lr_angle
);
171 for (unsigned int i
= 0; i
< getNumberOfScreens(); i
++) {
172 BScreen
*screen
= new BScreen(this, i
);
174 if (! screen
->isScreenManaged()) {
179 screenList
.push_back(screen
);
182 if (screenList
.empty()) {
184 i18n(blackboxSet
, blackboxNoManagableScreens
,
185 "Blackbox::Blackbox: no managable screens found, aborting.\n"));
189 // save current settings and default values
192 // set the screen with mouse to the first managed screen
193 active_screen
= screenList
.front();
196 XSynchronize(getXDisplay(), False
);
197 XSync(getXDisplay(), False
);
199 reconfigure_wait
= reread_menu_wait
= False
;
201 timer
= new BTimer(this, this);
202 timer
->setTimeout(0l);
206 Blackbox::~Blackbox(void) {
207 std::for_each(screenList
.begin(), screenList
.end(), PointerAssassin());
209 std::for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
218 void Blackbox::process_event(XEvent
*e
) {
221 // strip the lock key modifiers
222 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
224 last_time
= e
->xbutton
.time
;
226 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
227 Basemenu
*menu
= (Basemenu
*) 0;
228 Slit
*slit
= (Slit
*) 0;
229 Toolbar
*tbar
= (Toolbar
*) 0;
230 BScreen
*scrn
= (BScreen
*) 0;
232 if ((win
= searchWindow(e
->xbutton
.window
))) {
233 win
->buttonPressEvent(&e
->xbutton
);
235 /* XXX: is this sane on low colour desktops? */
236 if (e
->xbutton
.button
== 1)
237 win
->installColormap(True
);
238 } else if ((menu
= searchMenu(e
->xbutton
.window
))) {
239 menu
->buttonPressEvent(&e
->xbutton
);
240 } else if ((slit
= searchSlit(e
->xbutton
.window
))) {
241 slit
->buttonPressEvent(&e
->xbutton
);
242 } else if ((tbar
= searchToolbar(e
->xbutton
.window
))) {
243 tbar
->buttonPressEvent(&e
->xbutton
);
244 } else if ((scrn
= searchScreen(e
->xbutton
.window
))) {
245 scrn
->buttonPressEvent(&e
->xbutton
);
246 if (active_screen
!= scrn
) {
247 active_screen
= scrn
;
248 // first, set no focus window on the old screen
250 // and move focus to this screen
257 case ButtonRelease
: {
258 // strip the lock key modifiers
259 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
261 last_time
= e
->xbutton
.time
;
263 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
264 Basemenu
*menu
= (Basemenu
*) 0;
265 Toolbar
*tbar
= (Toolbar
*) 0;
267 if ((win
= searchWindow(e
->xbutton
.window
)))
268 win
->buttonReleaseEvent(&e
->xbutton
);
269 else if ((menu
= searchMenu(e
->xbutton
.window
)))
270 menu
->buttonReleaseEvent(&e
->xbutton
);
271 else if ((tbar
= searchToolbar(e
->xbutton
.window
)))
272 tbar
->buttonReleaseEvent(&e
->xbutton
);
277 case ConfigureRequest
: {
278 // compress configure requests...
281 while(XCheckTypedWindowEvent(getXDisplay(), e
->xconfigurerequest
.window
,
282 ConfigureRequest
, &realevent
)) {
288 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
289 Slit
*slit
= (Slit
*) 0;
291 if ((win
= searchWindow(e
->xconfigurerequest
.window
))) {
292 win
->configureRequestEvent(&e
->xconfigurerequest
);
293 } else if ((slit
= searchSlit(e
->xconfigurerequest
.window
))) {
294 slit
->configureRequestEvent(&e
->xconfigurerequest
);
296 if (validateWindow(e
->xconfigurerequest
.window
)) {
299 xwc
.x
= e
->xconfigurerequest
.x
;
300 xwc
.y
= e
->xconfigurerequest
.y
;
301 xwc
.width
= e
->xconfigurerequest
.width
;
302 xwc
.height
= e
->xconfigurerequest
.height
;
303 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
304 xwc
.sibling
= e
->xconfigurerequest
.above
;
305 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
307 XConfigureWindow(getXDisplay(), e
->xconfigurerequest
.window
,
308 e
->xconfigurerequest
.value_mask
, &xwc
);
317 fprintf(stderr
, "Blackbox::process_event(): MapRequest for 0x%lx\n",
318 e
->xmaprequest
.window
);
321 BlackboxWindow
*win
= searchWindow(e
->xmaprequest
.window
);
324 BScreen
*screen
= searchScreen(e
->xmaprequest
.parent
);
328 we got a map request for a window who's parent isn't root. this
329 can happen in only one circumstance:
331 a client window unmapped a managed window, and then remapped it
332 somewhere between unmapping the client window and reparenting it
335 regardless of how it happens, we need to find the screen that
338 XWindowAttributes wattrib
;
339 if (! XGetWindowAttributes(getXDisplay(), e
->xmaprequest
.window
,
341 // failed to get the window attributes, perhaps the window has
342 // now been destroyed?
346 screen
= searchScreen(wattrib
.root
);
347 assert(screen
!= 0); // this should never happen
350 screen
->manageWindow(e
->xmaprequest
.window
);
357 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
358 Slit
*slit
= (Slit
*) 0;
360 if ((win
= searchWindow(e
->xunmap
.window
))) {
361 win
->unmapNotifyEvent(&e
->xunmap
);
362 } else if ((slit
= searchSlit(e
->xunmap
.window
))) {
363 slit
->unmapNotifyEvent(&e
->xunmap
);
369 case DestroyNotify
: {
370 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
371 Slit
*slit
= (Slit
*) 0;
372 BWindowGroup
*group
= (BWindowGroup
*) 0;
374 if ((win
= searchWindow(e
->xdestroywindow
.window
))) {
375 win
->destroyNotifyEvent(&e
->xdestroywindow
);
376 } else if ((slit
= searchSlit(e
->xdestroywindow
.window
))) {
377 slit
->removeClient(e
->xdestroywindow
.window
, False
);
378 } else if ((group
= searchGroup(e
->xdestroywindow
.window
))) {
385 case ReparentNotify
: {
387 this event is quite rare and is usually handled in unmapNotify
388 however, if the window is unmapped when the reparent event occurs
389 the window manager never sees it because an unmap event is not sent
390 to an already unmapped window.
392 BlackboxWindow
*win
= searchWindow(e
->xreparent
.window
);
394 win
->reparentNotifyEvent(&e
->xreparent
);
396 Slit
*slit
= searchSlit(e
->xreparent
.window
);
397 if (slit
&& slit
->getWindowID() != e
->xreparent
.parent
)
398 slit
->removeClient(e
->xreparent
.window
, True
);
404 // motion notify compression...
407 while (XCheckTypedWindowEvent(getXDisplay(), e
->xmotion
.window
,
408 MotionNotify
, &realevent
)) {
412 // if we have compressed some motion events, use the last one
416 // strip the lock key modifiers
417 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
419 last_time
= e
->xmotion
.time
;
421 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
422 Basemenu
*menu
= (Basemenu
*) 0;
424 if ((win
= searchWindow(e
->xmotion
.window
)))
425 win
->motionNotifyEvent(&e
->xmotion
);
426 else if ((menu
= searchMenu(e
->xmotion
.window
)))
427 menu
->motionNotifyEvent(&e
->xmotion
);
432 case PropertyNotify
: {
433 last_time
= e
->xproperty
.time
;
435 if (e
->xproperty
.state
!= PropertyDelete
) {
436 BlackboxWindow
*win
= searchWindow(e
->xproperty
.window
);
439 win
->propertyNotifyEvent(e
->xproperty
.atom
);
446 last_time
= e
->xcrossing
.time
;
448 BScreen
*screen
= (BScreen
*) 0;
449 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
450 Basemenu
*menu
= (Basemenu
*) 0;
451 Toolbar
*tbar
= (Toolbar
*) 0;
452 Slit
*slit
= (Slit
*) 0;
454 if (e
->xcrossing
.mode
== NotifyGrab
) break;
458 sa
.w
= e
->xcrossing
.window
;
459 sa
.enter
= sa
.leave
= False
;
460 XCheckIfEvent(getXDisplay(), &dummy
, queueScanner
, (char *) &sa
);
462 if ((e
->xcrossing
.window
== e
->xcrossing
.root
) &&
463 (screen
= searchScreen(e
->xcrossing
.window
))) {
464 screen
->getImageControl()->installRootColormap();
465 } else if ((win
= searchWindow(e
->xcrossing
.window
))) {
466 if (win
->getScreen()->isSloppyFocus() &&
467 (! win
->isFocused()) && (! no_focus
)) {
468 if (((! sa
.leave
) || sa
.inferior
) && win
->isVisible()) {
469 if (win
->setInputFocus())
470 win
->installColormap(True
); // XXX: shouldnt we honour no install?
473 } else if ((menu
= searchMenu(e
->xcrossing
.window
))) {
474 menu
->enterNotifyEvent(&e
->xcrossing
);
475 } else if ((tbar
= searchToolbar(e
->xcrossing
.window
))) {
476 tbar
->enterNotifyEvent(&e
->xcrossing
);
477 } else if ((slit
= searchSlit(e
->xcrossing
.window
))) {
478 slit
->enterNotifyEvent(&e
->xcrossing
);
484 last_time
= e
->xcrossing
.time
;
486 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
487 Basemenu
*menu
= (Basemenu
*) 0;
488 Toolbar
*tbar
= (Toolbar
*) 0;
489 Slit
*slit
= (Slit
*) 0;
491 if ((menu
= searchMenu(e
->xcrossing
.window
)))
492 menu
->leaveNotifyEvent(&e
->xcrossing
);
493 else if ((win
= searchWindow(e
->xcrossing
.window
)))
494 win
->installColormap(False
);
495 else if ((tbar
= searchToolbar(e
->xcrossing
.window
)))
496 tbar
->leaveNotifyEvent(&e
->xcrossing
);
497 else if ((slit
= searchSlit(e
->xcrossing
.window
)))
498 slit
->leaveNotifyEvent(&e
->xcrossing
);
503 // compress expose events
506 int ex1
, ey1
, ex2
, ey2
;
509 ex2
= ex1
+ e
->xexpose
.width
- 1;
510 ey2
= ey1
+ e
->xexpose
.height
- 1;
511 while (XCheckTypedWindowEvent(getXDisplay(), e
->xexpose
.window
,
512 Expose
, &realevent
)) {
516 ex1
= std::min(realevent
.xexpose
.x
, ex1
);
517 ey1
= std::min(realevent
.xexpose
.y
, ey1
);
518 ex2
= std::max(realevent
.xexpose
.x
+ realevent
.xexpose
.width
- 1, ex2
);
519 ey2
= std::max(realevent
.xexpose
.y
+ realevent
.xexpose
.height
- 1, ey2
);
524 // use the merged area
527 e
->xexpose
.width
= ex2
- ex1
+ 1;
528 e
->xexpose
.height
= ey2
- ey1
+ 1;
530 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
531 Basemenu
*menu
= (Basemenu
*) 0;
532 Toolbar
*tbar
= (Toolbar
*) 0;
534 if ((win
= searchWindow(e
->xexpose
.window
)))
535 win
->exposeEvent(&e
->xexpose
);
536 else if ((menu
= searchMenu(e
->xexpose
.window
)))
537 menu
->exposeEvent(&e
->xexpose
);
538 else if ((tbar
= searchToolbar(e
->xexpose
.window
)))
539 tbar
->exposeEvent(&e
->xexpose
);
545 Toolbar
*tbar
= searchToolbar(e
->xkey
.window
);
547 if (tbar
&& tbar
->isEditing())
548 tbar
->keyPressEvent(&e
->xkey
);
553 case ColormapNotify
: {
554 BScreen
*screen
= searchScreen(e
->xcolormap
.window
);
557 screen
->setRootColormapInstalled((e
->xcolormap
.state
==
558 ColormapInstalled
) ? True
: False
);
564 if (e
->xfocus
.detail
!= NotifyNonlinear
&&
565 e
->xfocus
.detail
!= NotifyAncestor
) {
567 don't process FocusIns when:
568 1. the new focus window isn't an ancestor or inferior of the old
569 focus window (NotifyNonlinear)
570 make sure to allow the FocusIn when the old focus window was an
571 ancestor but didn't have a parent, such as root (NotifyAncestor)
576 BlackboxWindow
*win
= searchWindow(e
->xfocus
.window
);
578 if (! win
->isFocused())
579 win
->setFocusFlag(True
);
582 set the event window to None. when the FocusOut event handler calls
583 this function recursively, it uses this as an indication that focus
584 has moved to a known window.
586 e
->xfocus
.window
= None
;
593 if (e
->xfocus
.detail
!= NotifyNonlinear
) {
595 don't process FocusOuts when:
596 2. the new focus window isn't an ancestor or inferior of the old
597 focus window (NotifyNonlinear)
602 BlackboxWindow
*win
= searchWindow(e
->xfocus
.window
);
603 if (win
&& win
->isFocused()) {
605 before we mark "win" as unfocused, we need to verify that focus is
606 going to a known location, is in a known location, or set focus
611 // don't check the current focus if FocusOut was generated during a grab
612 bool check_focus
= (e
->xfocus
.mode
== NotifyNormal
);
615 First, check if there is a pending FocusIn event waiting. if there
616 is, process it and determine if focus has moved to another window
617 (the FocusIn event handler sets the window in the event
618 structure to None to indicate this).
620 if (XCheckTypedEvent(getXDisplay(), FocusIn
, &event
)) {
622 process_event(&event
);
623 if (event
.xfocus
.window
== None
) {
631 Second, we query the X server for the current input focus.
632 to make sure that we keep a consistent state.
634 BlackboxWindow
*focus
;
637 XGetInputFocus(getXDisplay(), &w
, &revert
);
638 focus
= searchWindow(w
);
641 focus got from "win" to "focus" under some very strange
642 circumstances, and we need to make sure that the focus indication
645 setFocusedWindow(focus
);
647 // we have no idea where focus went... so we set it to somewhere
656 case ClientMessage
: {
657 if (e
->xclient
.format
== 32) {
658 if (e
->xclient
.message_type
== xatom
->getAtom(XAtom::wm_change_state
)) {
659 BlackboxWindow
*win
= searchWindow(e
->xclient
.window
);
660 if (! win
|| ! win
->validateClient()) return;
662 if (e
->xclient
.data
.l
[0] == IconicState
)
664 if (e
->xclient
.data
.l
[0] == NormalState
)
666 } else if(e
->xclient
.message_type
== getBlackboxChangeWorkspaceAtom()) {
667 BScreen
*screen
= searchScreen(e
->xclient
.window
);
669 unsigned int workspace
= e
->xclient
.data
.l
[0];
670 if (screen
&& workspace
< screen
->getWorkspaceCount())
671 screen
->changeWorkspaceID(workspace
);
672 } else if (e
->xclient
.message_type
== getBlackboxChangeWindowFocusAtom()) {
673 BlackboxWindow
*win
= searchWindow(e
->xclient
.window
);
675 if (win
&& win
->isVisible() && win
->setInputFocus())
676 win
->installColormap(True
);
677 } else if (e
->xclient
.message_type
== getBlackboxCycleWindowFocusAtom()) {
678 BScreen
*screen
= searchScreen(e
->xclient
.window
);
681 if (! e
->xclient
.data
.l
[0])
686 } else if (e
->xclient
.message_type
== getBlackboxChangeAttributesAtom()) {
687 BlackboxWindow
*win
= searchWindow(e
->xclient
.window
);
689 if (win
&& win
->validateClient()) {
691 net
.flags
= e
->xclient
.data
.l
[0];
692 net
.attrib
= e
->xclient
.data
.l
[1];
693 net
.workspace
= e
->xclient
.data
.l
[2];
694 net
.stack
= e
->xclient
.data
.l
[3];
695 net
.decoration
= e
->xclient
.data
.l
[4];
697 win
->changeBlackboxHints(&net
);
706 case ConfigureNotify
:
708 break; // not handled, just ignore
712 if (e
->type
== getShapeEventBase()) {
713 XShapeEvent
*shape_event
= (XShapeEvent
*) e
;
714 BlackboxWindow
*win
= searchWindow(e
->xany
.window
);
717 win
->shapeEvent(shape_event
);
725 bool Blackbox::handleSignal(int sig
) {
751 bool Blackbox::validateWindow(Window window
) {
753 if (XCheckTypedWindowEvent(getXDisplay(), window
, DestroyNotify
, &event
)) {
754 XPutBackEvent(getXDisplay(), &event
);
763 BScreen
*Blackbox::searchScreen(Window window
) {
764 ScreenList::iterator it
= screenList
.begin();
766 for (; it
!= screenList
.end(); ++it
) {
768 if (s
->getRootWindow() == window
)
772 return (BScreen
*) 0;
776 BlackboxWindow
*Blackbox::searchWindow(Window window
) {
777 WindowLookup::iterator it
= windowSearchList
.find(window
);
778 if (it
!= windowSearchList
.end())
781 return (BlackboxWindow
*) 0;
785 BWindowGroup
*Blackbox::searchGroup(Window window
) {
786 GroupLookup::iterator it
= groupSearchList
.find(window
);
787 if (it
!= groupSearchList
.end())
790 return (BWindowGroup
*) 0;
794 Basemenu
*Blackbox::searchMenu(Window window
) {
795 MenuLookup::iterator it
= menuSearchList
.find(window
);
796 if (it
!= menuSearchList
.end())
799 return (Basemenu
*) 0;
803 Toolbar
*Blackbox::searchToolbar(Window window
) {
804 ToolbarLookup::iterator it
= toolbarSearchList
.find(window
);
805 if (it
!= toolbarSearchList
.end())
812 Slit
*Blackbox::searchSlit(Window window
) {
813 SlitLookup::iterator it
= slitSearchList
.find(window
);
814 if (it
!= slitSearchList
.end())
821 void Blackbox::saveWindowSearch(Window window
, BlackboxWindow
*data
) {
822 windowSearchList
.insert(WindowLookupPair(window
, data
));
826 void Blackbox::saveGroupSearch(Window window
, BWindowGroup
*data
) {
827 groupSearchList
.insert(GroupLookupPair(window
, data
));
831 void Blackbox::saveMenuSearch(Window window
, Basemenu
*data
) {
832 menuSearchList
.insert(MenuLookupPair(window
, data
));
836 void Blackbox::saveToolbarSearch(Window window
, Toolbar
*data
) {
837 toolbarSearchList
.insert(ToolbarLookupPair(window
, data
));
841 void Blackbox::saveSlitSearch(Window window
, Slit
*data
) {
842 slitSearchList
.insert(SlitLookupPair(window
, data
));
846 void Blackbox::removeWindowSearch(Window window
) {
847 windowSearchList
.erase(window
);
851 void Blackbox::removeGroupSearch(Window window
) {
852 groupSearchList
.erase(window
);
856 void Blackbox::removeMenuSearch(Window window
) {
857 menuSearchList
.erase(window
);
861 void Blackbox::removeToolbarSearch(Window window
) {
862 toolbarSearchList
.erase(window
);
866 void Blackbox::removeSlitSearch(Window window
) {
867 slitSearchList
.erase(window
);
871 void Blackbox::restart(const char *prog
) {
875 execlp(prog
, prog
, NULL
);
879 // fall back in case the above execlp doesn't work
880 execvp(argv
[0], argv
);
881 string name
= basename(argv
[0]);
882 execvp(name
.c_str(), argv
);
886 void Blackbox::shutdown(void) {
887 BaseDisplay::shutdown();
889 XSetInputFocus(getXDisplay(), PointerRoot
, None
, CurrentTime
);
891 std::for_each(screenList
.begin(), screenList
.end(),
892 std::mem_fun(&BScreen::shutdown
));
894 XSync(getXDisplay(), False
);
899 * Save all values as they are so that the defaults will be written to the rc
902 void Blackbox::save_rc(void) {
903 config
.setAutoSave(false);
905 config
.setValue("session.colorsPerChannel", resource
.colors_per_channel
);
906 config
.setValue("session.doubleClickInterval",
907 resource
.double_click_interval
);
908 config
.setValue("session.autoRaiseDelay",
909 ((resource
.auto_raise_delay
.tv_sec
* 1000) +
910 (resource
.auto_raise_delay
.tv_usec
/ 1000)));
911 config
.setValue("session.cacheLife", resource
.cache_life
/ 60000);
912 config
.setValue("session.cacheMax", resource
.cache_max
);
913 config
.setValue("session.styleFile", resource
.style_file
);
914 config
.setValue("session.titlebarLayout", resource
.titlebar_layout
);
916 std::for_each(screenList
.begin(), screenList
.end(),
917 std::mem_fun(&BScreen::save_rc
));
919 config
.setAutoSave(true);
924 void Blackbox::load_rc(void) {
930 if (! config
.getValue("session.colorsPerChannel",
931 resource
.colors_per_channel
))
932 resource
.colors_per_channel
= 4;
933 if (resource
.colors_per_channel
< 2) resource
.colors_per_channel
= 2;
934 else if (resource
.colors_per_channel
> 6) resource
.colors_per_channel
= 6;
936 if (config
.getValue("session.styleFile", s
))
937 resource
.style_file
= expandTilde(s
);
939 resource
.style_file
= DEFAULTSTYLE
;
941 if (! config
.getValue("session.doubleClickInterval",
942 resource
.double_click_interval
));
943 resource
.double_click_interval
= 250;
945 if (! config
.getValue("session.autoRaiseDelay",
946 resource
.auto_raise_delay
.tv_usec
))
947 resource
.auto_raise_delay
.tv_usec
= 400;
948 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
/ 1000;
949 resource
.auto_raise_delay
.tv_usec
-=
950 (resource
.auto_raise_delay
.tv_sec
* 1000);
951 resource
.auto_raise_delay
.tv_usec
*= 1000;
953 if (! config
.getValue("session.cacheLife", resource
.cache_life
))
954 resource
.cache_life
= 5;
955 resource
.cache_life
*= 60000;
957 if (! config
.getValue("session.cacheMax", resource
.cache_max
))
958 resource
.cache_max
= 200;
960 if (! config
.getValue("session.titlebarLayout", resource
.titlebar_layout
))
961 resource
.titlebar_layout
= "ILMC";
965 void Blackbox::reconfigure(void) {
966 reconfigure_wait
= True
;
968 if (! timer
->isTiming()) timer
->start();
972 void Blackbox::real_reconfigure(void) {
975 std::for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
977 menuTimestamps
.clear();
981 std::for_each(screenList
.begin(), screenList
.end(),
982 std::mem_fun(&BScreen::reconfigure
));
986 void Blackbox::checkMenu(void) {
988 MenuTimestampList::iterator it
= menuTimestamps
.begin();
989 for(; it
!= menuTimestamps
.end(); ++it
) {
990 MenuTimestamp
*tmp
= *it
;
993 if (! stat(tmp
->filename
.c_str(), &buf
)) {
994 if (tmp
->timestamp
!= buf
.st_ctime
)
1001 if (reread
) rereadMenu();
1005 void Blackbox::rereadMenu(void) {
1006 reread_menu_wait
= True
;
1008 if (! timer
->isTiming()) timer
->start();
1012 void Blackbox::real_rereadMenu(void) {
1013 std::for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
1015 menuTimestamps
.clear();
1017 std::for_each(screenList
.begin(), screenList
.end(),
1018 std::mem_fun(&BScreen::rereadMenu
));
1022 void Blackbox::saveStyleFilename(const string
& filename
) {
1023 assert(! filename
.empty());
1024 resource
.style_file
= filename
;
1025 config
.setValue("session.styleFile", resource
.style_file
);
1029 void Blackbox::addMenuTimestamp(const string
& filename
) {
1030 assert(! filename
.empty());
1033 MenuTimestampList::iterator it
= menuTimestamps
.begin();
1034 for (; it
!= menuTimestamps
.end() && ! found
; ++it
) {
1035 if ((*it
)->filename
== filename
) found
= True
;
1040 if (! stat(filename
.c_str(), &buf
)) {
1041 MenuTimestamp
*ts
= new MenuTimestamp
;
1043 ts
->filename
= filename
;
1044 ts
->timestamp
= buf
.st_ctime
;
1046 menuTimestamps
.push_back(ts
);
1052 void Blackbox::timeout(void) {
1053 if (reconfigure_wait
)
1056 if (reread_menu_wait
)
1059 reconfigure_wait
= reread_menu_wait
= False
;
1063 void Blackbox::setFocusedWindow(BlackboxWindow
*win
) {
1064 if (focused_window
&& focused_window
== win
) // nothing to do
1067 BScreen
*old_screen
= 0;
1069 if (focused_window
) {
1070 focused_window
->setFocusFlag(False
);
1071 old_screen
= focused_window
->getScreen();
1074 if (win
&& ! win
->isIconic()) {
1075 // the active screen is the one with the last focused window...
1076 // this will keep focus on this screen no matter where the mouse goes,
1077 // so multihead keybindings will continue to work on that screen until the
1078 // user focuses a window on a different screen.
1079 active_screen
= win
->getScreen();
1080 focused_window
= win
;
1084 if (active_screen
) {
1085 // set input focus to the toolbar of the screen with mouse
1086 XSetInputFocus(getXDisplay(),
1087 active_screen
->getRootWindow(),
1088 RevertToPointerRoot
, CurrentTime
);
1090 // set input focus to the toolbar of the first managed screen
1091 XSetInputFocus(getXDisplay(),
1092 screenList
.front()->getRootWindow(),
1093 RevertToPointerRoot
, CurrentTime
);
1096 // set input focus to the toolbar of the last screen
1097 XSetInputFocus(getXDisplay(), old_screen
->getRootWindow(),
1098 RevertToPointerRoot
, CurrentTime
);
1102 if (active_screen
&& active_screen
->isScreenManaged()) {
1103 active_screen
->getToolbar()->redrawWindowLabel(True
);
1104 active_screen
->updateNetizenWindowFocus();
1107 if (old_screen
&& old_screen
!= active_screen
) {
1108 old_screen
->getToolbar()->redrawWindowLabel(True
);
1109 old_screen
->updateNetizenWindowFocus();