1 // openbox.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
23 // stupid macros needed to access some functions in version 2 of the GNU C
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
34 #include <X11/Xutil.h>
35 #include <X11/Xresource.h>
36 #include <X11/Xatom.h>
37 #include <X11/keysym.h>
40 #include <X11/extensions/shape.h>
46 #include "Clientmenu.h"
56 #include "Workspace.h"
57 #include "Workspacemenu.h"
65 #endif // HAVE_STDIO_H
69 #endif // HAVE_STDLIB_H
73 #endif // HAVE_STRING_H
76 # include <sys/types.h>
78 #endif // HAVE_UNISTD_H
80 #ifdef HAVE_SYS_PARAM_H
81 # include <sys/param.h>
82 #endif // HAVE_SYS_PARAM_H
85 #define MAXPATHLEN 255
88 #ifdef HAVE_SYS_SELECT_H
89 # include <sys/select.h>
90 #endif // HAVE_SYS_SELECT_H
94 #endif // HAVE_SIGNAL_H
96 #ifdef HAVE_SYS_SIGNAL_H
97 # include <sys/signal.h>
98 #endif // HAVE_SYS_SIGNAL_H
100 #ifdef HAVE_SYS_STAT_H
101 # include <sys/types.h>
102 # include <sys/stat.h>
103 #endif // HAVE_SYS_STAT_H
105 #ifdef TIME_WITH_SYS_TIME
106 # include <sys/time.h>
108 #else // !TIME_WITH_SYS_TIME
109 # ifdef HAVE_SYS_TIME_H
110 # include <sys/time.h>
111 # else // !HAVE_SYS_TIME_H
113 # endif // HAVE_SYS_TIME_H
114 #endif // TIME_WITH_SYS_TIME
118 #endif // HAVE_LIBGEN_H
120 #ifndef HAVE_BASENAME
121 static inline char *basename (char *s
) {
124 while (*s
) if (*s
++ == '/') save
= s
;
128 #endif // HAVE_BASENAME
131 // X event scanner for enter/leave notifies - adapted from twm
132 typedef struct scanargs
{
134 Bool leave
, inferior
, enter
;
137 static Bool
queueScanner(Display
*, XEvent
*e
, char *args
) {
138 if ((e
->type
== LeaveNotify
) &&
139 (e
->xcrossing
.window
== ((scanargs
*) args
)->w
) &&
140 (e
->xcrossing
.mode
== NotifyNormal
)) {
141 ((scanargs
*) args
)->leave
= True
;
142 ((scanargs
*) args
)->inferior
= (e
->xcrossing
.detail
== NotifyInferior
);
143 } else if ((e
->type
== EnterNotify
) &&
144 (e
->xcrossing
.mode
== NotifyUngrab
)) {
145 ((scanargs
*) args
)->enter
= True
;
154 Openbox::Openbox(int m_argc
, char **m_argv
, char *dpy_name
, char *rc
)
155 : BaseDisplay(m_argv
[0], dpy_name
) {
158 if (! XSupportsLocale())
159 fprintf(stderr
, "X server does not support locale\n");
161 if (XSetLocaleModifiers("") == NULL
)
162 fprintf(stderr
, "cannot set locale modifiers\n");
168 char *homedir
= getenv("HOME");
170 rc_file
= new char[strlen(homedir
) + strlen("/.openbox/rc") + 1];
171 sprintf(rc_file
, "%s/.openbox", homedir
);
173 // try to make sure the ~/.openbox directory exists
174 mkdir(rc_file
, S_IREAD
| S_IWRITE
| S_IEXEC
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
175 S_IROTH
| S_IWOTH
| S_IXOTH
);
177 sprintf(rc_file
, "%s/.openbox/rc", homedir
);
179 rc_file
= bstrdup(rc
);
181 config
.setFile(rc_file
);
185 resource
.menu_file
= resource
.style_file
= NULL
;
186 resource
.titlebar_layout
= NULL
;
187 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
= 0;
189 masked_window
= NULL
;
195 openbox_pid
= XInternAtom(getXDisplay(), "_BLACKBOX_PID", False
);
196 #endif // HAVE_GETPID
198 for (int i
= 0; i
< getNumberOfScreens(); i
++) {
199 BScreen
*screen
= new BScreen(*this, i
, config
);
201 if (! screen
->isScreenManaged()) {
206 screenList
.push_back(screen
);
209 if (screenList
.empty()) {
211 i18n
->getMessage(openboxSet
, openboxNoManagableScreens
,
212 "Openbox::Openbox: no managable screens found, aborting.\n"));
215 focused_screen
= screenList
.front();
217 // save current settings and default values
220 XSynchronize(getXDisplay(), False
);
221 XSync(getXDisplay(), False
);
223 reconfigure_wait
= reread_menu_wait
= False
;
225 timer
= new BTimer(*this, *this);
226 timer
->setTimeout(0);
227 timer
->fireOnce(True
);
233 Openbox::~Openbox() {
234 for_each(screenList
.begin(), screenList
.end(),
237 for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
240 if (resource
.menu_file
)
241 delete [] resource
.menu_file
;
243 if (resource
.style_file
)
244 delete [] resource
.style_file
;
246 if (resource
.titlebar_layout
)
247 delete [] resource
.titlebar_layout
;
255 void Openbox::process_event(XEvent
*e
) {
256 if ((masked
== e
->xany
.window
&& masked_window
) &&
257 (e
->type
== MotionNotify
)) {
258 last_time
= e
->xmotion
.time
;
259 masked_window
->motionNotifyEvent(&e
->xmotion
);
265 // strip the lock key modifiers
266 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
268 last_time
= e
->xbutton
.time
;
270 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
271 Basemenu
*menu
= (Basemenu
*) 0;
274 Slit
*slit
= (Slit
*) 0;
277 Toolbar
*tbar
= (Toolbar
*) 0;
279 if ((win
= searchWindow(e
->xbutton
.window
))) {
280 win
->buttonPressEvent(&e
->xbutton
);
282 if (e
->xbutton
.button
== 1)
283 win
->installColormap(True
);
284 } else if ((menu
= searchMenu(e
->xbutton
.window
))) {
285 menu
->buttonPressEvent(&e
->xbutton
);
288 } else if ((slit
= searchSlit(e
->xbutton
.window
))) {
289 slit
->buttonPressEvent(&e
->xbutton
);
292 } else if ((tbar
= searchToolbar(e
->xbutton
.window
))) {
293 tbar
->buttonPressEvent(&e
->xbutton
);
295 ScreenList::iterator it
;
296 for (it
= screenList
.begin(); it
!= screenList
.end(); ++it
) {
297 BScreen
*screen
= *it
;
298 if (e
->xbutton
.window
== screen
->getRootWindow()) {
299 if (e
->xbutton
.button
== 1) {
300 if (! screen
->isRootColormapInstalled())
301 screen
->getImageControl()->installRootColormap();
303 if (screen
->getWorkspacemenu()->isVisible())
304 screen
->getWorkspacemenu()->hide();
306 if (screen
->getRootmenu()->isVisible())
307 screen
->getRootmenu()->hide();
308 } else if (e
->xbutton
.button
== 2) {
309 int mx
= e
->xbutton
.x_root
-
310 (screen
->getWorkspacemenu()->getWidth() / 2);
311 int my
= e
->xbutton
.y_root
-
312 (screen
->getWorkspacemenu()->getTitleHeight() / 2);
317 if (mx
+ screen
->getWorkspacemenu()->getWidth() >
319 mx
= screen
->size().w() -
320 screen
->getWorkspacemenu()->getWidth() -
321 screen
->getBorderWidth();
323 if (my
+ screen
->getWorkspacemenu()->getHeight() >
325 my
= screen
->size().h() -
326 screen
->getWorkspacemenu()->getHeight() -
327 screen
->getBorderWidth();
329 screen
->getWorkspacemenu()->move(mx
, my
);
331 if (! screen
->getWorkspacemenu()->isVisible()) {
332 screen
->getWorkspacemenu()->removeParent();
333 screen
->getWorkspacemenu()->show();
335 } else if (e
->xbutton
.button
== 3) {
336 int mx
= e
->xbutton
.x_root
-
337 (screen
->getRootmenu()->getWidth() / 2);
338 int my
= e
->xbutton
.y_root
-
339 (screen
->getRootmenu()->getTitleHeight() / 2);
344 if (mx
+ screen
->getRootmenu()->getWidth() > screen
->size().w())
345 mx
= screen
->size().w() -
346 screen
->getRootmenu()->getWidth() -
347 screen
->getBorderWidth();
349 if (my
+ screen
->getRootmenu()->getHeight() > screen
->size().h())
350 my
= screen
->size().h() -
351 screen
->getRootmenu()->getHeight() -
352 screen
->getBorderWidth();
354 screen
->getRootmenu()->move(mx
, my
);
356 if (! screen
->getRootmenu()->isVisible()) {
358 screen
->getRootmenu()->show();
360 } else if (e
->xbutton
.button
== 4) {
361 if ((screen
->getCurrentWorkspaceID() + 1) >
362 screen
->getWorkspaceCount() - 1)
363 screen
->changeWorkspaceID(0);
365 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID() + 1);
366 } else if (e
->xbutton
.button
== 5) {
367 if ((screen
->getCurrentWorkspaceID() - 1) < 0)
368 screen
->changeWorkspaceID(screen
->getWorkspaceCount() - 1);
370 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID() - 1);
379 case ButtonRelease
: {
380 // strip the lock key modifiers
381 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
383 last_time
= e
->xbutton
.time
;
385 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
386 Basemenu
*menu
= (Basemenu
*) 0;
387 Toolbar
*tbar
= (Toolbar
*) 0;
389 if ((win
= searchWindow(e
->xbutton
.window
)))
390 win
->buttonReleaseEvent(&e
->xbutton
);
391 else if ((menu
= searchMenu(e
->xbutton
.window
)))
392 menu
->buttonReleaseEvent(&e
->xbutton
);
393 else if ((tbar
= searchToolbar(e
->xbutton
.window
)))
394 tbar
->buttonReleaseEvent(&e
->xbutton
);
399 case ConfigureRequest
: {
400 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
403 Slit
*slit
= (Slit
*) 0;
406 if ((win
= searchWindow(e
->xconfigurerequest
.window
))) {
407 win
->configureRequestEvent(&e
->xconfigurerequest
);
410 } else if ((slit
= searchSlit(e
->xconfigurerequest
.window
))) {
411 slit
->configureRequestEvent(&e
->xconfigurerequest
);
417 if (validateWindow(e
->xconfigurerequest
.window
)) {
420 xwc
.x
= e
->xconfigurerequest
.x
;
421 xwc
.y
= e
->xconfigurerequest
.y
;
422 xwc
.width
= e
->xconfigurerequest
.width
;
423 xwc
.height
= e
->xconfigurerequest
.height
;
424 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
425 xwc
.sibling
= e
->xconfigurerequest
.above
;
426 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
428 XConfigureWindow(getXDisplay(), e
->xconfigurerequest
.window
,
429 e
->xconfigurerequest
.value_mask
, &xwc
);
441 i18n
->getMessage(openboxSet
, openboxMapRequest
,
442 "Openbox::process_event(): MapRequest for 0x%lx\n"),
443 e
->xmaprequest
.window
);
446 OpenboxWindow
*win
= searchWindow(e
->xmaprequest
.window
);
449 win
= new OpenboxWindow(*this, e
->xmaprequest
.window
);
451 if ((win
= searchWindow(e
->xmaprequest
.window
)))
452 win
->mapRequestEvent(&e
->xmaprequest
);
458 OpenboxWindow
*win
= searchWindow(e
->xmap
.window
);
461 win
->mapNotifyEvent(&e
->xmap
);
467 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
470 Slit
*slit
= (Slit
*) 0;
473 if ((win
= searchWindow(e
->xunmap
.window
))) {
474 win
->unmapNotifyEvent(&e
->xunmap
);
476 } else if ((slit
= searchSlit(e
->xunmap
.window
))) {
477 slit
->removeClient(e
->xunmap
.window
);
485 case DestroyNotify
: {
486 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
489 Slit
*slit
= (Slit
*) 0;
492 if ((win
= searchWindow(e
->xdestroywindow
.window
))) {
493 win
->destroyNotifyEvent(&e
->xdestroywindow
);
495 } else if ((slit
= searchSlit(e
->xdestroywindow
.window
))) {
496 slit
->removeClient(e
->xdestroywindow
.window
, False
);
504 // strip the lock key modifiers
505 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
507 last_time
= e
->xmotion
.time
;
509 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
510 Basemenu
*menu
= (Basemenu
*) 0;
512 if ((win
= searchWindow(e
->xmotion
.window
)))
513 win
->motionNotifyEvent(&e
->xmotion
);
514 else if ((menu
= searchMenu(e
->xmotion
.window
)))
515 menu
->motionNotifyEvent(&e
->xmotion
);
520 case PropertyNotify
: {
521 last_time
= e
->xproperty
.time
;
523 if (e
->xproperty
.state
!= PropertyDelete
) {
524 OpenboxWindow
*win
= searchWindow(e
->xproperty
.window
);
527 win
->propertyNotifyEvent(e
->xproperty
.atom
);
534 last_time
= e
->xcrossing
.time
;
536 BScreen
*screen
= (BScreen
*) 0;
537 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
538 Basemenu
*menu
= (Basemenu
*) 0;
539 Toolbar
*tbar
= (Toolbar
*) 0;
542 Slit
*slit
= (Slit
*) 0;
545 if (e
->xcrossing
.mode
== NotifyGrab
) break;
549 sa
.w
= e
->xcrossing
.window
;
550 sa
.enter
= sa
.leave
= False
;
551 XCheckIfEvent(getXDisplay(), &dummy
, queueScanner
, (char *) &sa
);
553 if ((e
->xcrossing
.window
== e
->xcrossing
.root
) &&
554 (screen
= searchScreen(e
->xcrossing
.window
))) {
555 screen
->getImageControl()->installRootColormap();
556 } else if ((win
= searchWindow(e
->xcrossing
.window
))) {
557 if (win
->getScreen()->sloppyFocus() &&
558 (! win
->isFocused()) && (! no_focus
)) {
561 if (((! sa
.leave
) || sa
.inferior
) && win
->isVisible() &&
562 win
->setInputFocus())
563 win
->installColormap(True
);
567 } else if ((menu
= searchMenu(e
->xcrossing
.window
))) {
568 menu
->enterNotifyEvent(&e
->xcrossing
);
569 } else if ((tbar
= searchToolbar(e
->xcrossing
.window
))) {
570 tbar
->enterNotifyEvent(&e
->xcrossing
);
572 } else if ((slit
= searchSlit(e
->xcrossing
.window
))) {
573 slit
->enterNotifyEvent(&e
->xcrossing
);
580 last_time
= e
->xcrossing
.time
;
582 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
583 Basemenu
*menu
= (Basemenu
*) 0;
584 Toolbar
*tbar
= (Toolbar
*) 0;
587 Slit
*slit
= (Slit
*) 0;
590 if ((menu
= searchMenu(e
->xcrossing
.window
)))
591 menu
->leaveNotifyEvent(&e
->xcrossing
);
592 else if ((win
= searchWindow(e
->xcrossing
.window
)))
593 win
->installColormap(False
);
594 else if ((tbar
= searchToolbar(e
->xcrossing
.window
)))
595 tbar
->leaveNotifyEvent(&e
->xcrossing
);
597 else if ((slit
= searchSlit(e
->xcrossing
.window
)))
598 slit
->leaveNotifyEvent(&e
->xcrossing
);
605 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
606 Basemenu
*menu
= (Basemenu
*) 0;
607 Toolbar
*tbar
= (Toolbar
*) 0;
609 if ((win
= searchWindow(e
->xexpose
.window
)))
610 win
->exposeEvent(&e
->xexpose
);
611 else if ((menu
= searchMenu(e
->xexpose
.window
)))
612 menu
->exposeEvent(&e
->xexpose
);
613 else if ((tbar
= searchToolbar(e
->xexpose
.window
)))
614 tbar
->exposeEvent(&e
->xexpose
);
620 Toolbar
*tbar
= searchToolbar(e
->xkey
.window
);
622 if (tbar
&& tbar
->isEditing())
623 tbar
->keyPressEvent(&e
->xkey
);
628 case ColormapNotify
: {
629 BScreen
*screen
= searchScreen(e
->xcolormap
.window
);
632 screen
->setRootColormapInstalled((e
->xcolormap
.state
==
633 ColormapInstalled
) ? True
: False
);
639 if (e
->xfocus
.mode
== NotifyUngrab
|| e
->xfocus
.detail
== NotifyPointer
)
642 OpenboxWindow
*win
= searchWindow(e
->xfocus
.window
);
643 if (win
&& !win
->isFocused())
652 case ClientMessage
: {
653 if (e
->xclient
.format
== 32) {
654 if (e
->xclient
.message_type
== getWMChangeStateAtom()) {
655 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
656 if (! win
|| ! win
->validateClient()) return;
658 if (e
->xclient
.data
.l
[0] == IconicState
)
660 if (e
->xclient
.data
.l
[0] == NormalState
)
662 } else if (e
->xclient
.message_type
== getOpenboxChangeWorkspaceAtom()) {
663 BScreen
*screen
= searchScreen(e
->xclient
.window
);
665 if (screen
&& e
->xclient
.data
.l
[0] >= 0 &&
666 e
->xclient
.data
.l
[0] < screen
->getWorkspaceCount())
667 screen
->changeWorkspaceID(e
->xclient
.data
.l
[0]);
668 } else if (e
->xclient
.message_type
== getOpenboxChangeWindowFocusAtom()) {
669 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
671 if (win
&& win
->isVisible() && win
->setInputFocus())
672 win
->installColormap(True
);
673 } else if (e
->xclient
.message_type
== getOpenboxCycleWindowFocusAtom()) {
674 BScreen
*screen
= searchScreen(e
->xclient
.window
);
677 if (! e
->xclient
.data
.l
[0])
682 } else if (e
->xclient
.message_type
== getOpenboxChangeAttributesAtom()) {
683 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
685 if (win
&& win
->validateClient()) {
687 net
.flags
= e
->xclient
.data
.l
[0];
688 net
.attrib
= e
->xclient
.data
.l
[1];
689 net
.workspace
= e
->xclient
.data
.l
[2];
690 net
.stack
= e
->xclient
.data
.l
[3];
691 net
.decoration
= e
->xclient
.data
.l
[4];
693 win
->changeOpenboxHints(&net
);
704 if (e
->type
== getShapeEventBase()) {
705 XShapeEvent
*shape_event
= (XShapeEvent
*) e
;
706 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
708 if ((win
= searchWindow(e
->xany
.window
)) ||
709 (shape_event
->kind
!= ShapeBounding
))
710 win
->shapeEvent(shape_event
);
719 Bool
Openbox::handleSignal(int sig
) {
745 BScreen
*Openbox::searchScreen(Window window
) {
746 ScreenList::iterator it
;
747 for (it
= screenList
.begin(); it
!= screenList
.end(); ++it
)
748 if ((*it
)->getRootWindow() == window
)
750 return (BScreen
*) 0;
754 OpenboxWindow
*Openbox::searchWindow(Window window
) {
755 WindowLookup::iterator it
= windowSearchList
.find(window
);
756 if (it
== windowSearchList
.end())
757 return (OpenboxWindow
*) 0;
762 OpenboxWindow
*Openbox::searchGroup(Window window
, OpenboxWindow
*win
) {
763 WindowLookup::iterator it
= groupSearchList
.find(window
);
764 if (it
!= groupSearchList
.end())
765 if (it
->second
->getClientWindow() != win
->getClientWindow())
767 return (OpenboxWindow
*) 0;
771 Basemenu
*Openbox::searchMenu(Window window
) {
772 MenuLookup::iterator it
= menuSearchList
.find(window
);
773 if (it
== menuSearchList
.end())
774 return (Basemenu
*) 0;
779 Toolbar
*Openbox::searchToolbar(Window window
) {
780 ToolbarLookup::iterator it
= toolbarSearchList
.find(window
);
781 if (it
== toolbarSearchList
.end())
782 return (Toolbar
*) 0;
788 Slit
*Openbox::searchSlit(Window window
) {
789 SlitLookup::iterator it
= slitSearchList
.find(window
);
790 if (it
== slitSearchList
.end())
797 void Openbox::saveWindowSearch(Window window
, OpenboxWindow
*data
) {
798 windowSearchList
.insert(WindowLookupPair(window
, data
));
802 void Openbox::saveGroupSearch(Window window
, OpenboxWindow
*data
) {
803 groupSearchList
.insert(WindowLookupPair(window
, data
));
807 void Openbox::saveMenuSearch(Window window
, Basemenu
*data
) {
808 menuSearchList
.insert(MenuLookupPair(window
, data
));
812 void Openbox::saveToolbarSearch(Window window
, Toolbar
*data
) {
813 toolbarSearchList
.insert(ToolbarLookupPair(window
, data
));
818 void Openbox::saveSlitSearch(Window window
, Slit
*data
) {
819 slitSearchList
.insert(SlitLookupPair(window
, data
));
824 void Openbox::removeWindowSearch(Window window
) {
825 windowSearchList
.erase(window
);
829 void Openbox::removeGroupSearch(Window window
) {
830 groupSearchList
.erase(window
);
834 void Openbox::removeMenuSearch(Window window
) {
835 menuSearchList
.erase(window
);
839 void Openbox::removeToolbarSearch(Window window
) {
840 toolbarSearchList
.erase(window
);
845 void Openbox::removeSlitSearch(Window window
) {
846 slitSearchList
.erase(window
);
851 void Openbox::restart(const char *prog
) {
855 execlp(prog
, prog
, NULL
);
859 // fall back in case the above execlp doesn't work
860 execvp(argv
[0], argv
);
861 execvp(basename(argv
[0]), argv
);
865 void Openbox::shutdown() {
866 BaseDisplay::shutdown();
868 XSetInputFocus(getXDisplay(), PointerRoot
, None
, CurrentTime
);
870 std::for_each(screenList
.begin(), screenList
.end(),
871 std::mem_fun(&BScreen::shutdown
));
873 XSync(getXDisplay(), False
);
877 void Openbox::save() {
878 config
.setAutoSave(false);
880 // save all values as they are so that the defaults will be written to the rc
883 config
.setValue("session.menuFile", getMenuFilename());
884 config
.setValue("session.colorsPerChannel",
885 resource
.colors_per_channel
);
886 config
.setValue("session.styleFile", resource
.style_file
);
887 config
.setValue("session.titlebarLayout", resource
.titlebar_layout
);
888 config
.setValue("session.doubleClickInterval",
889 (long)resource
.double_click_interval
);
890 config
.setValue("session.autoRaiseDelay",
891 ((resource
.auto_raise_delay
.tv_sec
* 1000) +
892 (resource
.auto_raise_delay
.tv_usec
/ 1000)));
893 config
.setValue("session.cacheLife", (long)resource
.cache_life
/ 60000);
894 config
.setValue("session.cacheMax", (long)resource
.cache_max
);
896 std::for_each(screenList
.begin(), screenList
.end(),
897 std::mem_fun(&BScreen::save
));
899 config
.setAutoSave(true);
903 void Openbox::load() {
910 if (resource
.menu_file
)
911 delete [] resource
.menu_file
;
912 if (config
.getValue("session.menuFile", "Session.MenuFile", s
))
913 resource
.menu_file
= bstrdup(s
.c_str());
915 resource
.menu_file
= bstrdup(DEFAULTMENU
);
917 if (config
.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
919 resource
.colors_per_channel
= (l
< 2 ? 2 : (l
> 6 ? 6 : l
)); // >= 2, <= 6
921 resource
.colors_per_channel
= 4;
923 if (resource
.style_file
)
924 delete [] resource
.style_file
;
925 if (config
.getValue("session.styleFile", "Session.StyleFile", s
))
926 resource
.style_file
= bstrdup(s
.c_str());
928 resource
.style_file
= bstrdup(DEFAULTSTYLE
);
930 if (resource
.titlebar_layout
)
931 delete [] resource
.titlebar_layout
;
932 if (config
.getValue("session.titlebarLayout", "Session.TitlebarLayout", s
))
933 resource
.titlebar_layout
= bstrdup(s
.c_str());
935 resource
.titlebar_layout
= bstrdup("ILMC");
937 if (config
.getValue("session.doubleClickInterval",
938 "Session.DoubleClickInterval", l
))
939 resource
.double_click_interval
= l
;
941 resource
.double_click_interval
= 250;
943 if (!config
.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l
))
944 resource
.auto_raise_delay
.tv_usec
= l
;
946 resource
.auto_raise_delay
.tv_usec
= 400;
947 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
/ 1000;
948 resource
.auto_raise_delay
.tv_usec
-=
949 (resource
.auto_raise_delay
.tv_sec
* 1000);
950 resource
.auto_raise_delay
.tv_usec
*= 1000;
952 if (config
.getValue("session.cacheLife", "Session.CacheLife", l
))
953 resource
.cache_life
= l
;
955 resource
.cache_life
= 51;
956 resource
.cache_life
*= 60000;
958 if (config
.getValue("session.cacheMax", "Session.CacheMax", l
))
959 resource
.cache_max
= l
;
961 resource
.cache_max
= 200;
965 void Openbox::reconfigure() {
966 reconfigure_wait
= True
;
968 if (! timer
->isTiming()) timer
->start();
972 void Openbox::real_reconfigure() {
977 for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
979 menuTimestamps
.clear();
981 std::for_each(screenList
.begin(), screenList
.end(),
982 std::mem_fun(&BScreen::reconfigure
));
988 void Openbox::checkMenu() {
989 MenuTimestampList::iterator it
;
990 for (it
= menuTimestamps
.begin(); it
!= menuTimestamps
.end(); ++it
) {
993 if (stat((*it
)->filename
, &buf
) || (*it
)->timestamp
!= buf
.st_ctime
) {
1001 void Openbox::rereadMenu() {
1002 reread_menu_wait
= True
;
1004 if (! timer
->isTiming()) timer
->start();
1008 void Openbox::real_rereadMenu() {
1009 std::for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
1011 menuTimestamps
.clear();
1013 std::for_each(screenList
.begin(), screenList
.end(),
1014 std::mem_fun(&BScreen::rereadMenu
));
1018 void Openbox::setStyleFilename(const char *filename
) {
1019 if (resource
.style_file
)
1020 delete [] resource
.style_file
;
1022 resource
.style_file
= bstrdup(filename
);
1023 config
.setValue("session.styleFile", resource
.style_file
);
1027 void Openbox::setMenuFilename(const char *filename
) {
1030 MenuTimestampList::iterator it
;
1031 for (it
= menuTimestamps
.begin(); it
!= menuTimestamps
.end(); ++it
)
1032 if (! strcmp((*it
)->filename
, filename
)) {
1039 if (! stat(filename
, &buf
)) {
1040 MenuTimestamp
*ts
= new MenuTimestamp
;
1042 ts
->filename
= bstrdup(filename
);
1043 ts
->timestamp
= buf
.st_ctime
;
1045 menuTimestamps
.push_back(ts
);
1051 void Openbox::timeout() {
1052 if (reconfigure_wait
)
1055 if (reread_menu_wait
)
1058 reconfigure_wait
= reread_menu_wait
= False
;
1062 OpenboxWindow
*Openbox::focusedWindow() {
1063 if (focused_screen
== (BScreen
*) 0)
1064 return (OpenboxWindow
*) 0;
1065 Workspace
*w
= focused_screen
->getCurrentWorkspace();
1066 if (w
== (Workspace
*) 0)
1067 return (OpenboxWindow
*) 0;
1068 return w
->focusedWindow();
1072 void Openbox::focusWindow(OpenboxWindow
*win
) {
1073 BScreen
*old_screen
= (BScreen
*) 0;
1074 Toolbar
*old_tbar
= (Toolbar
*) 0, *tbar
= (Toolbar
*) 0;
1075 Workspace
*old_wkspc
= (Workspace
*) 0, *wkspc
= (Workspace
*) 0;
1077 OpenboxWindow
*old_win
= focusedWindow();
1078 if (old_win
!= (OpenboxWindow
*) 0) {
1079 old_screen
= old_win
->getScreen();
1080 old_wkspc
= old_screen
->getWorkspace(old_win
->getWorkspaceNumber());
1081 old_tbar
= old_screen
->getToolbar();
1083 old_win
->setFocusFlag(False
);
1084 old_wkspc
->focusWindow((OpenboxWindow
*) 0);
1087 if (win
&& !win
->isIconic()) {
1088 focused_screen
= win
->getScreen();
1089 tbar
= focused_screen
->getToolbar();
1090 wkspc
= focused_screen
->getWorkspace(win
->getWorkspaceNumber());
1091 win
->setFocusFlag(true);
1092 wkspc
->focusWindow(win
);
1095 tbar
->redrawWindowLabel(true);
1096 focused_screen
->updateNetizenWindowFocus();
1098 // focused_window = (OpenboxWindow *) 0;
1101 if (old_tbar
&& old_tbar
!= tbar
)
1102 old_tbar
->redrawWindowLabel(true);
1103 if (old_screen
&& old_screen
!= focused_screen
)
1104 old_screen
->updateNetizenWindowFocus();