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