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"
64 #endif // HAVE_STDIO_H
69 #endif // STDC_HEADERS
72 # include <sys/types.h>
74 #endif // HAVE_UNISTD_H
76 #ifdef HAVE_SYS_PARAM_H
77 # include <sys/param.h>
78 #endif // HAVE_SYS_PARAM_H
81 #define MAXPATHLEN 255
84 #ifdef HAVE_SYS_SELECT_H
85 # include <sys/select.h>
86 #endif // HAVE_SYS_SELECT_H
90 #endif // HAVE_SIGNAL_H
92 #ifdef HAVE_SYS_SIGNAL_H
93 # include <sys/signal.h>
94 #endif // HAVE_SYS_SIGNAL_H
96 #ifdef HAVE_SYS_STAT_H
97 # include <sys/types.h>
98 # include <sys/stat.h>
99 #endif // HAVE_SYS_STAT_H
101 #ifdef TIME_WITH_SYS_TIME
102 # include <sys/time.h>
104 #else // !TIME_WITH_SYS_TIME
105 # ifdef HAVE_SYS_TIME_H
106 # include <sys/time.h>
107 # else // !HAVE_SYS_TIME_H
109 # endif // HAVE_SYS_TIME_H
110 #endif // TIME_WITH_SYS_TIME
114 #endif // HAVE_LIBGEN_H
116 #ifndef HAVE_BASENAME
117 static inline char *basename (char *s
) {
120 while (*s
) if (*s
++ == '/') save
= s
;
124 #endif // HAVE_BASENAME
127 // X event scanner for enter/leave notifies - adapted from twm
128 typedef struct scanargs
{
130 Bool leave
, inferior
, enter
;
133 static Bool
queueScanner(Display
*, XEvent
*e
, char *args
) {
134 if ((e
->type
== LeaveNotify
) &&
135 (e
->xcrossing
.window
== ((scanargs
*) args
)->w
) &&
136 (e
->xcrossing
.mode
== NotifyNormal
)) {
137 ((scanargs
*) args
)->leave
= True
;
138 ((scanargs
*) args
)->inferior
= (e
->xcrossing
.detail
== NotifyInferior
);
139 } else if ((e
->type
== EnterNotify
) &&
140 (e
->xcrossing
.mode
== NotifyUngrab
)) {
141 ((scanargs
*) args
)->enter
= True
;
150 Openbox::Openbox(int m_argc
, char **m_argv
, char *dpy_name
, char *rc
)
151 : BaseDisplay(m_argv
[0], dpy_name
) {
154 if (! XSupportsLocale())
155 fprintf(stderr
, "X server does not support locale\n");
157 if (XSetLocaleModifiers("") == NULL
)
158 fprintf(stderr
, "cannot set locale modifiers\n");
164 char *homedir
= getenv("HOME");
166 rc_file
= new char[strlen(homedir
) + strlen("/.openbox/rc") + 1];
167 sprintf(rc_file
, "%s/.openbox", homedir
);
169 // try to make sure the ~/.openbox directory exists
170 mkdir(rc_file
, S_IREAD
| S_IWRITE
| S_IEXEC
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
171 S_IROTH
| S_IWOTH
| S_IXOTH
);
173 sprintf(rc_file
, "%s/.openbox/rc", homedir
);
175 rc_file
= bstrdup(rc
);
178 config
.setFile(rc_file
);
182 resource
.menu_file
= resource
.style_file
= (char *) 0;
183 resource
.titlebar_layout
= (char *) NULL
;
184 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
= 0;
186 focused_window
= masked_window
= (OpenboxWindow
*) 0;
189 windowSearchList
= new LinkedList
<WindowSearch
>;
190 menuSearchList
= new LinkedList
<MenuSearch
>;
193 slitSearchList
= new LinkedList
<SlitSearch
>;
196 toolbarSearchList
= new LinkedList
<ToolbarSearch
>;
197 groupSearchList
= new LinkedList
<WindowSearch
>;
199 menuTimestamps
= new LinkedList
<MenuTimestamp
>;
204 openbox_pid
= XInternAtom(getXDisplay(), "_BLACKBOX_PID", False
);
205 #endif // HAVE_GETPID
207 screenList
= new LinkedList
<BScreen
>;
208 for (int i
= 0; i
< getNumberOfScreens(); i
++) {
209 BScreen
*screen
= new BScreen(*this, i
);
211 if (! screen
->isScreenManaged()) {
216 screenList
->insert(screen
);
219 if (! screenList
->count()) {
221 i18n
->getMessage(openboxSet
, openboxNoManagableScreens
,
222 "Openbox::Openbox: no managable screens found, aborting.\n"));
226 XSynchronize(getXDisplay(), False
);
227 XSync(getXDisplay(), False
);
229 reconfigure_wait
= reread_menu_wait
= False
;
231 timer
= new BTimer(*this, *this);
232 timer
->setTimeout(0);
233 timer
->fireOnce(True
);
239 Openbox::~Openbox(void) {
240 while (screenList
->count())
241 delete screenList
->remove(0);
243 while (menuTimestamps
->count()) {
244 MenuTimestamp
*ts
= menuTimestamps
->remove(0);
247 delete [] ts
->filename
;
252 if (resource
.menu_file
)
253 delete [] resource
.menu_file
;
255 if (resource
.style_file
)
256 delete [] resource
.style_file
;
261 delete menuTimestamps
;
263 delete windowSearchList
;
264 delete menuSearchList
;
265 delete toolbarSearchList
;
266 delete groupSearchList
;
271 delete slitSearchList
;
276 void Openbox::process_event(XEvent
*e
) {
277 if ((masked
== e
->xany
.window
) && masked_window
&&
278 (e
->type
== MotionNotify
)) {
279 last_time
= e
->xmotion
.time
;
280 masked_window
->motionNotifyEvent(&e
->xmotion
);
287 // strip the lock key modifiers
288 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
290 last_time
= e
->xbutton
.time
;
292 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
293 Basemenu
*menu
= (Basemenu
*) 0;
296 Slit
*slit
= (Slit
*) 0;
299 Toolbar
*tbar
= (Toolbar
*) 0;
301 if ((win
= searchWindow(e
->xbutton
.window
))) {
302 win
->buttonPressEvent(&e
->xbutton
);
304 if (e
->xbutton
.button
== 1)
305 win
->installColormap(True
);
306 } else if ((menu
= searchMenu(e
->xbutton
.window
))) {
307 menu
->buttonPressEvent(&e
->xbutton
);
310 } else if ((slit
= searchSlit(e
->xbutton
.window
))) {
311 slit
->buttonPressEvent(&e
->xbutton
);
314 } else if ((tbar
= searchToolbar(e
->xbutton
.window
))) {
315 tbar
->buttonPressEvent(&e
->xbutton
);
317 LinkedListIterator
<BScreen
> it(screenList
);
318 BScreen
*screen
= it
.current();
319 for (; screen
; it
++, screen
= it
.current()) {
320 if (e
->xbutton
.window
== screen
->getRootWindow()) {
321 if (e
->xbutton
.button
== 1) {
322 if (! screen
->isRootColormapInstalled())
323 screen
->getImageControl()->installRootColormap();
325 if (screen
->getWorkspacemenu()->isVisible())
326 screen
->getWorkspacemenu()->hide();
328 if (screen
->getRootmenu()->isVisible())
329 screen
->getRootmenu()->hide();
330 } else if (e
->xbutton
.button
== 2) {
331 int mx
= e
->xbutton
.x_root
-
332 (screen
->getWorkspacemenu()->getWidth() / 2);
333 int my
= e
->xbutton
.y_root
-
334 (screen
->getWorkspacemenu()->getTitleHeight() / 2);
339 if (mx
+ screen
->getWorkspacemenu()->getWidth() >
341 mx
= screen
->getWidth() -
342 screen
->getWorkspacemenu()->getWidth() -
343 screen
->getBorderWidth();
345 if (my
+ screen
->getWorkspacemenu()->getHeight() >
347 my
= screen
->getHeight() -
348 screen
->getWorkspacemenu()->getHeight() -
349 screen
->getBorderWidth();
351 screen
->getWorkspacemenu()->move(mx
, my
);
353 if (! screen
->getWorkspacemenu()->isVisible()) {
354 screen
->getWorkspacemenu()->removeParent();
355 screen
->getWorkspacemenu()->show();
357 } else if (e
->xbutton
.button
== 3) {
358 int mx
= e
->xbutton
.x_root
-
359 (screen
->getRootmenu()->getWidth() / 2);
360 int my
= e
->xbutton
.y_root
-
361 (screen
->getRootmenu()->getTitleHeight() / 2);
366 if (mx
+ screen
->getRootmenu()->getWidth() > screen
->getWidth())
367 mx
= screen
->getWidth() -
368 screen
->getRootmenu()->getWidth() -
369 screen
->getBorderWidth();
371 if (my
+ screen
->getRootmenu()->getHeight() > screen
->getHeight())
372 my
= screen
->getHeight() -
373 screen
->getRootmenu()->getHeight() -
374 screen
->getBorderWidth();
376 screen
->getRootmenu()->move(mx
, my
);
378 if (! screen
->getRootmenu()->isVisible()) {
380 screen
->getRootmenu()->show();
382 } else if (e
->xbutton
.button
== 4) {
383 if ((screen
->getCurrentWorkspaceID()-1)<0)
384 screen
->changeWorkspaceID(screen
->getWorkspaceCount()-1);
386 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID()-1);
387 } else if (e
->xbutton
.button
== 5) {
388 if ((screen
->getCurrentWorkspaceID()+1)>screen
->getWorkspaceCount()-1)
389 screen
->changeWorkspaceID(0);
391 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID()+1);
400 case ButtonRelease
: {
401 // strip the lock key modifiers
402 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
404 last_time
= e
->xbutton
.time
;
406 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
407 Basemenu
*menu
= (Basemenu
*) 0;
408 Toolbar
*tbar
= (Toolbar
*) 0;
410 if ((win
= searchWindow(e
->xbutton
.window
)))
411 win
->buttonReleaseEvent(&e
->xbutton
);
412 else if ((menu
= searchMenu(e
->xbutton
.window
)))
413 menu
->buttonReleaseEvent(&e
->xbutton
);
414 else if ((tbar
= searchToolbar(e
->xbutton
.window
)))
415 tbar
->buttonReleaseEvent(&e
->xbutton
);
420 case ConfigureRequest
: {
421 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
424 Slit
*slit
= (Slit
*) 0;
427 if ((win
= searchWindow(e
->xconfigurerequest
.window
))) {
428 win
->configureRequestEvent(&e
->xconfigurerequest
);
431 } else if ((slit
= searchSlit(e
->xconfigurerequest
.window
))) {
432 slit
->configureRequestEvent(&e
->xconfigurerequest
);
438 if (validateWindow(e
->xconfigurerequest
.window
)) {
441 xwc
.x
= e
->xconfigurerequest
.x
;
442 xwc
.y
= e
->xconfigurerequest
.y
;
443 xwc
.width
= e
->xconfigurerequest
.width
;
444 xwc
.height
= e
->xconfigurerequest
.height
;
445 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
446 xwc
.sibling
= e
->xconfigurerequest
.above
;
447 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
449 XConfigureWindow(getXDisplay(), e
->xconfigurerequest
.window
,
450 e
->xconfigurerequest
.value_mask
, &xwc
);
462 i18n
->getMessage(openboxSet
, openboxMapRequest
,
463 "Openbox::process_event(): MapRequest for 0x%lx\n"),
464 e
->xmaprequest
.window
);
467 OpenboxWindow
*win
= searchWindow(e
->xmaprequest
.window
);
470 win
= new OpenboxWindow(this, e
->xmaprequest
.window
);
472 if ((win
= searchWindow(e
->xmaprequest
.window
)))
473 win
->mapRequestEvent(&e
->xmaprequest
);
479 OpenboxWindow
*win
= searchWindow(e
->xmap
.window
);
482 win
->mapNotifyEvent(&e
->xmap
);
488 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
491 Slit
*slit
= (Slit
*) 0;
494 if ((win
= searchWindow(e
->xunmap
.window
))) {
495 win
->unmapNotifyEvent(&e
->xunmap
);
496 if (focused_window
== win
)
497 focused_window
= (OpenboxWindow
*) 0;
499 } else if ((slit
= searchSlit(e
->xunmap
.window
))) {
500 slit
->removeClient(e
->xunmap
.window
);
508 case DestroyNotify
: {
509 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
512 Slit
*slit
= (Slit
*) 0;
515 if ((win
= searchWindow(e
->xdestroywindow
.window
))) {
516 win
->destroyNotifyEvent(&e
->xdestroywindow
);
517 if (focused_window
== win
)
518 focused_window
= (OpenboxWindow
*) 0;
520 } else if ((slit
= searchSlit(e
->xdestroywindow
.window
))) {
521 slit
->removeClient(e
->xdestroywindow
.window
, False
);
529 // strip the lock key modifiers
530 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
532 last_time
= e
->xmotion
.time
;
534 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
535 Basemenu
*menu
= (Basemenu
*) 0;
537 if ((win
= searchWindow(e
->xmotion
.window
)))
538 win
->motionNotifyEvent(&e
->xmotion
);
539 else if ((menu
= searchMenu(e
->xmotion
.window
)))
540 menu
->motionNotifyEvent(&e
->xmotion
);
545 case PropertyNotify
: {
546 last_time
= e
->xproperty
.time
;
548 if (e
->xproperty
.state
!= PropertyDelete
) {
549 OpenboxWindow
*win
= searchWindow(e
->xproperty
.window
);
552 win
->propertyNotifyEvent(e
->xproperty
.atom
);
559 last_time
= e
->xcrossing
.time
;
561 BScreen
*screen
= (BScreen
*) 0;
562 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
563 Basemenu
*menu
= (Basemenu
*) 0;
564 Toolbar
*tbar
= (Toolbar
*) 0;
567 Slit
*slit
= (Slit
*) 0;
570 if (e
->xcrossing
.mode
== NotifyGrab
) break;
574 sa
.w
= e
->xcrossing
.window
;
575 sa
.enter
= sa
.leave
= False
;
576 XCheckIfEvent(getXDisplay(), &dummy
, queueScanner
, (char *) &sa
);
578 if ((e
->xcrossing
.window
== e
->xcrossing
.root
) &&
579 (screen
= searchScreen(e
->xcrossing
.window
))) {
580 screen
->getImageControl()->installRootColormap();
581 } else if ((win
= searchWindow(e
->xcrossing
.window
))) {
582 if (win
->getScreen()->isSloppyFocus() &&
583 (! win
->isFocused()) && (! no_focus
)) {
586 if (((! sa
.leave
) || sa
.inferior
) && win
->isVisible() &&
587 win
->setInputFocus())
588 win
->installColormap(True
);
592 } else if ((menu
= searchMenu(e
->xcrossing
.window
))) {
593 menu
->enterNotifyEvent(&e
->xcrossing
);
594 } else if ((tbar
= searchToolbar(e
->xcrossing
.window
))) {
595 tbar
->enterNotifyEvent(&e
->xcrossing
);
597 } else if ((slit
= searchSlit(e
->xcrossing
.window
))) {
598 slit
->enterNotifyEvent(&e
->xcrossing
);
605 last_time
= e
->xcrossing
.time
;
607 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
608 Basemenu
*menu
= (Basemenu
*) 0;
609 Toolbar
*tbar
= (Toolbar
*) 0;
612 Slit
*slit
= (Slit
*) 0;
615 if ((menu
= searchMenu(e
->xcrossing
.window
)))
616 menu
->leaveNotifyEvent(&e
->xcrossing
);
617 else if ((win
= searchWindow(e
->xcrossing
.window
)))
618 win
->installColormap(False
);
619 else if ((tbar
= searchToolbar(e
->xcrossing
.window
)))
620 tbar
->leaveNotifyEvent(&e
->xcrossing
);
622 else if ((slit
= searchSlit(e
->xcrossing
.window
)))
623 slit
->leaveNotifyEvent(&e
->xcrossing
);
630 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
631 Basemenu
*menu
= (Basemenu
*) 0;
632 Toolbar
*tbar
= (Toolbar
*) 0;
634 if ((win
= searchWindow(e
->xexpose
.window
)))
635 win
->exposeEvent(&e
->xexpose
);
636 else if ((menu
= searchMenu(e
->xexpose
.window
)))
637 menu
->exposeEvent(&e
->xexpose
);
638 else if ((tbar
= searchToolbar(e
->xexpose
.window
)))
639 tbar
->exposeEvent(&e
->xexpose
);
645 Toolbar
*tbar
= searchToolbar(e
->xkey
.window
);
647 if (tbar
&& tbar
->isEditing())
648 tbar
->keyPressEvent(&e
->xkey
);
653 case ColormapNotify
: {
654 BScreen
*screen
= searchScreen(e
->xcolormap
.window
);
657 screen
->setRootColormapInstalled((e
->xcolormap
.state
==
658 ColormapInstalled
) ? True
: False
);
664 if (e
->xfocus
.mode
== NotifyUngrab
|| e
->xfocus
.detail
== NotifyPointer
)
667 OpenboxWindow
*win
= searchWindow(e
->xfocus
.window
);
668 if (win
&& ! win
->isFocused())
669 setFocusedWindow(win
);
677 case ClientMessage
: {
678 if (e
->xclient
.format
== 32) {
679 if (e
->xclient
.message_type
== getWMChangeStateAtom()) {
680 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
681 if (! win
|| ! win
->validateClient()) return;
683 if (e
->xclient
.data
.l
[0] == IconicState
)
685 if (e
->xclient
.data
.l
[0] == NormalState
)
687 } else if (e
->xclient
.message_type
== getOpenboxChangeWorkspaceAtom()) {
688 BScreen
*screen
= searchScreen(e
->xclient
.window
);
690 if (screen
&& e
->xclient
.data
.l
[0] >= 0 &&
691 e
->xclient
.data
.l
[0] < screen
->getWorkspaceCount())
692 screen
->changeWorkspaceID(e
->xclient
.data
.l
[0]);
693 } else if (e
->xclient
.message_type
== getOpenboxChangeWindowFocusAtom()) {
694 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
696 if (win
&& win
->isVisible() && win
->setInputFocus())
697 win
->installColormap(True
);
698 } else if (e
->xclient
.message_type
== getOpenboxCycleWindowFocusAtom()) {
699 BScreen
*screen
= searchScreen(e
->xclient
.window
);
702 if (! e
->xclient
.data
.l
[0])
707 } else if (e
->xclient
.message_type
== getOpenboxChangeAttributesAtom()) {
708 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
710 if (win
&& win
->validateClient()) {
712 net
.flags
= e
->xclient
.data
.l
[0];
713 net
.attrib
= e
->xclient
.data
.l
[1];
714 net
.workspace
= e
->xclient
.data
.l
[2];
715 net
.stack
= e
->xclient
.data
.l
[3];
716 net
.decoration
= e
->xclient
.data
.l
[4];
718 win
->changeOpenboxHints(&net
);
729 if (e
->type
== getShapeEventBase()) {
730 XShapeEvent
*shape_event
= (XShapeEvent
*) e
;
731 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
733 if ((win
= searchWindow(e
->xany
.window
)) ||
734 (shape_event
->kind
!= ShapeBounding
))
735 win
->shapeEvent(shape_event
);
744 Bool
Openbox::handleSignal(int sig
) {
773 BScreen
*Openbox::searchScreen(Window window
) {
774 LinkedListIterator
<BScreen
> it(screenList
);
776 for (BScreen
*curr
= it
.current(); curr
; it
++, curr
= it
.current()) {
777 if (curr
->getRootWindow() == window
) {
782 return (BScreen
*) 0;
786 OpenboxWindow
*Openbox::searchWindow(Window window
) {
787 LinkedListIterator
<WindowSearch
> it(windowSearchList
);
789 for (WindowSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
790 if (tmp
->getWindow() == window
) {
791 return tmp
->getData();
795 return (OpenboxWindow
*) 0;
799 OpenboxWindow
*Openbox::searchGroup(Window window
, OpenboxWindow
*win
) {
800 OpenboxWindow
*w
= (OpenboxWindow
*) 0;
801 LinkedListIterator
<WindowSearch
> it(groupSearchList
);
803 for (WindowSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
804 if (tmp
->getWindow() == window
) {
806 if (w
->getClientWindow() != win
->getClientWindow())
811 return (OpenboxWindow
*) 0;
815 Basemenu
*Openbox::searchMenu(Window window
) {
816 LinkedListIterator
<MenuSearch
> it(menuSearchList
);
818 for (MenuSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
819 if (tmp
->getWindow() == window
)
820 return tmp
->getData();
823 return (Basemenu
*) 0;
827 Toolbar
*Openbox::searchToolbar(Window window
) {
828 LinkedListIterator
<ToolbarSearch
> it(toolbarSearchList
);
830 for (ToolbarSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
831 if (tmp
->getWindow() == window
)
832 return tmp
->getData();
835 return (Toolbar
*) 0;
840 Slit
*Openbox::searchSlit(Window window
) {
841 LinkedListIterator
<SlitSearch
> it(slitSearchList
);
843 for (SlitSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
844 if (tmp
->getWindow() == window
)
845 return tmp
->getData();
853 void Openbox::saveWindowSearch(Window window
, OpenboxWindow
*data
) {
854 windowSearchList
->insert(new WindowSearch(window
, data
));
858 void Openbox::saveGroupSearch(Window window
, OpenboxWindow
*data
) {
859 groupSearchList
->insert(new WindowSearch(window
, data
));
863 void Openbox::saveMenuSearch(Window window
, Basemenu
*data
) {
864 menuSearchList
->insert(new MenuSearch(window
, data
));
868 void Openbox::saveToolbarSearch(Window window
, Toolbar
*data
) {
869 toolbarSearchList
->insert(new ToolbarSearch(window
, data
));
874 void Openbox::saveSlitSearch(Window window
, Slit
*data
) {
875 slitSearchList
->insert(new SlitSearch(window
, data
));
880 void Openbox::removeWindowSearch(Window window
) {
881 LinkedListIterator
<WindowSearch
> it(windowSearchList
);
882 for (WindowSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
883 if (tmp
->getWindow() == window
) {
884 windowSearchList
->remove(tmp
);
892 void Openbox::removeGroupSearch(Window window
) {
893 LinkedListIterator
<WindowSearch
> it(groupSearchList
);
894 for (WindowSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
895 if (tmp
->getWindow() == window
) {
896 groupSearchList
->remove(tmp
);
904 void Openbox::removeMenuSearch(Window window
) {
905 LinkedListIterator
<MenuSearch
> it(menuSearchList
);
906 for (MenuSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
907 if (tmp
->getWindow() == window
) {
908 menuSearchList
->remove(tmp
);
916 void Openbox::removeToolbarSearch(Window window
) {
917 LinkedListIterator
<ToolbarSearch
> it(toolbarSearchList
);
918 for (ToolbarSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
919 if (tmp
->getWindow() == window
) {
920 toolbarSearchList
->remove(tmp
);
929 void Openbox::removeSlitSearch(Window window
) {
930 LinkedListIterator
<SlitSearch
> it(slitSearchList
);
931 for (SlitSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
932 if (tmp
->getWindow() == window
) {
933 slitSearchList
->remove(tmp
);
942 void Openbox::restart(const char *prog
) {
946 execlp(prog
, prog
, NULL
);
950 // fall back in case the above execlp doesn't work
951 execvp(argv
[0], argv
);
952 execvp(basename(argv
[0]), argv
);
956 void Openbox::shutdown(void) {
957 BaseDisplay::shutdown();
959 XSetInputFocus(getXDisplay(), PointerRoot
, None
, CurrentTime
);
961 LinkedListIterator
<BScreen
> it(screenList
);
962 for (BScreen
*s
= it
.current(); s
; it
++, s
= it
.current())
965 XSync(getXDisplay(), False
);
971 void Openbox::save_rc(void) {
972 config
.setAutoSave(false);
974 config
.setValue("session.menuFile", getMenuFilename());
975 config
.setValue("session.colorsPerChannel",
976 resource
.colors_per_channel
);
977 config
.setValue("session.doubleClickInterval",
978 (long)resource
.double_click_interval
);
979 config
.setValue("session.autoRaiseDelay",
980 ((resource
.auto_raise_delay
.tv_sec
* 1000) +
981 (resource
.auto_raise_delay
.tv_usec
/ 1000)));
982 config
.setValue("session.cacheLife", (long)resource
.cache_life
/ 60000);
983 config
.setValue("session.cacheMax", (long)resource
.cache_max
);
985 LinkedListIterator
<BScreen
> it(screenList
);
986 for (BScreen
*screen
= it
.current(); screen
; it
++, screen
= it
.current()) {
987 // ScreenList::iterator it = screenList.begin();
988 // for (; it != screenList.end(); ++it) {
989 // BScreen *screen = *it;
990 char rc_string
[1024];
991 const int screen_number
= screen
->getScreenNumber();
993 char *placement
= (char *) 0;
995 switch (screen
->getSlitPlacement()) {
996 case Slit::TopLeft
: placement
= "TopLeft"; break;
997 case Slit::CenterLeft
: placement
= "CenterLeft"; break;
998 case Slit::BottomLeft
: placement
= "BottomLeft"; break;
999 case Slit::TopCenter
: placement
= "TopCenter"; break;
1000 case Slit::BottomCenter
: placement
= "BottomCenter"; break;
1001 case Slit::TopRight
: placement
= "TopRight"; break;
1002 case Slit::BottomRight
: placement
= "BottomRight"; break;
1003 case Slit::CenterRight
: default: placement
= "CenterRight"; break;
1005 sprintf(rc_string
, "session.screen%d.slit.placement", screen_number
);
1006 config
.setValue(rc_string
, placement
);
1008 sprintf(rc_string
, "session.screen%d.slit.direction", screen_number
);
1009 config
.setValue(rc_string
,
1010 screen
->getSlitDirection() == Slit::Horizontal
?
1011 "Horizontal" : "Vertical");
1013 sprintf(rc_string
, "session.screen%d.slit.onTop", screen_number
);
1014 config
.setValue(rc_string
, screen
->getSlit()->isOnTop() ? "True" : "False");
1016 sprintf(rc_string
, "session.screen%d.slit.autoHide", screen_number
);
1017 config
.setValue(rc_string
, screen
->getSlit()->doAutoHide() ?
1020 config
.setValue("session.opaqueMove",
1021 (screen
->doOpaqueMove()) ? "True" : "False");
1022 config
.setValue("session.imageDither",
1023 (screen
->getImageControl()->doDither()) ? "True" : "False");
1025 sprintf(rc_string
, "session.screen%d.fullMaximization", screen_number
);
1026 config
.setValue(rc_string
, screen
->doFullMax() ? "True" : "False");
1028 sprintf(rc_string
, "session.screen%d.focusNewWindows", screen_number
);
1029 config
.setValue(rc_string
, screen
->doFocusNew() ? "True" : "False");
1031 sprintf(rc_string
, "session.screen%d.focusLastWindow", screen_number
);
1032 config
.setValue(rc_string
, screen
->doFocusLast() ? "True" : "False");
1034 sprintf(rc_string
, "session.screen%d.rowPlacementDirection", screen_number
);
1035 config
.setValue(rc_string
,
1036 screen
->getRowPlacementDirection() == BScreen::LeftRight
?
1037 "LeftToRight" : "RightToLeft");
1039 sprintf(rc_string
, "session.screen%d.colPlacementDirection", screen_number
);
1040 config
.setValue(rc_string
,
1041 screen
->getColPlacementDirection() == BScreen::TopBottom
?
1042 "TopToBottom" : "BottomToTop");
1044 switch (screen
->getPlacementPolicy()) {
1045 case BScreen::CascadePlacement
: placement
= "CascadePlacement"; break;
1046 case BScreen::BestFitPlacement
: placement
= "BestFitPlacement"; break;
1047 case BScreen::ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
1049 case BScreen::RowSmartPlacement
: placement
= "RowSmartPlacement"; break;
1051 sprintf(rc_string
, "session.screen%d.windowPlacement", screen_number
);
1052 config
.setValue(rc_string
, placement
);
1054 sprintf(rc_string
, "session.screen%d.focusModel", screen_number
);
1055 config
.setValue(rc_string
,
1056 (screen
->isSloppyFocus() ?
1057 (screen
->doAutoRaise() ? "AutoRaiseSloppyFocus" :
1058 "SloppyFocus") : "ClickToFocus"));
1060 sprintf(rc_string
, "session.screen%d.workspaces", screen_number
);
1061 config
.setValue(rc_string
, screen
->getWorkspaceCount());
1063 sprintf(rc_string
, "session.screen%d.toolbar.onTop", screen_number
);
1064 config
.setValue(rc_string
, screen
->getToolbar()->isOnTop() ?
1067 sprintf(rc_string
, "session.screen%d.toolbar.autoHide", screen_number
);
1068 config
.setValue(rc_string
, screen
->getToolbar()->doAutoHide() ?
1071 switch (screen
->getToolbarPlacement()) {
1072 case Toolbar::TopLeft
: placement
= "TopLeft"; break;
1073 case Toolbar::BottomLeft
: placement
= "BottomLeft"; break;
1074 case Toolbar::TopCenter
: placement
= "TopCenter"; break;
1075 case Toolbar::TopRight
: placement
= "TopRight"; break;
1076 case Toolbar::BottomRight
: placement
= "BottomRight"; break;
1078 case Toolbar::BottomCenter
: placement
= "BottomCenter"; break;
1081 sprintf(rc_string
, "session.screen%d.toolbar.placement", screen_number
);
1082 config
.setValue(rc_string
, placement
);
1084 #ifdef HAVE_STRFTIME
1085 sprintf(rc_string
, "session.screen%d.strftimeFormat", screen_number
);
1086 config
.setValue(rc_string
, screen
->getStrftimeFormat());
1087 #else // !HAVE_STRFTIME
1088 sprintf(rc_string
, "session.screen%d.dateFormat", screen_number
);
1089 config
.setValue(rc_string
, screen
->getDateFormat() == B_EuropeanDate
?
1090 "European" : "American");
1092 sprintf(rc_string
, "session.screen%d.clockFormat", screen_number
);
1093 config
.setValue(rc_string
, screen
->isClock24Hour() ? 24 : 12);
1094 #endif // HAVE_STRFTIME
1096 sprintf(rc_string
, "session.screen%d.edgeSnapThreshold", screen_number
);
1097 config
.setValue(rc_string
, screen
->getEdgeSnapThreshold());
1099 sprintf(rc_string
, "session.screen%d.toolbar.widthPercent", screen_number
);
1100 config
.setValue(rc_string
, screen
->getToolbarWidthPercent());
1102 // write out the user's workspace names
1104 for (i
= 0; i
< screen
->getWorkspaceCount(); i
++)
1105 len
+= strlen((screen
->getWorkspace(i
)->getName()) ?
1106 screen
->getWorkspace(i
)->getName() : "Null") + 1;
1108 char *resource_string
= new char[len
+ 1024],
1109 *save_string
= new char[len
], *save_string_pos
= save_string
,
1112 for (i
= 0; i
< screen
->getWorkspaceCount(); i
++) {
1113 len
= strlen((screen
->getWorkspace(i
)->getName()) ?
1114 screen
->getWorkspace(i
)->getName() : "Null") + 1;
1116 (char *) ((screen
->getWorkspace(i
)->getName()) ?
1117 screen
->getWorkspace(i
)->getName() : "Null");
1119 while (--len
) *(save_string_pos
++) = *(name_string_pos
++);
1120 *(save_string_pos
++) = ',';
1124 *(--save_string_pos
) = '\0';
1126 sprintf(resource_string
, "session.screen%d.workspaceNames", screen_number
);
1127 config
.setValue(resource_string
, save_string
);
1129 delete [] resource_string
;
1130 delete [] save_string
;
1132 std::string save_string = screen->getWorkspace(0)->getName();
1133 for (unsigned int i = 1; i < screen->getWorkspaceCount(); ++i) {
1135 save_string += screen->getWorkspace(i)->getName();
1138 char *resource_string = new char[save_string.length() + 48];
1139 sprintf(resource_string, "session.screen%d.workspaceNames", screen_number);
1140 config.setValue(rc_string, save_string);
1142 delete [] resource_string;*/
1145 config
.setAutoSave(true);
1149 void Openbox::load_rc(void) {
1156 if (resource
.menu_file
)
1157 delete [] resource
.menu_file
;
1158 if (config
.getValue("session.menuFile", "Session.MenuFile", s
))
1159 resource
.menu_file
= bstrdup(s
.c_str());
1161 resource
.menu_file
= bstrdup(DEFAULTMENU
);
1163 if (config
.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
1165 resource
.colors_per_channel
= (l
< 2 ? 2 : (l
> 6 ? 6 : l
)); // >= 2, <= 6
1167 resource
.colors_per_channel
= 4;
1169 if (resource
.style_file
)
1170 delete [] resource
.style_file
;
1171 if (config
.getValue("session.styleFile", "Session.StyleFile", s
))
1172 resource
.style_file
= bstrdup(s
.c_str());
1174 resource
.style_file
= bstrdup(DEFAULTSTYLE
);
1176 if (resource
.titlebar_layout
)
1177 delete [] resource
.titlebar_layout
;
1178 if (config
.getValue("session.titlebarLayout", "Session.TitlebarLayout", s
))
1179 resource
.titlebar_layout
= bstrdup(s
.c_str());
1181 resource
.titlebar_layout
= bstrdup("ILMC");
1183 if (config
.getValue("session.doubleClickInterval",
1184 "Session.DoubleClickInterval", l
))
1185 resource
.double_click_interval
= l
;
1187 resource
.double_click_interval
= 250;
1189 if (!config
.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l
))
1190 resource
.auto_raise_delay
.tv_usec
= l
;
1192 resource
.auto_raise_delay
.tv_usec
= 400;
1193 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
/ 1000;
1194 resource
.auto_raise_delay
.tv_usec
-=
1195 (resource
.auto_raise_delay
.tv_sec
* 1000);
1196 resource
.auto_raise_delay
.tv_usec
*= 1000;
1198 if (config
.getValue("session.cacheLife", "Session.CacheLife", l
))
1199 resource
.cache_life
= l
;
1201 resource
.cache_life
= 51;
1202 resource
.cache_life
*= 60000;
1204 if (config
.getValue("session.cacheMax", "Session.CacheMax", l
))
1205 resource
.cache_max
= l
;
1207 resource
.cache_max
= 200;
1211 void Openbox::load_rc(BScreen
*screen
) {
1212 assert (screen
!= NULL
);
1213 const int screen_number
= screen
->getScreenNumber();
1214 assert (screen_number
>= 0);
1222 char name_lookup
[1024], class_lookup
[1024];
1224 sprintf(name_lookup
, "session.screen%d.fullMaximization", screen_number
);
1225 sprintf(class_lookup
, "Session.Screen%d.FullMaximization", screen_number
);
1226 if (config
.getValue(name_lookup
, class_lookup
, b
))
1227 screen
->saveFullMax((Bool
)b
);
1229 screen
->saveFullMax(False
);
1231 sprintf(name_lookup
, "session.screen%d.focusNewWindows", screen_number
);
1232 sprintf(class_lookup
, "Session.Screen%d.FocusNewWindows", screen_number
);
1233 if (config
.getValue(name_lookup
, class_lookup
, b
))
1234 screen
->saveFocusNew((Bool
)b
);
1236 screen
->saveFocusNew(False
);
1238 sprintf(name_lookup
, "session.screen%d.focusLastWindow", screen_number
);
1239 sprintf(class_lookup
, "Session.Screen%d.focusLastWindow", screen_number
);
1240 if (config
.getValue(name_lookup
, class_lookup
, b
))
1241 screen
->saveFocusLast((Bool
)b
);
1243 screen
->saveFocusLast(False
);
1245 sprintf(name_lookup
, "session.screen%d.rowPlacementDirection",
1247 sprintf(class_lookup
, "Session.Screen%d.RowPlacementDirection",
1249 if (config
.getValue(name_lookup
, class_lookup
, s
)) {
1250 if (0 == strncasecmp(s
.c_str(), "righttoleft", s
.length()))
1251 screen
->saveRowPlacementDirection(BScreen::RightLeft
);
1253 screen
->saveRowPlacementDirection(BScreen::LeftRight
);
1255 screen
->saveRowPlacementDirection(BScreen::LeftRight
);
1257 sprintf(name_lookup
, "session.screen%d.colPlacementDirection",
1259 sprintf(class_lookup
, "Session.Screen%d.ColPlacementDirection",
1261 if (config
.getValue(name_lookup
, class_lookup
, s
)) {
1262 if (0 == strncasecmp(s
.c_str(), "bottomtotop", s
.length()))
1263 screen
->saveColPlacementDirection(BScreen::BottomTop
);
1265 screen
->saveColPlacementDirection(BScreen::TopBottom
);
1267 screen
->saveColPlacementDirection(BScreen::TopBottom
);
1269 sprintf(name_lookup
, "session.screen%d.workspaces", screen_number
);
1270 sprintf(class_lookup
, "Session.Screen%d.Workspaces", screen_number
);
1271 if (config
.getValue(name_lookup
, class_lookup
, l
))
1272 screen
->saveWorkspaces(l
);
1274 screen
->saveWorkspaces(1);
1276 sprintf(name_lookup
, "session.screen%d.toolbar.widthPercent",
1278 sprintf(class_lookup
, "Session.Screen%d.Toolbar.WidthPercent",
1280 if (config
.getValue(name_lookup
, class_lookup
, l
) && (l
> 0 && l
<= 100))
1281 screen
->saveToolbarWidthPercent(l
);
1283 screen
->saveToolbarWidthPercent(66);
1285 sprintf(name_lookup
, "session.screen%d.toolbar.placement", screen_number
);
1286 sprintf(class_lookup
, "Session.Screen%d.Toolbar.Placement", screen_number
);
1287 if (config
.getValue(name_lookup
, class_lookup
, s
)) {
1288 if (0 == strncasecmp(s
.c_str(), "TopLeft", s
.length()))
1289 screen
->saveToolbarPlacement(Toolbar::TopLeft
);
1290 else if (0 == strncasecmp(s
.c_str(), "BottomLeft", s
.length()))
1291 screen
->saveToolbarPlacement(Toolbar::BottomLeft
);
1292 else if (0 == strncasecmp(s
.c_str(), "TopCenter", s
.length()))
1293 screen
->saveToolbarPlacement(Toolbar::TopCenter
);
1294 else if (0 == strncasecmp(s
.c_str(), "TopRight", s
.length()))
1295 screen
->saveToolbarPlacement(Toolbar::TopRight
);
1296 else if ( 0 == strncasecmp(s
.c_str(), "BottomRight", s
.length()))
1297 screen
->saveToolbarPlacement(Toolbar::BottomRight
);
1299 screen
->saveToolbarPlacement(Toolbar::BottomCenter
);
1301 screen
->saveToolbarPlacement(Toolbar::BottomCenter
);
1303 screen
->removeWorkspaceNames();
1304 sprintf(name_lookup
, "session.screen%d.workspaceNames", screen_number
);
1305 sprintf(class_lookup
, "Session.Screen%d.WorkspaceNames", screen_number
);
1306 if (config
.getValue(name_lookup
, class_lookup
, s
)) {
1307 // for (int i = 0; i < screen->getNumberOfWorkspaces(); i++) {
1308 std::string::const_iterator it
= s
.begin(), end
= s
.end();
1310 std::string::const_iterator tmp
= it
;// current string.begin()
1311 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
1312 std::string
name(tmp
, it
); // name = s[tmp:it]
1313 screen
->addWorkspaceName(name
.c_str());
1320 sprintf(name_lookup
, "session.screen%d.toolbar.onTop", screen_number
);
1321 sprintf(class_lookup
, "Session.Screen%d.Toolbar.OnTop", screen_number
);
1322 if (config
.getValue(name_lookup
, class_lookup
, b
))
1323 screen
->saveToolbarOnTop((Bool
)b
);
1325 screen
->saveToolbarOnTop(False
);
1327 sprintf(name_lookup
, "session.screen%d.toolbar.autoHide", screen_number
);
1328 sprintf(class_lookup
, "Session.Screen%d.Toolbar.autoHide", screen_number
);
1329 if (config
.getValue(name_lookup
, class_lookup
, b
))
1330 screen
->saveToolbarAutoHide((Bool
)b
);
1332 screen
->saveToolbarAutoHide(False
);
1334 sprintf(name_lookup
, "session.screen%d.focusModel", screen_number
);
1335 sprintf(class_lookup
, "Session.Screen%d.FocusModel", screen_number
);
1336 if (config
.getValue(name_lookup
, class_lookup
, s
)) {
1337 if (0 == strncasecmp(s
.c_str(), "clicktofocus", s
.length())) {
1338 screen
->saveAutoRaise(False
);
1339 screen
->saveSloppyFocus(False
);
1340 } else if (0 == strncasecmp(s
.c_str(), "autoraisesloppyfocus",
1342 screen
->saveSloppyFocus(True
);
1343 screen
->saveAutoRaise(True
);
1345 screen
->saveSloppyFocus(True
);
1346 screen
->saveAutoRaise(False
);
1349 screen
->saveSloppyFocus(True
);
1350 screen
->saveAutoRaise(False
);
1353 sprintf(name_lookup
, "session.screen%d.windowZones", screen_number
);
1354 sprintf(class_lookup
, "Session.Screen%d.WindowZones", screen_number
);
1355 if (config
.getValue(name_lookup
, class_lookup
, l
))
1356 screen
->saveWindowZones((l
== 1 || l
== 2 || l
== 4) ? l
: 1);
1358 screen
->saveWindowZones(1);
1360 sprintf(name_lookup
, "session.screen%d.windowPlacement", screen_number
);
1361 sprintf(class_lookup
, "Session.Screen%d.WindowPlacement", screen_number
);
1362 if (config
.getValue(name_lookup
, class_lookup
, s
)) {
1363 if (0 == strncasecmp(s
.c_str(), "RowSmartPlacement", s
.length()))
1364 screen
->savePlacementPolicy(BScreen::RowSmartPlacement
);
1365 else if (0 == strncasecmp(s
.c_str(), "ColSmartPlacement", s
.length()))
1366 screen
->savePlacementPolicy(BScreen::ColSmartPlacement
);
1367 else if (0 == strncasecmp(s
.c_str(), "BestFitPlacement", s
.length()))
1368 screen
->savePlacementPolicy(BScreen::BestFitPlacement
);
1370 screen
->savePlacementPolicy(BScreen::CascadePlacement
);
1372 screen
->savePlacementPolicy(BScreen::RowSmartPlacement
);
1375 sprintf(name_lookup
, "session.screen%d.slit.placement", screen_number
);
1376 sprintf(class_lookup
, "Session.Screen%d.Slit.Placement", screen_number
);
1377 if (config
.getValue(name_lookup
, class_lookup
, s
)) {
1378 if (0 == strncasecmp(s
.c_str(), "TopLeft", s
.length()))
1379 screen
->saveSlitPlacement(Slit::TopLeft
);
1380 else if (0 == strncasecmp(s
.c_str(), "CenterLeft", s
.length()))
1381 screen
->saveSlitPlacement(Slit::CenterLeft
);
1382 else if (0 == strncasecmp(s
.c_str(), "BottomLeft", s
.length()))
1383 screen
->saveSlitPlacement(Slit::BottomLeft
);
1384 else if (0 == strncasecmp(s
.c_str(), "TopCenter", s
.length()))
1385 screen
->saveSlitPlacement(Slit::TopCenter
);
1386 else if (0 == strncasecmp(s
.c_str(), "BottomCenter", s
.length()))
1387 screen
->saveSlitPlacement(Slit::BottomCenter
);
1388 else if (0 == strncasecmp(s
.c_str(), "TopRight", s
.length()))
1389 screen
->saveSlitPlacement(Slit::TopRight
);
1390 else if (0 == strncasecmp(s
.c_str(), "BottomRight", s
.length()))
1391 screen
->saveSlitPlacement(Slit::BottomRight
);
1393 screen
->saveSlitPlacement(Slit::CenterRight
);
1395 screen
->saveSlitPlacement(Slit::CenterRight
);
1397 sprintf(name_lookup
, "session.screen%d.slit.direction", screen_number
);
1398 sprintf(class_lookup
, "Session.Screen%d.Slit.Direction", screen_number
);
1399 if (config
.getValue(name_lookup
, class_lookup
, s
)) {
1400 if (0 == strncasecmp(s
.c_str(), "Horizontal", s
.length()))
1401 screen
->saveSlitDirection(Slit::Horizontal
);
1403 screen
->saveSlitDirection(Slit::Vertical
);
1405 screen
->saveSlitDirection(Slit::Vertical
);
1407 sprintf(name_lookup
, "session.screen%d.slit.onTop", screen_number
);
1408 sprintf(class_lookup
, "Session.Screen%d.Slit.OnTop", screen_number
);
1409 if (config
.getValue(name_lookup
, class_lookup
, b
))
1410 screen
->saveSlitOnTop((Bool
)b
);
1412 screen
->saveSlitOnTop(False
);
1414 sprintf(name_lookup
, "session.screen%d.slit.autoHide", screen_number
);
1415 sprintf(class_lookup
, "Session.Screen%d.Slit.AutoHide", screen_number
);
1416 if (config
.getValue(name_lookup
, class_lookup
, b
))
1417 screen
->saveSlitAutoHide((Bool
)b
);
1419 screen
->saveSlitAutoHide(False
);
1422 #ifdef HAVE_STRFTIME
1423 sprintf(name_lookup
, "session.screen%d.strftimeFormat", screen_number
);
1424 sprintf(class_lookup
, "Session.Screen%d.StrftimeFormat", screen_number
);
1425 if (config
.getValue(name_lookup
, class_lookup
, s
))
1426 screen
->saveStrftimeFormat(s
.c_str());
1428 screen
->saveStrftimeFormat("%I:%M %p");
1430 #else // HAVE_STRFTIME
1431 sprintf(name_lookup
, "session.screen%d.dateFormat", screen_number
);
1432 sprintf(class_lookup
, "Session.Screen%d.DateFormat", screen_number
);
1433 if (config
.getValue(name_lookup
, class_lookup
, s
)) {
1434 if (strncasecmp(s
.c_str(), "european", s
.length()))
1435 screen
->saveDateFormat(B_AmericanDate
);
1437 screen
->saveDateFormat(B_EuropeanDate
);
1439 screen
->saveDateFormat(B_AmericanDate
);
1441 sprintf(name_lookup
, "session.screen%d.clockFormat", screen_number
);
1442 sprintf(class_lookup
, "Session.Screen%d.ClockFormat", screen_number
);
1443 if (config
.getValue(name_lookup
, class_lookup
, l
)) {
1445 screen
->saveClock24Hour(True
);
1447 screen
->saveClock24Hour(False
);
1449 screen
->saveClock24Hour(False
);
1450 #endif // HAVE_STRFTIME
1452 sprintf(name_lookup
, "session.screen%d.edgeSnapThreshold", screen_number
);
1453 sprintf(class_lookup
, "Session.Screen%d.EdgeSnapThreshold", screen_number
);
1454 if (config
.getValue(name_lookup
, class_lookup
, l
))
1455 screen
->saveEdgeSnapThreshold(l
);
1457 screen
->saveEdgeSnapThreshold(4);
1459 sprintf(name_lookup
, "session.screen%d.imageDither", screen_number
);
1460 sprintf(class_lookup
, "Session.Screen%d.ImageDither", screen_number
);
1461 if (config
.getValue("session.imageDither", "Session.ImageDither", b
))
1462 screen
->saveImageDither((Bool
)b
);
1464 screen
->saveImageDither(True
);
1466 sprintf(name_lookup
, "session.screen%d.rootCommand", screen_number
);
1467 sprintf(class_lookup
, "Session.Screen%d.RootCommand", screen_number
);
1468 if (config
.getValue(name_lookup
, class_lookup
, s
))
1469 screen
->saveRootCommand(s
.c_str());
1471 screen
->saveRootCommand(NULL
);
1473 if (config
.getValue("session.opaqueMove", "Session.OpaqueMove", b
))
1474 screen
->saveOpaqueMove((Bool
)b
);
1476 screen
->saveOpaqueMove(False
);
1480 void Openbox::reload_rc(void) {
1486 void Openbox::reconfigure(void) {
1487 reconfigure_wait
= True
;
1489 if (! timer
->isTiming()) timer
->start();
1493 void Openbox::real_reconfigure(void) {
1497 config
.setValue("session.styleFile", resource
.style_file
); // autosave's
1499 for (int i
= 0, n
= menuTimestamps
->count(); i
< n
; i
++) {
1500 MenuTimestamp
*ts
= menuTimestamps
->remove(0);
1504 delete [] ts
->filename
;
1510 LinkedListIterator
<BScreen
> it(screenList
);
1511 for (BScreen
*screen
= it
.current(); screen
; it
++, screen
= it
.current()) {
1512 screen
->reconfigure();
1519 void Openbox::checkMenu(void) {
1520 Bool reread
= False
;
1521 LinkedListIterator
<MenuTimestamp
> it(menuTimestamps
);
1522 for (MenuTimestamp
*tmp
= it
.current(); tmp
&& (! reread
);
1523 it
++, tmp
= it
.current()) {
1526 if (! stat(tmp
->filename
, &buf
)) {
1527 if (tmp
->timestamp
!= buf
.st_ctime
)
1534 if (reread
) rereadMenu();
1538 void Openbox::rereadMenu(void) {
1539 reread_menu_wait
= True
;
1541 if (! timer
->isTiming()) timer
->start();
1545 void Openbox::real_rereadMenu(void) {
1546 for (int i
= 0, n
= menuTimestamps
->count(); i
< n
; i
++) {
1547 MenuTimestamp
*ts
= menuTimestamps
->remove(0);
1551 delete [] ts
->filename
;
1557 LinkedListIterator
<BScreen
> it(screenList
);
1558 for (BScreen
*screen
= it
.current(); screen
; it
++, screen
= it
.current())
1559 screen
->rereadMenu();
1563 void Openbox::saveStyleFilename(const char *filename
) {
1564 if (resource
.style_file
)
1565 delete [] resource
.style_file
;
1567 resource
.style_file
= bstrdup(filename
);
1571 void Openbox::saveMenuFilename(const char *filename
) {
1574 LinkedListIterator
<MenuTimestamp
> it(menuTimestamps
);
1575 for (MenuTimestamp
*tmp
= it
.current(); tmp
&& (! found
);
1576 it
++, tmp
= it
.current()) {
1577 if (! strcmp(tmp
->filename
, filename
)) found
= True
;
1582 if (! stat(filename
, &buf
)) {
1583 MenuTimestamp
*ts
= new MenuTimestamp
;
1585 ts
->filename
= bstrdup(filename
);
1586 ts
->timestamp
= buf
.st_ctime
;
1588 menuTimestamps
->insert(ts
);
1594 void Openbox::timeout(void) {
1595 if (reconfigure_wait
)
1598 if (reread_menu_wait
)
1601 reconfigure_wait
= reread_menu_wait
= False
;
1605 void Openbox::setFocusedWindow(OpenboxWindow
*win
) {
1606 BScreen
*old_screen
= (BScreen
*) 0, *screen
= (BScreen
*) 0;
1607 OpenboxWindow
*old_win
= (OpenboxWindow
*) 0;
1608 Toolbar
*old_tbar
= (Toolbar
*) 0, *tbar
= (Toolbar
*) 0;
1609 Workspace
*old_wkspc
= (Workspace
*) 0, *wkspc
= (Workspace
*) 0;
1611 if (focused_window
) {
1612 old_win
= focused_window
;
1613 old_screen
= old_win
->getScreen();
1614 old_tbar
= old_screen
->getToolbar();
1615 old_wkspc
= old_screen
->getWorkspace(old_win
->getWorkspaceNumber());
1617 old_win
->setFocusFlag(False
);
1618 old_wkspc
->getMenu()->setItemSelected(old_win
->getWindowNumber(), False
);
1621 if (win
&& ! win
->isIconic()) {
1622 screen
= win
->getScreen();
1623 tbar
= screen
->getToolbar();
1624 wkspc
= screen
->getWorkspace(win
->getWorkspaceNumber());
1626 focused_window
= win
;
1628 win
->setFocusFlag(True
);
1629 wkspc
->getMenu()->setItemSelected(win
->getWindowNumber(), True
);
1631 focused_window
= (OpenboxWindow
*) 0;
1635 tbar
->redrawWindowLabel(True
);
1637 screen
->updateNetizenWindowFocus();
1639 if (old_tbar
&& old_tbar
!= tbar
)
1640 old_tbar
->redrawWindowLabel(True
);
1641 if (old_screen
&& old_screen
!= screen
)
1642 old_screen
->updateNetizenWindowFocus();
1645 #warning TODO: wrap in appropriate #ifdefs.
1647 void Openbox::symlink_rc(const char*rcfile
)const{
1648 char *homedir
= getenv("HOME");
1650 char *link_file
= new char[strlen(homedir
) + strlen("/.blackoxrc") + 1];
1651 sprintf(link_file
, "%s/.blackboxrc", homedir
);
1652 if(symlink(rcfile
, link_file
) == -1){
1653 perror("Cannot create symlink");