From f1dc9179f068dda1e9bc09b1408157967732847f Mon Sep 17 00:00:00 2001 From: fluxgen <fluxgen> Date: Sat, 17 Aug 2002 22:11:23 +0000 Subject: removed cursor functions, changed to singleton and changed to FbTk EventHandler --- src/BaseDisplay.cc | 73 ++++++++++++++++++++++++++++++------------------------ 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: BaseDisplay.cc,v 1.18 2002/08/14 21:41:21 fluxgen Exp $ +// $Id: BaseDisplay.cc,v 1.19 2002/08/17 22:11:23 fluxgen Exp $ -// use GNU extensions -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif // _GNU_SOURCE -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif // HAVE_CONFIG_H #include "BaseDisplay.hh" #include "i18n.hh" #include "Timer.hh" +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif // HAVE_CONFIG_H + +// use GNU extensions +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif // _GNU_SOURCE + #include <X11/Xutil.h> -#include <X11/cursorfont.h> -#ifdef SHAPE -# include <X11/extensions/shape.h> +#ifdef SHAPE +#include <X11/extensions/shape.h> #endif // SHAPE #ifdef HAVE_FCNTL_H @@ -87,17 +88,14 @@ # include <process.h> #endif // HAVE_PROCESS_H __EMX__ -#ifdef DEBUG #include <iostream> using namespace std; -#endif + // X error handler to handle any and all X errors while the application is // running static Bool internal_error = False; static Window last_bad_window = None; -BaseDisplay *base_display; - #ifdef DEBUG static int handleXErrors(Display *d, XErrorEvent *e) { char errtxt[128]; @@ -108,7 +106,7 @@ static int handleXErrors(Display *d, XErrorEvent *e) { getMessage( FBNLS::BaseDisplaySet, FBNLS::BaseDisplayXError, "%s: X error: %s(%d) opcodes %d/%d\n resource 0x%lx\n"), - base_display->getApplicationName(), errtxt, e->error_code, + BaseDisplay::instance()->getApplicationName(), errtxt, e->error_code, e->request_code, e->minor_code, e->resourceid); #else // !DEBUG @@ -137,15 +135,20 @@ void bexec(const char *command, char *displaystring) { #endif // !__EMX__ +BaseDisplay *BaseDisplay::s_singleton = 0; + BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name): m_startup(true), m_shutdown(false), m_display_name(XDisplayName(dpy_name)), m_app_name(app_name), m_server_grabs(0) { - + if (s_singleton != 0) + throw string("Can't create more than one instance of BaseDisplay!"); + + s_singleton = this; + last_bad_window = None; I18n *i18n = I18n::instance(); - ::base_display = this; if (! (m_display = XOpenDisplay(dpy_name))) { fprintf(stderr, @@ -175,33 +178,37 @@ m_server_grabs(0) shape.extensions = False; #endif // SHAPE - cursor.session = XCreateFontCursor(m_display, XC_left_ptr); - cursor.move = XCreateFontCursor(m_display, XC_fleur); - cursor.ll_angle = XCreateFontCursor(m_display, XC_ll_angle); - cursor.lr_angle = XCreateFontCursor(m_display, XC_lr_angle); - + XSetErrorHandler((XErrorHandler) handleXErrors); - int i; - for (i = 0; i < number_of_screens; i++) { + for (int i = 0; i < number_of_screens; i++) { ScreenInfo *screeninfo = new ScreenInfo(this, i); screenInfoList.push_back(screeninfo); } } -BaseDisplay::~BaseDisplay(void) { +BaseDisplay::~BaseDisplay() { ScreenInfoList::iterator it = screenInfoList.begin(); ScreenInfoList::iterator it_end = screenInfoList.end(); for (; it != it_end; ++it) { delete (*it); } - + XCloseDisplay(m_display); + + s_singleton = 0; +} + +BaseDisplay *BaseDisplay::instance() { + if (s_singleton == 0) + throw string("BaseDisplay not created!"); + + return s_singleton; } -void BaseDisplay::eventLoop(void) { +void BaseDisplay::eventLoop() { run(); while ((! m_shutdown) && (! internal_error)) { @@ -210,17 +217,17 @@ void BaseDisplay::eventLoop(void) { XNextEvent(m_display, &e); if (last_bad_window != None && e.xany.window == last_bad_window) { - #ifdef DEBUG +#ifdef DEBUG fprintf(stderr, I18n::instance()-> getMessage( FBNLS::BaseDisplaySet, FBNLS::BaseDisplayBadWindowRemove, "BaseDisplay::eventLoop(): removing bad window " "from event queue\n")); - #endif // DEBUG +#endif // DEBUG } else { last_bad_window = None; - process_event(&e); + handleEvent(&e); } } else { BTimer::updateTimers(ConnectionNumber(m_display)); //handle all timers @@ -240,13 +247,13 @@ bool BaseDisplay::validateWindow(Window window) { } -void BaseDisplay::grab(void) { +void BaseDisplay::grab() { if (! m_server_grabs++) XGrabServer(m_display); } -void BaseDisplay::ungrab(void) { +void BaseDisplay::ungrab() { if (! --m_server_grabs) XUngrabServer(m_display); 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: BaseDisplay.hh,v 1.25 2002/08/14 21:21:30 fluxgen Exp $ +// $Id: BaseDisplay.hh,v 1.26 2002/08/17 22:10:03 fluxgen Exp $ #ifndef BASEDISPLAY_HH #define BASEDISPLAY_HH #include "NotCopyable.hh" +#include "EventHandler.hh" #include <X11/Xlib.h> @@ -48,12 +49,16 @@ class ScreenInfo; /// obsolete void bexec(const char *command, char *displaystring); - -class BaseDisplay:private NotCopyable +/** + Singleton class to manage display connection +*/ +class BaseDisplay:private NotCopyable, FbTk::EventHandler<XEvent> { public: BaseDisplay(const char *app_name, const char *display_name = 0); virtual ~BaseDisplay(); + static BaseDisplay *instance(); + /** obsolete @see FluxboxWindow @@ -86,11 +91,7 @@ public: inline bool doShutdown() const { return m_shutdown; } inline bool isStartup() const { return m_startup; } - inline const Cursor &getSessionCursor() const { return cursor.session; } - inline const Cursor &getMoveCursor() const { return cursor.move; } - inline const Cursor &getLowerLeftAngleCursor() const { return cursor.ll_angle; } - inline const Cursor &getLowerRightAngleCursor() const { return cursor.lr_angle; } - + inline Display *getXDisplay() { return m_display; } inline const char *getXDisplayName() const { return m_display_name; } @@ -119,13 +120,7 @@ public: BaseDisplay &m_bd; }; -protected: - virtual void process_event(XEvent *) = 0; - private: - struct cursor { - Cursor session, move, ll_angle, lr_angle; - } cursor; struct shape { Bool extensions; @@ -139,8 +134,9 @@ private: ScreenInfoList screenInfoList; const char *m_display_name, *m_app_name; - int number_of_screens, m_server_grabs, colors_per_channel; + int number_of_screens, m_server_grabs; + static BaseDisplay *s_singleton; }; -- cgit v0.11.2