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 focused_window
= masked_window
= NULL
;
192 windowSearchList
= new LinkedList
<WindowSearch
>;
193 menuSearchList
= new LinkedList
<MenuSearch
>;
196 slitSearchList
= new LinkedList
<SlitSearch
>;
199 toolbarSearchList
= new LinkedList
<ToolbarSearch
>;
200 groupSearchList
= new LinkedList
<WindowSearch
>;
202 menuTimestamps
= new LinkedList
<MenuTimestamp
>;
207 openbox_pid
= XInternAtom(getXDisplay(), "_BLACKBOX_PID", False
);
208 #endif // HAVE_GETPID
210 screenList
= new LinkedList
<BScreen
>;
211 for (int i
= 0; i
< getNumberOfScreens(); i
++) {
212 BScreen
*screen
= new BScreen(*this, i
, config
);
214 if (! screen
->isScreenManaged()) {
219 screenList
->insert(screen
);
222 if (! screenList
->count()) {
224 i18n
->getMessage(openboxSet
, openboxNoManagableScreens
,
225 "Openbox::Openbox: no managable screens found, aborting.\n"));
229 // save current settings and default values
232 XSynchronize(getXDisplay(), False
);
233 XSync(getXDisplay(), False
);
235 reconfigure_wait
= reread_menu_wait
= False
;
237 timer
= new BTimer(*this, *this);
238 timer
->setTimeout(0);
239 timer
->fireOnce(True
);
245 Openbox::~Openbox() {
246 while (screenList
->count())
247 delete screenList
->remove(0);
249 while (menuTimestamps
->count()) {
250 MenuTimestamp
*ts
= menuTimestamps
->remove(0);
253 delete [] ts
->filename
;
258 if (resource
.menu_file
)
259 delete [] resource
.menu_file
;
261 if (resource
.style_file
)
262 delete [] resource
.style_file
;
264 if (resource
.titlebar_layout
)
265 delete [] resource
.titlebar_layout
;
270 delete menuTimestamps
;
272 delete windowSearchList
;
273 delete menuSearchList
;
274 delete toolbarSearchList
;
275 delete groupSearchList
;
280 delete slitSearchList
;
285 void Openbox::process_event(XEvent
*e
) {
286 if ((masked
== e
->xany
.window
) && masked_window
&&
287 (e
->type
== MotionNotify
)) {
288 last_time
= e
->xmotion
.time
;
289 masked_window
->motionNotifyEvent(&e
->xmotion
);
296 // strip the lock key modifiers
297 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
299 last_time
= e
->xbutton
.time
;
301 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
302 Basemenu
*menu
= (Basemenu
*) 0;
305 Slit
*slit
= (Slit
*) 0;
308 Toolbar
*tbar
= (Toolbar
*) 0;
310 if ((win
= searchWindow(e
->xbutton
.window
))) {
311 win
->buttonPressEvent(&e
->xbutton
);
313 if (e
->xbutton
.button
== 1)
314 win
->installColormap(True
);
315 } else if ((menu
= searchMenu(e
->xbutton
.window
))) {
316 menu
->buttonPressEvent(&e
->xbutton
);
319 } else if ((slit
= searchSlit(e
->xbutton
.window
))) {
320 slit
->buttonPressEvent(&e
->xbutton
);
323 } else if ((tbar
= searchToolbar(e
->xbutton
.window
))) {
324 tbar
->buttonPressEvent(&e
->xbutton
);
326 LinkedListIterator
<BScreen
> it(screenList
);
327 BScreen
*screen
= it
.current();
328 for (; screen
; it
++, screen
= it
.current()) {
329 if (e
->xbutton
.window
== screen
->getRootWindow()) {
330 if (e
->xbutton
.button
== 1) {
331 if (! screen
->isRootColormapInstalled())
332 screen
->getImageControl()->installRootColormap();
334 if (screen
->getWorkspacemenu()->isVisible())
335 screen
->getWorkspacemenu()->hide();
337 if (screen
->getRootmenu()->isVisible())
338 screen
->getRootmenu()->hide();
339 } else if (e
->xbutton
.button
== 2) {
340 int mx
= e
->xbutton
.x_root
-
341 (screen
->getWorkspacemenu()->getWidth() / 2);
342 int my
= e
->xbutton
.y_root
-
343 (screen
->getWorkspacemenu()->getTitleHeight() / 2);
348 if (mx
+ screen
->getWorkspacemenu()->getWidth() >
350 mx
= screen
->size().w() -
351 screen
->getWorkspacemenu()->getWidth() -
352 screen
->getBorderWidth();
354 if (my
+ screen
->getWorkspacemenu()->getHeight() >
356 my
= screen
->size().h() -
357 screen
->getWorkspacemenu()->getHeight() -
358 screen
->getBorderWidth();
360 screen
->getWorkspacemenu()->move(mx
, my
);
362 if (! screen
->getWorkspacemenu()->isVisible()) {
363 screen
->getWorkspacemenu()->removeParent();
364 screen
->getWorkspacemenu()->show();
366 } else if (e
->xbutton
.button
== 3) {
367 int mx
= e
->xbutton
.x_root
-
368 (screen
->getRootmenu()->getWidth() / 2);
369 int my
= e
->xbutton
.y_root
-
370 (screen
->getRootmenu()->getTitleHeight() / 2);
375 if (mx
+ screen
->getRootmenu()->getWidth() > screen
->size().w())
376 mx
= screen
->size().w() -
377 screen
->getRootmenu()->getWidth() -
378 screen
->getBorderWidth();
380 if (my
+ screen
->getRootmenu()->getHeight() > screen
->size().h())
381 my
= screen
->size().h() -
382 screen
->getRootmenu()->getHeight() -
383 screen
->getBorderWidth();
385 screen
->getRootmenu()->move(mx
, my
);
387 if (! screen
->getRootmenu()->isVisible()) {
389 screen
->getRootmenu()->show();
391 } else if (e
->xbutton
.button
== 4) {
392 if ((screen
->getCurrentWorkspaceID() + 1) >
393 screen
->getWorkspaceCount() - 1)
394 screen
->changeWorkspaceID(0);
396 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID() + 1);
397 } else if (e
->xbutton
.button
== 5) {
398 if ((screen
->getCurrentWorkspaceID() - 1) < 0)
399 screen
->changeWorkspaceID(screen
->getWorkspaceCount() - 1);
401 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID() - 1);
410 case ButtonRelease
: {
411 // strip the lock key modifiers
412 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
414 last_time
= e
->xbutton
.time
;
416 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
417 Basemenu
*menu
= (Basemenu
*) 0;
418 Toolbar
*tbar
= (Toolbar
*) 0;
420 if ((win
= searchWindow(e
->xbutton
.window
)))
421 win
->buttonReleaseEvent(&e
->xbutton
);
422 else if ((menu
= searchMenu(e
->xbutton
.window
)))
423 menu
->buttonReleaseEvent(&e
->xbutton
);
424 else if ((tbar
= searchToolbar(e
->xbutton
.window
)))
425 tbar
->buttonReleaseEvent(&e
->xbutton
);
430 case ConfigureRequest
: {
431 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
434 Slit
*slit
= (Slit
*) 0;
437 if ((win
= searchWindow(e
->xconfigurerequest
.window
))) {
438 win
->configureRequestEvent(&e
->xconfigurerequest
);
441 } else if ((slit
= searchSlit(e
->xconfigurerequest
.window
))) {
442 slit
->configureRequestEvent(&e
->xconfigurerequest
);
448 if (validateWindow(e
->xconfigurerequest
.window
)) {
451 xwc
.x
= e
->xconfigurerequest
.x
;
452 xwc
.y
= e
->xconfigurerequest
.y
;
453 xwc
.width
= e
->xconfigurerequest
.width
;
454 xwc
.height
= e
->xconfigurerequest
.height
;
455 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
456 xwc
.sibling
= e
->xconfigurerequest
.above
;
457 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
459 XConfigureWindow(getXDisplay(), e
->xconfigurerequest
.window
,
460 e
->xconfigurerequest
.value_mask
, &xwc
);
472 i18n
->getMessage(openboxSet
, openboxMapRequest
,
473 "Openbox::process_event(): MapRequest for 0x%lx\n"),
474 e
->xmaprequest
.window
);
477 OpenboxWindow
*win
= searchWindow(e
->xmaprequest
.window
);
480 win
= new OpenboxWindow(*this, e
->xmaprequest
.window
);
482 if ((win
= searchWindow(e
->xmaprequest
.window
)))
483 win
->mapRequestEvent(&e
->xmaprequest
);
489 OpenboxWindow
*win
= searchWindow(e
->xmap
.window
);
492 win
->mapNotifyEvent(&e
->xmap
);
498 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
501 Slit
*slit
= (Slit
*) 0;
504 if ((win
= searchWindow(e
->xunmap
.window
))) {
505 win
->unmapNotifyEvent(&e
->xunmap
);
506 if (focused_window
== win
)
507 focused_window
= (OpenboxWindow
*) 0;
509 } else if ((slit
= searchSlit(e
->xunmap
.window
))) {
510 slit
->removeClient(e
->xunmap
.window
);
518 case DestroyNotify
: {
519 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
522 Slit
*slit
= (Slit
*) 0;
525 if ((win
= searchWindow(e
->xdestroywindow
.window
))) {
526 win
->destroyNotifyEvent(&e
->xdestroywindow
);
527 if (focused_window
== win
)
528 focused_window
= (OpenboxWindow
*) 0;
530 } else if ((slit
= searchSlit(e
->xdestroywindow
.window
))) {
531 slit
->removeClient(e
->xdestroywindow
.window
, False
);
539 // strip the lock key modifiers
540 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
542 last_time
= e
->xmotion
.time
;
544 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
545 Basemenu
*menu
= (Basemenu
*) 0;
547 if ((win
= searchWindow(e
->xmotion
.window
)))
548 win
->motionNotifyEvent(&e
->xmotion
);
549 else if ((menu
= searchMenu(e
->xmotion
.window
)))
550 menu
->motionNotifyEvent(&e
->xmotion
);
555 case PropertyNotify
: {
556 last_time
= e
->xproperty
.time
;
558 if (e
->xproperty
.state
!= PropertyDelete
) {
559 OpenboxWindow
*win
= searchWindow(e
->xproperty
.window
);
562 win
->propertyNotifyEvent(e
->xproperty
.atom
);
569 last_time
= e
->xcrossing
.time
;
571 BScreen
*screen
= (BScreen
*) 0;
572 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
573 Basemenu
*menu
= (Basemenu
*) 0;
574 Toolbar
*tbar
= (Toolbar
*) 0;
577 Slit
*slit
= (Slit
*) 0;
580 if (e
->xcrossing
.mode
== NotifyGrab
) break;
584 sa
.w
= e
->xcrossing
.window
;
585 sa
.enter
= sa
.leave
= False
;
586 XCheckIfEvent(getXDisplay(), &dummy
, queueScanner
, (char *) &sa
);
588 if ((e
->xcrossing
.window
== e
->xcrossing
.root
) &&
589 (screen
= searchScreen(e
->xcrossing
.window
))) {
590 screen
->getImageControl()->installRootColormap();
591 } else if ((win
= searchWindow(e
->xcrossing
.window
))) {
592 if (win
->getScreen()->sloppyFocus() &&
593 (! win
->isFocused()) && (! no_focus
)) {
596 if (((! sa
.leave
) || sa
.inferior
) && win
->isVisible() &&
597 win
->setInputFocus())
598 win
->installColormap(True
);
602 } else if ((menu
= searchMenu(e
->xcrossing
.window
))) {
603 menu
->enterNotifyEvent(&e
->xcrossing
);
604 } else if ((tbar
= searchToolbar(e
->xcrossing
.window
))) {
605 tbar
->enterNotifyEvent(&e
->xcrossing
);
607 } else if ((slit
= searchSlit(e
->xcrossing
.window
))) {
608 slit
->enterNotifyEvent(&e
->xcrossing
);
615 last_time
= e
->xcrossing
.time
;
617 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
618 Basemenu
*menu
= (Basemenu
*) 0;
619 Toolbar
*tbar
= (Toolbar
*) 0;
622 Slit
*slit
= (Slit
*) 0;
625 if ((menu
= searchMenu(e
->xcrossing
.window
)))
626 menu
->leaveNotifyEvent(&e
->xcrossing
);
627 else if ((win
= searchWindow(e
->xcrossing
.window
)))
628 win
->installColormap(False
);
629 else if ((tbar
= searchToolbar(e
->xcrossing
.window
)))
630 tbar
->leaveNotifyEvent(&e
->xcrossing
);
632 else if ((slit
= searchSlit(e
->xcrossing
.window
)))
633 slit
->leaveNotifyEvent(&e
->xcrossing
);
640 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
641 Basemenu
*menu
= (Basemenu
*) 0;
642 Toolbar
*tbar
= (Toolbar
*) 0;
644 if ((win
= searchWindow(e
->xexpose
.window
)))
645 win
->exposeEvent(&e
->xexpose
);
646 else if ((menu
= searchMenu(e
->xexpose
.window
)))
647 menu
->exposeEvent(&e
->xexpose
);
648 else if ((tbar
= searchToolbar(e
->xexpose
.window
)))
649 tbar
->exposeEvent(&e
->xexpose
);
655 Toolbar
*tbar
= searchToolbar(e
->xkey
.window
);
657 if (tbar
&& tbar
->isEditing())
658 tbar
->keyPressEvent(&e
->xkey
);
663 case ColormapNotify
: {
664 BScreen
*screen
= searchScreen(e
->xcolormap
.window
);
667 screen
->setRootColormapInstalled((e
->xcolormap
.state
==
668 ColormapInstalled
) ? True
: False
);
674 if (e
->xfocus
.mode
== NotifyUngrab
|| e
->xfocus
.detail
== NotifyPointer
)
677 OpenboxWindow
*win
= searchWindow(e
->xfocus
.window
);
678 if (win
&& ! win
->isFocused())
679 setFocusedWindow(win
);
687 case ClientMessage
: {
688 if (e
->xclient
.format
== 32) {
689 if (e
->xclient
.message_type
== getWMChangeStateAtom()) {
690 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
691 if (! win
|| ! win
->validateClient()) return;
693 if (e
->xclient
.data
.l
[0] == IconicState
)
695 if (e
->xclient
.data
.l
[0] == NormalState
)
697 } else if (e
->xclient
.message_type
== getOpenboxChangeWorkspaceAtom()) {
698 BScreen
*screen
= searchScreen(e
->xclient
.window
);
700 if (screen
&& e
->xclient
.data
.l
[0] >= 0 &&
701 e
->xclient
.data
.l
[0] < screen
->getWorkspaceCount())
702 screen
->changeWorkspaceID(e
->xclient
.data
.l
[0]);
703 } else if (e
->xclient
.message_type
== getOpenboxChangeWindowFocusAtom()) {
704 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
706 if (win
&& win
->isVisible() && win
->setInputFocus())
707 win
->installColormap(True
);
708 } else if (e
->xclient
.message_type
== getOpenboxCycleWindowFocusAtom()) {
709 BScreen
*screen
= searchScreen(e
->xclient
.window
);
712 if (! e
->xclient
.data
.l
[0])
717 } else if (e
->xclient
.message_type
== getOpenboxChangeAttributesAtom()) {
718 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
720 if (win
&& win
->validateClient()) {
722 net
.flags
= e
->xclient
.data
.l
[0];
723 net
.attrib
= e
->xclient
.data
.l
[1];
724 net
.workspace
= e
->xclient
.data
.l
[2];
725 net
.stack
= e
->xclient
.data
.l
[3];
726 net
.decoration
= e
->xclient
.data
.l
[4];
728 win
->changeOpenboxHints(&net
);
739 if (e
->type
== getShapeEventBase()) {
740 XShapeEvent
*shape_event
= (XShapeEvent
*) e
;
741 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
743 if ((win
= searchWindow(e
->xany
.window
)) ||
744 (shape_event
->kind
!= ShapeBounding
))
745 win
->shapeEvent(shape_event
);
754 Bool
Openbox::handleSignal(int sig
) {
780 BScreen
*Openbox::searchScreen(Window window
) {
781 LinkedListIterator
<BScreen
> it(screenList
);
783 for (BScreen
*curr
= it
.current(); curr
; it
++, curr
= it
.current()) {
784 if (curr
->getRootWindow() == window
) {
789 return (BScreen
*) 0;
793 OpenboxWindow
*Openbox::searchWindow(Window window
) {
794 LinkedListIterator
<WindowSearch
> it(windowSearchList
);
796 for (WindowSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
797 if (tmp
->getWindow() == window
) {
798 return tmp
->getData();
802 return (OpenboxWindow
*) 0;
806 OpenboxWindow
*Openbox::searchGroup(Window window
, OpenboxWindow
*win
) {
807 OpenboxWindow
*w
= (OpenboxWindow
*) 0;
808 LinkedListIterator
<WindowSearch
> it(groupSearchList
);
810 for (WindowSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
811 if (tmp
->getWindow() == window
) {
813 if (w
->getClientWindow() != win
->getClientWindow())
818 return (OpenboxWindow
*) 0;
822 Basemenu
*Openbox::searchMenu(Window window
) {
823 LinkedListIterator
<MenuSearch
> it(menuSearchList
);
825 for (MenuSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
826 if (tmp
->getWindow() == window
)
827 return tmp
->getData();
830 return (Basemenu
*) 0;
834 Toolbar
*Openbox::searchToolbar(Window window
) {
835 LinkedListIterator
<ToolbarSearch
> it(toolbarSearchList
);
837 for (ToolbarSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
838 if (tmp
->getWindow() == window
)
839 return tmp
->getData();
842 return (Toolbar
*) 0;
847 Slit
*Openbox::searchSlit(Window window
) {
848 LinkedListIterator
<SlitSearch
> it(slitSearchList
);
850 for (SlitSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
851 if (tmp
->getWindow() == window
)
852 return tmp
->getData();
860 void Openbox::saveWindowSearch(Window window
, OpenboxWindow
*data
) {
861 windowSearchList
->insert(new WindowSearch(window
, data
));
865 void Openbox::saveGroupSearch(Window window
, OpenboxWindow
*data
) {
866 groupSearchList
->insert(new WindowSearch(window
, data
));
870 void Openbox::saveMenuSearch(Window window
, Basemenu
*data
) {
871 menuSearchList
->insert(new MenuSearch(window
, data
));
875 void Openbox::saveToolbarSearch(Window window
, Toolbar
*data
) {
876 toolbarSearchList
->insert(new ToolbarSearch(window
, data
));
881 void Openbox::saveSlitSearch(Window window
, Slit
*data
) {
882 slitSearchList
->insert(new SlitSearch(window
, data
));
887 void Openbox::removeWindowSearch(Window window
) {
888 LinkedListIterator
<WindowSearch
> it(windowSearchList
);
889 for (WindowSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
890 if (tmp
->getWindow() == window
) {
891 windowSearchList
->remove(tmp
);
899 void Openbox::removeGroupSearch(Window window
) {
900 LinkedListIterator
<WindowSearch
> it(groupSearchList
);
901 for (WindowSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
902 if (tmp
->getWindow() == window
) {
903 groupSearchList
->remove(tmp
);
911 void Openbox::removeMenuSearch(Window window
) {
912 LinkedListIterator
<MenuSearch
> it(menuSearchList
);
913 for (MenuSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
914 if (tmp
->getWindow() == window
) {
915 menuSearchList
->remove(tmp
);
923 void Openbox::removeToolbarSearch(Window window
) {
924 LinkedListIterator
<ToolbarSearch
> it(toolbarSearchList
);
925 for (ToolbarSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
926 if (tmp
->getWindow() == window
) {
927 toolbarSearchList
->remove(tmp
);
936 void Openbox::removeSlitSearch(Window window
) {
937 LinkedListIterator
<SlitSearch
> it(slitSearchList
);
938 for (SlitSearch
*tmp
= it
.current(); tmp
; it
++, tmp
= it
.current()) {
939 if (tmp
->getWindow() == window
) {
940 slitSearchList
->remove(tmp
);
949 void Openbox::restart(const char *prog
) {
953 execlp(prog
, prog
, NULL
);
957 // fall back in case the above execlp doesn't work
958 execvp(argv
[0], argv
);
959 execvp(basename(argv
[0]), argv
);
963 void Openbox::shutdown() {
964 BaseDisplay::shutdown();
966 XSetInputFocus(getXDisplay(), PointerRoot
, None
, CurrentTime
);
968 LinkedListIterator
<BScreen
> it(screenList
);
969 for (BScreen
*s
= it
.current(); s
; it
++, s
= it
.current())
972 XSync(getXDisplay(), False
);
976 void Openbox::save() {
977 config
.setAutoSave(false);
979 // save all values as they are so that the defaults will be written to the rc
982 config
.setValue("session.menuFile", getMenuFilename());
983 config
.setValue("session.colorsPerChannel",
984 resource
.colors_per_channel
);
985 config
.setValue("session.doubleClickInterval",
986 (long)resource
.double_click_interval
);
987 config
.setValue("session.autoRaiseDelay",
988 ((resource
.auto_raise_delay
.tv_sec
* 1000) +
989 (resource
.auto_raise_delay
.tv_usec
/ 1000)));
990 config
.setValue("session.cacheLife", (long)resource
.cache_life
/ 60000);
991 config
.setValue("session.cacheMax", (long)resource
.cache_max
);
992 config
.setValue("session.styleFile", resource
.style_file
);
994 LinkedListIterator
<BScreen
> it(screenList
);
995 for (BScreen
*s
= it
.current(); s
!= NULL
; it
++, s
= it
.current()) {
997 s
->getToolbar()->save();
999 s
->getSlit()->save();
1003 config
.setAutoSave(true);
1007 void Openbox::load() {
1014 if (resource
.menu_file
)
1015 delete [] resource
.menu_file
;
1016 if (config
.getValue("session.menuFile", "Session.MenuFile", s
))
1017 resource
.menu_file
= bstrdup(s
.c_str());
1019 resource
.menu_file
= bstrdup(DEFAULTMENU
);
1021 if (config
.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
1023 resource
.colors_per_channel
= (l
< 2 ? 2 : (l
> 6 ? 6 : l
)); // >= 2, <= 6
1025 resource
.colors_per_channel
= 4;
1027 if (resource
.style_file
)
1028 delete [] resource
.style_file
;
1029 if (config
.getValue("session.styleFile", "Session.StyleFile", s
))
1030 resource
.style_file
= bstrdup(s
.c_str());
1032 resource
.style_file
= bstrdup(DEFAULTSTYLE
);
1034 if (resource
.titlebar_layout
)
1035 delete [] resource
.titlebar_layout
;
1036 if (config
.getValue("session.titlebarLayout", "Session.TitlebarLayout", s
))
1037 resource
.titlebar_layout
= bstrdup(s
.c_str());
1039 resource
.titlebar_layout
= bstrdup("ILMC");
1041 if (config
.getValue("session.doubleClickInterval",
1042 "Session.DoubleClickInterval", l
))
1043 resource
.double_click_interval
= l
;
1045 resource
.double_click_interval
= 250;
1047 if (!config
.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l
))
1048 resource
.auto_raise_delay
.tv_usec
= l
;
1050 resource
.auto_raise_delay
.tv_usec
= 400;
1051 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
/ 1000;
1052 resource
.auto_raise_delay
.tv_usec
-=
1053 (resource
.auto_raise_delay
.tv_sec
* 1000);
1054 resource
.auto_raise_delay
.tv_usec
*= 1000;
1056 if (config
.getValue("session.cacheLife", "Session.CacheLife", l
))
1057 resource
.cache_life
= l
;
1059 resource
.cache_life
= 51;
1060 resource
.cache_life
*= 60000;
1062 if (config
.getValue("session.cacheMax", "Session.CacheMax", l
))
1063 resource
.cache_max
= l
;
1065 resource
.cache_max
= 200;
1069 void Openbox::reconfigure() {
1070 reconfigure_wait
= True
;
1072 if (! timer
->isTiming()) timer
->start();
1076 void Openbox::real_reconfigure() {
1081 for (int i
= 0, n
= menuTimestamps
->count(); i
< n
; i
++) {
1082 MenuTimestamp
*ts
= menuTimestamps
->remove(0);
1086 delete [] ts
->filename
;
1092 LinkedListIterator
<BScreen
> it(screenList
);
1093 for (BScreen
*screen
= it
.current(); screen
; it
++, screen
= it
.current()) {
1094 screen
->reconfigure();
1101 void Openbox::checkMenu() {
1102 Bool reread
= False
;
1103 LinkedListIterator
<MenuTimestamp
> it(menuTimestamps
);
1104 for (MenuTimestamp
*tmp
= it
.current(); tmp
&& (! reread
);
1105 it
++, tmp
= it
.current()) {
1108 if (! stat(tmp
->filename
, &buf
)) {
1109 if (tmp
->timestamp
!= buf
.st_ctime
)
1116 if (reread
) rereadMenu();
1120 void Openbox::rereadMenu() {
1121 reread_menu_wait
= True
;
1123 if (! timer
->isTiming()) timer
->start();
1127 void Openbox::real_rereadMenu() {
1128 for (int i
= 0, n
= menuTimestamps
->count(); i
< n
; i
++) {
1129 MenuTimestamp
*ts
= menuTimestamps
->remove(0);
1133 delete [] ts
->filename
;
1139 LinkedListIterator
<BScreen
> it(screenList
);
1140 for (BScreen
*screen
= it
.current(); screen
; it
++, screen
= it
.current())
1141 screen
->rereadMenu();
1145 void Openbox::setStyleFilename(const char *filename
) {
1146 if (resource
.style_file
)
1147 delete [] resource
.style_file
;
1149 resource
.style_file
= bstrdup(filename
);
1150 config
.setValue("session.styleFile", resource
.style_file
);
1154 void Openbox::setMenuFilename(const char *filename
) {
1157 LinkedListIterator
<MenuTimestamp
> it(menuTimestamps
);
1158 for (MenuTimestamp
*tmp
= it
.current(); tmp
&& (! found
);
1159 it
++, tmp
= it
.current()) {
1160 if (! strcmp(tmp
->filename
, filename
)) found
= True
;
1165 if (! stat(filename
, &buf
)) {
1166 MenuTimestamp
*ts
= new MenuTimestamp
;
1168 ts
->filename
= bstrdup(filename
);
1169 ts
->timestamp
= buf
.st_ctime
;
1171 menuTimestamps
->insert(ts
);
1177 void Openbox::timeout() {
1178 if (reconfigure_wait
)
1181 if (reread_menu_wait
)
1184 reconfigure_wait
= reread_menu_wait
= False
;
1188 void Openbox::setFocusedWindow(OpenboxWindow
*win
) {
1189 BScreen
*old_screen
= (BScreen
*) 0, *screen
= (BScreen
*) 0;
1190 OpenboxWindow
*old_win
= (OpenboxWindow
*) 0;
1191 Toolbar
*old_tbar
= (Toolbar
*) 0, *tbar
= (Toolbar
*) 0;
1192 Workspace
*old_wkspc
= (Workspace
*) 0, *wkspc
= (Workspace
*) 0;
1194 if (focused_window
) {
1195 old_win
= focused_window
;
1196 old_screen
= old_win
->getScreen();
1197 old_tbar
= old_screen
->getToolbar();
1198 old_wkspc
= old_screen
->getWorkspace(old_win
->getWorkspaceNumber());
1200 old_win
->setFocusFlag(False
);
1201 old_wkspc
->getMenu()->setItemSelected(old_win
->getWindowNumber(), False
);
1204 if (win
&& ! win
->isIconic()) {
1205 screen
= win
->getScreen();
1206 tbar
= screen
->getToolbar();
1207 wkspc
= screen
->getWorkspace(win
->getWorkspaceNumber());
1209 focused_window
= win
;
1211 win
->setFocusFlag(True
);
1212 wkspc
->getMenu()->setItemSelected(win
->getWindowNumber(), True
);
1214 focused_window
= (OpenboxWindow
*) 0;
1218 tbar
->redrawWindowLabel(True
);
1220 screen
->updateNetizenWindowFocus();
1222 if (old_tbar
&& old_tbar
!= tbar
)
1223 old_tbar
->redrawWindowLabel(True
);
1224 if (old_screen
&& old_screen
!= screen
)
1225 old_screen
->updateNetizenWindowFocus();