all repos — openbox @ 5705ea361305e03bd557896b449f0672005f9159

openbox fork - make it a bit more like ryudo

src/Window.h (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// Window.h for Openbox
// Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#ifndef   __Window_hh
#define   __Window_hh

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef    SHAPE
#  include <X11/extensions/shape.h>
#endif // SHAPE

#include "BaseDisplay.h"
#include "Timer.h"
#include "Windowmenu.h"
#include "Geometry.h"

// forward declaration
class OpenboxWindow;

#define MwmHintsFunctions     (1l << 0)
#define MwmHintsDecorations   (1l << 1)

#define MwmFuncAll            (1l << 0)
#define MwmFuncResize         (1l << 1)
#define MwmFuncMove           (1l << 2)
#define MwmFuncIconify        (1l << 3)
#define MwmFuncMaximize       (1l << 4)
#define MwmFuncClose          (1l << 5)

#define MwmDecorAll           (1l << 0)
#define MwmDecorBorder        (1l << 1)
#define MwmDecorHandle        (1l << 2)
#define MwmDecorTitle         (1l << 3)
#define MwmDecorMenu          (1l << 4)
#define MwmDecorIconify       (1l << 5)
#define MwmDecorMaximize      (1l << 6)

// this structure only contains 3 elements... the Motif 2.0 structure contains
// 5... we only need the first 3... so that is all we will define
typedef struct MwmHints {
  unsigned long flags, functions, decorations;
} MwmHints;

#define PropMwmHintsElements  3


class OpenboxWindow : public TimeoutHandler {
private:
  BImageControl *image_ctrl;
  Openbox &openbox;
  BScreen *screen;
  Display *display;
  BTimer *timer;
  OpenboxAttributes openbox_attrib;

  Time lastButtonPressTime;  // used for double clicks, when were we clicked
  Windowmenu *windowmenu;

  int window_number, workspace_number;
  unsigned long current_state;
  bool place_window;         // place the window ourselves when mapped

  enum FocusMode { F_NoInput = 0, F_Passive,
		   F_LocallyActive, F_GloballyActive };
  FocusMode focus_mode;

  enum ResizeZones {
    ZoneTop     = 1 << 0,
    ZoneBottom  = 1 << 1,
    ZoneLeft    = 1 << 2,
    ZoneRight   = 1 << 3
  };
  unsigned int resize_zone;     // bitmask of ResizeZones values

  struct _flags {
    Bool moving,             // is moving?
      resizing,              // is resizing?
      shaded,                // is shaded?
      visible,               // is visible?
      iconic,                // is iconified?
      transient,             // is a transient window?
      focused,               // has focus?
      stuck,                 // is omnipresent
      modal,                 // is modal? (must be dismissed to continue)
      send_focus_message,    // should we send focus messages to our client?
      shaped,                // does the frame use the shape extension?
      managed;               // under openbox's control?
                             // maximize is special, the number corresponds
                             // with a mouse button
                             // if 0, not maximized
    unsigned int maximized;  // 1 = HorizVert, 2 = Vertical, 3 = Horizontal
  } flags;

  struct _client {
    OpenboxWindow *transient_for,   // which window are we a transient for?
      *transient;                   // which window is our transient?

    Window window,                  // the client's window
      window_group;                 // the client's window group

    char *title, *icon_title;
    size_t title_len;               // strlen(title)

    int x, y,
      old_bw;                       // client's borderwidth

    unsigned int width, height,
      title_text_w,                 // width as rendered in the current font
      min_width, min_height,        // can not be resized smaller
      max_width, max_height,        // can not be resized larger
      width_inc, height_inc,        // increment step
      min_aspect_x, min_aspect_y,   // minimum aspect ratio
      max_aspect_x, max_aspect_y,   // maximum aspect ratio
      base_width, base_height,
      win_gravity;

    unsigned long initial_state, normal_hint_flags, wm_hint_flags;

    MwmHints *mwm_hint;
    OpenboxHints *openbox_hint;
  } client;

  struct _functions {
    Bool resize, move, iconify, maximize, close;
  } functions;

  /*
   * client window = the application's window
   * frame window = the window drawn around the outside of the client window
   *                by the window manager which contains items like the
   *                titlebar and close button
   * title = the titlebar drawn above the client window, it displays the
   *         window's name and any buttons for interacting with the window,
   *         such as iconify, maximize, and close
   * label = the window in the titlebar where the title is drawn
   * buttons = maximize, iconify, close
   * handle = the bar drawn at the bottom of the window, which contains the
   *          left and right grips used for resizing the window
   * grips = the smaller reactangles in the handle, one of each side of it.
   *         When clicked and dragged, these resize the window interactively
   * border = the line drawn around the outside edge of the frame window,
   *          between the title, the bordered client window, and the handle.
   *          Also drawn between the grips and the handle
   */

  /*
   * what decorations do we have?
   * this is based on the type of the client window as well as user input
   * the menu is not really decor, but it goes hand in hand with the decor
   */
  struct _decorations {
    Bool titlebar, handle, border, iconify, maximize, close, menu;
  } decorations;

  struct _frame {
    // u -> unfocused, f -> has focus
    unsigned long ulabel_pixel, flabel_pixel, utitle_pixel,
      ftitle_pixel, uhandle_pixel, fhandle_pixel, ubutton_pixel,
      fbutton_pixel, pbutton_pixel, uborder_pixel, fborder_pixel,
      ugrip_pixel, fgrip_pixel;
    Pixmap ulabel, flabel, utitle, ftitle, uhandle, fhandle,
      ubutton, fbutton, pbutton, ugrip, fgrip;

    Window window,       // the frame
      plate,             // holds the client
      title,
      label,
      handle,
      close_button, iconify_button, maximize_button,
      right_grip, left_grip;


    unsigned int resize_w, resize_h;
    int resize_x, resize_y,    // size and location of box drawn while resizing
      move_x, move_y;          // location of box drawn while moving

    int x, y,
      grab_x, grab_y,          // where was the window when it was grabbed?
      y_border, y_handle;      // where within frame is the border and handle

    unsigned int width, height, title_h, label_w, label_h, handle_h,
      button_w, button_h, grip_w, grip_h, mwm_border_w, border_h, border_w,
      bevel_w;
  } frame;

protected:
  Bool getState();
  Window createToplevelWindow(int x, int y, unsigned int width,
			      unsigned int height, unsigned int borderwidth);
  Window createChildWindow(Window parent, Cursor = None);

  void getWMName();
  void getWMIconName();
  void getWMNormalHints();
  void getWMProtocols();
  void getWMHints();
  void getMWMHints();
  void getOpenboxHints();
  void setNetWMAttributes();
  void associateClientWindow();
  void decorate();
  void decorateLabel();
  void positionButtons(Bool redecorate_label = False);
  void positionWindows();
  void createCloseButton();
  void createIconifyButton();
  void createMaximizeButton();
  void redrawLabel();
  void redrawAllButtons();
  void redrawCloseButton(Bool);
  void redrawIconifyButton(Bool);
  void redrawMaximizeButton(Bool);
  void restoreGravity();
  void setGravityOffsets();
  void setState(unsigned long);
  void upsize();
  void downsize();
  void right_fixsize(int *gx = 0, int *gy = 0);
  void left_fixsize(int *gx = 0, int *gy = 0);
  void doMove(int x, int y);


public:
  OpenboxWindow(Openbox &b, Window w, BScreen *s = (BScreen *) 0);
  virtual ~OpenboxWindow();

  inline Bool isTransient() const { return flags.transient; }
  inline Bool isFocused() const { return flags.focused; }
  inline Bool isVisible() const { return flags.visible; }
  inline Bool isIconic() const { return flags.iconic; }
  inline Bool isShaded() const { return flags.shaded; }
  inline Bool isMaximized() const { return flags.maximized; }
  inline Bool isMaximizedFull() const { return flags.maximized == 1; }
  inline Bool isStuck() const { return flags.stuck; }
  inline Bool isIconifiable() const { return functions.iconify; }
  inline Bool isMaximizable() const { return functions.maximize; }
  inline Bool isResizable() const { return functions.resize; }
  inline Bool isClosable() const { return functions.close; }

  inline Bool hasTitlebar() const { return decorations.titlebar; }
  inline Bool hasTransient() const
  { return ((client.transient) ? True : False); }

  inline OpenboxWindow *getTransient() { return client.transient; }
  inline OpenboxWindow *getTransientFor() { return client.transient_for; }

  inline BScreen *getScreen() { return screen; }

  inline const Window &getFrameWindow() const { return frame.window; }
  inline const Window &getClientWindow() const { return client.window; }

  inline Windowmenu * getWindowmenu() { return windowmenu; }

  inline char **getTitle() { return &client.title; }
  inline char **getIconTitle() { return &client.icon_title; }
  //inline const int &getXFrame() const { return frame.x; }
  //inline const int &getYFrame() const { return frame.y; }
  //inline const int &getXClient() const { return client.x; }
  //inline const int &getYClient() const { return client.y; }
  inline const int &getWorkspaceNumber() const { return workspace_number; }
  inline const int &getWindowNumber() const { return window_number; }

  //inline const unsigned int &getWidth() const { return frame.width; }
  //inline const unsigned int &getHeight() const {
  //  if (!flags.shaded)
  //    return frame.height;
  //  else
  //    return frame.title_h;
  //}
  //inline const unsigned int &getClientHeight() const
  //{ return client.height; }
  //inline const unsigned int &getClientWidth() const
  //{ return client.width; }
  inline const unsigned int &getTitleHeight() const
  { return frame.title_h; }

  //inline const Point origin() const {
  //  return Point(frame.x, frame.y);
  //}
  //inline const Point clientOrigin() const {
  //  return Point(client.x, client.y);
  //}
  //inline const Size size() const {
  //  return Size(frame.width, flags.shaded ? frame.title_h : frame.height);
  //}
  //inline const Size clientSize() const {
  //  return Size(client.width, client.height);
  //}
  inline const Rect area() const {
    return Rect(frame.x, frame.y, frame.width,
                flags.shaded ? frame.title_h : frame.height);
  }
  inline const Rect clientArea() const {
    return Rect(client.x, client.y, client.width, client.height);
  }
  
  inline void setWindowNumber(int n) { window_number = n; }
  
  Bool validateClient();
  Bool setInputFocus();

  void setFocusFlag(Bool);
  void iconify();
  void deiconify(Bool reassoc = True, Bool raise = True);
  void close();
  void withdraw();
  void maximize(unsigned int button);
  void shade();
  void stick();
  void unstick();
  void reconfigure();
  void installColormap(Bool);
  void restore();
  void configure(int dx, int dy, unsigned int dw, unsigned int dh);
  void setWorkspace(int n);
  void changeOpenboxHints(OpenboxHints *);
  void restoreAttributes();

  void startMove(int x, int y);
  void endMove();
  
  void buttonPressEvent(XButtonEvent *);
  void buttonReleaseEvent(XButtonEvent *);
  void motionNotifyEvent(XMotionEvent *);
  void destroyNotifyEvent(XDestroyWindowEvent *);
  void mapRequestEvent(XMapRequestEvent *);
  void mapNotifyEvent(XMapEvent *);
  void unmapNotifyEvent(XUnmapEvent *);
  void propertyNotifyEvent(Atom);
  void exposeEvent(XExposeEvent *);
  void configureRequestEvent(XConfigureRequestEvent *);

#ifdef    SHAPE
  void shapeEvent(XShapeEvent *);
#endif // SHAPE

  virtual void timeout();
};


#endif // __Window_hh