aboutsummaryrefslogtreecommitdiff
path: root/src/BaseDisplay.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/BaseDisplay.hh')
-rw-r--r--src/BaseDisplay.hh432
1 files changed, 121 insertions, 311 deletions
diff --git a/src/BaseDisplay.hh b/src/BaseDisplay.hh
index c25860e..09af9c5 100644
--- a/src/BaseDisplay.hh
+++ b/src/BaseDisplay.hh
@@ -1,3 +1,6 @@
1// BaseDisplay.hh for Fluxbox Window Manager
2// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
3//
1// BaseDisplay.hh for Blackbox - an X11 Window manager 4// BaseDisplay.hh for Blackbox - an X11 Window manager
2// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) 5// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
3// 6//
@@ -13,356 +16,163 @@
13// 16//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
21 24
22#ifndef _BASEDISPLAY_HH_ 25// $Id: BaseDisplay.hh,v 1.28 2002/08/30 13:09:24 fluxgen Exp $
23#define _BASEDISPLAY_HH_ 26
27#ifndef BASEDISPLAY_HH
28#define BASEDISPLAY_HH
29
30#include "NotCopyable.hh"
31#include "EventHandler.hh"
24 32
25#include <X11/Xlib.h> 33#include <X11/Xlib.h>
26#include <X11/Xatom.h> 34
35#ifdef XINERAMA
36extern "C" {
37#include <X11/extensions/Xinerama.h>
38}
39#endif // XINERAMA
40
41#include <list>
42#include <vector>
27 43
28// forward declaration 44// forward declaration
29class BaseDisplay;
30class ScreenInfo; 45class ScreenInfo;
31 46
32#include "LinkedList.hh" 47#define PropBlackboxHintsElements (5)
33#include "Timer.hh" 48#define PropBlackboxAttributesElements (8)
34 49
35#define AttribShaded (1l << 0) 50/// obsolete
36#define AttribMaxHoriz (1l << 1) 51void bexec(const char *command, char *displaystring);
37#define AttribMaxVert (1l << 2) 52/**
38#define AttribOmnipresent (1l << 3) 53 Singleton class to manage display connection
39#define AttribWorkspace (1l << 4) 54*/
40#define AttribStack (1l << 5) 55class BaseDisplay:private NotCopyable, FbTk::EventHandler<XEvent>
41#define AttribDecoration (1l << 6) 56{
57public:
58 BaseDisplay(const char *app_name, const char *display_name = 0);
59 virtual ~BaseDisplay();
60 static BaseDisplay *instance();
61
62 /**
63 obsolete
64 @see FluxboxWindow
65 */
66 enum Attrib {
67 ATTRIB_SHADED = 0x01,
68 ATTRIB_MAXHORIZ = 0x02,
69 ATTRIB_MAXVERT = 0x04,
70 ATTRIB_OMNIPRESENT = 0x08,
71 ATTRIB_WORKSPACE = 0x10,
72 ATTRIB_STACK = 0x20,
73 ATTRIB_DECORATION = 0x40
74 };
75
76 typedef struct _blackbox_hints {
77 unsigned long flags, attrib, workspace, stack;
78 int decoration;
79 } BlackboxHints;
42 80
43#define StackTop (0) 81 typedef struct _blackbox_attributes {
44#define StackNormal (1) 82 unsigned long flags, attrib, workspace, stack;
45#define StackBottom (2) 83 int premax_x, premax_y;
84 unsigned int premax_w, premax_h;
85 } BlackboxAttributes;
46 86
47#define DecorNone (0)
48#define DecorNormal (1)
49#define DecorTiny (2)
50#define DecorTool (3)
51 87
52typedef struct _blackbox_hints { 88 inline ScreenInfo *getScreenInfo(int s) { return screenInfoList[s]; }
53 unsigned long flags, attrib, workspace, stack, decoration;
54} BlackboxHints;
55 89
56typedef struct _blackbox_attributes { 90 inline bool hasShapeExtensions() const { return shape.extensions; }
57 unsigned long flags, attrib, workspace, stack; 91 inline bool doShutdown() const { return m_shutdown; }
58 int premax_x, premax_y; 92 inline bool isStartup() const { return m_startup; }
59 unsigned int premax_w, premax_h;
60} BlackboxAttributes;
61 93
62#define PropBlackboxHintsElements (5) 94
63#define PropBlackboxAttributesElements (8) 95 static Display *getXDisplay() { return s_display; }
64 96
65#ifndef __EMX__ 97 inline const char *getXDisplayName() const { return m_display_name; }
66void bexec(const char *, char *); 98 inline const char *getApplicationName() const { return m_app_name; }
67#endif // !__EMX__
68 99
69char *bstrdup(const char *); 100 inline int getNumberOfScreens() const { return number_of_screens; }
70template <typename Z> inline Z min(Z a, Z b) { return ((a < b) ? a : b); } 101 inline int getShapeEventBase() const { return shape.event_basep; }
71template <typename Z> inline Z max(Z a, Z b) { return ((a > b) ? a : b); }
72 102
73class BaseDisplay { 103 inline void shutdown() { m_shutdown = true; }
104 inline void run() { m_startup = m_shutdown = false; }
74 105
75public: 106 bool validateWindow(Window);
76 BaseDisplay(char *, char * = 0); 107
77 virtual ~BaseDisplay(void); 108 void grab();
78 109 void ungrab();
79#ifdef GNOME 110 void eventLoop();
80 inline Atom *getGnomeListAtoms() { return gnome_atom_list; }
81 inline Atom &getGnomeProtAtom() { return gnome_wm_prot; }
82 inline Atom &getGnomeClientListAtom() { return gnome_wm_win_client_list; }
83 inline Atom &getGnomeSupportingWMCheckAtom() { return gnome_wm_supporting_wm_check; }
84 inline Atom &getGnomeWorkspaceAtom() { return gnome_wm_win_workspace; }
85 inline Atom &getGnomeWorkspaceCountAtom() { return gnome_wm_win_workspace_count; }
86 inline Atom &getGnomeWorkspaceNamesAtom() { return gnome_wm_win_workspace_names; }
87#endif //GNOME
88
89 inline const Atom &getWMChangeStateAtom(void) const
90 { return xa_wm_change_state; }
91 inline const Atom &getWMStateAtom(void) const
92 { return xa_wm_state; }
93 inline const Atom &getWMDeleteAtom(void) const
94 { return xa_wm_delete_window; }
95 inline const Atom &getWMProtocolsAtom(void) const
96 { return xa_wm_protocols; }
97 inline const Atom &getWMTakeFocusAtom(void) const
98 { return xa_wm_take_focus; }
99 inline const Atom &getWMColormapAtom(void) const
100 { return xa_wm_colormap_windows; }
101 inline const Atom &getMotifWMHintsAtom(void) const
102 { return motif_wm_hints; }
103
104 // this atom is for normal app->WM hints about decorations, stacking,
105 // starting workspace etc...
106 inline const Atom &getFluxboxHintsAtom(void) const
107 { return blackbox_hints;}
108
109 // these atoms are for normal app->WM interaction beyond the scope of the
110 // ICCCM...
111 inline const Atom &getFluxboxAttributesAtom(void) const
112 { return blackbox_attributes; }
113 inline const Atom &getFluxboxChangeAttributesAtom(void) const
114 { return blackbox_change_attributes; }
115
116 // these atoms are for window->WM interaction, with more control and
117 // information on window "structure"... common examples are
118 // notifying apps when windows are raised/lowered... when the user changes
119 // workspaces... i.e. "pager talk"
120 inline const Atom &getFluxboxStructureMessagesAtom(void) const
121 { return blackbox_structure_messages; }
122
123 // *Notify* portions of the NETStructureMessages protocol
124 inline const Atom &getFluxboxNotifyStartupAtom(void) const
125 { return blackbox_notify_startup; }
126 inline const Atom &getFluxboxNotifyWindowAddAtom(void) const
127 { return blackbox_notify_window_add; }
128 inline const Atom &getFluxboxNotifyWindowDelAtom(void) const
129 { return blackbox_notify_window_del; }
130 inline const Atom &getFluxboxNotifyWindowFocusAtom(void) const
131 { return blackbox_notify_window_focus; }
132 inline const Atom &getFluxboxNotifyCurrentWorkspaceAtom(void) const
133 { return blackbox_notify_current_workspace; }
134 inline const Atom &getFluxboxNotifyWorkspaceCountAtom(void) const
135 { return blackbox_notify_workspace_count; }
136 inline const Atom &getFluxboxNotifyWindowRaiseAtom(void) const
137 { return blackbox_notify_window_raise; }
138 inline const Atom &getFluxboxNotifyWindowLowerAtom(void) const
139 { return blackbox_notify_window_lower; }
140
141 // atoms to change that request changes to the desktop environment during
142 // runtime... these messages can be sent by any client... as the sending
143 // client window id is not included in the ClientMessage event...
144 inline const Atom &getFluxboxChangeWorkspaceAtom(void) const
145 { return blackbox_change_workspace; }
146 inline const Atom &getFluxboxChangeWindowFocusAtom(void) const
147 { return blackbox_change_window_focus; }
148 inline const Atom &getFluxboxCycleWindowFocusAtom(void) const
149 { return blackbox_cycle_window_focus; }
150
151#ifdef NEWWMSPEC
152
153 // root window properties
154 inline const Atom &getNETSupportedAtom(void) const
155 { return net_supported; }
156 inline const Atom &getNETClientListAtom(void) const
157 { return net_client_list; }
158 inline const Atom &getNETClientListStackingAtom(void) const
159 { return net_client_list_stacking; }
160 inline const Atom &getNETNumberOfDesktopsAtom(void) const
161 { return net_number_of_desktops; }
162 inline const Atom &getNETDesktopGeometryAtom(void) const
163 { return net_desktop_geometry; }
164 inline const Atom &getNETDesktopViewportAtom(void) const
165 { return net_desktop_viewport; }
166 inline const Atom &getNETCurrentDesktopAtom(void) const
167 { return net_current_desktop; }
168 inline const Atom &getNETDesktopNamesAtom(void) const
169 { return net_desktop_names; }
170 inline const Atom &getNETActiveWindowAtom(void) const
171 { return net_active_window; }
172 inline const Atom &getNETWorkareaAtom(void) const
173 { return net_workarea; }
174 inline const Atom &getNETSupportingWMCheckAtom(void) const
175 { return net_supporting_wm_check; }
176 inline const Atom &getNETVirtualRootsAtom(void) const
177 { return net_virtual_roots; }
178
179 // root window messages
180 inline const Atom &getNETCloseWindowAtom(void) const
181 { return net_close_window; }
182 inline const Atom &getNETWMMoveResizeAtom(void) const
183 { return net_wm_moveresize; }
184
185 // application window properties
186 inline const Atom &getNETPropertiesAtom(void) const
187 { return net_properties; }
188 inline const Atom &getNETWMNameAtom(void) const
189 { return net_wm_name; }
190 inline const Atom &getNETWMDesktopAtom(void) const
191 { return net_wm_desktop; }
192 inline const Atom &getNETWMWindowTypeAtom(void) const
193 { return net_wm_window_type; }
194 inline const Atom &getNETWMStateAtom(void) const
195 { return net_wm_state; }
196 inline const Atom &getNETWMStrutAtom(void) const
197 { return net_wm_strut; }
198 inline const Atom &getNETWMIconGeometryAtom(void) const
199 { return net_wm_icon_geometry; }
200 inline const Atom &getNETWMIconAtom(void) const
201 { return net_wm_icon; }
202 inline const Atom &getNETWMPidAtom(void) const
203 { return net_wm_pid; }
204 inline const Atom &getNETWMHandledIconsAtom(void) const
205 { return net_wm_handled_icons; }
206
207 // application protocols
208 inline const Atom &getNETWMPingAtom(void) const
209 { return net_wm_ping; }
210
211#endif // NEWWMSPEC
212
213 inline ScreenInfo *getScreenInfo(int s)
214 { return (ScreenInfo *) screenInfoList->find(s); }
215
216 inline const Bool &hasShapeExtensions(void) const
217 { return shape.extensions; }
218 inline const Bool &doShutdown(void) const
219 { return _shutdown; }
220 inline const Bool &isStartup(void) const
221 { return _startup; }
222
223 inline const Cursor &getSessionCursor(void) const
224 { return cursor.session; }
225 inline const Cursor &getMoveCursor(void) const
226 { return cursor.move; }
227 inline const Cursor &getLowerLeftAngleCursor(void) const
228 { return cursor.ll_angle; }
229 inline const Cursor &getLowerRightAngleCursor(void) const
230 { return cursor.lr_angle; }
231
232 inline Display *getXDisplay(void) { return display; }
233
234 inline const char *getXDisplayName(void) const
235 { return (const char *) display_name; }
236 inline const char *getApplicationName(void) const
237 { return (const char *) application_name; }
238
239 inline const int &getNumberOfScreens(void) const
240 { return number_of_screens; }
241 inline const int &getShapeEventBase(void) const
242 { return shape.event_basep; }
243
244 inline void shutdown(void) { _shutdown = True; }
245 inline void run(void) { _startup = _shutdown = False; }
246
247 const Bool validateWindow(Window);
248
249 void grab(void);
250 void ungrab(void);
251 void eventLoop(void);
252 void addTimer(BTimer *);
253 void removeTimer(BTimer *);
254
255 // another pure virtual... this is used to handle signals that BaseDisplay
256 // doesn't understand itself
257 virtual Bool handleSignal(int) = 0;
258
259private:
260 struct cursor {
261 Cursor session, move, ll_angle, lr_angle;
262 } cursor;
263
264 struct shape {
265 Bool extensions;
266 int event_basep, error_basep;
267 } shape;
268
269 Atom xa_wm_colormap_windows, xa_wm_protocols, xa_wm_state,
270 xa_wm_delete_window, xa_wm_take_focus, xa_wm_change_state,
271 motif_wm_hints;
272
273 // NETAttributes
274 Atom blackbox_attributes, blackbox_change_attributes, blackbox_hints;
275
276 // NETStructureMessages
277 Atom blackbox_structure_messages, blackbox_notify_startup,
278 blackbox_notify_window_add, blackbox_notify_window_del,
279 blackbox_notify_window_focus, blackbox_notify_current_workspace,
280 blackbox_notify_workspace_count, blackbox_notify_window_raise,
281 blackbox_notify_window_lower;
282
283 // message_types for client -> wm messages
284 Atom blackbox_change_workspace, blackbox_change_window_focus,
285 blackbox_cycle_window_focus;
286
287#ifdef NEWWMSPEC
288
289 // root window properties
290 Atom net_supported, net_client_list, net_client_list_stacking,
291 net_number_of_desktops, net_desktop_geometry, net_desktop_viewport,
292 net_current_desktop, net_desktop_names, net_active_window, net_workarea,
293 net_supporting_wm_check, net_virtual_roots;
294
295 // root window messages
296 Atom net_close_window, net_wm_moveresize;
297
298 // application window properties
299 Atom net_properties, net_wm_name, net_wm_desktop, net_wm_window_type,
300 net_wm_state, net_wm_strut, net_wm_icon_geometry, net_wm_icon, net_wm_pid,
301 net_wm_handled_icons;
302
303
304 // application protocols
305 Atom net_wm_ping;
306
307#endif // NEWWMSPEC
308
309#ifdef GNOME
310 union {
311 Atom gnome_wm_win_layer, gnome_wm_win_state, gnome_wm_win_hints,
312 gnome_wm_win_app_state, gnome_wm_win_expanded_size,
313 gnome_wm_win_icons, gnome_wm_win_workspace,
314 gnome_wm_win_workspace_count, gnome_wm_win_workspace_names,
315 gnome_wm_win_client_list;
316 Atom gnome_atom_list[10];
317 };
318 Atom gnome_wm_prot;
319 Atom gnome_wm_supporting_wm_check;
320#endif // GNOME
321 111
112private:
322 113
323 Bool _startup, _shutdown; 114 struct shape {
324 Display *display; 115 Bool extensions;
325 LinkedList<ScreenInfo> *screenInfoList; 116 int event_basep, error_basep;
326 LinkedList<BTimer> *timerList; 117 } shape;
327 118
328 char *display_name, *application_name; 119 bool m_startup, m_shutdown;
329 int number_of_screens, server_grabs, colors_per_channel; 120 static Display *s_display;
330 121
331protected: 122 typedef std::vector<ScreenInfo *> ScreenInfoList;
332 123 ScreenInfoList screenInfoList;
333 virtual void process_event(XEvent *) = 0;
334 124
125 const char *m_display_name, *m_app_name;
126 int number_of_screens, m_server_grabs;
335 127
128 static BaseDisplay *s_singleton;
336}; 129};
337 130
338 131
339class ScreenInfo { 132class ScreenInfo {
340public: 133public:
341 ScreenInfo(BaseDisplay *, int); 134 ScreenInfo(BaseDisplay *bdisp, int screen_num);
342 135 ~ScreenInfo();
343 inline BaseDisplay *getBaseDisplay(void) { return basedisplay; }
344 136
345 inline Visual *getVisual(void) { return visual; } 137 inline BaseDisplay *getBaseDisplay() { return basedisplay; }
346 inline const Window &getRootWindow(void) const { return root_window; }
347 inline const Colormap &getColormap(void) const { return colormap; }
348 138
349 inline const int &getDepth(void) const { return depth; } 139 inline Visual *getVisual() { return visual; }
350 inline const int &getScreenNumber(void) const { return screen_number; } 140 inline const Window &getRootWindow() const { return root_window; }
141 inline const Colormap &colormap() const { return m_colormap; }
351 142
352 inline const unsigned int &getWidth(void) const { return width; } 143 inline int getDepth() const { return depth; }
353 inline const unsigned int &getHeight(void) const { return height; } 144 inline int getScreenNumber() const { return screen_number; }
354 145
355private: 146 inline unsigned int getWidth() const { return width; }
356 BaseDisplay *basedisplay; 147 inline unsigned int getHeight() const { return height; }
357 Visual *visual;
358 Window root_window;
359 Colormap colormap;
360 148
361 int depth, screen_number; 149#ifdef XINERAMA
362 unsigned int width, height; 150 inline bool hasXinerama() const { return m_hasXinerama; }
151 inline int getNumHeads() const { return xineramaNumHeads; }
152 unsigned int getHead(int x, int y) const;
153 unsigned int getCurrHead() const;
154 unsigned int getHeadWidth(unsigned int head) const;
155 unsigned int getHeadHeight(unsigned int head) const;
156 int getHeadX(unsigned int head) const;
157 int getHeadY(unsigned int head) const;
158#endif // XINERAMA
363 159
160private:
161 BaseDisplay *basedisplay;
162 Visual *visual;
163 Window root_window;
164 Colormap m_colormap;
165
166 int depth, screen_number;
167 unsigned int width, height;
168#ifdef XINERAMA
169 bool m_hasXinerama;
170 int xineramaMajor, xineramaMinor, xineramaNumHeads, xineramaLastHead;
171 XineramaScreenInfo *xineramaInfos;
172#endif // XINERAMA
364 173
365}; 174};
366 175
367 176
368#endif // __BaseDisplay_hh 177
178#endif // BASEDISPLAY_HH