diff options
author | fluxgen <fluxgen> | 2002-08-17 22:11:23 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-08-17 22:11:23 (GMT) |
commit | f1dc9179f068dda1e9bc09b1408157967732847f (patch) | |
tree | 148cead2aeede9bc361e50a6158659d656241796 /src | |
parent | 8e00a92e403451362ce8845148e5558706e5eedd (diff) | |
download | fluxbox_lack-f1dc9179f068dda1e9bc09b1408157967732847f.zip fluxbox_lack-f1dc9179f068dda1e9bc09b1408157967732847f.tar.bz2 |
removed cursor functions, changed to singleton and changed to FbTk EventHandler
Diffstat (limited to 'src')
-rw-r--r-- | src/BaseDisplay.cc | 73 | ||||
-rw-r--r-- | src/BaseDisplay.hh | 26 |
2 files changed, 51 insertions, 48 deletions
diff --git a/src/BaseDisplay.cc b/src/BaseDisplay.cc index 1c29179..d38e2e9 100644 --- a/src/BaseDisplay.cc +++ b/src/BaseDisplay.cc | |||
@@ -22,26 +22,27 @@ | |||
22 | // 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 |
23 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
24 | 24 | ||
25 | // $Id: BaseDisplay.cc,v 1.18 2002/08/14 21:41:21 fluxgen Exp $ | 25 | // $Id: BaseDisplay.cc,v 1.19 2002/08/17 22:11:23 fluxgen Exp $ |
26 | 26 | ||
27 | // use GNU extensions | ||
28 | #ifndef _GNU_SOURCE | ||
29 | #define _GNU_SOURCE | ||
30 | #endif // _GNU_SOURCE | ||
31 | 27 | ||
32 | #ifdef HAVE_CONFIG_H | ||
33 | # include "../config.h" | ||
34 | #endif // HAVE_CONFIG_H | ||
35 | 28 | ||
36 | #include "BaseDisplay.hh" | 29 | #include "BaseDisplay.hh" |
37 | #include "i18n.hh" | 30 | #include "i18n.hh" |
38 | #include "Timer.hh" | 31 | #include "Timer.hh" |
39 | 32 | ||
33 | #ifdef HAVE_CONFIG_H | ||
34 | #include "../config.h" | ||
35 | #endif // HAVE_CONFIG_H | ||
36 | |||
37 | // use GNU extensions | ||
38 | #ifndef _GNU_SOURCE | ||
39 | #define _GNU_SOURCE | ||
40 | #endif // _GNU_SOURCE | ||
41 | |||
40 | #include <X11/Xutil.h> | 42 | #include <X11/Xutil.h> |
41 | #include <X11/cursorfont.h> | ||
42 | 43 | ||
43 | #ifdef SHAPE | 44 | #ifdef SHAPE |
44 | # include <X11/extensions/shape.h> | 45 | #include <X11/extensions/shape.h> |
45 | #endif // SHAPE | 46 | #endif // SHAPE |
46 | 47 | ||
47 | #ifdef HAVE_FCNTL_H | 48 | #ifdef HAVE_FCNTL_H |
@@ -87,17 +88,14 @@ | |||
87 | # include <process.h> | 88 | # include <process.h> |
88 | #endif // HAVE_PROCESS_H __EMX__ | 89 | #endif // HAVE_PROCESS_H __EMX__ |
89 | 90 | ||
90 | #ifdef DEBUG | ||
91 | #include <iostream> | 91 | #include <iostream> |
92 | using namespace std; | 92 | using namespace std; |
93 | #endif | 93 | |
94 | // X error handler to handle any and all X errors while the application is | 94 | // X error handler to handle any and all X errors while the application is |
95 | // running | 95 | // running |
96 | static Bool internal_error = False; | 96 | static Bool internal_error = False; |
97 | static Window last_bad_window = None; | 97 | static Window last_bad_window = None; |
98 | 98 | ||
99 | BaseDisplay *base_display; | ||
100 | |||
101 | #ifdef DEBUG | 99 | #ifdef DEBUG |
102 | static int handleXErrors(Display *d, XErrorEvent *e) { | 100 | static int handleXErrors(Display *d, XErrorEvent *e) { |
103 | char errtxt[128]; | 101 | char errtxt[128]; |
@@ -108,7 +106,7 @@ static int handleXErrors(Display *d, XErrorEvent *e) { | |||
108 | getMessage( | 106 | getMessage( |
109 | FBNLS::BaseDisplaySet, FBNLS::BaseDisplayXError, | 107 | FBNLS::BaseDisplaySet, FBNLS::BaseDisplayXError, |
110 | "%s: X error: %s(%d) opcodes %d/%d\n resource 0x%lx\n"), | 108 | "%s: X error: %s(%d) opcodes %d/%d\n resource 0x%lx\n"), |
111 | base_display->getApplicationName(), errtxt, e->error_code, | 109 | BaseDisplay::instance()->getApplicationName(), errtxt, e->error_code, |
112 | e->request_code, e->minor_code, e->resourceid); | 110 | e->request_code, e->minor_code, e->resourceid); |
113 | 111 | ||
114 | #else // !DEBUG | 112 | #else // !DEBUG |
@@ -137,15 +135,20 @@ void bexec(const char *command, char *displaystring) { | |||
137 | #endif // !__EMX__ | 135 | #endif // !__EMX__ |
138 | 136 | ||
139 | 137 | ||
138 | BaseDisplay *BaseDisplay::s_singleton = 0; | ||
139 | |||
140 | BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name): | 140 | BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name): |
141 | m_startup(true), m_shutdown(false), | 141 | m_startup(true), m_shutdown(false), |
142 | m_display_name(XDisplayName(dpy_name)), m_app_name(app_name), | 142 | m_display_name(XDisplayName(dpy_name)), m_app_name(app_name), |
143 | m_server_grabs(0) | 143 | m_server_grabs(0) |
144 | { | 144 | { |
145 | 145 | if (s_singleton != 0) | |
146 | throw string("Can't create more than one instance of BaseDisplay!"); | ||
147 | |||
148 | s_singleton = this; | ||
149 | |||
146 | last_bad_window = None; | 150 | last_bad_window = None; |
147 | I18n *i18n = I18n::instance(); | 151 | I18n *i18n = I18n::instance(); |
148 | ::base_display = this; | ||
149 | 152 | ||
150 | if (! (m_display = XOpenDisplay(dpy_name))) { | 153 | if (! (m_display = XOpenDisplay(dpy_name))) { |
151 | fprintf(stderr, | 154 | fprintf(stderr, |
@@ -175,33 +178,37 @@ m_server_grabs(0) | |||
175 | shape.extensions = False; | 178 | shape.extensions = False; |
176 | #endif // SHAPE | 179 | #endif // SHAPE |
177 | 180 | ||
178 | cursor.session = XCreateFontCursor(m_display, XC_left_ptr); | 181 | |
179 | cursor.move = XCreateFontCursor(m_display, XC_fleur); | ||
180 | cursor.ll_angle = XCreateFontCursor(m_display, XC_ll_angle); | ||
181 | cursor.lr_angle = XCreateFontCursor(m_display, XC_lr_angle); | ||
182 | |||
183 | XSetErrorHandler((XErrorHandler) handleXErrors); | 182 | XSetErrorHandler((XErrorHandler) handleXErrors); |
184 | 183 | ||
185 | int i; | 184 | for (int i = 0; i < number_of_screens; i++) { |
186 | for (i = 0; i < number_of_screens; i++) { | ||
187 | ScreenInfo *screeninfo = new ScreenInfo(this, i); | 185 | ScreenInfo *screeninfo = new ScreenInfo(this, i); |
188 | screenInfoList.push_back(screeninfo); | 186 | screenInfoList.push_back(screeninfo); |
189 | } | 187 | } |
190 | } | 188 | } |
191 | 189 | ||
192 | 190 | ||
193 | BaseDisplay::~BaseDisplay(void) { | 191 | BaseDisplay::~BaseDisplay() { |
194 | 192 | ||
195 | ScreenInfoList::iterator it = screenInfoList.begin(); | 193 | ScreenInfoList::iterator it = screenInfoList.begin(); |
196 | ScreenInfoList::iterator it_end = screenInfoList.end(); | 194 | ScreenInfoList::iterator it_end = screenInfoList.end(); |
197 | for (; it != it_end; ++it) { | 195 | for (; it != it_end; ++it) { |
198 | delete (*it); | 196 | delete (*it); |
199 | } | 197 | } |
200 | 198 | ||
201 | XCloseDisplay(m_display); | 199 | XCloseDisplay(m_display); |
200 | |||
201 | s_singleton = 0; | ||
202 | } | ||
203 | |||
204 | BaseDisplay *BaseDisplay::instance() { | ||
205 | if (s_singleton == 0) | ||
206 | throw string("BaseDisplay not created!"); | ||
207 | |||
208 | return s_singleton; | ||
202 | } | 209 | } |
203 | 210 | ||
204 | void BaseDisplay::eventLoop(void) { | 211 | void BaseDisplay::eventLoop() { |
205 | run(); | 212 | run(); |
206 | 213 | ||
207 | while ((! m_shutdown) && (! internal_error)) { | 214 | while ((! m_shutdown) && (! internal_error)) { |
@@ -210,17 +217,17 @@ void BaseDisplay::eventLoop(void) { | |||
210 | XNextEvent(m_display, &e); | 217 | XNextEvent(m_display, &e); |
211 | 218 | ||
212 | if (last_bad_window != None && e.xany.window == last_bad_window) { | 219 | if (last_bad_window != None && e.xany.window == last_bad_window) { |
213 | #ifdef DEBUG | 220 | #ifdef DEBUG |
214 | fprintf(stderr, | 221 | fprintf(stderr, |
215 | I18n::instance()-> | 222 | I18n::instance()-> |
216 | getMessage( | 223 | getMessage( |
217 | FBNLS::BaseDisplaySet, FBNLS::BaseDisplayBadWindowRemove, | 224 | FBNLS::BaseDisplaySet, FBNLS::BaseDisplayBadWindowRemove, |
218 | "BaseDisplay::eventLoop(): removing bad window " | 225 | "BaseDisplay::eventLoop(): removing bad window " |
219 | "from event queue\n")); | 226 | "from event queue\n")); |
220 | #endif // DEBUG | 227 | #endif // DEBUG |
221 | } else { | 228 | } else { |
222 | last_bad_window = None; | 229 | last_bad_window = None; |
223 | process_event(&e); | 230 | handleEvent(&e); |
224 | } | 231 | } |
225 | } else { | 232 | } else { |
226 | BTimer::updateTimers(ConnectionNumber(m_display)); //handle all timers | 233 | BTimer::updateTimers(ConnectionNumber(m_display)); //handle all timers |
@@ -240,13 +247,13 @@ bool BaseDisplay::validateWindow(Window window) { | |||
240 | } | 247 | } |
241 | 248 | ||
242 | 249 | ||
243 | void BaseDisplay::grab(void) { | 250 | void BaseDisplay::grab() { |
244 | if (! m_server_grabs++) | 251 | if (! m_server_grabs++) |
245 | XGrabServer(m_display); | 252 | XGrabServer(m_display); |
246 | } | 253 | } |
247 | 254 | ||
248 | 255 | ||
249 | void BaseDisplay::ungrab(void) { | 256 | void BaseDisplay::ungrab() { |
250 | if (! --m_server_grabs) | 257 | if (! --m_server_grabs) |
251 | XUngrabServer(m_display); | 258 | XUngrabServer(m_display); |
252 | if (m_server_grabs < 0) | 259 | if (m_server_grabs < 0) |
diff --git a/src/BaseDisplay.hh b/src/BaseDisplay.hh index 5b2ea2c..1624a05 100644 --- a/src/BaseDisplay.hh +++ b/src/BaseDisplay.hh | |||
@@ -22,12 +22,13 @@ | |||
22 | // 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 |
23 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
24 | 24 | ||
25 | // $Id: BaseDisplay.hh,v 1.25 2002/08/14 21:21:30 fluxgen Exp $ | 25 | // $Id: BaseDisplay.hh,v 1.26 2002/08/17 22:10:03 fluxgen Exp $ |
26 | 26 | ||
27 | #ifndef BASEDISPLAY_HH | 27 | #ifndef BASEDISPLAY_HH |
28 | #define BASEDISPLAY_HH | 28 | #define BASEDISPLAY_HH |
29 | 29 | ||
30 | #include "NotCopyable.hh" | 30 | #include "NotCopyable.hh" |
31 | #include "EventHandler.hh" | ||
31 | 32 | ||
32 | #include <X11/Xlib.h> | 33 | #include <X11/Xlib.h> |
33 | 34 | ||
@@ -48,12 +49,16 @@ class ScreenInfo; | |||
48 | 49 | ||
49 | /// obsolete | 50 | /// obsolete |
50 | void bexec(const char *command, char *displaystring); | 51 | void bexec(const char *command, char *displaystring); |
51 | 52 | /** | |
52 | class BaseDisplay:private NotCopyable | 53 | Singleton class to manage display connection |
54 | */ | ||
55 | class BaseDisplay:private NotCopyable, FbTk::EventHandler<XEvent> | ||
53 | { | 56 | { |
54 | public: | 57 | public: |
55 | BaseDisplay(const char *app_name, const char *display_name = 0); | 58 | BaseDisplay(const char *app_name, const char *display_name = 0); |
56 | virtual ~BaseDisplay(); | 59 | virtual ~BaseDisplay(); |
60 | static BaseDisplay *instance(); | ||
61 | |||
57 | /** | 62 | /** |
58 | obsolete | 63 | obsolete |
59 | @see FluxboxWindow | 64 | @see FluxboxWindow |
@@ -86,11 +91,7 @@ public: | |||
86 | inline bool doShutdown() const { return m_shutdown; } | 91 | inline bool doShutdown() const { return m_shutdown; } |
87 | inline bool isStartup() const { return m_startup; } | 92 | inline bool isStartup() const { return m_startup; } |
88 | 93 | ||
89 | inline const Cursor &getSessionCursor() const { return cursor.session; } | 94 | |
90 | inline const Cursor &getMoveCursor() const { return cursor.move; } | ||
91 | inline const Cursor &getLowerLeftAngleCursor() const { return cursor.ll_angle; } | ||
92 | inline const Cursor &getLowerRightAngleCursor() const { return cursor.lr_angle; } | ||
93 | |||
94 | inline Display *getXDisplay() { return m_display; } | 95 | inline Display *getXDisplay() { return m_display; } |
95 | 96 | ||
96 | inline const char *getXDisplayName() const { return m_display_name; } | 97 | inline const char *getXDisplayName() const { return m_display_name; } |
@@ -119,13 +120,7 @@ public: | |||
119 | BaseDisplay &m_bd; | 120 | BaseDisplay &m_bd; |
120 | }; | 121 | }; |
121 | 122 | ||
122 | protected: | ||
123 | virtual void process_event(XEvent *) = 0; | ||
124 | |||
125 | private: | 123 | private: |
126 | struct cursor { | ||
127 | Cursor session, move, ll_angle, lr_angle; | ||
128 | } cursor; | ||
129 | 124 | ||
130 | struct shape { | 125 | struct shape { |
131 | Bool extensions; | 126 | Bool extensions; |
@@ -139,8 +134,9 @@ private: | |||
139 | ScreenInfoList screenInfoList; | 134 | ScreenInfoList screenInfoList; |
140 | 135 | ||
141 | const char *m_display_name, *m_app_name; | 136 | const char *m_display_name, *m_app_name; |
142 | int number_of_screens, m_server_grabs, colors_per_channel; | 137 | int number_of_screens, m_server_grabs; |
143 | 138 | ||
139 | static BaseDisplay *s_singleton; | ||
144 | }; | 140 | }; |
145 | 141 | ||
146 | 142 | ||