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)
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:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
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.
24 #ifndef __BaseDisplay_hh
25 #define __BaseDisplay_hh
29 #include <X11/Xatom.h>
35 // forward declaration
44 BaseDisplay *basedisplay;
50 unsigned int screen_number;
51 std::string display_string;
55 ScreenInfo(BaseDisplay *d, unsigned int num);
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; }
72 class BaseDisplay: public TimerQueueManager {
76 int event_basep, error_basep;
81 unsigned int MaskList[8];
82 size_t MaskListLength;
85 enum RunState { STARTUP, RUNNING, SHUTDOWN };
89 mutable BGCCache *gccache;
91 typedef std::vector<ScreenInfo> ScreenInfoList;
92 ScreenInfoList screenInfoList;
95 const char *display_name, *application_name;
98 BaseDisplay(const BaseDisplay &);
99 BaseDisplay& operator=(const BaseDisplay&);
102 // pure virtual function... you must override this
103 virtual void process_event(XEvent *e) = 0;
105 // the masks of the modifiers which are ignored in button events.
106 int NumLockMask, ScrollLockMask;
110 BaseDisplay(const char *app_name, const char *dpy_name = 0);
111 virtual ~BaseDisplay(void);
113 const ScreenInfo* getScreenInfo(const unsigned int s) const;
115 BGCCache *gcCache(void) const;
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; }
124 inline Display *getXDisplay(void) const { return display; }
126 inline const char *getXDisplayName(void) const
127 { return display_name; }
128 inline const char *getApplicationName(void) const
129 { return application_name; }
131 inline unsigned int getNumberOfScreens(void) const
132 { return screenInfoList.size(); }
133 inline int getShapeEventBase(void) const
134 { return shape.event_basep; }
136 inline void shutdown(void) { run_state = SHUTDOWN; }
137 inline void run(void) { run_state = RUNNING; }
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;
146 void eventLoop(void);
148 // from TimerQueueManager interface
149 virtual void addTimer(BTimer *timer);
150 virtual void removeTimer(BTimer *timer);
152 // another pure virtual... this is used to handle signals that BaseDisplay
153 // doesn't understand itself
154 virtual bool handleSignal(int sig) = 0;
158 #endif // __BaseDisplay_hh