version bump
[blackbox.git] / lib / Application.hh
blob555c878eba48f59a6f6c8d0f368f698b474e7b11
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Application.hh for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <shaleh at debian.org>
4 // Copyright (c) 1997 - 2000, 2002 - 2005
5 // Bradley T Hughes <bhughes at trolltech.com>
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
25 #ifndef __Application_hh
26 #define __Application_hh
28 #include "Timer.hh"
29 #include "Util.hh"
31 #include <map>
33 namespace bt {
35 // forward declarations
36 class Display;
37 class EventHandler;
38 class Menu;
41 The application object. It provides event delivery, timer
42 activation and signal handling functionality to fit most
43 application needs.
45 class Application : public TimerQueueManager, public NoCopy {
46 protected:
47 enum RunState { STARTUP, RUNNING, SHUTDOWN, SIGNALLED };
49 private:
50 struct {
51 bool extensions;
52 int event_basep, error_basep;
53 } shape;
55 Display *_display;
56 std::string _app_name;
58 RunState run_state;
59 Time xserver_time;
61 typedef std::map<Window,EventHandler*> EventHandlerMap;
62 EventHandlerMap eventhandlers;
64 timeval currentTime;
65 TimerQueue timerList;
66 void adjustTimers(const timeval &offset);
68 typedef std::deque<Menu*> MenuStack;
69 MenuStack menus;
70 bool menu_grab;
71 void openMenu(Menu *menu);
72 void closeMenu(Menu *menu);
73 friend class Menu; // give Menu access to the above 2 functions
75 unsigned int MaskList[8];
76 size_t MaskListLength;
78 // the masks of the modifiers which are ignored in button events.
79 unsigned int NumLockMask, ScrollLockMask;
81 protected:
82 inline RunState runState(void) const
83 { return run_state; }
84 inline void setRunState(RunState new_state)
85 { run_state = new_state; }
88 Called from run() just before the event loop starts.
90 virtual void startup(void);
92 Called from shutdown() after the event loop stops.
94 virtual void shutdown(void);
97 Processes the X11 event {event} by delivering the event to the
98 appropriate EventHandler.
100 Reimplement this function if you need to filter/intercept events
101 before normal processing.
103 virtual void process_event(XEvent *event);
106 Processes the specified signal. Returns true if the signal was
107 handled; otherwise it returns false.
109 Reimplement this function if you need to handle signals.
111 virtual bool process_signal(int signal);
113 public:
114 Application(const std::string &app_name, const char *dpy_name = 0,
115 bool multi_head = false);
116 virtual ~Application(void);
118 inline bool hasShapeExtensions(void) const
119 { return shape.extensions; }
121 inline bool startingUp(void) const
122 { return run_state == STARTUP; }
123 inline bool running(void) const
124 { return run_state == RUNNING; }
125 inline bool shuttingDown(void) const
126 { return run_state == SHUTDOWN; }
128 ::Display *XDisplay(void) const;
129 inline const Display& display(void) const
130 { return *_display; }
131 inline Time XTime() const
132 { return xserver_time; }
134 inline const std::string &applicationName(void) const
135 { return _app_name; }
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,
141 bool allow_scroll_lock) const;
142 void ungrabButton(unsigned int button, unsigned int modifiers,
143 Window grab_window) const;
145 void run(void);
146 inline void quit(void)
147 { setRunState( SHUTDOWN ); }
149 inline unsigned int scrollLockMask(void) const
150 { return ScrollLockMask; }
151 inline unsigned int numLockMask(void) const
152 { return NumLockMask; }
154 // from TimerQueueManager interface
155 virtual void addTimer(Timer *timer);
156 virtual void removeTimer(Timer *timer);
159 Inserts the EventHandler {handler} for Window {window}. All
160 events generated for {window} will be sent through {handler}.
162 void insertEventHandler(Window window, EventHandler *handler);
164 Removes all EventHandlers for Window {window}.
166 void removeEventHandler(Window window);
168 Returns the event handler registered for Window {window}. If no
169 handler has been registered, this function returns zero.
171 EventHandler *findEventHandler(Window window);
174 } // namespace bt
176 #endif // __Application_hh