]> icculus.org git repositories - dana/openbox.git/blob - src/screen.hh
fix the HOOOGE mem leak! YAY MANMOWER!
[dana/openbox.git] / src / screen.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef   __screen_hh
3 #define   __screen_hh
4
5 /*! @file screen.hh
6   @brief Screen manages a single screen
7 */
8
9 extern "C" {
10 #include <X11/Xlib.h>
11 }
12
13 #include "client.hh"
14 #include "widgetbase.hh"
15 #include "otk/renderstyle.hh"
16 #include "otk/strut.hh"
17 #include "otk/rect.hh"
18 #include "otk/screeninfo.hh"
19 #include "otk/eventhandler.hh"
20 #include "otk/property.hh"
21 #include "otk/ustring.hh"
22
23 #include <string>
24 #include <list>
25
26 namespace ob {
27
28 class Client;
29
30 //! Manages a single screen
31 /*!
32 */
33 class Screen : public otk::EventHandler, public WidgetBase {
34 public:
35   //! Holds a list of otk::Strut objects
36   typedef std::list<otk::Strut*> StrutList;
37
38   static const unsigned long event_mask = ColormapChangeMask |
39                                           EnterWindowMask |
40                                           LeaveWindowMask |
41                                           PropertyChangeMask |
42                                           SubstructureNotifyMask |
43                                           SubstructureRedirectMask |
44                                           ButtonPressMask |
45                                           ButtonReleaseMask;
46
47   //! All managed clients on the screen (in order of being mapped)
48   Client::List clients;
49   
50 private:
51   //! Was %Openbox able to manage the screen?
52   bool _managed;
53
54   //! The number of the screen on the X server
55   int _number;
56
57   //! Information about this screen
58   const otk::ScreenInfo *_info;
59   
60   //! The style with which to render on the screen
61   otk::RenderStyle _style;
62
63   //! Is the root colormap currently installed?
64   bool _root_cmap_installed;
65
66   //! Area usable for placement etc (total - struts)
67   otk::Rect _area;
68
69   //! Combined strut from all of the clients' struts
70   otk::Strut _strut;
71
72   //!  An offscreen window which gets focus when nothing else has it
73   Window _focuswindow;
74
75   //! An offscreen window which shows that a NETWM compliant window manager is
76   //! running
77   Window _supportwindow;
78
79   //! A list of all managed clients on the screen, in their stacking order
80   Client::List _stacking;
81
82   //! The desktop currently being displayed
83   long _desktop;
84
85   //! The number of desktops
86   long _num_desktops;
87
88   //! The names of all desktops
89   otk::Property::StringVect _desktop_names;
90
91   //! Calculate the Screen::_area member
92   void calcArea();
93   //! Set the list of supported NETWM atoms on the root window
94   void changeSupportedAtoms();
95   //! Set the client list on the root window
96   /*!
97     Sets the _NET_CLIENT_LIST root window property.<br>
98     Also calls Screen::updateStackingList.
99   */
100   void changeClientList();
101   //! Set the client stacking list on the root window
102   /*!
103     Set the _NET_CLIENT_LIST_STACKING root window property.
104   */
105   void changeStackingList();
106   //! Set the work area hint on the root window
107   /*!
108     Set the _NET_WORKAREA root window property.
109   */
110   void changeWorkArea();
111
112   //! Get desktop names from the root window property
113   void updateDesktopNames();
114
115   //! Changes to the specified desktop, displaying windows on it and hiding
116   //! windows on the others.
117   /*!
118     @param desktop The number of the desktop to switch to (starts from 0).
119     If the desktop is out of valid range, it is ignored.
120   */
121   void changeDesktop(long desktop);
122
123   //! Changes the number of desktops.
124   /*!
125     @param num The number of desktops that should exist. This value must be
126                greater than 0 or it will be ignored.
127   */
128   void changeNumDesktops(long num);
129
130 public:
131 #ifndef SWIG
132   //! Constructs a new Screen object
133   Screen(int screen);
134   //! Destroys the Screen object
135   virtual ~Screen();
136 #endif
137
138   inline int number() const { return _number; }
139   
140   //! Returns if the screen was successfully managed
141   /*!
142     If this is false, then the screen should be deleted and should NOT be
143     used.
144   */
145   inline bool managed() const { return _managed; }
146   //! Returns the area of the screen not reserved by applications' Struts
147   inline const otk::Rect &area() const { return _area; }
148   //! Returns the style in use on the screen
149   inline const otk::RenderStyle *style() const { return &_style; }
150   //!  An offscreen window which gets focus when nothing else has it
151   inline Window focuswindow() const { return _focuswindow; }
152   //! Returns the desktop being displayed
153   inline long desktop() const { return _desktop; }
154   //! Returns the number of desktops
155   inline long numDesktops() const { return _num_desktops; }
156
157   //! Update's the screen's combined strut of all the clients.
158   /*!
159     Clients should call this whenever they change their strut.
160   */
161   void updateStrut();
162
163   //! Manage any pre-existing windows on the screen
164   void manageExisting();
165   //! Manage a client window
166   /*!
167     This gives the window a frame, reparents it, selects events on it, etc.
168   */
169   void manageWindow(Window window);
170   //! Unmanage a client
171   /*!
172     This removes the window's frame, reparents it to root, unselects events on
173     it, etc.
174     @param client The client to unmanage
175   */
176   void unmanageWindow(Client *client);
177
178   //! Raises a client window above all others in its stacking layer
179   /*!
180     raiseWindow has a couple of constraints that lowerWindow does not.<br>
181     1) raiseWindow can be called after changing a Client's stack layer, and
182        the list will be reorganized properly.<br>
183     2) raiseWindow guarantees that XRestackWindows() will <i>always</i> be
184        called for the specified client.
185   */
186   void raiseWindow(Client *client);
187
188   //! Lowers a client window below all others in its stacking layer
189   void lowerWindow(Client *client);
190
191   //! Sets the name of a desktop by changing the root window property
192   /*!
193     @param i The index of the desktop to set the name for (starts at 0)
194     @param name The name to set for the desktop
195     If the index is too large, it is simply ignored.
196   */
197   void setDesktopName(long i, const otk::ustring &name);
198
199   virtual void propertyHandler(const XPropertyEvent &e);
200   virtual void clientMessageHandler(const XClientMessageEvent &e);
201   virtual void mapRequestHandler(const XMapRequestEvent &e);
202 };
203
204 }
205
206 #endif// __screen_hh