]> Dogcows Code - chaz/openbox/blob - src/BaseDisplay.hh
build a 'openbox' binary
[chaz/openbox] / 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 unsigned int MaskList[8];
81 size_t MaskListLength;
82
83 enum RunState { STARTUP, RUNNING, SHUTDOWN };
84 RunState run_state;
85
86 Display *display;
87 mutable BGCCache *gccache;
88
89 typedef std::vector<ScreenInfo> ScreenInfoList;
90 ScreenInfoList screenInfoList;
91 TimerQueue timerList;
92
93 const char *display_name, *application_name;
94
95 // no copying!
96 BaseDisplay(const BaseDisplay &);
97 BaseDisplay& operator=(const BaseDisplay&);
98
99 protected:
100 // pure virtual function... you must override this
101 virtual void process_event(XEvent *e) = 0;
102
103 // the masks of the modifiers which are ignored in button events.
104 int NumLockMask, ScrollLockMask;
105
106
107 public:
108 BaseDisplay(const char *app_name, const char *dpy_name = 0);
109 virtual ~BaseDisplay(void);
110
111 const ScreenInfo* getScreenInfo(const unsigned int s) const;
112
113 BGCCache *gcCache(void) const;
114
115 inline bool hasShapeExtensions(void) const
116 { return shape.extensions; }
117 inline bool doShutdown(void) const
118 { return run_state == SHUTDOWN; }
119 inline bool isStartup(void) const
120 { return run_state == STARTUP; }
121
122 inline Display *getXDisplay(void) const { return display; }
123
124 inline const char *getXDisplayName(void) const
125 { return display_name; }
126 inline const char *getApplicationName(void) const
127 { return application_name; }
128
129 inline unsigned int getNumberOfScreens(void) const
130 { return screenInfoList.size(); }
131 inline int getShapeEventBase(void) const
132 { return shape.event_basep; }
133
134 inline void shutdown(void) { run_state = SHUTDOWN; }
135 inline void run(void) { run_state = RUNNING; }
136
137 void grabButton(unsigned int button, unsigned int modifiers,
138 Window grab_window, bool owner_events,
139 unsigned int event_mask, int pointer_mode,
140 int keyboard_mode, Window confine_to, Cursor cursor) const;
141 void ungrabButton(unsigned int button, unsigned int modifiers,
142 Window grab_window) const;
143
144 void eventLoop(void);
145
146 // from TimerQueueManager interface
147 virtual void addTimer(BTimer *timer);
148 virtual void removeTimer(BTimer *timer);
149
150 // another pure virtual... this is used to handle signals that BaseDisplay
151 // doesn't understand itself
152 virtual bool handleSignal(int sig) = 0;
153 };
154
155
156 #endif // __BaseDisplay_hh
This page took 0.045245 seconds and 4 git commands to generate.