]> icculus.org git repositories - dana/openbox.git/blob - src/basedisplay.hh
move Rect and PointerAssassin into the toolkit
[dana/openbox.git] / src / basedisplay.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 #ifndef   __BaseDisplay_hh
3 #define   __BaseDisplay_hh
4
5 #include "screeninfo.hh"
6 #include "timer.hh"
7
8 extern "C" {
9 #include <X11/Xlib.h>
10 #include <X11/Xatom.h>
11 }
12
13 #include <vector>
14
15 // forward declaration
16 class BaseDisplay;
17 class BGCCache;
18
19 class BaseDisplay: public TimerQueueManager {
20 private:
21   struct BShape {
22     bool extensions;
23     int event_basep, error_basep;
24   };
25   BShape shape;
26
27 #ifdef    XINERAMA
28   struct BXinerama {
29     bool extensions;
30     int event_basep, error_basep;
31     int major, minor; // version
32   };
33   BXinerama xinerama;
34 #endif // XINERAMA
35
36   unsigned int MaskList[8];
37   size_t MaskListLength;
38
39   enum RunState { STARTUP, RUNNING, SHUTDOWN };
40   RunState run_state;
41
42   Display *display;
43   mutable BGCCache *gccache;
44
45   typedef std::vector<ScreenInfo> ScreenInfoList;
46   ScreenInfoList screenInfoList;
47   TimerQueue timerList;
48
49   const char *display_name, *application_name;
50
51   // no copying!
52   BaseDisplay(const BaseDisplay &);
53   BaseDisplay& operator=(const BaseDisplay&);
54
55 protected:
56   // pure virtual function... you must override this
57   virtual void process_event(XEvent *e) = 0;
58
59   // the masks of the modifiers which are ignored in button events.
60   int NumLockMask, ScrollLockMask;
61
62
63 public:
64   BaseDisplay(const char *app_name, const char *dpy_name = 0);
65   virtual ~BaseDisplay(void);
66
67   const ScreenInfo* getScreenInfo(const unsigned int s) const;
68
69   BGCCache *gcCache(void) const;
70
71   inline bool hasShapeExtensions(void) const
72     { return shape.extensions; }
73 #ifdef    XINERAMA
74   inline bool hasXineramaExtensions(void) const
75     { return xinerama.extensions; }
76 #endif // XINERAMA
77   inline bool doShutdown(void) const
78     { return run_state == SHUTDOWN; }
79   inline bool isStartup(void) const
80     { return run_state == STARTUP; }
81
82   inline Display *getXDisplay(void) const { return display; }
83
84   inline const char *getXDisplayName(void) const
85     { return display_name; }
86   inline const char *getApplicationName(void) const
87     { return application_name; }
88
89   inline unsigned int getNumberOfScreens(void) const
90     { return screenInfoList.size(); }
91   inline int getShapeEventBase(void) const
92     { return shape.event_basep; }
93 #ifdef    XINERAMA
94   inline int getXineramaMajorVersion(void) const
95     { return xinerama.major; }
96 #endif // XINERAMA
97
98   inline void shutdown(void) { run_state = SHUTDOWN; }
99   inline void run(void) { run_state = RUNNING; }
100
101   void grabButton(unsigned int button, unsigned int modifiers,
102                   Window grab_window, bool owner_events,
103                   unsigned int event_mask, int pointer_mode,
104                   int keyboard_mode, Window confine_to, Cursor cursor,
105                   bool allow_scroll_lock) const;
106   void ungrabButton(unsigned int button, unsigned int modifiers,
107                     Window grab_window) const;
108
109   void eventLoop(void);
110
111   // from TimerQueueManager interface
112   virtual void addTimer(BTimer *timer);
113   virtual void removeTimer(BTimer *timer);
114
115   // another pure virtual... this is used to handle signals that BaseDisplay
116   // doesn't understand itself
117   virtual bool handleSignal(int sig) = 0;
118 };
119
120
121 #endif // __BaseDisplay_hh