]> icculus.org git repositories - dana/openbox.git/blob - src/client.hh
support for the Mwm Hints
[dana/openbox.git] / src / client.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef   __client_hh
3 #define   __client_hh
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 }
8
9 #include <string>
10
11 #include "otk/strut.hh"
12 #include "otk/rect.hh"
13
14 namespace ob {
15
16 class OBClient {
17 public:
18   enum Max { Max_None,
19              Max_Horz,
20              Max_Vert,
21              Max_Full };
22
23   enum WindowType { Type_Desktop,
24                     Type_Dock,
25                     Type_Toolbar,
26                     Type_Menu,
27                     Type_Utility,
28                     Type_Splash,
29                     Type_Dialog,
30                     Type_Normal };
31
32   enum MwmFlags { MwmFunctions   = 1 << 0,
33                   MwmDecorations = 1 << 1 };
34
35   enum MwmFunctions { MwmFunc_All      = 1 << 0,
36                       MwmFunc_Resize   = 1 << 1,
37                       MwmFunc_Move     = 1 << 2,
38                       MwmFunc_Iconify  = 1 << 3,
39                       MwmFunc_Maximize = 1 << 4,
40                       MwmFunc_Close    = 1 << 5 };
41
42   enum MemDecorations { MemDecor_All      = 1 << 0,
43                         MemDecor_Border   = 1 << 1,
44                         MemDecor_Handle   = 1 << 2,
45                         MemDecor_Title    = 1 << 3,
46                         //MemDecor_Menu     = 1 << 4,
47                         MemDecor_Iconify  = 1 << 5,
48                         MemDecor_Maximize = 1 << 6 };
49
50   // the things the user can do to the client window
51   enum Function { Func_Resize   = 1 << 0,
52                   Func_Move     = 1 << 1,
53                   Func_Iconify  = 1 << 2,
54                   Func_Maximize = 1 << 3,
55                   Func_Close    = 1 << 4 };
56   typedef unsigned char FunctionFlags;
57
58   // the decorations the client window wants to be displayed on it
59   enum Decoration { Decor_Titlebar = 1 << 0,
60                     Decor_Handle   = 1 << 1,
61                     Decor_Border   = 1 << 2,
62                     Decor_Iconify  = 1 << 3,
63                     Decor_Maximize = 1 << 4,
64                     Decor_Close    = 1 << 5 };
65   typedef unsigned char DecorationFlags;
66
67   // this structure only contains 3 elements... the Motif 2.0 structure
68   // contains 5... we only need the first 3... so that is all we will define
69   typedef struct MwmHints {
70     static const int elements = 3;
71     unsigned long flags;
72     unsigned long functions;
73     unsigned long decorations;
74   };
75
76   enum StateAction { State_Remove = 0, // _NET_WM_STATE_REMOVE
77                      State_Add,        // _NET_WM_STATE_ADD
78                      State_Toggle      // _NET_WM_STATE_TOGGLE
79   };
80
81 private:
82   //! The actual window that this class is wrapping up
83   Window   _window;
84
85   //! The id of the group the window belongs to
86   Window   _group;
87
88   // XXX: transient_for, transients
89
90   //! The desktop on which the window resides (0xffffffff for all desktops)
91   unsigned long _desktop;
92
93   //! Normal window title
94   std::string  _title; // XXX: Have to keep track if this string is Utf8 or not
95   //! Window title when iconifiged
96   std::string  _icon_title;
97
98   //! The application that created the window
99   std::string  _app_name;
100   //! The class of the window, can used for grouping
101   std::string  _app_class;
102
103   //! The type of window (what its function is)
104   WindowType   _type;
105
106   //! Position and size of the window (relative to the root window)
107   otk::Rect    _area;
108
109   //! Width of the border on the window.
110   /*!
111     The window manager will set this to 0 while the window is being managed,
112     but needs to restore it afterwards, so it is saved here.
113   */
114   int _border_width;
115
116   // size bounds
117   // if min > max, then the window is not resizable
118   int _min_x, _min_y; // minumum size
119   int _max_x, _max_y; // maximum size
120   int _inc_x, _inc_y; // resize increments
121   int _base_x, _base_y; // base size
122
123   //! Where to place the decorated window in relation to the undecorated window
124   int _gravity;
125
126   //! The state of the window, one of WithdrawnState, IconicState, or
127   //! NormalState
128   long _wmstate;
129
130   //! Was the window's position requested by the application? if not, we should
131   //! place the window ourselves when it first appears
132   bool _positioned;
133   
134   //! Can the window receive input focus?
135   bool _can_focus;
136   //! Urgency flag
137   bool _urgent;
138   //! Notify the window when it receives focus?
139   bool _focus_notify;
140
141   //! The window uses shape extension to be non-rectangular?
142   bool _shaped;
143
144   //! The window is modal, so it must be processed before any windows it is
145   //! related to can be focused
146   bool _modal;
147   //! Only the window's titlebar is displayed
148   bool _shaded;
149   //! The window is iconified
150   bool _iconic;
151   //! The window is maximized to fill the screen vertically
152   bool _max_vert;
153   //! The window is maximized to fill the screen horizontally
154   bool _max_horz;
155   //! The window is a 'fullscreen' window, and should be on top of all others
156   bool _fullscreen;
157   //! The window should be on top of other windows of the same type
158   bool _floating;
159
160   //! A bitmask of values in the OBClient::Decoration enum
161   /*!
162     The values in the variable are the decorations that the client wants to be
163     displayed around it.
164   */
165   DecorationFlags _decorations;
166
167   //! The functions requested by the Mwm Hints
168   int _mwm_functions;
169
170   //! A bitmask of values in the OBClient::Function enum
171   /*!
172     The values in the variable specify the ways in which the user is allowed to
173     modify this window.
174   */
175   FunctionFlags _functions;
176
177   void getDesktop();
178   void getType();
179   void getMwmHints();
180   void getArea();
181   void getState();
182   void getShaped();
183
184   void setWMState(long state);
185   void setDesktop(long desktop);
186   void setState(StateAction action, long data1, long data2);
187
188   void updateProtocols();
189   void updateNormalHints();
190   void updateWMHints();
191   // XXX: updateTransientFor();
192   void updateTitle();
193   void updateClass();
194
195 public:
196   OBClient(Window window);
197   virtual ~OBClient();
198
199   inline Window window() const { return _window; }
200
201   inline WindowType type() const { return _type; }
202   inline unsigned long desktop() const { return _desktop; }
203   inline const std::string &title() const { return _title; }
204   inline const std::string &iconTitle() const { return _title; }
205   inline const std::string &appName() const { return _app_name; }
206   inline const std::string &appClass() const { return _app_class; }
207   inline bool canFocus() const { return _can_focus; }
208   inline bool urgent() const { return _urgent; }
209   inline bool focusNotify() const { return _focus_notify; }
210   inline bool shaped() const { return _shaped; }
211   inline int gravity() const { return _gravity; }
212   inline bool positionRequested() const { return _positioned; }
213   inline DecorationFlags decorations() const { return _decorations; }
214   inline FunctionFlags funtions() const { return _functions; }
215
216   // states
217   inline bool modal() const { return _modal; }
218   inline bool shaded() const { return _shaded; }
219   inline bool iconic() const { return _iconic; }
220   inline bool maxVert() const { return _max_vert; }
221   inline bool maxHorz() const { return _max_horz; }
222   inline bool fullscreen() const { return _fullscreen; }
223   inline bool floating() const { return _floating; }
224
225   inline int borderWidth() const { return _border_width; }
226   inline int minX() const { return _min_x; }
227   inline int minY() const { return _min_y; }
228   inline int maxX() const { return _max_x; }
229   inline int maxY() const { return _max_y; }
230   inline int incrementX() const { return _inc_x; }
231   inline int incrementY() const { return _inc_y; }
232   inline int baseX() const { return _base_x; }
233   inline int baseY() const { return _base_y; }
234
235   inline const otk::Rect &area() const { return _area; }
236
237   void update(const XPropertyEvent &e);
238   void update(const XClientMessageEvent &e);
239
240   void setArea(const otk::Rect &area);
241 };
242
243 }
244
245 #endif // __client_hh