-// -*- mode: C++; indent-tabs-mode: nil; -*-
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifndef __openbox_hh
#define __openbox_hh
+/*! @file openbox.hh
+ @brief The main class for the Openbox window manager
+*/
+
extern "C" {
#include <X11/Xlib.h>
}
#include <string>
#include <vector>
+#include <map>
+#include "otk/display.hh"
#include "otk/screeninfo.hh"
-#include "timer.hh"
+#include "otk/eventdispatcher.hh"
+#include "otk/eventhandler.hh"
namespace ob {
-class Openbox
+class Screen;
+class Client;
+class Actions;
+class Bindings;
+
+//! Mouse cursors used throughout Openbox
+struct Cursors {
+ Cursor session; //!< The default mouse cursor
+ Cursor move; //!< For moving a window
+ Cursor ll_angle; //!< For resizing the bottom left corner of a window
+ Cursor lr_angle; //!< For resizing the bottom right corner of a window
+ Cursor ul_angle; //!< For resizing the top left corner of a window
+ Cursor ur_angle; //!< For resizing the right corner of a window
+};
+
+class Openbox;
+
+//! The single instance of the Openbox class for the application
+/*!
+ Since this variable is globally available in the application, the Openbox
+ class does not need to be passed around to any of the other classes.
+*/
+extern Openbox *openbox;
+
+//! The main class for the Openbox window manager
+/*!
+ Only a single instance of the Openbox class may be used in the application. A
+ pointer to this instance is held in the Openbox::instance static member
+ variable.
+ Instantiation of this class begins the window manager. After instantiation,
+ the Openbox::eventLoop function should be called. The eventLoop method does
+ not exit until the window manager is ready to be destroyed. Destruction of
+ the Openbox class instance will shutdown the window manager.
+*/
+class Openbox : public otk::EventDispatcher, public otk::EventHandler
{
public:
- static Openbox *instance; // there can only be ONE instance of this class in
- // the program, and it is held in here
-
- typedef std::vector<otk::ScreenInfo> ScreenInfoList;
-
+ //! The posible running states of the window manager
enum RunState {
- State_Starting,
- State_Normal,
- State_Exiting
+ State_Starting, //!< The window manager is starting up (being created)
+ State_Normal, //!< The window manager is running in its normal state
+ State_Exiting //!< The window manager is exiting (being destroyed)
};
+
+ //! A map for looking up a specific client class from the window id
+ typedef std::map<Window, Client *> ClientMap;
+
+ //! A list of Screen classes
+ typedef std::vector<Screen *> ScreenList;
private:
// stuff that can be passed on the command line
- std::string _rcfilepath; // path to the config file to use/in use
- std::string _menufilepath; // path to the menu file to use/in use
- char *_displayreq; // display requested by the user
- char *_argv0; // argv[0], how the program was called
+ //! Path to the config file to use/in use
+ /*!
+ Defaults to $(HOME)/.openbox/rc3
+ */
+ std::string _rcfilepath;
+ //! Path to the menu file to use/in use
+ /*!
+ Defaults to $(HOME)/.openbox/menu3
+ */
+ std::string _menufilepath;
+ //! Path to the script file to execute on startup
+ /*!
+ Defaults to $(HOME)/.openbox/user.py
+ */
+ std::string _scriptfilepath;
+ //! The value of argv, i.e. how this application was executed
+ char **_argv;
+ //! Run the application in synchronous mode? (for debugging)
+ bool _sync;
+ //! Should Openbox run on a single screen or on all available screens?
+ bool _single;
+
+ //! A list of all managed clients
+ ClientMap _clients;
+
+ //! A list of all the managed screens
+ ScreenList _screens;
+
+ //! The action interface through which all user-available actions occur
+ Actions *_actions;
+
+ //! The interface through which keys/buttons are grabbed and handled
+ Bindings *_bindings;
+
+ //! The running state of the window manager
+ RunState _state;
- OBTimerQueueManager _timermanager; // manages timers, so that they fire when
- // their time elapses
+ //! Mouse cursors used throughout Openbox
+ Cursors _cursors;
- RunState _state; // the state of the window manager
+ //! When set to true, the Openbox::eventLoop function will stop and return
+ bool _shutdown;
- ScreenInfoList _screenInfoList; // info for all screens on the display
+ //! When set to true, and Openbox is about to exit, it will spawn a new
+ //! process
+ bool _restart;
+ //! If this contains anything, a restart will try to execute the program in
+ //! this variable, and will fallback to reexec'ing itself if that fails
+ std::string _restart_prog;
+
+ //! The client with input focus
+ /*!
+ Updated by the clients themselves.
+ */
+ Client *_focused_client;
+
+ //! The screen with input focus
+ /*!
+ Updated by the clients when they update the Openbox::focused_client
+ property.
+ */
+ Screen *_focused_screen;
+
+ //! Parses the command line used when executing this application
void parseCommandLine(int argv, char **argv);
+ //! Displays the version string to stdout
void showVersion();
+ //! Displays usage information and help to stdout
void showHelp();
- static int xerrorHandler(Display *d, XErrorEvent *e);
+ //! Handles signal events for the application
static void signalHandler(int signal);
public:
+#ifndef SWIG
//! Openbox constructor.
/*!
\param argc Number of command line arguments, as received in main()
Openbox(int argc, char **argv);
//! Openbox destructor.
virtual ~Openbox();
+#endif
- //! Returns the state of the window manager (starting, exiting, etc).
+ //! Returns the state of the window manager (starting, exiting, etc)
inline RunState state() const { return _state; }
- inline OBTimerQueueManager *timerManager() { return &_timermanager; }
+ //! Returns the Actions instance for the window manager
+ inline Actions *actions() const { return _actions; }
+
+ //! Returns the Bindings instance for the window manager
+ inline Bindings *bindings() const { return _bindings; }
+
+ //! Returns a managed screen or a null pointer
+ /*!
+ ALWAYS check the return value for a non-null, as any unmanaged screens
+ will return one. This includes screen(0) if the first managed screen is 1.
+ */
+ inline Screen *screen(int num) {
+ assert(num >= 0); assert(num < (signed)ScreenCount(**otk::display));
+ if (num >= (signed)_screens.size()) return 0;
+ return _screens[num];
+ }
+ //! Returns the mouse cursors used throughout Openbox
+ inline const Cursors &cursors() const { return _cursors; }
+
+#ifndef SWIG
+ //! The main function of the Openbox class
+ /*!
+ This function should be called after instantiating the Openbox class.
+ It loops indefinately while handling all events for the application.
+ The Openbox::shutdown method will cause this function to exit.
+ */
void eventLoop();
+#endif
+
+ //! Adds an Client to the client list for lookups
+ void addClient(Window window, Client *client);
+
+ //! Removes an Client from the client list for lookups
+ void removeClient(Window window);
+
+ //! Finds an Client based on its window id
+ Client *findClient(Window window);
+
+ //! The client with input focus
+ inline Client *focusedClient() { return _focused_client; }
+
+ //! Change the client which has focus.
+ /*!
+ This is called by the clients themselves when their focus state changes.
+ */
+ void setFocusedClient(Client *c);
+
+ //! The screen with input focus
+ inline Screen *focusedScreen() { return _focused_screen; }
+
+ //! Requests that the window manager exit
+ /*!
+ Causes the Openbox::eventLoop function to stop looping, so that the window
+ manager can be destroyed.
+ */
+ inline void shutdown() { _shutdown = true; }
+
+ inline void restart(const std::string &bin = "") {
+ _shutdown = true; _restart = true; _restart_prog = bin;
+ }
- // XXX: TEMPORARY!#!@%*!^#*!#!#!
- virtual void process_event(XEvent *) = 0;
+ //! True if Openbox should be restarted instead of exiting
+ inline bool doRestart() const { return _restart; }
- //! Requests that the window manager exit.
- inline void shutdown() { _state = State_Exiting; }
+ //! The command line requested to be executed in place of restarting
+ //! Openbox the way it was run previously.
+ inline const std::string &restartProgram() const { return _restart_prog; }
};
}