00001 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- 00002 #ifndef __openbox_hh 00003 #define __openbox_hh 00004 00005 /*! @file openbox.hh 00006 @brief The main class for the Openbox window manager 00007 */ 00008 00009 extern "C" { 00010 #include <X11/Xlib.h> 00011 } 00012 00013 #include <string> 00014 #include <vector> 00015 #include <map> 00016 00017 #include "otk/display.hh" 00018 #include "otk/screeninfo.hh" 00019 #include "otk/eventdispatcher.hh" 00020 #include "otk/eventhandler.hh" 00021 00022 namespace ob { 00023 00024 class Screen; 00025 class Client; 00026 class Actions; 00027 class Bindings; 00028 00029 //! Mouse cursors used throughout Openbox 00030 struct Cursors { 00031 Cursor session; //!< The default mouse cursor 00032 Cursor move; //!< For moving a window 00033 Cursor ll_angle; //!< For resizing the bottom left corner of a window 00034 Cursor lr_angle; //!< For resizing the bottom right corner of a window 00035 Cursor ul_angle; //!< For resizing the top left corner of a window 00036 Cursor ur_angle; //!< For resizing the right corner of a window 00037 }; 00038 00039 class Openbox; 00040 00041 //! The single instance of the Openbox class for the application 00042 /*! 00043 Since this variable is globally available in the application, the Openbox 00044 class does not need to be passed around to any of the other classes. 00045 */ 00046 extern Openbox *openbox; 00047 00048 //! The main class for the Openbox window manager 00049 /*! 00050 Only a single instance of the Openbox class may be used in the application. A 00051 pointer to this instance is held in the Openbox::instance static member 00052 variable. 00053 Instantiation of this class begins the window manager. After instantiation, 00054 the Openbox::eventLoop function should be called. The eventLoop method does 00055 not exit until the window manager is ready to be destroyed. Destruction of 00056 the Openbox class instance will shutdown the window manager. 00057 */ 00058 class Openbox : public otk::EventDispatcher, public otk::EventHandler 00059 { 00060 public: 00061 //! The posible running states of the window manager 00062 enum RunState { 00063 State_Starting, //!< The window manager is starting up (being created) 00064 State_Normal, //!< The window manager is running in its normal state 00065 State_Exiting //!< The window manager is exiting (being destroyed) 00066 }; 00067 00068 //! A map for looking up a specific client class from the window id 00069 typedef std::map<Window, Client *> ClientMap; 00070 00071 //! A list of Screen classes 00072 typedef std::vector<Screen *> ScreenList; 00073 00074 private: 00075 //! The display on which Openbox is running 00076 otk::Display _display; 00077 00078 // stuff that can be passed on the command line 00079 //! Path to the config file to use/in use 00080 /*! 00081 Defaults to $(HOME)/.openbox/rc3 00082 */ 00083 std::string _rcfilepath; 00084 //! Path to the menu file to use/in use 00085 /*! 00086 Defaults to $(HOME)/.openbox/menu3 00087 */ 00088 std::string _menufilepath; 00089 //! Path to the script file to execute on startup 00090 /*! 00091 Defaults to $(HOME)/.openbox/user.py 00092 */ 00093 std::string _scriptfilepath; 00094 //! The display requested by the user, or null to use the DISPLAY env var 00095 char *_displayreq; 00096 //! The value of argv, i.e. how this application was executed 00097 char **_argv; 00098 //! Run the application in synchronous mode? (for debugging) 00099 bool _sync; 00100 //! Should Openbox run on a single screen or on all available screens? 00101 bool _single; 00102 00103 //! A list of all managed clients 00104 ClientMap _clients; 00105 00106 //! A list of all the managed screens 00107 ScreenList _screens; 00108 00109 //! The action interface through which all user-available actions occur 00110 Actions *_actions; 00111 00112 //! The interface through which keys/buttons are grabbed and handled 00113 Bindings *_bindings; 00114 00115 //! The running state of the window manager 00116 RunState _state; 00117 00118 //! Mouse cursors used throughout Openbox 00119 Cursors _cursors; 00120 00121 //! When set to true, the Openbox::eventLoop function will stop and return 00122 bool _shutdown; 00123 00124 //! When set to true, and Openbox is about to exit, it will spawn a new 00125 //! process 00126 bool _restart; 00127 00128 //! If this contains anything, a restart will try to execute the program in 00129 //! this variable, and will fallback to reexec'ing itself if that fails 00130 std::string _restart_prog; 00131 00132 //! The client with input focus 00133 /*! 00134 Updated by the clients themselves. 00135 */ 00136 Client *_focused_client; 00137 00138 //! The screen with input focus 00139 /*! 00140 Updated by the clients when they update the Openbox::focused_client 00141 property. 00142 */ 00143 Screen *_focused_screen; 00144 00145 //! Parses the command line used when executing this application 00146 void parseCommandLine(int argv, char **argv); 00147 //! Displays the version string to stdout 00148 void showVersion(); 00149 //! Displays usage information and help to stdout 00150 void showHelp(); 00151 00152 //! Handles signal events for the application 00153 static void signalHandler(int signal); 00154 00155 public: 00156 #ifndef SWIG 00157 //! Openbox constructor. 00158 /*! 00159 \param argc Number of command line arguments, as received in main() 00160 \param argv The command line arguments, as received in main() 00161 */ 00162 Openbox(int argc, char **argv); 00163 //! Openbox destructor. 00164 virtual ~Openbox(); 00165 #endif 00166 00167 //! Returns the state of the window manager (starting, exiting, etc) 00168 inline RunState state() const { return _state; } 00169 00170 //! Returns the Actions instance for the window manager 00171 inline Actions *actions() const { return _actions; } 00172 00173 //! Returns the Bindings instance for the window manager 00174 inline Bindings *bindings() const { return _bindings; } 00175 00176 //! Returns a managed screen or a null pointer 00177 /*! 00178 ALWAYS check the return value for a non-null, as any unmanaged screens 00179 will return one. This includes screen(0) if the first managed screen is 1. 00180 */ 00181 inline Screen *screen(int num) { 00182 assert(num >= 0); assert(num < (signed)ScreenCount(**otk::display)); 00183 if (num >= (signed)_screens.size()) return 0; 00184 return _screens[num]; 00185 } 00186 00187 //! Returns the mouse cursors used throughout Openbox 00188 inline const Cursors &cursors() const { return _cursors; } 00189 00190 #ifndef SWIG 00191 //! The main function of the Openbox class 00192 /*! 00193 This function should be called after instantiating the Openbox class. 00194 It loops indefinately while handling all events for the application. 00195 The Openbox::shutdown method will cause this function to exit. 00196 */ 00197 void eventLoop(); 00198 #endif 00199 00200 //! Adds an Client to the client list for lookups 00201 void addClient(Window window, Client *client); 00202 00203 //! Removes an Client from the client list for lookups 00204 void removeClient(Window window); 00205 00206 //! Finds an Client based on its window id 00207 Client *findClient(Window window); 00208 00209 //! The client with input focus 00210 inline Client *focusedClient() { return _focused_client; } 00211 00212 //! Change the client which has focus. 00213 /*! 00214 This is called by the clients themselves when their focus state changes. 00215 */ 00216 void setFocusedClient(Client *c); 00217 00218 //! The screen with input focus 00219 inline Screen *focusedScreen() { return _focused_screen; } 00220 00221 //! Requests that the window manager exit 00222 /*! 00223 Causes the Openbox::eventLoop function to stop looping, so that the window 00224 manager can be destroyed. 00225 */ 00226 inline void shutdown() { _shutdown = true; } 00227 00228 inline void restart(const std::string &bin = "") { 00229 _shutdown = true; _restart = true; _restart_prog = bin; 00230 } 00231 00232 //! True if Openbox should be restarted instead of exiting 00233 inline bool doRestart() const { return _restart; } 00234 00235 //! The command line requested to be executed in place of restarting 00236 //! Openbox the way it was run previously. 00237 inline const std::string &restartProgram() const { return _restart_prog; } 00238 }; 00239 00240 } 00241 00242 #endif // __openbox_hh