]> icculus.org git repositories - mikachu/openbox.git/blob - src/BaseDisplay.hh
make use of the --enable-clobber option
[mikachu/openbox.git] / 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
54 public:
55   ScreenInfo(BaseDisplay *d, unsigned int num);
56
57   inline BaseDisplay *getBaseDisplay(void) const { return basedisplay; }
58   inline Visual *getVisual(void) const { return visual; }
59   inline Window getRootWindow(void) const { return root_window; }
60   inline Colormap getColormap(void) const { return colormap; }
61   inline int getDepth(void) const { return depth; }
62   inline unsigned int getScreenNumber(void) const
63     { return screen_number; }
64   inline const Rect& getRect(void) const { return rect; }
65   inline unsigned int getWidth(void) const { return rect.width(); }
66   inline unsigned int getHeight(void) const { return rect.height(); }
67   inline const std::string& displayString(void) const
68   { return display_string; }
69 };
70
71
72 class BaseDisplay: public TimerQueueManager {
73 private:
74   struct BShape {
75     bool extensions;
76     int event_basep, error_basep;
77   };
78   BShape shape;
79
80 #ifndef   NOCLOBBER
81   unsigned int MaskList[8];
82   size_t MaskListLength;
83 #endif // NOCLOBBER
84
85   enum RunState { STARTUP, RUNNING, SHUTDOWN };
86   RunState run_state;
87
88   Display *display;
89   mutable BGCCache *gccache;
90
91   typedef std::vector<ScreenInfo> ScreenInfoList;
92   ScreenInfoList screenInfoList;
93   TimerQueue timerList;
94
95   const char *display_name, *application_name;
96
97   // no copying!
98   BaseDisplay(const BaseDisplay &);
99   BaseDisplay& operator=(const BaseDisplay&);
100
101 protected:
102   // pure virtual function... you must override this
103   virtual void process_event(XEvent *e) = 0;
104
105   // the masks of the modifiers which are ignored in button events.
106   int NumLockMask, ScrollLockMask;
107
108
109 public:
110   BaseDisplay(const char *app_name, const char *dpy_name = 0);
111   virtual ~BaseDisplay(void);
112
113   const ScreenInfo* getScreenInfo(const unsigned int s) const;
114
115   BGCCache *gcCache(void) const;
116
117   inline bool hasShapeExtensions(void) const
118     { return shape.extensions; }
119   inline bool doShutdown(void) const
120     { return run_state == SHUTDOWN; }
121   inline bool isStartup(void) const
122     { return run_state == STARTUP; }
123
124   inline Display *getXDisplay(void) const { return display; }
125
126   inline const char *getXDisplayName(void) const
127     { return display_name; }
128   inline const char *getApplicationName(void) const
129     { return application_name; }
130
131   inline unsigned int getNumberOfScreens(void) const
132     { return screenInfoList.size(); }
133   inline int getShapeEventBase(void) const
134     { return shape.event_basep; }
135
136   inline void shutdown(void) { run_state = SHUTDOWN; }
137   inline void run(void) { run_state = RUNNING; }
138
139   void grabButton(unsigned int button, unsigned int modifiers,
140                   Window grab_window, bool owner_events,
141                   unsigned int event_mask, int pointer_mode,
142                   int keyboard_mode, Window confine_to, Cursor cursor) const;
143   void ungrabButton(unsigned int button, unsigned int modifiers,
144                     Window grab_window) const;
145
146   void eventLoop(void);
147
148   // from TimerQueueManager interface
149   virtual void addTimer(BTimer *timer);
150   virtual void removeTimer(BTimer *timer);
151
152   // another pure virtual... this is used to handle signals that BaseDisplay
153   // doesn't understand itself
154   virtual bool handleSignal(int sig) = 0;
155 };
156
157
158 #endif // __BaseDisplay_hh