]> icculus.org git repositories - mikachu/openbox.git/blob - src/blackbox.hh
rename, remove bullshit. ya
[mikachu/openbox.git] / src / blackbox.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // blackbox.hh for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #ifndef   __blackbox_hh
25 #define   __blackbox_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29
30 #ifdef    HAVE_STDIO_H
31 # include <stdio.h>
32 #endif // HAVE_STDIO_H
33
34 #ifdef    TIME_WITH_SYS_TIME
35 #  include <sys/time.h>
36 #  include <time.h>
37 #else // !TIME_WITH_SYS_TIME
38 #  ifdef    HAVE_SYS_TIME_H
39 #    include <sys/time.h>
40 #  else // !HAVE_SYS_TIME_H
41 #    include <time.h>
42 #  endif // HAVE_SYS_TIME_H
43 #endif // TIME_WITH_SYS_TIME
44 }
45
46 #include <list>
47 #include <map>
48 #include <string>
49
50 #include "basedisplay.hh"
51 #include "configuration.hh"
52 #include "timer.hh"
53 #include "xatom.hh"
54
55 #define AttribShaded      (1l << 0)
56 #define AttribMaxHoriz    (1l << 1)
57 #define AttribMaxVert     (1l << 2)
58 #define AttribOmnipresent (1l << 3)
59 #define AttribWorkspace   (1l << 4)
60 #define AttribStack       (1l << 5)
61 #define AttribDecoration  (1l << 6)
62
63 #define StackTop          (0)
64 #define StackNormal       (1)
65 #define StackBottom       (2)
66
67 #define DecorNone         (0)
68 #define DecorNormal       (1)
69 #define DecorTiny         (2)
70 #define DecorTool         (3)
71
72 struct BlackboxHints {
73   unsigned long flags, attrib, workspace, stack, decoration;
74 };
75
76 struct BlackboxAttributes {
77   unsigned long flags, attrib, workspace, stack, decoration;
78   int premax_x, premax_y;
79   unsigned int premax_w, premax_h;
80 };
81
82 #define PropBlackboxHintsElements      (5)
83 #define PropBlackboxAttributesElements (9)
84
85
86 //forward declaration
87 class BScreen;
88 class Blackbox;
89 class BlackboxWindow;
90 class BWindowGroup;
91 class Basemenu;
92 class Toolbar;
93 class Slit;
94
95 extern I18n i18n;
96
97 class Blackbox : public BaseDisplay, public TimeoutHandler {
98 private:
99   struct BCursor {
100     Cursor session, move, ll_angle, lr_angle, ul_angle, ur_angle;
101   };
102   BCursor cursor;
103
104   struct MenuTimestamp {
105     std::string filename;
106     time_t timestamp;
107   };
108
109   struct BResource {
110     Time double_click_interval;
111
112     std::string style_file;
113     int colors_per_channel;
114     timeval auto_raise_delay;
115     unsigned long cache_life, cache_max;
116     std::string titlebar_layout;
117     unsigned int mod_mask;  // modifier mask used for window-mouse interaction
118
119
120 #ifdef    XINERAMA
121     bool xinerama_placement, xinerama_maximize, xinerama_snap;
122 #endif // XINERAMA
123   } resource;
124
125   typedef std::map<Window, BlackboxWindow*> WindowLookup;
126   typedef WindowLookup::value_type WindowLookupPair;
127   WindowLookup windowSearchList;
128
129   typedef std::map<Window, BScreen*> WindowScreenLookup;
130   typedef WindowScreenLookup::value_type WindowScreenLookupPair;
131   WindowScreenLookup systraySearchList;
132
133   typedef std::map<Window, BWindowGroup*> GroupLookup;
134   typedef GroupLookup::value_type GroupLookupPair;
135   GroupLookup groupSearchList;
136
137   typedef std::map<Window, Basemenu*> MenuLookup;
138   typedef MenuLookup::value_type MenuLookupPair;
139   MenuLookup menuSearchList;
140
141   typedef std::map<Window, Toolbar*> ToolbarLookup;
142   typedef ToolbarLookup::value_type ToolbarLookupPair;
143   ToolbarLookup toolbarSearchList;
144
145   typedef std::map<Window, Slit*> SlitLookup;
146   typedef SlitLookup::value_type SlitLookupPair;
147   SlitLookup slitSearchList;
148
149   typedef std::list<MenuTimestamp*> MenuTimestampList;
150   MenuTimestampList menuTimestamps;
151
152   typedef std::list<BScreen*> ScreenList;
153   ScreenList screenList;
154
155   BScreen *active_screen;
156   BlackboxWindow *focused_window, *changing_window;
157   BTimer *timer;
158   Configuration config;
159   XAtom *xatom;
160
161   bool no_focus, reconfigure_wait, reread_menu_wait;
162   Time last_time;
163   char **argv;
164   std::string menu_file, rc_file;
165
166   Blackbox(const Blackbox&);
167   Blackbox& operator=(const Blackbox&);
168
169   void load_rc(void);
170   void save_rc(void);
171   void real_rereadMenu(void);
172   void real_reconfigure(void);
173
174   virtual void process_event(XEvent *);
175
176
177 public:
178   Blackbox(char **m_argv, char *dpy_name = 0, char *rc = 0, char *menu = 0);
179   virtual ~Blackbox(void);
180
181   Basemenu *searchMenu(Window window);
182   BWindowGroup *searchGroup(Window window);
183   BScreen *searchSystrayWindow(Window window);
184   BlackboxWindow *searchWindow(Window window);
185   BScreen *searchScreen(Window window);
186   Toolbar *searchToolbar(Window);
187   Slit *searchSlit(Window);
188
189 #ifdef    XINERAMA
190   inline bool doXineramaPlacement(void) const
191     { return resource.xinerama_placement; }
192   inline bool doXineramaMaximizing(void) const
193     { return resource.xinerama_maximize; }
194   inline bool doXineramaSnapping(void) const
195     { return resource.xinerama_snap; }
196
197   void saveXineramaPlacement(bool x);
198   void saveXineramaMaximizing(bool x);
199   void saveXineramaSnapping(bool x);
200 #endif // XINERAMA
201   
202   void saveMenuSearch(Window window, Basemenu *data);
203   void saveSystrayWindowSearch(Window window, BScreen *screen);
204   void saveWindowSearch(Window window, BlackboxWindow *data);
205   void saveGroupSearch(Window window, BWindowGroup *data);
206   void saveToolbarSearch(Window window, Toolbar *data);
207   void saveSlitSearch(Window window, Slit *data);
208   void removeMenuSearch(Window window);
209   void removeSystrayWindowSearch(Window window);
210   void removeWindowSearch(Window window);
211   void removeGroupSearch(Window window);
212   void removeToolbarSearch(Window window);
213   void removeSlitSearch(Window window);
214
215   inline XAtom *getXAtom(void) { return xatom; }
216
217   inline BlackboxWindow *getFocusedWindow(void) { return focused_window; }
218   inline BlackboxWindow *getChangingWindow(void) { return changing_window; }
219
220   inline Configuration *getConfig() { return &config; }
221   inline const Time &getDoubleClickInterval(void) const
222   { return resource.double_click_interval; }
223   inline const Time &getLastTime(void) const { return last_time; }
224
225   inline const char *getStyleFilename(void) const
226     { return resource.style_file.c_str(); }
227   inline const char *getMenuFilename(void) const
228     { return menu_file.c_str(); }
229
230   inline int getColorsPerChannel(void) const
231     { return resource.colors_per_channel; }
232
233   inline std::string getTitlebarLayout(void) const
234     { return resource.titlebar_layout; }
235
236   inline const timeval &getAutoRaiseDelay(void) const
237     { return resource.auto_raise_delay; }
238
239   inline unsigned long getCacheLife(void) const
240     { return resource.cache_life; }
241   inline unsigned long getCacheMax(void) const
242     { return resource.cache_max; }
243
244   inline void setNoFocus(bool f) { no_focus = f; }
245
246   inline Cursor getSessionCursor(void) const
247     { return cursor.session; }
248   inline Cursor getMoveCursor(void) const
249     { return cursor.move; }
250   inline Cursor getLowerLeftAngleCursor(void) const
251     { return cursor.ll_angle; }
252   inline Cursor getLowerRightAngleCursor(void) const
253     { return cursor.lr_angle; }
254   inline Cursor getUpperLeftAngleCursor(void) const
255     { return cursor.ul_angle; }
256   inline Cursor getUpperRightAngleCursor(void) const
257     { return cursor.ur_angle; }
258   
259   inline unsigned int getMouseModMask(void) const
260     { return resource.mod_mask; }
261
262   void setFocusedWindow(BlackboxWindow *win);
263   void setChangingWindow(BlackboxWindow *win);
264   void shutdown(void);
265   void saveStyleFilename(const std::string& filename);
266   void addMenuTimestamp(const std::string& filename);
267   void restart(const char *prog = 0);
268   void reconfigure(void);
269   void rereadMenu(void);
270   void checkMenu(void);
271
272   bool validateWindow(Window window);
273
274   virtual bool handleSignal(int sig);
275
276   virtual void timeout(void);
277
278 #ifndef   HAVE_STRFTIME
279   enum { B_AmericanDate = 1, B_EuropeanDate };
280 #endif // HAVE_STRFTIME
281 };
282
283
284 #endif // __blackbox_hh