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 char *menu
) : 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");
167 if (rc
== NULL
|| menu
== NULL
) {
168 char *homedir
= getenv("HOME");
169 char *configdir
= new char[strlen(homedir
) + strlen("/.openbox") + 1];
170 sprintf(configdir
, "%s/.openbox", homedir
);
171 // try to make sure the ~/.openbox directory exists
172 mkdir(configdir
, S_IREAD
| S_IWRITE
| S_IEXEC
|
173 S_IRGRP
| S_IWGRP
| S_IXGRP
|
174 S_IROTH
| S_IWOTH
| S_IXOTH
);
178 rc_file
= new char[strlen(configdir
) + strlen("/rc") + 1];
179 sprintf(rc_file
, "%s/rc", configdir
);
181 rc_file
= bstrdup(rc
);
184 menu_file
= new char[strlen(configdir
) + strlen("/menu") + 1];
185 sprintf(menu_file
, "%s/menu", configdir
);
187 menu_file
= bstrdup(menu
);
191 config
.setFile(rc_file
);
195 resource
.style_file
= NULL
;
196 resource
.titlebar_layout
= NULL
;
197 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
= 0;
199 current_screen
= (BScreen
*) 0;
200 masked_window
= (OpenboxWindow
*) 0;
206 openbox_pid
= XInternAtom(getXDisplay(), "_BLACKBOX_PID", False
);
207 #endif // HAVE_GETPID
209 for (unsigned int s
= 0; s
< numberOfScreens(); s
++) {
210 BScreen
*screen
= new BScreen(*this, s
, config
);
212 if (! screen
->isScreenManaged()) {
217 screenList
.push_back(screen
);
220 if (screenList
.empty()) {
222 i18n
->getMessage(openboxSet
, openboxNoManagableScreens
,
223 "Openbox::Openbox: no managable screens found, aborting.\n"));
226 current_screen
= screenList
.front();
228 // save current settings and default values
231 XSynchronize(getXDisplay(), False
);
232 XSync(getXDisplay(), False
);
234 reconfigure_wait
= reread_menu_wait
= False
;
236 timer
= new BTimer(*this, *this);
237 timer
->setTimeout(0);
238 timer
->fireOnce(True
);
246 Openbox::~Openbox() {
247 for_each(screenList
.begin(), screenList
.end(),
250 for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
253 if (resource
.style_file
)
254 delete [] resource
.style_file
;
256 if (resource
.titlebar_layout
)
257 delete [] resource
.titlebar_layout
;
266 void Openbox::process_event(XEvent
*e
) {
267 if ((masked
== e
->xany
.window
&& masked_window
) &&
268 (e
->type
== MotionNotify
)) {
269 last_time
= e
->xmotion
.time
;
270 masked_window
->motionNotifyEvent(&e
->xmotion
);
276 // strip the lock key modifiers
277 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
279 last_time
= e
->xbutton
.time
;
281 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
282 Basemenu
*menu
= (Basemenu
*) 0;
285 Slit
*slit
= (Slit
*) 0;
288 Toolbar
*tbar
= (Toolbar
*) 0;
290 if ((win
= searchWindow(e
->xbutton
.window
))) {
291 win
->buttonPressEvent(&e
->xbutton
);
293 if (e
->xbutton
.button
== 1)
294 win
->installColormap(True
);
295 } else if ((menu
= searchMenu(e
->xbutton
.window
))) {
296 menu
->buttonPressEvent(&e
->xbutton
);
299 } else if ((slit
= searchSlit(e
->xbutton
.window
))) {
300 slit
->buttonPressEvent(&e
->xbutton
);
303 } else if ((tbar
= searchToolbar(e
->xbutton
.window
))) {
304 tbar
->buttonPressEvent(&e
->xbutton
);
306 ScreenList::iterator it
;
307 for (it
= screenList
.begin(); it
!= screenList
.end(); ++it
) {
308 BScreen
*screen
= *it
;
309 if (e
->xbutton
.window
== screen
->getRootWindow()) {
310 if (e
->xbutton
.button
== 1) {
311 if (! screen
->isRootColormapInstalled())
312 screen
->getImageControl()->installRootColormap();
314 if (screen
->getWorkspacemenu()->isVisible())
315 screen
->getWorkspacemenu()->hide();
317 if (screen
->getRootmenu()->isVisible())
318 screen
->getRootmenu()->hide();
319 } else if (e
->xbutton
.button
== 2) {
320 int mx
= e
->xbutton
.x_root
-
321 (screen
->getWorkspacemenu()->getWidth() / 2);
322 int my
= e
->xbutton
.y_root
-
323 (screen
->getWorkspacemenu()->getTitleHeight() / 2);
328 if (mx
+ screen
->getWorkspacemenu()->getWidth() >
330 mx
= screen
->size().w() -
331 screen
->getWorkspacemenu()->getWidth() -
332 screen
->getBorderWidth();
334 if (my
+ screen
->getWorkspacemenu()->getHeight() >
336 my
= screen
->size().h() -
337 screen
->getWorkspacemenu()->getHeight() -
338 screen
->getBorderWidth();
340 screen
->getWorkspacemenu()->move(mx
, my
);
342 if (! screen
->getWorkspacemenu()->isVisible()) {
343 screen
->getWorkspacemenu()->removeParent();
344 screen
->getWorkspacemenu()->show();
346 } else if (e
->xbutton
.button
== 3) {
347 int mx
= e
->xbutton
.x_root
-
348 (screen
->getRootmenu()->getWidth() / 2);
349 int my
= e
->xbutton
.y_root
-
350 (screen
->getRootmenu()->getTitleHeight() / 2);
355 if (mx
+ screen
->getRootmenu()->getWidth() > screen
->size().w())
356 mx
= screen
->size().w() -
357 screen
->getRootmenu()->getWidth() -
358 screen
->getBorderWidth();
360 if (my
+ screen
->getRootmenu()->getHeight() > screen
->size().h())
361 my
= screen
->size().h() -
362 screen
->getRootmenu()->getHeight() -
363 screen
->getBorderWidth();
365 screen
->getRootmenu()->move(mx
, my
);
367 if (! screen
->getRootmenu()->isVisible()) {
369 screen
->getRootmenu()->show();
371 } else if (e
->xbutton
.button
== 4) {
372 if ((screen
->getCurrentWorkspaceID() + 1) >
373 screen
->getWorkspaceCount() - 1)
374 screen
->changeWorkspaceID(0);
376 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID() + 1);
377 } else if (e
->xbutton
.button
== 5) {
378 if ((screen
->getCurrentWorkspaceID() - 1) < 0)
379 screen
->changeWorkspaceID(screen
->getWorkspaceCount() - 1);
381 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID() - 1);
390 case ButtonRelease
: {
391 // strip the lock key modifiers
392 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
394 last_time
= e
->xbutton
.time
;
396 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
397 Basemenu
*menu
= (Basemenu
*) 0;
398 Toolbar
*tbar
= (Toolbar
*) 0;
400 if ((win
= searchWindow(e
->xbutton
.window
)))
401 win
->buttonReleaseEvent(&e
->xbutton
);
402 else if ((menu
= searchMenu(e
->xbutton
.window
)))
403 menu
->buttonReleaseEvent(&e
->xbutton
);
404 else if ((tbar
= searchToolbar(e
->xbutton
.window
)))
405 tbar
->buttonReleaseEvent(&e
->xbutton
);
410 case ConfigureRequest
: {
411 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
414 Slit
*slit
= (Slit
*) 0;
417 if ((win
= searchWindow(e
->xconfigurerequest
.window
))) {
418 win
->configureRequestEvent(&e
->xconfigurerequest
);
421 } else if ((slit
= searchSlit(e
->xconfigurerequest
.window
))) {
422 slit
->configureRequestEvent(&e
->xconfigurerequest
);
428 if (validateWindow(e
->xconfigurerequest
.window
)) {
431 xwc
.x
= e
->xconfigurerequest
.x
;
432 xwc
.y
= e
->xconfigurerequest
.y
;
433 xwc
.width
= e
->xconfigurerequest
.width
;
434 xwc
.height
= e
->xconfigurerequest
.height
;
435 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
436 xwc
.sibling
= e
->xconfigurerequest
.above
;
437 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
439 XConfigureWindow(getXDisplay(), e
->xconfigurerequest
.window
,
440 e
->xconfigurerequest
.value_mask
, &xwc
);
452 i18n
->getMessage(openboxSet
, openboxMapRequest
,
453 "Openbox::process_event(): MapRequest for 0x%lx\n"),
454 e
->xmaprequest
.window
);
457 OpenboxWindow
*win
= searchWindow(e
->xmaprequest
.window
);
460 win
= new OpenboxWindow(*this, e
->xmaprequest
.window
);
462 if ((win
= searchWindow(e
->xmaprequest
.window
)))
463 win
->mapRequestEvent(&e
->xmaprequest
);
469 OpenboxWindow
*win
= searchWindow(e
->xmap
.window
);
472 win
->mapNotifyEvent(&e
->xmap
);
478 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
481 Slit
*slit
= (Slit
*) 0;
484 if ((win
= searchWindow(e
->xunmap
.window
))) {
485 win
->unmapNotifyEvent(&e
->xunmap
);
487 } else if ((slit
= searchSlit(e
->xunmap
.window
))) {
488 slit
->removeClient(e
->xunmap
.window
);
496 case DestroyNotify
: {
497 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
500 Slit
*slit
= (Slit
*) 0;
503 if ((win
= searchWindow(e
->xdestroywindow
.window
))) {
504 win
->destroyNotifyEvent(&e
->xdestroywindow
);
506 } else if ((slit
= searchSlit(e
->xdestroywindow
.window
))) {
507 slit
->removeClient(e
->xdestroywindow
.window
, False
);
515 // strip the lock key modifiers
516 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
518 last_time
= e
->xmotion
.time
;
520 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
521 Basemenu
*menu
= (Basemenu
*) 0;
523 if ((win
= searchWindow(e
->xmotion
.window
)))
524 win
->motionNotifyEvent(&e
->xmotion
);
525 else if ((menu
= searchMenu(e
->xmotion
.window
)))
526 menu
->motionNotifyEvent(&e
->xmotion
);
531 case PropertyNotify
: {
532 last_time
= e
->xproperty
.time
;
534 if (e
->xproperty
.state
!= PropertyDelete
) {
535 OpenboxWindow
*win
= searchWindow(e
->xproperty
.window
);
538 win
->propertyNotifyEvent(e
->xproperty
.atom
);
545 last_time
= e
->xcrossing
.time
;
547 BScreen
*screen
= (BScreen
*) 0;
548 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
549 Basemenu
*menu
= (Basemenu
*) 0;
550 Toolbar
*tbar
= (Toolbar
*) 0;
553 Slit
*slit
= (Slit
*) 0;
556 if (e
->xcrossing
.mode
== NotifyGrab
) break;
560 sa
.w
= e
->xcrossing
.window
;
561 sa
.enter
= sa
.leave
= False
;
562 XCheckIfEvent(getXDisplay(), &dummy
, queueScanner
, (char *) &sa
);
564 if ((e
->xcrossing
.window
== e
->xcrossing
.root
) &&
565 (screen
= searchScreen(e
->xcrossing
.window
))) {
566 screen
->getImageControl()->installRootColormap();
567 } else if ((win
= searchWindow(e
->xcrossing
.window
))) {
568 if (win
->getScreen()->sloppyFocus() &&
569 (! win
->isFocused()) && (! no_focus
)) {
572 if (((! sa
.leave
) || sa
.inferior
) && win
->isVisible() &&
573 win
->setInputFocus())
574 win
->installColormap(True
);
578 } else if ((menu
= searchMenu(e
->xcrossing
.window
))) {
579 menu
->enterNotifyEvent(&e
->xcrossing
);
580 } else if ((tbar
= searchToolbar(e
->xcrossing
.window
))) {
581 tbar
->enterNotifyEvent(&e
->xcrossing
);
583 } else if ((slit
= searchSlit(e
->xcrossing
.window
))) {
584 slit
->enterNotifyEvent(&e
->xcrossing
);
591 last_time
= e
->xcrossing
.time
;
593 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
594 Basemenu
*menu
= (Basemenu
*) 0;
595 Toolbar
*tbar
= (Toolbar
*) 0;
598 Slit
*slit
= (Slit
*) 0;
601 if ((menu
= searchMenu(e
->xcrossing
.window
)))
602 menu
->leaveNotifyEvent(&e
->xcrossing
);
603 else if ((win
= searchWindow(e
->xcrossing
.window
)))
604 win
->installColormap(False
);
605 else if ((tbar
= searchToolbar(e
->xcrossing
.window
)))
606 tbar
->leaveNotifyEvent(&e
->xcrossing
);
608 else if ((slit
= searchSlit(e
->xcrossing
.window
)))
609 slit
->leaveNotifyEvent(&e
->xcrossing
);
616 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
617 Basemenu
*menu
= (Basemenu
*) 0;
618 Toolbar
*tbar
= (Toolbar
*) 0;
620 if ((win
= searchWindow(e
->xexpose
.window
)))
621 win
->exposeEvent(&e
->xexpose
);
622 else if ((menu
= searchMenu(e
->xexpose
.window
)))
623 menu
->exposeEvent(&e
->xexpose
);
624 else if ((tbar
= searchToolbar(e
->xexpose
.window
)))
625 tbar
->exposeEvent(&e
->xexpose
);
631 Toolbar
*tbar
= searchToolbar(e
->xkey
.window
);
633 if (tbar
&& tbar
->isEditing())
634 tbar
->keyPressEvent(&e
->xkey
);
639 case ColormapNotify
: {
640 BScreen
*screen
= searchScreen(e
->xcolormap
.window
);
643 screen
->setRootColormapInstalled((e
->xcolormap
.state
==
644 ColormapInstalled
) ? True
: False
);
650 if (e
->xfocus
.mode
== NotifyUngrab
|| e
->xfocus
.detail
== NotifyPointer
)
653 OpenboxWindow
*win
= searchWindow(e
->xfocus
.window
);
654 if (win
&& !win
->isFocused())
663 case ClientMessage
: {
664 if (e
->xclient
.format
== 32) {
665 if (e
->xclient
.message_type
== getWMChangeStateAtom()) {
666 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
667 if (! win
|| ! win
->validateClient()) return;
669 if (e
->xclient
.data
.l
[0] == IconicState
)
671 if (e
->xclient
.data
.l
[0] == NormalState
)
673 } else if (e
->xclient
.message_type
== getOpenboxChangeWorkspaceAtom()) {
674 BScreen
*screen
= searchScreen(e
->xclient
.window
);
676 if (screen
&& e
->xclient
.data
.l
[0] >= 0 &&
677 e
->xclient
.data
.l
[0] < screen
->getWorkspaceCount())
678 screen
->changeWorkspaceID(e
->xclient
.data
.l
[0]);
679 } else if (e
->xclient
.message_type
== getOpenboxChangeWindowFocusAtom()) {
680 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
682 if (win
&& win
->isVisible() && win
->setInputFocus())
683 win
->installColormap(True
);
684 } else if (e
->xclient
.message_type
== getOpenboxCycleWindowFocusAtom()) {
685 BScreen
*screen
= searchScreen(e
->xclient
.window
);
688 if (! e
->xclient
.data
.l
[0])
693 } else if (e
->xclient
.message_type
== getOpenboxChangeAttributesAtom()) {
694 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
696 if (win
&& win
->validateClient()) {
698 net
.flags
= e
->xclient
.data
.l
[0];
699 net
.attrib
= e
->xclient
.data
.l
[1];
700 net
.workspace
= e
->xclient
.data
.l
[2];
701 net
.stack
= e
->xclient
.data
.l
[3];
702 net
.decoration
= e
->xclient
.data
.l
[4];
704 win
->changeOpenboxHints(&net
);
715 if (e
->type
== getShapeEventBase()) {
716 XShapeEvent
*shape_event
= (XShapeEvent
*) e
;
717 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
719 if ((win
= searchWindow(e
->xany
.window
)) ||
720 (shape_event
->kind
!= ShapeBounding
))
721 win
->shapeEvent(shape_event
);
730 Bool
Openbox::handleSignal(int sig
) {
756 BScreen
*Openbox::searchScreen(Window window
) {
757 ScreenList::iterator it
;
758 for (it
= screenList
.begin(); it
!= screenList
.end(); ++it
)
759 if ((*it
)->getRootWindow() == window
)
761 return (BScreen
*) 0;
765 OpenboxWindow
*Openbox::searchWindow(Window window
) {
766 WindowLookup::iterator it
= windowSearchList
.find(window
);
767 if (it
== windowSearchList
.end())
768 return (OpenboxWindow
*) 0;
773 OpenboxWindow
*Openbox::searchGroup(Window window
, OpenboxWindow
*win
) {
774 WindowLookup::iterator it
= groupSearchList
.find(window
);
775 if (it
!= groupSearchList
.end())
776 if (it
->second
->getClientWindow() != win
->getClientWindow())
778 return (OpenboxWindow
*) 0;
782 Basemenu
*Openbox::searchMenu(Window window
) {
783 MenuLookup::iterator it
= menuSearchList
.find(window
);
784 if (it
== menuSearchList
.end())
785 return (Basemenu
*) 0;
790 Toolbar
*Openbox::searchToolbar(Window window
) {
791 ToolbarLookup::iterator it
= toolbarSearchList
.find(window
);
792 if (it
== toolbarSearchList
.end())
793 return (Toolbar
*) 0;
799 Slit
*Openbox::searchSlit(Window window
) {
800 SlitLookup::iterator it
= slitSearchList
.find(window
);
801 if (it
== slitSearchList
.end())
808 void Openbox::saveWindowSearch(Window window
, OpenboxWindow
*data
) {
809 windowSearchList
.insert(WindowLookupPair(window
, data
));
813 void Openbox::saveGroupSearch(Window window
, OpenboxWindow
*data
) {
814 groupSearchList
.insert(WindowLookupPair(window
, data
));
818 void Openbox::saveMenuSearch(Window window
, Basemenu
*data
) {
819 menuSearchList
.insert(MenuLookupPair(window
, data
));
823 void Openbox::saveToolbarSearch(Window window
, Toolbar
*data
) {
824 toolbarSearchList
.insert(ToolbarLookupPair(window
, data
));
829 void Openbox::saveSlitSearch(Window window
, Slit
*data
) {
830 slitSearchList
.insert(SlitLookupPair(window
, data
));
835 void Openbox::removeWindowSearch(Window window
) {
836 windowSearchList
.erase(window
);
840 void Openbox::removeGroupSearch(Window window
) {
841 groupSearchList
.erase(window
);
845 void Openbox::removeMenuSearch(Window window
) {
846 menuSearchList
.erase(window
);
850 void Openbox::removeToolbarSearch(Window window
) {
851 toolbarSearchList
.erase(window
);
856 void Openbox::removeSlitSearch(Window window
) {
857 slitSearchList
.erase(window
);
862 void Openbox::restart(const char *prog
) {
866 execlp(prog
, prog
, NULL
);
870 // fall back in case the above execlp doesn't work
871 execvp(argv
[0], argv
);
872 execvp(basename(argv
[0]), argv
);
876 void Openbox::shutdown() {
877 BaseDisplay::shutdown();
879 std::for_each(screenList
.begin(), screenList
.end(),
880 std::mem_fun(&BScreen::shutdown
));
884 XSync(getXDisplay(), False
);
888 void Openbox::save() {
889 config
.setAutoSave(false);
891 // save all values as they are so that the defaults will be written to the rc
894 config
.setValue("session.colorsPerChannel",
895 resource
.colors_per_channel
);
896 config
.setValue("session.styleFile", resource
.style_file
);
897 config
.setValue("session.titlebarLayout", resource
.titlebar_layout
);
898 config
.setValue("session.doubleClickInterval",
899 (long)resource
.double_click_interval
);
900 config
.setValue("session.autoRaiseDelay",
901 ((resource
.auto_raise_delay
.tv_sec
* 1000) +
902 (resource
.auto_raise_delay
.tv_usec
/ 1000)));
903 config
.setValue("session.cacheLife", (long)resource
.cache_life
/ 60000);
904 config
.setValue("session.cacheMax", (long)resource
.cache_max
);
906 std::for_each(screenList
.begin(), screenList
.end(),
907 std::mem_fun(&BScreen::save
));
909 config
.setAutoSave(true);
913 void Openbox::load() {
920 if (config
.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
922 resource
.colors_per_channel
= (l
< 2 ? 2 : (l
> 6 ? 6 : l
)); // >= 2, <= 6
924 resource
.colors_per_channel
= 4;
926 if (resource
.style_file
)
927 delete [] resource
.style_file
;
928 if (config
.getValue("session.styleFile", "Session.StyleFile", s
))
929 resource
.style_file
= bstrdup(s
.c_str());
931 resource
.style_file
= bstrdup(DEFAULTSTYLE
);
933 if (resource
.titlebar_layout
)
934 delete [] resource
.titlebar_layout
;
935 if (config
.getValue("session.titlebarLayout", "Session.TitlebarLayout", s
))
936 resource
.titlebar_layout
= bstrdup(s
.c_str());
938 resource
.titlebar_layout
= bstrdup("ILMC");
940 if (config
.getValue("session.doubleClickInterval",
941 "Session.DoubleClickInterval", l
))
942 resource
.double_click_interval
= l
;
944 resource
.double_click_interval
= 250;
946 if (!config
.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l
))
947 resource
.auto_raise_delay
.tv_usec
= l
;
949 resource
.auto_raise_delay
.tv_usec
= 400;
950 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
/ 1000;
951 resource
.auto_raise_delay
.tv_usec
-=
952 (resource
.auto_raise_delay
.tv_sec
* 1000);
953 resource
.auto_raise_delay
.tv_usec
*= 1000;
955 if (config
.getValue("session.cacheLife", "Session.CacheLife", l
))
956 resource
.cache_life
= l
;
958 resource
.cache_life
= 51;
959 resource
.cache_life
*= 60000;
961 if (config
.getValue("session.cacheMax", "Session.CacheMax", l
))
962 resource
.cache_max
= l
;
964 resource
.cache_max
= 200;
968 void Openbox::reconfigure() {
969 reconfigure_wait
= True
;
971 if (! timer
->isTiming()) timer
->start();
975 void Openbox::real_reconfigure() {
980 for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
982 menuTimestamps
.clear();
984 std::for_each(screenList
.begin(), screenList
.end(),
985 std::mem_fun(&BScreen::reconfigure
));
991 void Openbox::checkMenu() {
992 MenuTimestampList::iterator it
;
993 for (it
= menuTimestamps
.begin(); it
!= menuTimestamps
.end(); ++it
) {
996 if (stat((*it
)->filename
, &buf
) || (*it
)->timestamp
!= buf
.st_ctime
) {
1004 void Openbox::addMenuTimestamp(const char *filename
) {
1007 MenuTimestampList::iterator it
;
1008 for (it
= menuTimestamps
.begin(); it
!= menuTimestamps
.end(); ++it
)
1009 if (! strcmp((*it
)->filename
, filename
)) {
1016 if (! stat(filename
, &buf
)) {
1017 MenuTimestamp
*ts
= new MenuTimestamp
;
1019 ts
->filename
= bstrdup(filename
);
1020 ts
->timestamp
= buf
.st_ctime
;
1022 menuTimestamps
.push_back(ts
);
1027 void Openbox::rereadMenu() {
1028 reread_menu_wait
= True
;
1030 if (! timer
->isTiming()) timer
->start();
1034 void Openbox::real_rereadMenu() {
1035 std::for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
1037 menuTimestamps
.clear();
1039 std::for_each(screenList
.begin(), screenList
.end(),
1040 std::mem_fun(&BScreen::rereadMenu
));
1044 void Openbox::setStyleFilename(const char *filename
) {
1045 if (resource
.style_file
)
1046 delete [] resource
.style_file
;
1048 resource
.style_file
= bstrdup(filename
);
1049 config
.setValue("session.styleFile", resource
.style_file
);
1053 void Openbox::timeout() {
1054 if (reconfigure_wait
)
1057 if (reread_menu_wait
)
1060 reconfigure_wait
= reread_menu_wait
= False
;
1064 OpenboxWindow
*Openbox::focusedWindow() {
1067 if ((w
= current_screen
->getCurrentWorkspace()))
1068 return w
->focusedWindow();
1069 return (OpenboxWindow
*) 0;
1073 void Openbox::focusWindow(OpenboxWindow
*win
) {
1074 BScreen
*old_screen
= (BScreen
*) 0;
1075 Toolbar
*old_tbar
= (Toolbar
*) 0, *tbar
= (Toolbar
*) 0;
1076 Workspace
*old_wkspc
= (Workspace
*) 0, *wkspc
= (Workspace
*) 0;
1078 OpenboxWindow
*old_win
= focusedWindow();
1079 if (old_win
!= (OpenboxWindow
*) 0) {
1080 old_screen
= old_win
->getScreen();
1081 old_wkspc
= old_screen
->getWorkspace(old_win
->getWorkspaceNumber());
1082 old_tbar
= old_screen
->getToolbar();
1084 old_win
->setFocusFlag(false);
1085 old_wkspc
->focusWindow((OpenboxWindow
*) 0);
1088 if (win
&& !win
->isIconic()) {
1089 current_screen
= win
->getScreen();
1090 tbar
= current_screen
->getToolbar();
1091 wkspc
= current_screen
->getWorkspace(win
->getWorkspaceNumber());
1092 win
->setFocusFlag(true);
1093 wkspc
->focusWindow(win
);
1096 tbar
->redrawWindowLabel(true);
1097 current_screen
->updateNetizenWindowFocus();
1099 XSetInputFocus(getXDisplay(), PointerRoot
, None
, CurrentTime
);
1102 if (old_tbar
&& old_tbar
!= tbar
)
1103 old_tbar
->redrawWindowLabel(true);
1104 if (old_screen
&& old_screen
!= current_screen
)
1105 old_screen
->updateNetizenWindowFocus();