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