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