]> icculus.org git repositories - mikachu/openbox.git/blob - src/BaseDisplay.h
make a new autoRaiseDelay value take effect without having to restart
[mikachu/openbox.git] / src / BaseDisplay.h
1 // BaseDisplay.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   __BaseDisplay_hh
24 #define   __BaseDisplay_hh
25
26 #include <X11/Xlib.h>
27 #include <X11/Xatom.h>
28
29 // forward declaration
30 class BaseDisplay;
31 class ScreenInfo;
32
33 #include "Timer.h"
34 #include "Geometry.h"
35 #include "Util.h"
36 #include <vector>
37 #include <list>
38
39 #define AttribShaded      (1l << 0)
40 #define AttribMaxHoriz    (1l << 1)
41 #define AttribMaxVert     (1l << 2)
42 #define AttribOmnipresent (1l << 3)
43 #define AttribWorkspace   (1l << 4)
44 #define AttribStack       (1l << 5)
45 #define AttribDecoration  (1l << 6)
46
47 #define StackTop          (0)
48 #define StackNormal       (1)
49 #define StackBottom       (2)
50
51 #define DecorNone         (0)
52 #define DecorNormal       (1)
53 #define DecorTiny         (2)
54 #define DecorTool         (3)
55
56 typedef struct _openbox_hints {
57   unsigned long flags, attrib, workspace, stack, decoration;
58 } OpenboxHints;
59
60 typedef struct _openbox_attributes {
61   unsigned long flags, attrib, workspace, stack, decoration;
62   int premax_x, premax_y;
63   unsigned int premax_w, premax_h;
64 } OpenboxAttributes;
65
66 #define PropOpenboxHintsElements      (5)
67 #define PropOpenboxAttributesElements (9)
68
69 #ifndef    __EMX__
70 void bexec(const char *, char *);
71 #endif // !__EMX__
72
73 char *bstrdup(const char *);
74
75 class BaseDisplay {
76 private:
77   struct cursor {
78     Cursor session, move, ll_angle, lr_angle, ul_angle, ur_angle;
79   } cursor;
80
81   struct shape {
82     Bool extensions;
83     int event_basep, error_basep;
84   } shape;
85
86 #ifndef   NOCLOBBER
87   unsigned int MaskList[8];
88   size_t MaskListLength;
89 #endif // NOCLOBBER
90   
91   Atom xa_wm_colormap_windows, xa_wm_protocols, xa_wm_state,
92     xa_wm_delete_window, xa_wm_take_focus, xa_wm_change_state,
93     motif_wm_hints;
94
95   // NETAttributes
96   Atom openbox_attributes, openbox_change_attributes, openbox_hints;
97
98   // NETStructureMessages
99   Atom openbox_structure_messages, openbox_notify_startup,
100     openbox_notify_window_add, openbox_notify_window_del,
101     openbox_notify_window_focus, openbox_notify_current_workspace,
102     openbox_notify_workspace_count, openbox_notify_window_raise,
103     openbox_notify_window_lower;
104
105   // message_types for client -> wm messages
106   Atom openbox_change_workspace, openbox_change_window_focus,
107     openbox_cycle_window_focus;
108
109 #ifdef    NEWWMSPEC
110
111   // root window properties
112   Atom net_supported, net_client_list, net_client_list_stacking,
113     net_number_of_desktops, net_desktop_geometry, net_desktop_viewport,
114     net_current_desktop, net_desktop_names, net_active_window, net_workarea,
115     net_supporting_wm_check, net_virtual_roots;
116
117   // root window messages
118   Atom net_close_window, net_wm_moveresize;
119
120   // application window properties
121   Atom net_properties, net_wm_name, net_wm_desktop, net_wm_window_type,
122     net_wm_state, net_wm_strut, net_wm_icon_geometry, net_wm_icon, net_wm_pid,
123     net_wm_handled_icons;
124
125   // application protocols
126   Atom net_wm_ping;
127
128 #endif // NEWWMSPEC
129
130   Bool _startup, _shutdown;
131   Display *display;
132
133   typedef std::vector<ScreenInfo*> ScreenInfoList;
134   ScreenInfoList screenInfoList;
135  
136   typedef std::list<BTimer*> TimerList;
137   TimerList timerList;
138
139   char *display_name, *application_name;
140   unsigned int server_grabs, colors_per_channel;
141
142
143 protected:
144   // pure virtual function... you must override this
145   virtual void process_event(XEvent *) = 0;
146
147   // the masks of the modifiers which are ignored in button events.
148   int NumLockMask, ScrollLockMask;
149
150
151 public:
152   BaseDisplay(const char *, char * = 0);
153   virtual ~BaseDisplay();
154
155   inline const Atom &getWMChangeStateAtom() const
156     { return xa_wm_change_state; }
157   inline const Atom &getWMStateAtom() const
158     { return xa_wm_state; }
159   inline const Atom &getWMDeleteAtom() const
160     { return xa_wm_delete_window; }
161   inline const Atom &getWMProtocolsAtom() const
162     { return xa_wm_protocols; }
163   inline const Atom &getWMTakeFocusAtom() const
164     { return xa_wm_take_focus; }
165   inline const Atom &getWMColormapAtom() const
166     { return xa_wm_colormap_windows; }
167   inline const Atom &getMotifWMHintsAtom() const
168     { return motif_wm_hints; }
169
170   // this atom is for normal app->WM hints about decorations, stacking,
171   // starting workspace etc...
172   inline const Atom &getOpenboxHintsAtom() const
173     { return openbox_hints;}
174
175   // these atoms are for normal app->WM interaction beyond the scope of the
176   // ICCCM...
177   inline const Atom &getOpenboxAttributesAtom() const
178     { return openbox_attributes; }
179   inline const Atom &getOpenboxChangeAttributesAtom() const
180     { return openbox_change_attributes; }
181
182   // these atoms are for window->WM interaction, with more control and
183   // information on window "structure"... common examples are
184   // notifying apps when windows are raised/lowered... when the user changes
185   // workspaces... i.e. "pager talk"
186   inline const Atom &getOpenboxStructureMessagesAtom() const
187     { return openbox_structure_messages; }
188
189   // *Notify* portions of the NETStructureMessages protocol
190   inline const Atom &getOpenboxNotifyStartupAtom() const
191     { return openbox_notify_startup; }
192   inline const Atom &getOpenboxNotifyWindowAddAtom() const
193     { return openbox_notify_window_add; }
194   inline const Atom &getOpenboxNotifyWindowDelAtom() const
195     { return openbox_notify_window_del; }
196   inline const Atom &getOpenboxNotifyWindowFocusAtom() const
197     { return openbox_notify_window_focus; }
198   inline const Atom &getOpenboxNotifyCurrentWorkspaceAtom() const
199     { return openbox_notify_current_workspace; }
200   inline const Atom &getOpenboxNotifyWorkspaceCountAtom() const
201     { return openbox_notify_workspace_count; }
202   inline const Atom &getOpenboxNotifyWindowRaiseAtom() const
203     { return openbox_notify_window_raise; }
204   inline const Atom &getOpenboxNotifyWindowLowerAtom() const
205     { return openbox_notify_window_lower; }
206
207   // atoms to change that request changes to the desktop environment during
208   // runtime... these messages can be sent by any client... as the sending
209   // client window id is not included in the ClientMessage event...
210   inline const Atom &getOpenboxChangeWorkspaceAtom() const
211     { return openbox_change_workspace; }
212   inline const Atom &getOpenboxChangeWindowFocusAtom() const
213     { return openbox_change_window_focus; }
214   inline const Atom &getOpenboxCycleWindowFocusAtom() const
215     { return openbox_cycle_window_focus; }
216
217 #ifdef    NEWWMSPEC
218
219   // root window properties
220   inline const Atom &getNETSupportedAtom() const
221     { return net_supported; }
222   inline const Atom &getNETClientListAtom() const
223     { return net_client_list; }
224   inline const Atom &getNETClientListStackingAtom() const
225     { return net_client_list_stacking; }
226   inline const Atom &getNETNumberOfDesktopsAtom() const
227     { return net_number_of_desktops; }
228   inline const Atom &getNETDesktopGeometryAtom() const
229     { return net_desktop_geometry; }
230   inline const Atom &getNETDesktopViewportAtom() const
231     { return net_desktop_viewport; }
232   inline const Atom &getNETCurrentDesktopAtom() const
233     { return net_current_desktop; }
234   inline const Atom &getNETDesktopNamesAtom() const
235     { return net_desktop_names; }
236   inline const Atom &getNETActiveWindowAtom() const
237     { return net_active_window; }
238   inline const Atom &getNETWorkareaAtom() const
239     { return net_workarea; }
240   inline const Atom &getNETSupportingWMCheckAtom() const
241     { return net_supporting_wm_check; }
242   inline const Atom &getNETVirtualRootsAtom() const
243     { return net_virtual_roots; }
244
245   // root window messages
246   inline const Atom &getNETCloseWindowAtom() const
247     { return net_close_window; }
248   inline const Atom &getNETWMMoveResizeAtom() const
249     { return net_wm_moveresize; }
250
251   // application window properties
252   inline const Atom &getNETPropertiesAtom() const
253     { return net_properties; }
254   inline const Atom &getNETWMNameAtom() const
255     { return net_wm_name; }
256   inline const Atom &getNETWMDesktopAtom() const
257     { return net_wm_desktop; }
258   inline const Atom &getNETWMWindowTypeAtom() const
259     { return net_wm_window_type; }
260   inline const Atom &getNETWMStateAtom() const
261     { return net_wm_state; }
262   inline const Atom &getNETWMStrutAtom() const
263     { return net_wm_strut; }
264   inline const Atom &getNETWMIconGeometryAtom() const
265     { return net_wm_icon_geometry; }
266   inline const Atom &getNETWMIconAtom() const
267     { return net_wm_icon; }
268   inline const Atom &getNETWMPidAtom() const
269     { return net_wm_pid; }
270   inline const Atom &getNETWMHandledIconsAtom() const
271     { return net_wm_handled_icons; }
272
273   // application protocols
274   inline const Atom &getNETWMPingAtom() const
275     { return net_wm_ping; }
276
277 #endif // NEWWMSPEC
278
279   inline ScreenInfo *getScreenInfo(unsigned int s) {
280     ASSERT(s < screenInfoList.size());
281     return screenInfoList[s];
282   }
283
284   inline const Bool &hasShapeExtensions() const
285     { return shape.extensions; }
286   inline const Bool &doShutdown() const
287     { return _shutdown; }
288   inline const Bool &isStartup() const
289     { return _startup; }
290
291   inline const Cursor &getSessionCursor() const
292     { return cursor.session; }
293   inline const Cursor &getMoveCursor() const
294     { return cursor.move; }
295   inline const Cursor &getLowerLeftAngleCursor() const
296     { return cursor.ll_angle; }
297   inline const Cursor &getLowerRightAngleCursor() const
298     { return cursor.lr_angle; }
299   inline const Cursor &getUpperLeftAngleCursor() const
300     { return cursor.ul_angle; }
301   inline const Cursor &getUpperRightAngleCursor() const
302     { return cursor.ur_angle; }
303
304   inline Display *getXDisplay() { return display; }
305
306   inline const char *getXDisplayName() const
307     { return (const char *) display_name; }
308   inline const char *getApplicationName() const
309     { return (const char *) application_name; }
310
311   inline const unsigned int numberOfScreens() const
312     { return ScreenCount(display); }
313   inline const int &getShapeEventBase() const
314     { return shape.event_basep; }
315
316   inline void shutdown() { _shutdown = True; }
317   inline void run() { _startup = _shutdown = False; }
318
319   const Bool validateWindow(Window);
320
321   void grabButton(unsigned int, unsigned int, Window, Bool, unsigned int, int,
322       int, Window, Cursor) const;
323   void ungrabButton(unsigned int button, unsigned int modifiers,
324       Window grab_window) const;
325   
326   void grab();
327   void ungrab();
328   void eventLoop();
329   void addTimer(BTimer *);
330   void removeTimer(BTimer *);
331
332   // another pure virtual... this is used to handle signals that BaseDisplay
333   // doesn't understand itself
334   virtual Bool handleSignal(int) = 0;
335 };
336
337
338 class ScreenInfo {
339 private:
340   BaseDisplay &basedisplay;
341   Visual *visual;
342   Window root_window;
343   Colormap colormap;
344
345   int depth, screen_number;
346   Size m_size;
347
348
349 public:
350   ScreenInfo(BaseDisplay &, int);
351
352   inline BaseDisplay &getBaseDisplay() { return basedisplay; }
353
354   inline Visual *getVisual() const { return visual; }
355   inline const Window &getRootWindow() const { return root_window; }
356   inline const Colormap &getColormap() const { return colormap; }
357
358   inline const int &getDepth() const { return depth; }
359   inline const int &getScreenNumber() const { return screen_number; }
360
361 //  inline const unsigned int &getWidth() const { return width; }
362 //  inline const unsigned int &getHeight() const { return height; }
363   inline const Size &size() const { return m_size; }
364 };
365
366
367 #endif // __BaseDisplay_hh