]> Dogcows Code - chaz/openbox/blob - src/openbox.hh
9001db60285bd5c6b92c19be305db56dff0420d2
[chaz/openbox] / src / openbox.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __openbox_hh
3 #define __openbox_hh
4
5 /*! @file openbox.hh
6 @brief The main class for the Openbox window manager
7 */
8
9 extern "C" {
10 #include <X11/Xlib.h>
11 }
12
13 #include <string>
14 #include <vector>
15 #include <map>
16
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"
23
24 namespace ob {
25
26 class Screen;
27 class Client;
28 class Actions;
29 class Bindings;
30
31 //! Mouse cursors used throughout Openbox
32 struct Cursors {
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
39 };
40
41 class Openbox;
42
43 //! The single instance of the Openbox class for the application
44 /*!
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.
47 */
48 extern Openbox *openbox;
49
50 //! The main class for the Openbox window manager
51 /*!
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
54 variable.
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.
59 */
60 class Openbox : public otk::EventDispatcher, public otk::EventHandler
61 {
62 public:
63 //! The posible running states of the window manager
64 enum RunState {
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)
68 };
69
70 //! A map for looking up a specific client class from the window id
71 typedef std::map<Window, Client *> ClientMap;
72
73 //! A list of Screen classes
74 typedef std::vector<Screen *> ScreenList;
75
76 private:
77 // stuff that can be passed on the command line
78 //! Path to the config file to use/in use
79 /*!
80 Defaults to $(HOME)/.openbox/rc3
81 */
82 std::string _rcfilepath;
83 //! Path to the menu file to use/in use
84 /*!
85 Defaults to $(HOME)/.openbox/menu3
86 */
87 std::string _menufilepath;
88 //! Path to the script file to execute on startup
89 /*!
90 Defaults to $(HOME)/.openbox/user.py
91 */
92 std::string _scriptfilepath;
93 //! The display requested by the user, or null to use the DISPLAY env var
94 char *_displayreq;
95 //! The value of argv, i.e. how this application was executed
96 char **_argv;
97 //! Run the application in synchronous mode? (for debugging)
98 bool _sync;
99 //! Should Openbox run on a single screen or on all available screens?
100 bool _single;
101
102 //! A list of all managed clients
103 ClientMap _clients;
104
105 //! A list of all the managed screens
106 ScreenList _screens;
107
108 //! Manages all timers for the application
109 /*!
110 Use of the otk::TimerQueueManager::fire funtion in this object ensures
111 that all timers fire when their times elapse.
112 */
113 otk::TimerQueueManager _timermanager;
114
115 //! Cached atoms on the display
116 /*!
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.
120 */
121 otk::Property *_property;
122
123 //! The action interface through which all user-available actions occur
124 Actions *_actions;
125
126 //! The interface through which keys/buttons are grabbed and handled
127 Bindings *_bindings;
128
129 //! The running state of the window manager
130 RunState _state;
131
132 //! Mouse cursors used throughout Openbox
133 Cursors _cursors;
134
135 //! When set to true, the Openbox::eventLoop function will stop and return
136 bool _shutdown;
137
138 //! When set to true, and Openbox is about to exit, it will spawn a new
139 //! process
140 bool _restart;
141
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;
145
146 //! The client with input focus
147 /*!
148 Updated by the clients themselves.
149 */
150 Client *_focused_client;
151
152 //! The screen with input focus
153 /*!
154 Updated by the clients when they update the Openbox::focused_client
155 property.
156 */
157 Screen *_focused_screen;
158
159 //! Parses the command line used when executing this application
160 void parseCommandLine(int argv, char **argv);
161 //! Displays the version string to stdout
162 void showVersion();
163 //! Displays usage information and help to stdout
164 void showHelp();
165
166 //! Handles signal events for the application
167 static void signalHandler(int signal);
168
169 public:
170 #ifndef SWIG
171 //! Openbox constructor.
172 /*!
173 \param argc Number of command line arguments, as received in main()
174 \param argv The command line arguments, as received in main()
175 */
176 Openbox(int argc, char **argv);
177 //! Openbox destructor.
178 virtual ~Openbox();
179 #endif
180
181 //! Returns the state of the window manager (starting, exiting, etc)
182 inline RunState state() const { return _state; }
183
184 //! Returns the otk::TimerQueueManager for the application
185 /*!
186 All otk::Timer objects used in the application should be made to use this
187 otk::TimerQueueManager.
188 */
189 inline otk::TimerQueueManager *timerManager() { return &_timermanager; }
190
191 //! Returns the otk::Property instance for the window manager
192 inline const otk::Property *property() const { return _property; }
193
194 //! Returns the Actions instance for the window manager
195 inline Actions *actions() const { return _actions; }
196
197 //! Returns the Bindings instance for the window manager
198 inline Bindings *bindings() const { return _bindings; }
199
200 //! Returns a managed screen
201 inline Screen *screen(int num) {
202 assert(num >= 0); assert(num < (signed)_screens.size());
203 if (num >= screenCount())
204 return NULL;
205 return _screens[num];
206 }
207
208 //! Returns the number of managed screens
209 inline int screenCount() const {
210 return (signed)_screens.size();
211 }
212
213 //! Returns the mouse cursors used throughout Openbox
214 inline const Cursors &cursors() const { return _cursors; }
215
216 #ifndef SWIG
217 //! The main function of the Openbox class
218 /*!
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.
222 */
223 void eventLoop();
224 #endif
225
226 //! Adds an Client to the client list for lookups
227 void addClient(Window window, Client *client);
228
229 //! Removes an Client from the client list for lookups
230 void removeClient(Window window);
231
232 //! Finds an Client based on its window id
233 Client *findClient(Window window);
234
235 //! The client with input focus
236 inline Client *focusedClient() { return _focused_client; }
237
238 //! Change the client which has focus.
239 /*!
240 This is called by the clients themselves when their focus state changes.
241 */
242 void setFocusedClient(Client *c);
243
244 //! The screen with input focus
245 inline Screen *focusedScreen() { return _focused_screen; }
246
247 //! Requests that the window manager exit
248 /*!
249 Causes the Openbox::eventLoop function to stop looping, so that the window
250 manager can be destroyed.
251 */
252 inline void shutdown() { _shutdown = true; }
253
254 inline void restart(const std::string &bin = "") {
255 _shutdown = true; _restart = true; _restart_prog = bin;
256 }
257
258 //! Executes a command on a screen
259 void execute(int screen, const std::string &bin);
260 };
261
262 }
263
264 #endif // __openbox_hh
This page took 0.047981 seconds and 4 git commands to generate.