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