]> Dogcows Code - chaz/openbox/blob - src/BaseDisplay.hh
sync with bb-cvs
[chaz/openbox] / src / BaseDisplay.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // BaseDisplay.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 __BaseDisplay_hh
25 #define __BaseDisplay_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29 #include <X11/Xatom.h>
30 }
31
32 #include <vector>
33 #include <string>
34
35 // forward declaration
36 class BaseDisplay;
37 class BGCCache;
38
39 #include "Timer.hh"
40 #include "Util.hh"
41
42 class ScreenInfo {
43 private:
44 BaseDisplay *basedisplay;
45 Visual *visual;
46 Window root_window;
47 Colormap colormap;
48
49 int depth;
50 unsigned int screen_number;
51 std::string display_string;
52 Rect rect;
53 #ifdef XINERAMA
54 RectList xinerama_areas;
55 bool xinerama_active;
56 #endif
57
58 public:
59 ScreenInfo(BaseDisplay *d, unsigned int num);
60
61 inline BaseDisplay *getBaseDisplay(void) const { return basedisplay; }
62 inline Visual *getVisual(void) const { return visual; }
63 inline Window getRootWindow(void) const { return root_window; }
64 inline Colormap getColormap(void) const { return colormap; }
65 inline int getDepth(void) const { return depth; }
66 inline unsigned int getScreenNumber(void) const
67 { return screen_number; }
68 inline const Rect& getRect(void) const { return rect; }
69 inline unsigned int getWidth(void) const { return rect.width(); }
70 inline unsigned int getHeight(void) const { return rect.height(); }
71 inline const std::string& displayString(void) const
72 { return display_string; }
73 #ifdef XINERAMA
74 inline const RectList &getXineramaAreas(void) const { return xinerama_areas; }
75 inline bool isXineramaActive(void) const { return xinerama_active; }
76 #endif
77 };
78
79
80 class BaseDisplay: public TimerQueueManager {
81 private:
82 struct BShape {
83 bool extensions;
84 int event_basep, error_basep;
85 };
86 BShape shape;
87
88 #ifdef XINERAMA
89 struct BXinerama {
90 bool extensions;
91 int event_basep, error_basep;
92 int major, minor; // version
93 };
94 BXinerama xinerama;
95 #endif // XINERAMA
96
97 unsigned int MaskList[8];
98 size_t MaskListLength;
99
100 enum RunState { STARTUP, RUNNING, SHUTDOWN };
101 RunState run_state;
102
103 Display *display;
104 mutable BGCCache *gccache;
105
106 typedef std::vector<ScreenInfo> ScreenInfoList;
107 ScreenInfoList screenInfoList;
108 TimerQueue timerList;
109
110 const char *display_name, *application_name;
111
112 // no copying!
113 BaseDisplay(const BaseDisplay &);
114 BaseDisplay& operator=(const BaseDisplay&);
115
116 protected:
117 // pure virtual function... you must override this
118 virtual void process_event(XEvent *e) = 0;
119
120 // the masks of the modifiers which are ignored in button events.
121 int NumLockMask, ScrollLockMask;
122
123
124 public:
125 BaseDisplay(const char *app_name, const char *dpy_name = 0);
126 virtual ~BaseDisplay(void);
127
128 const ScreenInfo* getScreenInfo(const unsigned int s) const;
129
130 BGCCache *gcCache(void) const;
131
132 inline bool hasShapeExtensions(void) const
133 { return shape.extensions; }
134 #ifdef XINERAMA
135 inline bool hasXineramaExtensions(void) const
136 { return xinerama.extensions; }
137 #endif // XINERAMA
138 inline bool doShutdown(void) const
139 { return run_state == SHUTDOWN; }
140 inline bool isStartup(void) const
141 { return run_state == STARTUP; }
142
143 inline Display *getXDisplay(void) const { return display; }
144
145 inline const char *getXDisplayName(void) const
146 { return display_name; }
147 inline const char *getApplicationName(void) const
148 { return application_name; }
149
150 inline unsigned int getNumberOfScreens(void) const
151 { return screenInfoList.size(); }
152 inline int getShapeEventBase(void) const
153 { return shape.event_basep; }
154 #ifdef XINERAMA
155 inline int getXineramaMajorVersion(void) const
156 { return xinerama.major; }
157 #endif // XINERAMA
158
159 inline void shutdown(void) { run_state = SHUTDOWN; }
160 inline void run(void) { run_state = RUNNING; }
161
162 void grabButton(unsigned int button, unsigned int modifiers,
163 Window grab_window, bool owner_events,
164 unsigned int event_mask, int pointer_mode,
165 int keyboard_mode, Window confine_to, Cursor cursor,
166 bool allow_scroll_lock) const;
167 void ungrabButton(unsigned int button, unsigned int modifiers,
168 Window grab_window) const;
169
170 void eventLoop(void);
171
172 // from TimerQueueManager interface
173 virtual void addTimer(BTimer *timer);
174 virtual void removeTimer(BTimer *timer);
175
176 // another pure virtual... this is used to handle signals that BaseDisplay
177 // doesn't understand itself
178 virtual bool handleSignal(int sig) = 0;
179 };
180
181
182 #endif // __BaseDisplay_hh
This page took 0.040078 seconds and 4 git commands to generate.