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
43 //! The single instance of the Openbox class for the application
45 Since this variable is globally available in the application, the Openbox
46 class does not need to be passed around to any of the other classes.
48 extern Openbox
*openbox
;
50 //! The main class for the Openbox window manager
52 Only a single instance of the Openbox class may be used in the application. A
53 pointer to this instance is held in the Openbox::instance static member
55 Instantiation of this class begins the window manager. After instantiation,
56 the Openbox::eventLoop function should be called. The eventLoop method does
57 not exit until the window manager is ready to be destroyed. Destruction of
58 the Openbox class instance will shutdown the window manager.
60 class Openbox
: public otk::EventDispatcher
, public otk::EventHandler
63 //! The posible running states of the window manager
65 State_Starting
, //!< The window manager is starting up (being created)
66 State_Normal
, //!< The window manager is running in its normal state
67 State_Exiting
//!< The window manager is exiting (being destroyed)
70 //! A map for looking up a specific client class from the window id
71 typedef std::map
<Window
, Client
*> ClientMap
;
73 //! A list of Screen classes
74 typedef std::vector
<Screen
*> ScreenList
;
77 // stuff that can be passed on the command line
78 //! Path to the config file to use/in use
80 Defaults to $(HOME)/.openbox/rc3
82 std::string _rcfilepath
;
83 //! Path to the menu file to use/in use
85 Defaults to $(HOME)/.openbox/menu3
87 std::string _menufilepath
;
88 //! Path to the script file to execute on startup
90 Defaults to $(HOME)/.openbox/user.py
92 std::string _scriptfilepath
;
93 //! The display requested by the user, or null to use the DISPLAY env var
95 //! The value of argv, i.e. how this application was executed
97 //! Run the application in synchronous mode? (for debugging)
99 //! Should Openbox run on a single screen or on all available screens?
102 //! A list of all managed clients
105 //! A list of all the managed screens
108 //! Manages all timers for the application
110 Use of the otk::TimerQueueManager::fire funtion in this object ensures
111 that all timers fire when their times elapse.
113 otk::TimerQueueManager _timermanager
;
115 //! Cached atoms on the display
117 This is a pointer because the Property class uses otk::Display::display
118 in its constructor, so, it needs to be initialized <b>after</b> the display
119 is initialized in this class' constructor.
121 otk::Property
*_property
;
123 //! The action interface through which all user-available actions occur
126 //! The interface through which keys/buttons are grabbed and handled
129 //! The running state of the window manager
132 //! Mouse cursors used throughout Openbox
135 //! When set to true, the Openbox::eventLoop function will stop and return
138 //! When set to true, and Openbox is about to exit, it will spawn a new
142 //! If this contains anything, a restart will try to execute the program in
143 //! this variable, and will fallback to reexec'ing itself if that fails
144 std::string _restart_prog
;
146 //! The client with input focus
148 Updated by the clients themselves.
150 Client
*_focused_client
;
152 //! The screen with input focus
154 Updated by the clients when they update the Openbox::focused_client
157 Screen
*_focused_screen
;
159 //! Parses the command line used when executing this application
160 void parseCommandLine(int argv
, char **argv
);
161 //! Displays the version string to stdout
163 //! Displays usage information and help to stdout
166 //! Handles signal events for the application
167 static void signalHandler(int signal
);
171 //! Openbox constructor.
173 \param argc Number of command line arguments, as received in main()
174 \param argv The command line arguments, as received in main()
176 Openbox(int argc
, char **argv
);
177 //! Openbox destructor.
181 //! Returns the state of the window manager (starting, exiting, etc)
182 inline RunState
state() const { return _state
; }
184 //! Returns the otk::TimerQueueManager for the application
186 All otk::Timer objects used in the application should be made to use this
187 otk::TimerQueueManager.
189 inline otk::TimerQueueManager
*timerManager() { return &_timermanager
; }
191 //! Returns the otk::Property instance for the window manager
192 inline const otk::Property
*property() const { return _property
; }
194 //! Returns the Actions instance for the window manager
195 inline Actions
*actions() const { return _actions
; }
197 //! Returns the Bindings instance for the window manager
198 inline Bindings
*bindings() const { return _bindings
; }
200 //! Returns a managed screen
201 inline Screen
*screen(int num
) {
202 assert(num
>= 0); assert(num
< (signed)_screens
.size());
203 if (num
>= screenCount())
205 return _screens
[num
];
208 //! Returns the number of managed screens
209 inline int screenCount() const {
210 return (signed)_screens
.size();
213 //! Returns the mouse cursors used throughout Openbox
214 inline const Cursors
&cursors() const { return _cursors
; }
217 //! The main function of the Openbox class
219 This function should be called after instantiating the Openbox class.
220 It loops indefinately while handling all events for the application.
221 The Openbox::shutdown method will cause this function to exit.
226 //! Adds an Client to the client list for lookups
227 void addClient(Window window
, Client
*client
);
229 //! Removes an Client from the client list for lookups
230 void removeClient(Window window
);
232 //! Finds an Client based on its window id
233 Client
*findClient(Window window
);
235 //! The client with input focus
236 inline Client
*focusedClient() { return _focused_client
; }
238 //! Change the client which has focus.
240 This is called by the clients themselves when their focus state changes.
242 void setFocusedClient(Client
*c
);
244 //! The screen with input focus
245 inline Screen
*focusedScreen() { return _focused_screen
; }
247 //! Requests that the window manager exit
249 Causes the Openbox::eventLoop function to stop looping, so that the window
250 manager can be destroyed.
252 inline void shutdown() { _shutdown
= true; }
254 inline void restart(const std::string
&bin
= "") {
255 _shutdown
= true; _restart
= true; _restart_prog
= bin
;
258 //! Executes a command on a screen
259 void execute(int screen
, const std::string
&bin
);
264 #endif // __openbox_hh