]> icculus.org git repositories - mikachu/openbox.git/blob - src/blackbox.hh
documentation fixes
[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 "i18n.hh"
51 #include "BaseDisplay.hh"
52 #include "Configuration.hh"
53 #include "Timer.hh"
54 #include "XAtom.hh"
55
56 #define AttribShaded      (1l << 0)
57 #define AttribMaxHoriz    (1l << 1)
58 #define AttribMaxVert     (1l << 2)
59 #define AttribOmnipresent (1l << 3)
60 #define AttribWorkspace   (1l << 4)
61 #define AttribStack       (1l << 5)
62 #define AttribDecoration  (1l << 6)
63
64 #define StackTop          (0)
65 #define StackNormal       (1)
66 #define StackBottom       (2)
67
68 #define DecorNone         (0)
69 #define DecorNormal       (1)
70 #define DecorTiny         (2)
71 #define DecorTool         (3)
72
73 struct BlackboxHints {
74   unsigned long flags, attrib, workspace, stack, decoration;
75 };
76
77 struct BlackboxAttributes {
78   unsigned long flags, attrib, workspace, stack, decoration;
79   int premax_x, premax_y;
80   unsigned int premax_w, premax_h;
81 };
82
83 #define PropBlackboxHintsElements      (5)
84 #define PropBlackboxAttributesElements (9)
85
86
87 //forward declaration
88 class BScreen;
89 class Blackbox;
90 class BlackboxWindow;
91 class BWindowGroup;
92 class Basemenu;
93 class Toolbar;
94 class Slit;
95
96 extern I18n i18n;
97
98 class Blackbox : public BaseDisplay, public TimeoutHandler {
99 private:
100   struct BCursor {
101     Cursor session, move, ll_angle, lr_angle;
102   };
103   BCursor cursor;
104
105   struct MenuTimestamp {
106     std::string filename;
107     time_t timestamp;
108   };
109
110   struct BResource {
111     Time double_click_interval;
112
113     std::string style_file;
114     int colors_per_channel;
115     timeval auto_raise_delay;
116     unsigned long cache_life, cache_max;
117     std::string titlebar_layout;
118     bool window_to_window_snap;
119     bool window_corner_snap;
120   } resource;
121
122   typedef std::map<Window, BlackboxWindow*> WindowLookup;
123   typedef WindowLookup::value_type WindowLookupPair;
124   WindowLookup windowSearchList;
125
126   typedef std::map<Window, BWindowGroup*> GroupLookup;
127   typedef GroupLookup::value_type GroupLookupPair;
128   GroupLookup groupSearchList;
129
130   typedef std::map<Window, Basemenu*> MenuLookup;
131   typedef MenuLookup::value_type MenuLookupPair;
132   MenuLookup menuSearchList;
133
134   typedef std::map<Window, Toolbar*> ToolbarLookup;
135   typedef ToolbarLookup::value_type ToolbarLookupPair;
136   ToolbarLookup toolbarSearchList;
137
138   typedef std::map<Window, Slit*> SlitLookup;
139   typedef SlitLookup::value_type SlitLookupPair;
140   SlitLookup slitSearchList;
141
142   typedef std::list<MenuTimestamp*> MenuTimestampList;
143   MenuTimestampList menuTimestamps;
144
145   typedef std::list<BScreen*> ScreenList;
146   ScreenList screenList;
147
148   BScreen *active_screen;
149   BlackboxWindow *focused_window;
150   BTimer *timer;
151   Configuration config;
152   XAtom *xatom;
153
154   bool no_focus, reconfigure_wait, reread_menu_wait;
155   Time last_time;
156   char **argv;
157   std::string menu_file, rc_file;
158
159   Blackbox(const Blackbox&);
160   Blackbox& operator=(const Blackbox&);
161
162   void load_rc(void);
163   void save_rc(void);
164   void real_rereadMenu(void);
165   void real_reconfigure(void);
166
167   virtual void process_event(XEvent *);
168
169
170 public:
171   Blackbox(char **m_argv, char *dpy_name = 0, char *rc = 0, char *menu = 0);
172   virtual ~Blackbox(void);
173
174   Basemenu *searchMenu(Window window);
175   BWindowGroup *searchGroup(Window window);
176   BlackboxWindow *searchWindow(Window window);
177   BScreen *searchScreen(Window window);
178   Toolbar *searchToolbar(Window);
179   Slit *searchSlit(Window);
180
181   void saveMenuSearch(Window window, Basemenu *data);
182   void saveWindowSearch(Window window, BlackboxWindow *data);
183   void saveGroupSearch(Window window, BWindowGroup *data);
184   void saveToolbarSearch(Window window, Toolbar *data);
185   void saveSlitSearch(Window window, Slit *data);
186   void removeMenuSearch(Window window);
187   void removeWindowSearch(Window window);
188   void removeGroupSearch(Window window);
189   void removeToolbarSearch(Window window);
190   void removeSlitSearch(Window window);
191
192   inline XAtom *getXAtom(void) { return xatom; }
193   
194   inline BlackboxWindow *getFocusedWindow(void) { return focused_window; }
195
196   inline Configuration *getConfig() { return &config; }
197   inline const Time &getDoubleClickInterval(void) const
198   { return resource.double_click_interval; }
199   inline const Time &getLastTime(void) const { return last_time; }
200
201   inline const char *getStyleFilename(void) const
202     { return resource.style_file.c_str(); }
203   inline const char *getMenuFilename(void) const
204     { return menu_file.c_str(); }
205
206   inline int getColorsPerChannel(void) const
207     { return resource.colors_per_channel; }
208
209   inline std::string getTitlebarLayout(void) const
210     { return resource.titlebar_layout; }
211
212   inline const timeval &getAutoRaiseDelay(void) const
213     { return resource.auto_raise_delay; }
214
215   inline unsigned long getCacheLife(void) const
216     { return resource.cache_life; }
217   inline unsigned long getCacheMax(void) const
218     { return resource.cache_max; }
219
220   inline bool getWindowToWindowSnap(void) const
221     { return resource.window_to_window_snap; }
222   inline bool getWindowCornerSnap(void) const
223     { return resource.window_corner_snap; }
224
225   inline void setNoFocus(bool f) { no_focus = f; }
226
227   inline Cursor getSessionCursor(void) const
228     { return cursor.session; }
229   inline Cursor getMoveCursor(void) const
230     { return cursor.move; }
231   inline Cursor getLowerLeftAngleCursor(void) const
232     { return cursor.ll_angle; }
233   inline Cursor getLowerRightAngleCursor(void) const
234     { return cursor.lr_angle; }
235
236   void setFocusedWindow(BlackboxWindow *w);
237   void shutdown(void);
238   void saveStyleFilename(const std::string& filename);
239   void saveWindowToWindowSnap(bool);
240   void saveWindowCornerSnap(bool);
241   void addMenuTimestamp(const std::string& filename);
242   void restart(const char *prog = 0);
243   void reconfigure(void);
244   void rereadMenu(void);
245   void checkMenu(void);
246
247   bool validateWindow(Window window);
248
249   virtual bool handleSignal(int sig);
250
251   virtual void timeout(void);
252
253 #ifndef   HAVE_STRFTIME
254   enum { B_AmericanDate = 1, B_EuropeanDate };
255 #endif // HAVE_STRFTIME
256
257   inline Atom getWMDeleteAtom(void) const
258     { return xatom->getAtom(XAtom::wm_delete_window); }
259   inline Atom getWMProtocolsAtom(void) const
260     { return xatom->getAtom(XAtom::wm_protocols); }
261   inline Atom getWMTakeFocusAtom(void) const
262     { return xatom->getAtom(XAtom::wm_take_focus); }
263   inline Atom getWMColormapAtom(void) const
264     { return xatom->getAtom(XAtom::wm_colormap_windows); }
265   inline Atom getMotifWMHintsAtom(void) const
266     { return xatom->getAtom(XAtom::motif_wm_hints); }
267
268   // this atom is for normal app->WM hints about decorations, stacking,
269   // starting workspace etc...
270   inline Atom getBlackboxHintsAtom(void) const
271     { return xatom->getAtom(XAtom::blackbox_hints); }
272
273   // these atoms are for normal app->WM interaction beyond the scope of the
274   // ICCCM...
275   inline Atom getBlackboxAttributesAtom(void) const
276     { return xatom->getAtom(XAtom::blackbox_attributes); }
277   inline Atom getBlackboxChangeAttributesAtom(void) const
278     { return xatom->getAtom(XAtom::blackbox_change_attributes); }
279
280   // these atoms are for window->WM interaction, with more control and
281   // information on window "structure"... common examples are
282   // notifying apps when windows are raised/lowered... when the user changes
283   // workspaces... i.e. "pager talk"
284   inline Atom getBlackboxStructureMessagesAtom(void) const
285     { return xatom->getAtom(XAtom::blackbox_structure_messages); }
286
287   // *Notify* portions of the NETStructureMessages protocol
288   inline Atom getBlackboxNotifyStartupAtom(void) const
289     { return xatom->getAtom(XAtom::blackbox_notify_startup); }
290   inline Atom getBlackboxNotifyWindowAddAtom(void) const
291     { return xatom->getAtom(XAtom::blackbox_notify_window_add); }
292   inline Atom getBlackboxNotifyWindowDelAtom(void) const
293     { return xatom->getAtom(XAtom::blackbox_notify_window_del); }
294   inline Atom getBlackboxNotifyWindowFocusAtom(void) const
295     { return xatom->getAtom(XAtom::blackbox_notify_window_focus); }
296   inline Atom getBlackboxNotifyCurrentWorkspaceAtom(void) const
297     { return xatom->getAtom(XAtom::blackbox_notify_current_workspace); }
298   inline Atom getBlackboxNotifyWorkspaceCountAtom(void) const
299     { return xatom->getAtom(XAtom::blackbox_notify_workspace_count); }
300   inline Atom getBlackboxNotifyWindowRaiseAtom(void) const
301     { return xatom->getAtom(XAtom::blackbox_notify_window_raise); }
302   inline Atom getBlackboxNotifyWindowLowerAtom(void) const
303     { return xatom->getAtom(XAtom::blackbox_notify_window_lower); }
304
305   // atoms to change that request changes to the desktop environment during
306   // runtime... these messages can be sent by any client... as the sending
307   // client window id is not included in the ClientMessage event...
308   inline Atom getBlackboxChangeWorkspaceAtom(void) const
309     { return xatom->getAtom(XAtom::blackbox_change_workspace); }
310   inline Atom getBlackboxChangeWindowFocusAtom(void) const
311     { return xatom->getAtom(XAtom::blackbox_change_window_focus); }
312   inline Atom getBlackboxCycleWindowFocusAtom(void) const
313     { return xatom->getAtom(XAtom::blackbox_cycle_window_focus); }
314 };
315
316
317 #endif // __blackbox_hh