~ubuntu-branches/ubuntu/oneiric/nux/oneiric

« back to all changes in this revision

Viewing changes to NuxGraphics/XInputWindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-06-22 17:16:16 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20110622171616-3cyhhiwsb6ga9d30
Tags: 1.0.2-0ubuntu1
* New upstream release.
* Cherry-pick a fix for FTBFS with -fpermissive
* debian/control:
  - add new libxdamage-dev and libxcomposite-dev build-dep
  - add new libboost1.42-dev dep as well, should be transitionned to 1.46 once
    compiz is transitionned as well
* remove debian/patches/01_build_with_gcc46.patch as included upstream
* debian/rules:
  - disable google code tests while building
* debian/control, debian/rules, debian/libnux-1.0-common.install,
  debian/libnux-1.0-dev.install, debian/libnux-1.0-doc.install,
  debian/libnux-1.0-0.install:
  - change, prepare next ABI breakage and remove no more needed Breaks: with
    new soname bump
* libnux-1.0-common now replaces: libnux-0.9-common for the apport hook

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "GraphicsDisplayX11.h"
24
24
#include "GLThread.h"
25
25
 
 
26
// Jay, what is this for?  It isn't referenced anywhere.
26
27
#define xdnd_version 5
27
28
 
28
29
namespace nux
29
30
{
30
 
 
31
 
  std::list<Window> XInputWindow::_native_windows;
 
31
  std::list<Window> XInputWindow::native_windows_;
32
32
 
33
33
  XInputWindow::XInputWindow(const char* title,
34
34
                             bool        take_focus,
35
35
                             int         override_redirect)
 
36
    : strutsEnabled_(false)
 
37
    , display_(GetGraphicsDisplay()->GetX11Display())
 
38
    , geometry_(0, 0, 1, 1)
 
39
    , shown_(false)
 
40
    , mapped_(false)
36
41
  {
37
 
    Display* d = GetThreadGLWindow()->GetX11Display();
38
 
    _display = d;
39
42
    XSetWindowAttributes attrib;
40
 
    
41
 
    _shown = false;
42
 
    _mapped = false;
43
 
    
44
 
    _x = 0;
45
 
    _y = 0;
46
 
    _width = 1;
47
 
    _height = 1;
48
 
    _strutsEnabled = false;
49
 
    
 
43
 
50
44
    attrib.override_redirect = override_redirect;
51
45
    attrib.event_mask = KeyPressMask        |
52
46
                        KeyReleaseMask      |
60
54
                        StructureNotifyMask |
61
55
                        FocusChangeMask;
62
56
 
63
 
    _window = XCreateWindow (d, XDefaultRootWindow (d), _x, _y, _width, _height, 0,
64
 
                             CopyFromParent, InputOutput, CopyFromParent,
65
 
                             CWOverrideRedirect | CWEventMask, &attrib);
66
 
    
67
 
    _native_windows.push_front (_window);
68
 
    
 
57
    window_ = XCreateWindow(display_, XDefaultRootWindow(display_),
 
58
                            geometry_.x, geometry_.y,
 
59
                            geometry_.width, geometry_.height, 0,
 
60
                            CopyFromParent, InputOutput, CopyFromParent,
 
61
                            CWOverrideRedirect | CWEventMask, &attrib);
 
62
 
 
63
    native_windows_.push_front(window_);
 
64
 
69
65
    Atom data[32];
70
66
    int     i = 0;
71
 
    data[i++] = XInternAtom (d, "_NET_WM_STATE_STICKY", 0);
72
 
    data[i++] = XInternAtom (d, "_NET_WM_STATE_SKIP_TASKBAR", 0);
73
 
    data[i++] = XInternAtom (d, "_NET_WM_STATE_SKIP_PAGER", 0);
74
 
 
75
 
    XChangeProperty (d, _window, XInternAtom (d, "_NET_WM_STATE", 0),
76
 
                 XA_ATOM, 32, PropModeReplace,
77
 
                 (unsigned char *) data, i);
78
 
    
 
67
    data[i++] = XInternAtom(display_, "_NET_WM_STATE_STICKY", 0);
 
68
    data[i++] = XInternAtom(display_, "_NET_WM_STATE_SKIP_TASKBAR", 0);
 
69
    data[i++] = XInternAtom(display_, "_NET_WM_STATE_SKIP_PAGER", 0);
 
70
 
 
71
    XChangeProperty(display_, window_,
 
72
                    XInternAtom(display_, "_NET_WM_STATE", 0),
 
73
                    XA_ATOM, 32, PropModeReplace,
 
74
                    (unsigned char *) data, i);
 
75
 
79
76
    Atom type[1];
80
 
    type[0] = XInternAtom (d, "_NET_WM_WINDOW_TYPE_DOCK", 0);
81
 
    XChangeProperty (d, _window, XInternAtom (d, "_NET_WM_WINDOW_TYPE", 0),
82
 
                     XA_ATOM, 32, PropModeReplace,
83
 
                     (unsigned char *) type, 1);
84
 
 
85
 
    XStoreName (d, _window, title);
86
 
 
 
77
    type[0] = XInternAtom(display_, "_NET_WM_WINDOW_TYPE_DOCK", 0);
 
78
    XChangeProperty(display_, window_,
 
79
                    XInternAtom(display_, "_NET_WM_WINDOW_TYPE", 0),
 
80
                    XA_ATOM, 32, PropModeReplace,
 
81
                    (unsigned char *) type, 1);
 
82
 
 
83
    XStoreName(display_, window_, title);
87
84
    EnsureInputs ();
88
85
 
89
86
    if (take_focus)
94
91
 
95
92
  XInputWindow::~XInputWindow()
96
93
  {
97
 
    _native_windows.remove (_window);
98
 
    XDestroyWindow (_display, _window);
 
94
    native_windows_.remove(window_);
 
95
    XDestroyWindow(display_, window_);
99
96
  }
100
97
 
101
98
  /* static */
102
99
  std::list<Window> XInputWindow::NativeHandleList()
103
100
  {
104
 
    return _native_windows;
 
101
    return native_windows_;
105
102
  }
106
103
 
107
104
  void XInputWindow::SetStruts()
108
105
  {
109
106
    int screenHeight, screenWidth;
110
107
    long int data[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
111
 
    
112
 
    screenHeight = XDisplayHeight (_display, 0);
113
 
    screenWidth = XDisplayWidth (_display, 0);    
114
 
    
115
 
    if (_width > _height)
 
108
 
 
109
    screenHeight = XDisplayHeight(display_, 0);
 
110
    screenWidth = XDisplayWidth(display_, 0);
 
111
 
 
112
    if (geometry_.width > geometry_.height)
116
113
    {
117
 
      if (_y < screenHeight / 2)
 
114
      if (geometry_.y < screenHeight / 2)
118
115
      {
119
116
        /* top */
120
 
        data[2] = _y + _height;
121
 
        data[8] = _x;
122
 
        data[9] = _x + _width - 1;
 
117
        data[2] = geometry_.y + geometry_.height;
 
118
        data[8] = geometry_.x;
 
119
        data[9] = geometry_.x + geometry_.width - 1;
123
120
      }
124
121
      else
125
122
      {
126
123
        /* bottom */
127
 
        data[3] = (screenHeight - 1) - _y;
128
 
        data[10] = _x;
129
 
        data[11] = _x + _width - 1;
 
124
        data[3] = (screenHeight - 1) - geometry_.y;
 
125
        data[10] = geometry_.x;
 
126
        data[11] = geometry_.x + geometry_.width - 1;
130
127
      }
131
128
    }
132
129
    else
133
130
    {
134
 
      if (_x < screenWidth / 2)
 
131
      if (geometry_.x < screenWidth / 2)
135
132
      {
136
133
        /* left */
137
 
        data[0] = _x + _width;
138
 
        data[4] = _y;
139
 
        data[5] = _y + _height - 1;
 
134
        data[0] = geometry_.x + geometry_.width;
 
135
        data[4] = geometry_.y;
 
136
        data[5] = geometry_.y + geometry_.height - 1;
140
137
      }
141
138
      else
142
139
      {
143
140
        /* right */
144
 
        data[1] = (screenWidth - 1) - _y;
145
 
        data[6] = _y;
146
 
        data[7] = _y + _height - 1;
 
141
        data[1] = (screenWidth - 1) - geometry_.y;
 
142
        data[6] = geometry_.y;
 
143
        data[7] = geometry_.y + geometry_.height - 1;
147
144
      }
148
145
    }
149
 
    
150
 
    XChangeProperty (_display, _window, XInternAtom (_display, "_NET_WM_STRUT_PARTIAL", 0),
151
 
                     XA_CARDINAL, 32, PropModeReplace,
152
 
                     (unsigned char *) data, 12);
 
146
 
 
147
    XChangeProperty(display_, window_,
 
148
                    XInternAtom(display_, "_NET_WM_STRUT_PARTIAL", 0),
 
149
                    XA_CARDINAL, 32, PropModeReplace,
 
150
                    (unsigned char *) data, 12);
153
151
  }
154
152
 
155
153
  void XInputWindow::UnsetStruts()
156
154
  {
157
 
    XDeleteProperty (_display, _window, XInternAtom (_display, "_NET_WM_STRUT_PARTIAL", 0));
 
155
    XDeleteProperty(display_, window_,
 
156
                    XInternAtom(display_, "_NET_WM_STRUT_PARTIAL", 0));
158
157
  }
159
158
 
160
159
  void XInputWindow::EnableStruts(bool enable)
161
160
  {
162
 
    if (_strutsEnabled == enable)
 
161
    if (strutsEnabled_ == enable)
163
162
      return;
164
 
    
165
 
    _strutsEnabled = enable;
 
163
 
 
164
    strutsEnabled_ = enable;
166
165
    if (enable)
167
166
      SetStruts();
168
167
    else
171
170
 
172
171
  bool XInputWindow::StrutsEnabled()
173
172
  {
174
 
    return _strutsEnabled;
 
173
    return strutsEnabled_;
175
174
  }
176
175
 
177
176
  void XInputWindow::EnsureInputs()
178
177
  {
179
 
    XSelectInput (_display, _window,
 
178
    XSelectInput(display_, window_,
180
179
                  KeyPressMask        |
181
180
                  KeyReleaseMask      |
182
181
                  ButtonPressMask     |
188
187
                  PropertyChangeMask  |
189
188
                  StructureNotifyMask |
190
189
                  FocusChangeMask);
191
 
    
192
190
  }
193
191
 
194
 
  void XInputWindow::EnableTakeFocus ()
 
192
  void XInputWindow::EnableTakeFocus()
195
193
  {
196
 
    Atom      wmTakeFocus = XInternAtom (_display, "WM_TAKE_FOCUS", False);
197
 
    XWMHints* wmHints     = NULL;
 
194
    Atom wmTakeFocus = XInternAtom (display_, "WM_TAKE_FOCUS", False);
 
195
    XWMHints* wmHints = NULL;
198
196
 
199
197
    wmHints = (XWMHints*) calloc (1, sizeof (XWMHints));
200
198
    wmHints->flags |= InputHint;
201
199
    wmHints->input = False;
202
 
    XSetWMHints (_display, _window, wmHints);
203
 
    free (wmHints);
204
 
    XSetWMProtocols (_display, _window, &wmTakeFocus, 1);
 
200
    XSetWMHints(display_, window_, wmHints);
 
201
    free(wmHints);
 
202
    XSetWMProtocols(display_, window_, &wmTakeFocus, 1);
205
203
  }
206
204
 
207
 
  void XInputWindow::EnableDnd ()
 
205
  void XInputWindow::EnableDnd()
208
206
  {
209
207
    int version = 5;
210
 
    XChangeProperty (_display, _window, XInternAtom (_display, "XdndAware", false),
211
 
                     XA_ATOM, 32, PropModeReplace, (unsigned char *) &version, 1);
 
208
    XChangeProperty(display_, window_,
 
209
                    XInternAtom(display_, "XdndAware", false),
 
210
                    XA_ATOM, 32, PropModeReplace,
 
211
                    (unsigned char *) &version, 1);
212
212
  }
213
 
  
214
 
  void XInputWindow::DisableDnd ()
 
213
 
 
214
  void XInputWindow::DisableDnd()
215
215
  {
216
 
    XDeleteProperty (_display, _window, XInternAtom (_display, "XdndAware", false));
 
216
    XDeleteProperty(display_, window_,
 
217
                    XInternAtom(display_, "XdndAware", false));
217
218
  }
218
219
 
219
220
  //! Set the position and size of the window
220
 
  void XInputWindow::SetGeometry(const Rect& geo)
 
221
  void XInputWindow::SetGeometry(Rect const& geo)
221
222
  {
222
 
    SetGeometry(geo.x, geo.y, geo.width, geo.height);
 
223
    geometry_ = geo;
 
224
 
 
225
    if (shown_)
 
226
      XMoveResizeWindow(display_, window_,
 
227
                        geo.x, geo.y, geo.width, geo.height);
 
228
    EnsureInputs();
 
229
 
 
230
    if (strutsEnabled_)
 
231
      SetStruts();
223
232
  }
224
233
 
225
234
  //! Set the position and size of the window
226
235
  void XInputWindow::SetGeometry(int x, int y, int width, int height)
227
236
  {
228
 
    _x = x;
229
 
    _y = y;
230
 
    _width = width;
231
 
    _height = height;
232
 
    
233
 
    if (_shown)
234
 
      XMoveResizeWindow (_display, _window, x, y, width, height);
235
 
    EnsureInputs ();
236
 
    
237
 
    if (_strutsEnabled)
238
 
      SetStruts ();
 
237
    SetGeometry(Rect(x, y, width, height));
239
238
  }
240
239
 
241
240
  //! Get the window geometry.
242
 
  Rect XInputWindow::GetGeometry() const
 
241
  Rect const& XInputWindow::GetGeometry() const
243
242
  {
244
 
    Rect r(_x, _y, _width, _height);
245
 
    
246
 
    return r;
 
243
    return geometry_;
247
244
  }
248
245
 
249
246
  Window XInputWindow::GetWindow ()
250
247
  {
251
 
    return _window;
 
248
    return window_;
252
249
  }
253
250
 
254
251
  void XInputWindow::SetInputFocus ()
255
252
  {
256
 
    XSetInputFocus (_display, _window, RevertToParent, CurrentTime);
 
253
    XSetInputFocus(display_, window_, RevertToParent, CurrentTime);
257
254
  }
258
 
  
 
255
 
259
256
  void XInputWindow::Hide ()
260
257
  {
261
 
    XMoveResizeWindow (_display, _window, -100 - _width, -100 - _height, _width, _height);
262
 
    _shown = false;
 
258
    XMoveResizeWindow(display_, window_,
 
259
                      -100 - geometry_.width,
 
260
                      -100 - geometry_.height,
 
261
                      geometry_.width,
 
262
                      geometry_.height);
 
263
    shown_ = false;
263
264
  }
264
 
  
 
265
 
265
266
  void XInputWindow::Show ()
266
267
  {
267
 
    _shown = true;
268
 
    
269
 
    if (!_mapped)
 
268
    shown_ = true;
 
269
 
 
270
    if (!mapped_)
270
271
    {
271
 
      XMapRaised (_display, _window);
272
 
      _mapped = true;
 
272
      XMapRaised (display_, window_);
 
273
      mapped_ = true;
273
274
    }
274
 
    XMoveResizeWindow (_display, _window, _x, _y, _width, _height);
 
275
    XMoveResizeWindow(display_, window_,
 
276
                      geometry_.x, geometry_.y,
 
277
                      geometry_.width, geometry_.height);
275
278
  }
276
279
}
277
280