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>
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
35 // forward declarations
41 The application object. It provides event delivery, timer
42 activation and signal handling functionality to fit most
45 class Application
: public TimerQueueManager
, public NoCopy
{
47 enum RunState
{ STARTUP
, RUNNING
, SHUTDOWN
, SIGNALLED
};
52 int event_basep
, error_basep
;
56 std::string _app_name
;
61 typedef std::map
<Window
,EventHandler
*> EventHandlerMap
;
62 EventHandlerMap eventhandlers
;
66 typedef std::deque
<Menu
*> MenuStack
;
69 void openMenu(Menu
*menu
);
70 void closeMenu(Menu
*menu
);
71 friend class Menu
; // give Menu access to the above 2 functions
73 unsigned int MaskList
[8];
74 size_t MaskListLength
;
76 // the masks of the modifiers which are ignored in button events.
77 unsigned int NumLockMask
, ScrollLockMask
;
80 inline RunState
runState(void) const
82 inline void setRunState(RunState new_state
)
83 { run_state
= new_state
; }
86 Called from run() just before the event loop starts.
88 virtual void startup(void);
90 Called from shutdown() after the event loop stops.
92 virtual void shutdown(void);
95 Processes the X11 event {event} by delivering the event to the
96 appropriate EventHandler.
98 Reimplement this function if you need to filter/intercept events
99 before normal processing.
101 virtual void process_event(XEvent
*event
);
104 Processes the specified signal. Returns true if the signal was
105 handled; otherwise it returns false.
107 Reimplement this function if you need to handle signals.
109 virtual bool process_signal(int signal
);
112 Application(const std::string
&app_name
, const char *dpy_name
= 0,
113 bool multi_head
= false);
114 virtual ~Application(void);
116 inline bool hasShapeExtensions(void) const
117 { return shape
.extensions
; }
119 inline bool startingUp(void) const
120 { return run_state
== STARTUP
; }
121 inline bool running(void) const
122 { return run_state
== RUNNING
; }
123 inline bool shuttingDown(void) const
124 { return run_state
== SHUTDOWN
; }
126 ::Display
*XDisplay(void) const;
127 inline const Display
& display(void) const
128 { return *_display
; }
129 inline Time
XTime() const
130 { return xserver_time
; }
132 inline const std::string
&applicationName(void) const
133 { return _app_name
; }
135 void grabButton(unsigned int button
, unsigned int modifiers
,
136 Window grab_window
, bool owner_events
,
137 unsigned int event_mask
, int pointer_mode
,
138 int keyboard_mode
, Window confine_to
, Cursor cursor
,
139 bool allow_scroll_lock
) const;
140 void ungrabButton(unsigned int button
, unsigned int modifiers
,
141 Window grab_window
) const;
144 inline void quit(void)
145 { setRunState( SHUTDOWN
); }
147 inline unsigned int scrollLockMask(void) const
148 { return ScrollLockMask
; }
149 inline unsigned int numLockMask(void) const
150 { return NumLockMask
; }
152 // from TimerQueueManager interface
153 virtual void addTimer(Timer
*timer
);
154 virtual void removeTimer(Timer
*timer
);
157 Inserts the EventHandler {handler} for Window {window}. All
158 events generated for {window} will be sent through {handler}.
160 void insertEventHandler(Window window
, EventHandler
*handler
);
162 Removes all EventHandlers for Window {window}.
164 void removeEventHandler(Window window
);
166 Returns the event handler registered for Window {window}. If no
167 handler has been registered, this function returns zero.
169 EventHandler
*findEventHandler(Window window
);
174 #endif // __Application_hh