]> icculus.org git repositories - mikachu/openbox.git/blob - src/blackbox.hh
mouse wheel support
[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
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;
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   } resource;
118
119   typedef std::map<Window, BlackboxWindow*> WindowLookup;
120   typedef WindowLookup::value_type WindowLookupPair;
121   WindowLookup windowSearchList;
122
123   typedef std::map<Window, BWindowGroup*> GroupLookup;
124   typedef GroupLookup::value_type GroupLookupPair;
125   GroupLookup groupSearchList;
126
127   typedef std::map<Window, Basemenu*> MenuLookup;
128   typedef MenuLookup::value_type MenuLookupPair;
129   MenuLookup menuSearchList;
130
131   typedef std::map<Window, Toolbar*> ToolbarLookup;
132   typedef ToolbarLookup::value_type ToolbarLookupPair;
133   ToolbarLookup toolbarSearchList;
134
135   typedef std::map<Window, Slit*> SlitLookup;
136   typedef SlitLookup::value_type SlitLookupPair;
137   SlitLookup slitSearchList;
138
139   typedef std::list<MenuTimestamp*> MenuTimestampList;
140   MenuTimestampList menuTimestamps;
141
142   typedef std::list<BScreen*> ScreenList;
143   ScreenList screenList;
144
145   BScreen *active_screen;
146   BlackboxWindow *focused_window;
147   BTimer *timer;
148   Configuration config;
149
150   bool no_focus, reconfigure_wait, reread_menu_wait;
151   Time last_time;
152   char **argv;
153   std::string menu_file, rc_file;
154
155   Atom xa_wm_colormap_windows, xa_wm_protocols, xa_wm_state,
156     xa_wm_delete_window, xa_wm_take_focus, xa_wm_change_state,
157     motif_wm_hints;
158
159   // NETAttributes
160   Atom blackbox_attributes, blackbox_change_attributes, blackbox_hints;
161 #ifdef    HAVE_GETPID
162   Atom blackbox_pid;
163 #endif // HAVE_GETPID
164
165   // NETStructureMessages
166   Atom blackbox_structure_messages, blackbox_notify_startup,
167     blackbox_notify_window_add, blackbox_notify_window_del,
168     blackbox_notify_window_focus, blackbox_notify_current_workspace,
169     blackbox_notify_workspace_count, blackbox_notify_window_raise,
170     blackbox_notify_window_lower;
171
172   // message_types for client -> wm messages
173   Atom blackbox_change_workspace, blackbox_change_window_focus,
174     blackbox_cycle_window_focus;
175
176 #ifdef    NEWWMSPEC
177   // root window properties
178   Atom net_supported, net_client_list, net_client_list_stacking,
179     net_number_of_desktops, net_desktop_geometry, net_desktop_viewport,
180     net_current_desktop, net_desktop_names, net_active_window, net_workarea,
181     net_supporting_wm_check, net_virtual_roots;
182
183   // root window messages
184   Atom net_close_window, net_wm_moveresize;
185
186   // application window properties
187   Atom net_properties, net_wm_name, net_wm_desktop, net_wm_window_type,
188     net_wm_state, net_wm_strut, net_wm_icon_geometry, net_wm_icon, net_wm_pid,
189     net_wm_handled_icons;
190
191   // application protocols
192   Atom net_wm_ping;
193 #endif // NEWWMSPEC
194
195   Blackbox(const Blackbox&);
196   Blackbox& operator=(const Blackbox&);
197
198   void load_rc(void);
199   void save_rc(void);
200   void real_rereadMenu(void);
201   void real_reconfigure(void);
202
203   void init_icccm(void);
204
205   virtual void process_event(XEvent *);
206
207
208 public:
209   Blackbox(char **m_argv, char *dpy_name = 0, char *rc = 0, char *menu = 0);
210   virtual ~Blackbox(void);
211
212   Basemenu *searchMenu(Window window);
213   BWindowGroup *searchGroup(Window window);
214   BlackboxWindow *searchWindow(Window window);
215   BScreen *searchScreen(Window window);
216   Toolbar *searchToolbar(Window);
217   Slit *searchSlit(Window);
218
219   void saveMenuSearch(Window window, Basemenu *data);
220   void saveWindowSearch(Window window, BlackboxWindow *data);
221   void saveGroupSearch(Window window, BWindowGroup *data);
222   void saveToolbarSearch(Window window, Toolbar *data);
223   void saveSlitSearch(Window window, Slit *data);
224   void removeMenuSearch(Window window);
225   void removeWindowSearch(Window window);
226   void removeGroupSearch(Window window);
227   void removeToolbarSearch(Window window);
228   void removeSlitSearch(Window window);
229
230   inline BlackboxWindow *getFocusedWindow(void) { return focused_window; }
231
232   inline Configuration *getConfig() { return &config; }
233   inline const Time &getDoubleClickInterval(void) const
234   { return resource.double_click_interval; }
235   inline const Time &getLastTime(void) const { return last_time; }
236
237   inline const char *getStyleFilename(void) const
238     { return resource.style_file.c_str(); }
239   inline const char *getMenuFilename(void) const
240     { return menu_file.c_str(); }
241
242   inline int getColorsPerChannel(void) const
243     { return resource.colors_per_channel; }
244
245   inline std::string getTitlebarLayout(void) const
246     { return resource.titlebar_layout; }
247
248   inline const timeval &getAutoRaiseDelay(void) const
249     { return resource.auto_raise_delay; }
250
251   inline unsigned long getCacheLife(void) const
252     { return resource.cache_life; }
253   inline unsigned long getCacheMax(void) const
254     { return resource.cache_max; }
255
256   inline void setNoFocus(bool f) { no_focus = f; }
257
258   inline Cursor getSessionCursor(void) const
259     { return cursor.session; }
260   inline Cursor getMoveCursor(void) const
261     { return cursor.move; }
262   inline Cursor getLowerLeftAngleCursor(void) const
263     { return cursor.ll_angle; }
264   inline Cursor getLowerRightAngleCursor(void) const
265     { return cursor.lr_angle; }
266
267   void setFocusedWindow(BlackboxWindow *w);
268   void shutdown(void);
269   void saveStyleFilename(const std::string& filename);
270   void addMenuTimestamp(const std::string& filename);
271   void restart(const char *prog = 0);
272   void reconfigure(void);
273   void rereadMenu(void);
274   void checkMenu(void);
275
276   bool validateWindow(Window window);
277
278   virtual bool handleSignal(int sig);
279
280   virtual void timeout(void);
281
282 #ifndef   HAVE_STRFTIME
283   enum { B_AmericanDate = 1, B_EuropeanDate };
284 #endif // HAVE_STRFTIME
285
286 #ifdef    HAVE_GETPID
287   inline Atom getBlackboxPidAtom(void) const { return blackbox_pid; }
288 #endif // HAVE_GETPID
289
290   inline Atom getWMChangeStateAtom(void) const
291     { return xa_wm_change_state; }
292   inline Atom getWMStateAtom(void) const
293     { return xa_wm_state; }
294   inline Atom getWMDeleteAtom(void) const
295     { return xa_wm_delete_window; }
296   inline Atom getWMProtocolsAtom(void) const
297     { return xa_wm_protocols; }
298   inline Atom getWMTakeFocusAtom(void) const
299     { return xa_wm_take_focus; }
300   inline Atom getWMColormapAtom(void) const
301     { return xa_wm_colormap_windows; }
302   inline Atom getMotifWMHintsAtom(void) const
303     { return motif_wm_hints; }
304
305   // this atom is for normal app->WM hints about decorations, stacking,
306   // starting workspace etc...
307   inline Atom getBlackboxHintsAtom(void) const
308     { return blackbox_hints;}
309
310   // these atoms are for normal app->WM interaction beyond the scope of the
311   // ICCCM...
312   inline Atom getBlackboxAttributesAtom(void) const
313     { return blackbox_attributes; }
314   inline Atom getBlackboxChangeAttributesAtom(void) const
315     { return blackbox_change_attributes; }
316
317   // these atoms are for window->WM interaction, with more control and
318   // information on window "structure"... common examples are
319   // notifying apps when windows are raised/lowered... when the user changes
320   // workspaces... i.e. "pager talk"
321   inline Atom getBlackboxStructureMessagesAtom(void) const
322     { return blackbox_structure_messages; }
323
324   // *Notify* portions of the NETStructureMessages protocol
325   inline Atom getBlackboxNotifyStartupAtom(void) const
326     { return blackbox_notify_startup; }
327   inline Atom getBlackboxNotifyWindowAddAtom(void) const
328     { return blackbox_notify_window_add; }
329   inline Atom getBlackboxNotifyWindowDelAtom(void) const
330     { return blackbox_notify_window_del; }
331   inline Atom getBlackboxNotifyWindowFocusAtom(void) const
332     { return blackbox_notify_window_focus; }
333   inline Atom getBlackboxNotifyCurrentWorkspaceAtom(void) const
334     { return blackbox_notify_current_workspace; }
335   inline Atom getBlackboxNotifyWorkspaceCountAtom(void) const
336     { return blackbox_notify_workspace_count; }
337   inline Atom getBlackboxNotifyWindowRaiseAtom(void) const
338     { return blackbox_notify_window_raise; }
339   inline Atom getBlackboxNotifyWindowLowerAtom(void) const
340     { return blackbox_notify_window_lower; }
341
342   // atoms to change that request changes to the desktop environment during
343   // runtime... these messages can be sent by any client... as the sending
344   // client window id is not included in the ClientMessage event...
345   inline Atom getBlackboxChangeWorkspaceAtom(void) const
346     { return blackbox_change_workspace; }
347   inline Atom getBlackboxChangeWindowFocusAtom(void) const
348     { return blackbox_change_window_focus; }
349   inline Atom getBlackboxCycleWindowFocusAtom(void) const
350     { return blackbox_cycle_window_focus; }
351
352 #ifdef    NEWWMSPEC
353   // root window properties
354   inline Atom getNETSupportedAtom(void) const
355     { return net_supported; }
356   inline Atom getNETClientListAtom(void) const
357     { return net_client_list; }
358   inline Atom getNETClientListStackingAtom(void) const
359     { return net_client_list_stacking; }
360   inline Atom getNETNumberOfDesktopsAtom(void) const
361     { return net_number_of_desktops; }
362   inline Atom getNETDesktopGeometryAtom(void) const
363     { return net_desktop_geometry; }
364   inline Atom getNETDesktopViewportAtom(void) const
365     { return net_desktop_viewport; }
366   inline Atom getNETCurrentDesktopAtom(void) const
367     { return net_current_desktop; }
368   inline Atom getNETDesktopNamesAtom(void) const
369     { return net_desktop_names; }
370   inline Atom getNETActiveWindowAtom(void) const
371     { return net_active_window; }
372   inline Atom getNETWorkareaAtom(void) const
373     { return net_workarea; }
374   inline Atom getNETSupportingWMCheckAtom(void) const
375     { return net_supporting_wm_check; }
376   inline Atom getNETVirtualRootsAtom(void) const
377     { return net_virtual_roots; }
378
379   // root window messages
380   inline Atom getNETCloseWindowAtom(void) const
381     { return net_close_window; }
382   inline Atom getNETWMMoveResizeAtom(void) const
383     { return net_wm_moveresize; }
384
385   // application window properties
386   inline Atom getNETPropertiesAtom(void) const
387     { return net_properties; }
388   inline Atom getNETWMNameAtom(void) const
389     { return net_wm_name; }
390   inline Atom getNETWMDesktopAtom(void) const
391     { return net_wm_desktop; }
392   inline Atom getNETWMWindowTypeAtom(void) const
393     { return net_wm_window_type; }
394   inline Atom getNETWMStateAtom(void) const
395     { return net_wm_state; }
396   inline Atom getNETWMStrutAtom(void) const
397     { return net_wm_strut; }
398   inline Atom getNETWMIconGeometryAtom(void) const
399     { return net_wm_icon_geometry; }
400   inline Atom getNETWMIconAtom(void) const
401     { return net_wm_icon; }
402   inline Atom getNETWMPidAtom(void) const
403     { return net_wm_pid; }
404   inline Atom getNETWMHandledIconsAtom(void) const
405     { return net_wm_handled_icons; }
406
407   // application protocols
408   inline Atom getNETWMPingAtom(void) const
409     { return net_wm_ping; }
410 #endif // NEWWMSPEC
411 };
412
413
414 #endif // __blackbox_hh