1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 @brief The main class for the Openbox window manager
17 #include "otk/screeninfo.hh"
18 #include "otk/timerqueuemanager.hh"
19 #include "otk/property.hh"
20 #include "otk/configuration.hh"
21 #include "otk/eventdispatcher.hh"
22 #include "otk/eventhandler.hh"
31 //! Mouse cursors used throughout Openbox
33 Cursor session
; //!< The default mouse cursor
34 Cursor move
; //!< For moving a window
35 Cursor ll_angle
; //!< For resizing the bottom left corner of a window
36 Cursor lr_angle
; //!< For resizing the bottom right corner of a window
37 Cursor ul_angle
; //!< For resizing the top left corner of a window
38 Cursor ur_angle
; //!< For resizing the right corner of a window
42 //! The main class for the Openbox window manager
44 Only a single instance of the Openbox class may be used in the application. A
45 pointer to this instance is held in the Openbox::instance static member
47 Instantiation of this class begins the window manager. After instantiation,
48 the Openbox::eventLoop function should be called. The eventLoop method does
49 not exit until the window manager is ready to be destroyed. Destruction of
50 the Openbox class instance will shutdown the window manager.
52 class Openbox
: public otk::OtkEventDispatcher
, public otk::OtkEventHandler
55 //! The single instance of the Openbox class for the application
57 Since this variable is globally available in the application, the Openbox
58 class does not need to be passed around to any of the other classes.
60 static Openbox
*instance
;
62 //! The posible running states of the window manager
64 State_Starting
, //!< The window manager is starting up (being created)
65 State_Normal
, //!< The window manager is running in its normal state
66 State_Exiting
//!< The window manager is exiting (being destroyed)
69 //! A map for looking up a specific client class from the window id
70 typedef std::map
<Window
, OBClient
*> ClientMap
;
72 //! A list of OBScreen classes
73 typedef std::vector
<OBScreen
*> ScreenList
;
76 // stuff that can be passed on the command line
77 //! Path to the config file to use/in use
79 Defaults to $(HOME)/.openbox/rc3
81 std::string _rcfilepath
;
82 //! Path to the menu file to use/in use
84 Defaults to $(HOME)/.openbox/menu3
86 std::string _menufilepath
;
87 //! Path to the script file to execute on startup
89 Defaults to $(HOME)/.openbox/user.py
91 std::string _scriptfilepath
;
92 //! The display requested by the user, or null to use the DISPLAY env var
94 //! The value of argv, i.e. how this application was executed
96 //! Run the application in synchronous mode? (for debugging)
98 //! Should Openbox run on a single screen or on all available screens?
101 //! A list of all managed clients
104 //! A list of all the managed screens
107 //! Manages all timers for the application
109 Use of the otk::OBTimerQueueManager::fire funtion in this object ensures
110 that all timers fire when their times elapse.
112 otk::OBTimerQueueManager _timermanager
;
114 //! Cached atoms on the display
116 This is a pointer because the OBProperty class uses otk::OBDisplay::display
117 in its constructor, so, it needs to be initialized <b>after</b> the display
118 is initialized in this class' constructor.
120 otk::OBProperty
*_property
;
122 //! The action interface through which all user-available actions occur
125 //! The interface through which keys/buttons are grabbed and handled
126 OBBindings
*_bindings
;
128 //! The running state of the window manager
131 //! Mouse cursors used throughout Openbox
134 //! When set to true, the Openbox::eventLoop function will stop and return
137 //! When set to true, and Openbox is about to exit, it will spawn a new
141 //! If this contains anything, a restart will try to execute the program in
142 //! this variable, and will fallback to reexec'ing itself if that fails
143 std::string _restart_prog
;
145 //! The client with input focus
147 Updated by the clients themselves.
149 OBClient
*_focused_client
;
151 //! The screen with input focus
153 Updated by the clients when they update the Openbox::focused_client
156 OBScreen
*_focused_screen
;
158 //! Parses the command line used when executing this application
159 void parseCommandLine(int argv
, char **argv
);
160 //! Displays the version string to stdout
162 //! Displays usage information and help to stdout
165 //! Handles signal events for the application
166 static void signalHandler(int signal
);
170 //! Openbox constructor.
172 \param argc Number of command line arguments, as received in main()
173 \param argv The command line arguments, as received in main()
175 Openbox(int argc
, char **argv
);
176 //! Openbox destructor.
180 //! Returns the state of the window manager (starting, exiting, etc)
181 inline RunState
state() const { return _state
; }
183 //! Returns the otk::OBTimerQueueManager for the application
185 All otk::OBTimer objects used in the application should be made to use this
186 otk::OBTimerQueueManager.
188 inline otk::OBTimerQueueManager
*timerManager() { return &_timermanager
; }
190 //! Returns the otk::OBProperty instance for the window manager
191 inline const otk::OBProperty
*property() const { return _property
; }
193 //! Returns the OBActions instance for the window manager
194 inline OBActions
*actions() const { return _actions
; }
196 //! Returns the OBBindings instance for the window manager
197 inline OBBindings
*bindings() const { return _bindings
; }
199 //! Returns a managed screen
200 inline OBScreen
*screen(int num
) {
201 assert(num
>= 0); assert(num
< (signed)_screens
.size());
202 if (num
>= screenCount())
204 return _screens
[num
];
207 //! Returns the number of managed screens
208 inline int screenCount() const {
209 return (signed)_screens
.size();
212 //! Returns the mouse cursors used throughout Openbox
213 inline const Cursors
&cursors() const { return _cursors
; }
216 //! The main function of the Openbox class
218 This function should be called after instantiating the Openbox class.
219 It loops indefinately while handling all events for the application.
220 The Openbox::shutdown method will cause this function to exit.
225 //! Adds an OBClient to the client list for lookups
226 void addClient(Window window
, OBClient
*client
);
228 //! Removes an OBClient from the client list for lookups
229 void removeClient(Window window
);
231 //! Finds an OBClient based on its window id
232 OBClient
*findClient(Window window
);
234 //! The client with input focus
235 inline OBClient
*focusedClient() { return _focused_client
; }
237 //! Change the client which has focus.
239 This is called by the clients themselves when their focus state changes.
241 void setFocusedClient(OBClient
*c
);
243 //! The screen with input focus
244 inline OBScreen
*focusedScreen() { return _focused_screen
; }
246 //! Requests that the window manager exit
248 Causes the Openbox::eventLoop function to stop looping, so that the window
249 manager can be destroyed.
251 inline void shutdown() { _shutdown
= true; }
253 inline void restart(const std::string
&bin
= "") {
254 _shutdown
= true; _restart
= true; _restart_prog
= bin
;
257 //! Executes a command on a screen
258 void execute(int screen
, const std::string
&bin
);
263 #endif // __openbox_hh