1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 @brief The main class for the Openbox window manager
17 #include "otk/display.hh"
18 #include "otk/screeninfo.hh"
19 #include "otk/timerqueuemanager.hh"
20 #include "otk/property.hh"
21 #include "otk/configuration.hh"
22 #include "otk/eventdispatcher.hh"
23 #include "otk/eventhandler.hh"
32 //! Mouse cursors used throughout Openbox
34 Cursor session
; //!< The default mouse cursor
35 Cursor move
; //!< For moving a window
36 Cursor ll_angle
; //!< For resizing the bottom left corner of a window
37 Cursor lr_angle
; //!< For resizing the bottom right corner of a window
38 Cursor ul_angle
; //!< For resizing the top left corner of a window
39 Cursor ur_angle
; //!< For resizing the right corner of a window
44 //! The single instance of the Openbox class for the application
46 Since this variable is globally available in the application, the Openbox
47 class does not need to be passed around to any of the other classes.
49 extern Openbox
*openbox
;
51 //! The main class for the Openbox window manager
53 Only a single instance of the Openbox class may be used in the application. A
54 pointer to this instance is held in the Openbox::instance static member
56 Instantiation of this class begins the window manager. After instantiation,
57 the Openbox::eventLoop function should be called. The eventLoop method does
58 not exit until the window manager is ready to be destroyed. Destruction of
59 the Openbox class instance will shutdown the window manager.
61 class Openbox
: public otk::EventDispatcher
, public otk::EventHandler
64 //! The posible running states of the window manager
66 State_Starting
, //!< The window manager is starting up (being created)
67 State_Normal
, //!< The window manager is running in its normal state
68 State_Exiting
//!< The window manager is exiting (being destroyed)
71 //! A map for looking up a specific client class from the window id
72 typedef std::map
<Window
, Client
*> ClientMap
;
74 //! A list of Screen classes
75 typedef std::vector
<Screen
*> ScreenList
;
78 //! The display on which Openbox is running
79 otk::Display _display
;
81 // stuff that can be passed on the command line
82 //! Path to the config file to use/in use
84 Defaults to $(HOME)/.openbox/rc3
86 std::string _rcfilepath
;
87 //! Path to the menu file to use/in use
89 Defaults to $(HOME)/.openbox/menu3
91 std::string _menufilepath
;
92 //! Path to the script file to execute on startup
94 Defaults to $(HOME)/.openbox/user.py
96 std::string _scriptfilepath
;
97 //! The display requested by the user, or null to use the DISPLAY env var
99 //! The value of argv, i.e. how this application was executed
101 //! Run the application in synchronous mode? (for debugging)
103 //! Should Openbox run on a single screen or on all available screens?
106 //! A list of all managed clients
109 //! A list of all the managed screens
112 //! Manages all timers for the application
114 Use of the otk::TimerQueueManager::fire funtion in this object ensures
115 that all timers fire when their times elapse.
117 otk::TimerQueueManager _timermanager
;
119 //! Cached atoms on the display
121 This is a pointer because the Property class uses otk::Display::display
122 in its constructor, so, it needs to be initialized <b>after</b> the display
123 is initialized in this class' constructor.
125 otk::Property
*_property
;
127 //! The action interface through which all user-available actions occur
130 //! The interface through which keys/buttons are grabbed and handled
133 //! The running state of the window manager
136 //! Mouse cursors used throughout Openbox
139 //! When set to true, the Openbox::eventLoop function will stop and return
142 //! When set to true, and Openbox is about to exit, it will spawn a new
146 //! If this contains anything, a restart will try to execute the program in
147 //! this variable, and will fallback to reexec'ing itself if that fails
148 std::string _restart_prog
;
150 //! The client with input focus
152 Updated by the clients themselves.
154 Client
*_focused_client
;
156 //! The screen with input focus
158 Updated by the clients when they update the Openbox::focused_client
161 Screen
*_focused_screen
;
163 //! Parses the command line used when executing this application
164 void parseCommandLine(int argv
, char **argv
);
165 //! Displays the version string to stdout
167 //! Displays usage information and help to stdout
170 //! Handles signal events for the application
171 static void signalHandler(int signal
);
175 //! Openbox constructor.
177 \param argc Number of command line arguments, as received in main()
178 \param argv The command line arguments, as received in main()
180 Openbox(int argc
, char **argv
);
181 //! Openbox destructor.
185 //! Returns the state of the window manager (starting, exiting, etc)
186 inline RunState
state() const { return _state
; }
188 //! Returns the otk::TimerQueueManager for the application
190 All otk::Timer objects used in the application should be made to use this
191 otk::TimerQueueManager.
193 inline otk::TimerQueueManager
*timerManager() { return &_timermanager
; }
195 //! Returns the otk::Property instance for the window manager
196 inline const otk::Property
*property() const { return _property
; }
198 //! Returns the Actions instance for the window manager
199 inline Actions
*actions() const { return _actions
; }
201 //! Returns the Bindings instance for the window manager
202 inline Bindings
*bindings() const { return _bindings
; }
204 //! Returns a managed screen
205 inline Screen
*screen(int num
) {
206 assert(num
>= 0); assert(num
< (signed)_screens
.size());
207 if (num
>= screenCount())
209 return _screens
[num
];
212 //! Returns the number of managed screens
213 inline int screenCount() const {
214 return (signed)_screens
.size();
217 //! Returns the mouse cursors used throughout Openbox
218 inline const Cursors
&cursors() const { return _cursors
; }
221 //! The main function of the Openbox class
223 This function should be called after instantiating the Openbox class.
224 It loops indefinately while handling all events for the application.
225 The Openbox::shutdown method will cause this function to exit.
230 //! Adds an Client to the client list for lookups
231 void addClient(Window window
, Client
*client
);
233 //! Removes an Client from the client list for lookups
234 void removeClient(Window window
);
236 //! Finds an Client based on its window id
237 Client
*findClient(Window window
);
239 //! The client with input focus
240 inline Client
*focusedClient() { return _focused_client
; }
242 //! Change the client which has focus.
244 This is called by the clients themselves when their focus state changes.
246 void setFocusedClient(Client
*c
);
248 //! The screen with input focus
249 inline Screen
*focusedScreen() { return _focused_screen
; }
251 //! Requests that the window manager exit
253 Causes the Openbox::eventLoop function to stop looping, so that the window
254 manager can be destroyed.
256 inline void shutdown() { _shutdown
= true; }
258 inline void restart(const std::string
&bin
= "") {
259 _shutdown
= true; _restart
= true; _restart_prog
= bin
;
262 //! Executes a command on a screen
263 void execute(int screen
, const std::string
&bin
);
268 #endif // __openbox_hh