]> icculus.org git repositories - mikachu/openbox.git/blob - src/openbox.hh
otk::Timer-ng!! thanks ManMower for this shizznit!
[mikachu/openbox.git] / 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/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   //! The display on which Openbox is running
78   otk::Display _display;
79   
80   // stuff that can be passed on the command line
81   //! Path to the config file to use/in use
82   /*!
83     Defaults to $(HOME)/.openbox/rc3
84   */
85   std::string _rcfilepath;
86   //! Path to the menu file to use/in use
87   /*!
88     Defaults to $(HOME)/.openbox/menu3
89   */
90   std::string _menufilepath;
91   //! Path to the script file to execute on startup
92   /*!
93     Defaults to $(HOME)/.openbox/user.py
94   */
95   std::string _scriptfilepath;
96   //! The display requested by the user, or null to use the DISPLAY env var
97   char *_displayreq;
98   //! The value of argv, i.e. how this application was executed
99   char **_argv;
100   //! Run the application in synchronous mode? (for debugging)
101   bool _sync;
102   //! Should Openbox run on a single screen or on all available screens?
103   bool _single;
104
105   //! A list of all managed clients
106   ClientMap _clients;
107
108   //! A list of all the managed screens
109   ScreenList _screens;
110   
111   //! Cached atoms on the display
112   /*!
113     This is a pointer because the Property class uses otk::Display::display
114     in its constructor, so, it needs to be initialized <b>after</b> the display
115     is initialized in this class' constructor.
116   */
117   otk::Property *_property;
118
119   //! The action interface through which all user-available actions occur
120   Actions *_actions;
121
122   //! The interface through which keys/buttons are grabbed and handled
123   Bindings *_bindings;
124
125   //! The running state of the window manager
126   RunState _state;
127
128   //! Mouse cursors used throughout Openbox
129   Cursors _cursors;
130
131   //! When set to true, the Openbox::eventLoop function will stop and return
132   bool _shutdown;
133
134   //! When set to true, and Openbox is about to exit, it will spawn a new
135   //! process
136   bool _restart;
137
138   //! If this contains anything, a restart will try to execute the program in
139   //! this variable, and will fallback to reexec'ing itself if that fails
140   std::string _restart_prog;
141
142   //! The client with input focus
143   /*!
144     Updated by the clients themselves.
145   */
146   Client *_focused_client;
147
148   //! The screen with input focus
149   /*!
150     Updated by the clients when they update the Openbox::focused_client
151     property.
152   */
153   Screen *_focused_screen;
154   
155   //! Parses the command line used when executing this application
156   void parseCommandLine(int argv, char **argv);
157   //! Displays the version string to stdout
158   void showVersion();
159   //! Displays usage information and help to stdout
160   void showHelp();
161
162   //! Handles signal events for the application
163   static void signalHandler(int signal);
164
165 public:
166 #ifndef SWIG
167   //! Openbox constructor.
168   /*!
169     \param argc Number of command line arguments, as received in main()
170     \param argv The command line arguments, as received in main()
171   */
172   Openbox(int argc, char **argv);
173   //! Openbox destructor.
174   virtual ~Openbox();
175 #endif
176
177   //! Returns the state of the window manager (starting, exiting, etc)
178   inline RunState state() const { return _state; }
179
180   //! Returns the otk::Property instance for the window manager
181   inline const otk::Property *property() const { return _property; }
182
183   //! Returns the Actions instance for the window manager
184   inline Actions *actions() const { return _actions; }
185
186   //! Returns the Bindings instance for the window manager
187   inline Bindings *bindings() const { return _bindings; }
188
189   //! Returns a managed screen
190   inline Screen *screen(int num) {
191     assert(num >= 0); assert(num < (signed)_screens.size());
192     if (num >= screenCount())
193       return NULL;
194     return _screens[num];
195   }
196
197   //! Returns the number of managed screens
198   inline int screenCount() const {
199     return (signed)_screens.size();
200   }
201
202   //! Returns the mouse cursors used throughout Openbox
203   inline const Cursors &cursors() const { return _cursors; }
204
205 #ifndef SWIG
206   //! The main function of the Openbox class
207   /*!
208     This function should be called after instantiating the Openbox class.
209     It loops indefinately while handling all events for the application.
210     The Openbox::shutdown method will cause this function to exit.
211   */
212   void eventLoop();
213 #endif
214
215   //! Adds an Client to the client list for lookups
216   void addClient(Window window, Client *client);
217
218   //! Removes an Client from the client list for lookups
219   void removeClient(Window window);
220
221   //! Finds an Client based on its window id
222   Client *findClient(Window window);
223
224   //! The client with input focus
225   inline Client *focusedClient() { return _focused_client; }
226
227   //! Change the client which has focus.
228   /*!
229     This is called by the clients themselves when their focus state changes.
230   */
231   void setFocusedClient(Client *c);
232
233   //! The screen with input focus
234   inline Screen *focusedScreen() { return _focused_screen; }
235   
236   //! Requests that the window manager exit
237   /*!
238     Causes the Openbox::eventLoop function to stop looping, so that the window
239     manager can be destroyed.
240   */
241   inline void shutdown() { _shutdown = true; }
242
243   inline void restart(const std::string &bin = "") {
244     _shutdown = true; _restart = true; _restart_prog = bin;
245   }
246
247   //! Executes a command on a screen
248   void execute(int screen, const std::string &bin);
249 };
250
251 }
252
253 #endif // __openbox_hh