]> Dogcows Code - chaz/openbox/blob - src/openbox.hh
163b9132e0e6794dd548b436390ff88dc04a20cc
[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/configuration.hh"
20 #include "otk/eventdispatcher.hh"
21 #include "otk/eventhandler.hh"
22
23 namespace ob {
24
25 class Screen;
26 class Client;
27 class Actions;
28 class Bindings;
29
30 //! Mouse cursors used throughout Openbox
31 struct Cursors {
32 Cursor session; //!< The default mouse cursor
33 Cursor move; //!< For moving a window
34 Cursor ll_angle; //!< For resizing the bottom left corner of a window
35 Cursor lr_angle; //!< For resizing the bottom right corner of a window
36 Cursor ul_angle; //!< For resizing the top left corner of a window
37 Cursor ur_angle; //!< For resizing the right corner of a window
38 };
39
40 class Openbox;
41
42 //! The single instance of the Openbox class for the application
43 /*!
44 Since this variable is globally available in the application, the Openbox
45 class does not need to be passed around to any of the other classes.
46 */
47 extern Openbox *openbox;
48
49 //! The main class for the Openbox window manager
50 /*!
51 Only a single instance of the Openbox class may be used in the application. A
52 pointer to this instance is held in the Openbox::instance static member
53 variable.
54 Instantiation of this class begins the window manager. After instantiation,
55 the Openbox::eventLoop function should be called. The eventLoop method does
56 not exit until the window manager is ready to be destroyed. Destruction of
57 the Openbox class instance will shutdown the window manager.
58 */
59 class Openbox : public otk::EventDispatcher, public otk::EventHandler
60 {
61 public:
62 //! The posible running states of the window manager
63 enum RunState {
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)
67 };
68
69 //! A map for looking up a specific client class from the window id
70 typedef std::map<Window, Client *> ClientMap;
71
72 //! A list of Screen classes
73 typedef std::vector<Screen *> ScreenList;
74
75 private:
76 //! The display on which Openbox is running
77 otk::Display _display;
78
79 // stuff that can be passed on the command line
80 //! Path to the config file to use/in use
81 /*!
82 Defaults to $(HOME)/.openbox/rc3
83 */
84 std::string _rcfilepath;
85 //! Path to the menu file to use/in use
86 /*!
87 Defaults to $(HOME)/.openbox/menu3
88 */
89 std::string _menufilepath;
90 //! Path to the script file to execute on startup
91 /*!
92 Defaults to $(HOME)/.openbox/user.py
93 */
94 std::string _scriptfilepath;
95 //! The display requested by the user, or null to use the DISPLAY env var
96 char *_displayreq;
97 //! The value of argv, i.e. how this application was executed
98 char **_argv;
99 //! Run the application in synchronous mode? (for debugging)
100 bool _sync;
101 //! Should Openbox run on a single screen or on all available screens?
102 bool _single;
103
104 //! A list of all managed clients
105 ClientMap _clients;
106
107 //! A list of all the managed screens
108 ScreenList _screens;
109
110 //! The action interface through which all user-available actions occur
111 Actions *_actions;
112
113 //! The interface through which keys/buttons are grabbed and handled
114 Bindings *_bindings;
115
116 //! The running state of the window manager
117 RunState _state;
118
119 //! Mouse cursors used throughout Openbox
120 Cursors _cursors;
121
122 //! When set to true, the Openbox::eventLoop function will stop and return
123 bool _shutdown;
124
125 //! When set to true, and Openbox is about to exit, it will spawn a new
126 //! process
127 bool _restart;
128
129 //! If this contains anything, a restart will try to execute the program in
130 //! this variable, and will fallback to reexec'ing itself if that fails
131 std::string _restart_prog;
132
133 //! The client with input focus
134 /*!
135 Updated by the clients themselves.
136 */
137 Client *_focused_client;
138
139 //! The screen with input focus
140 /*!
141 Updated by the clients when they update the Openbox::focused_client
142 property.
143 */
144 Screen *_focused_screen;
145
146 //! Parses the command line used when executing this application
147 void parseCommandLine(int argv, char **argv);
148 //! Displays the version string to stdout
149 void showVersion();
150 //! Displays usage information and help to stdout
151 void showHelp();
152
153 //! Handles signal events for the application
154 static void signalHandler(int signal);
155
156 public:
157 #ifndef SWIG
158 //! Openbox constructor.
159 /*!
160 \param argc Number of command line arguments, as received in main()
161 \param argv The command line arguments, as received in main()
162 */
163 Openbox(int argc, char **argv);
164 //! Openbox destructor.
165 virtual ~Openbox();
166 #endif
167
168 //! Returns the state of the window manager (starting, exiting, etc)
169 inline RunState state() const { return _state; }
170
171 //! Returns the Actions instance for the window manager
172 inline Actions *actions() const { return _actions; }
173
174 //! Returns the Bindings instance for the window manager
175 inline Bindings *bindings() const { return _bindings; }
176
177 //! Returns a managed screen or a null pointer
178 /*!
179 ALWAYS check the return value for a non-null, as any unmanaged screens
180 will return one. This includes screen(0) if the first managed screen is 1.
181 */
182 inline Screen *screen(int num) {
183 assert(num >= 0); assert(num < (signed)ScreenCount(**otk::display));
184 if (num >= (signed)_screens.size()) return 0;
185 return _screens[num];
186 }
187
188 //! Returns the mouse cursors used throughout Openbox
189 inline const Cursors &cursors() const { return _cursors; }
190
191 #ifndef SWIG
192 //! The main function of the Openbox class
193 /*!
194 This function should be called after instantiating the Openbox class.
195 It loops indefinately while handling all events for the application.
196 The Openbox::shutdown method will cause this function to exit.
197 */
198 void eventLoop();
199 #endif
200
201 //! Adds an Client to the client list for lookups
202 void addClient(Window window, Client *client);
203
204 //! Removes an Client from the client list for lookups
205 void removeClient(Window window);
206
207 //! Finds an Client based on its window id
208 Client *findClient(Window window);
209
210 //! The client with input focus
211 inline Client *focusedClient() { return _focused_client; }
212
213 //! Change the client which has focus.
214 /*!
215 This is called by the clients themselves when their focus state changes.
216 */
217 void setFocusedClient(Client *c);
218
219 //! The screen with input focus
220 inline Screen *focusedScreen() { return _focused_screen; }
221
222 //! Requests that the window manager exit
223 /*!
224 Causes the Openbox::eventLoop function to stop looping, so that the window
225 manager can be destroyed.
226 */
227 inline void shutdown() { _shutdown = true; }
228
229 inline void restart(const std::string &bin = "") {
230 _shutdown = true; _restart = true; _restart_prog = bin;
231 }
232 };
233
234 }
235
236 #endif // __openbox_hh
This page took 0.043871 seconds and 3 git commands to generate.