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