]> icculus.org git repositories - mikachu/openbox.git/blob - src/openbox.h
make work with new i18n
[mikachu/openbox.git] / src / openbox.h
1 // openbox.h for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
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:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
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.
22
23 #ifndef   __openbox_hh
24 #define   __openbox_hh
25
26 #include <X11/Xlib.h>
27 #include <X11/Xresource.h>
28
29 #ifdef    HAVE_STDIO_H
30 # include <stdio.h>
31 #endif // HAVE_STDIO_H
32
33 #ifdef    TIME_WITH_SYS_TIME
34 #  include <sys/time.h>
35 #  include <time.h>
36 #else // !TIME_WITH_SYS_TIME
37 #  ifdef    HAVE_SYS_TIME_H
38 #    include <sys/time.h>
39 #  else // !HAVE_SYS_TIME_H
40 #    include <time.h>
41 #  endif // HAVE_SYS_TIME_H
42 #endif // TIME_WITH_SYS_TIME
43
44 #include "Resource.h"
45 #include "BaseDisplay.h"
46 #include "Timer.h"
47
48 #include <map>
49 #include <list>
50
51 //forward declaration
52 class BScreen;
53 class Openbox;
54 class BImageControl;
55 class OpenboxWindow;
56 class Basemenu;
57 class Toolbar;
58 #ifdef    SLIT
59 class Slit;
60 #endif // SLIT
61
62 template <class Z>
63 class DataSearch {
64 private:
65   Window window;
66   Z *data;
67
68 public:
69   DataSearch(Window w, Z *d): window(w), data(d) {}
70
71   inline const Window &getWindow() const { return window; }
72   inline Z *getData() { return data; }
73 };
74
75
76 class Openbox : public BaseDisplay, public TimeoutHandler {
77 private:
78   typedef struct MenuTimestamp {
79     virtual ~MenuTimestamp() {
80       if (filename != (char *) 0)
81         delete [] filename;
82     }
83     char *filename;
84     time_t timestamp;
85   } MenuTimestamp;
86
87   struct resource {
88     Time double_click_interval;
89
90     char *style_file;
91     char *titlebar_layout;
92     int colors_per_channel;
93     timeval auto_raise_delay;
94     unsigned long cache_life, cache_max;
95   } resource;
96
97   typedef std::map<Window, OpenboxWindow*> WindowLookup;
98   typedef WindowLookup::value_type WindowLookupPair;
99   WindowLookup windowSearchList, groupSearchList;
100   
101   typedef std::map<Window, Basemenu*> MenuLookup;
102   typedef MenuLookup::value_type MenuLookupPair;
103   MenuLookup menuSearchList;
104
105   typedef std::map<Window, Toolbar*> ToolbarLookup;
106   typedef ToolbarLookup::value_type ToolbarLookupPair;
107   ToolbarLookup toolbarSearchList;
108
109 #ifdef    SLIT
110   typedef std::map<Window, Slit*> SlitLookup;
111   typedef SlitLookup::value_type SlitLookupPair;
112   SlitLookup slitSearchList; 
113 #endif // SLIT
114
115   typedef std::list<MenuTimestamp*> MenuTimestampList;
116   MenuTimestampList menuTimestamps;
117
118   typedef std::list<BScreen*> ScreenList;
119   ScreenList screenList;
120
121   BScreen *current_screen;
122   OpenboxWindow *masked_window;
123   BTimer *timer;
124
125 #ifdef    HAVE_GETPID
126   Atom openbox_pid;
127 #endif // HAVE_GETPID
128
129   Bool no_focus, reconfigure_wait, reread_menu_wait;
130   Time last_time;
131   Window masked;
132   char *menu_file, *rc_file, **argv;
133   int argc;
134   Resource config;
135
136
137 protected:
138   void load();
139   void save();
140   void real_rereadMenu();
141   void real_reconfigure();
142
143   virtual void process_event(XEvent *);
144
145
146 public:
147   Openbox(int, char **, char * = 0, char * = 0, char * = 0);
148   virtual ~Openbox();
149
150 #ifdef    HAVE_GETPID
151   inline const Atom &getOpenboxPidAtom() const { return openbox_pid; }
152 #endif // HAVE_GETPID
153
154   Basemenu *searchMenu(Window);
155
156   OpenboxWindow *searchGroup(Window, OpenboxWindow *);
157   OpenboxWindow *searchWindow(Window);
158   OpenboxWindow *focusedWindow();
159   void focusWindow(OpenboxWindow *w);
160
161   BScreen *getScreen(int);
162   BScreen *searchScreen(Window);
163
164   inline Resource &getConfig() {
165     return config;
166   }
167   inline const Time &getDoubleClickInterval() const
168     { return resource.double_click_interval; }
169   inline const Time &getLastTime() const { return last_time; }
170
171   Toolbar *searchToolbar(Window);
172
173   inline const char *getStyleFilename() const
174     { return resource.style_file; }
175   inline const char *getMenuFilename() const
176     { return menu_file; }
177   void addMenuTimestamp(const char *filename);
178
179   inline const int &getColorsPerChannel() const
180     { return resource.colors_per_channel; }
181
182   inline const timeval &getAutoRaiseDelay() const
183     { return resource.auto_raise_delay; }
184
185   inline const char *getTitleBarLayout() const
186     { return resource.titlebar_layout; }
187
188   inline const unsigned long &getCacheLife() const
189     { return resource.cache_life; }
190   inline const unsigned long &getCacheMax() const
191     { return resource.cache_max; }
192
193   inline OpenboxWindow *getMaskedWindow() const
194     { return masked_window; }
195   inline void maskWindowEvents(Window w, OpenboxWindow *bw)
196     { masked = w; masked_window = bw; }
197   inline void setNoFocus(Bool f) { no_focus = f; }
198
199   void shutdown();
200   void setStyleFilename(const char *);
201   void saveMenuSearch(Window, Basemenu *);
202   void saveWindowSearch(Window, OpenboxWindow *);
203   void saveToolbarSearch(Window, Toolbar *);
204   void saveGroupSearch(Window, OpenboxWindow *);
205   void removeMenuSearch(Window);
206   void removeWindowSearch(Window);
207   void removeToolbarSearch(Window);
208   void removeGroupSearch(Window);
209   void restart(const char * = 0);
210   void reconfigure();
211   void rereadMenu();
212   void checkMenu();
213
214   virtual Bool handleSignal(int);
215
216   virtual void timeout();
217
218 #ifdef    SLIT
219   Slit *searchSlit(Window);
220
221   void saveSlitSearch(Window, Slit *);
222   void removeSlitSearch(Window);
223 #endif // SLIT
224
225 #ifndef   HAVE_STRFTIME
226
227   enum { B_AmericanDate = 1, B_EuropeanDate };
228 #endif // HAVE_STRFTIME
229 };
230
231
232 #endif // __openbox_hh