~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to vmware-user/dragDetWnd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*********************************************************
2
 
 * Copyright (C) 2009 VMware, Inc. All rights reserved.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify it
5
 
 * under the terms of the GNU Lesser General Public License as published
6
 
 * by the Free Software Foundation version 2.1 and no later version.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
 
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
11
 
 * License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program; if not, write to the Free Software Foundation, Inc.,
15
 
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
16
 
 *
17
 
 *********************************************************/
18
 
 
19
 
/**
20
 
 * @file dragDetWnd.cpp
21
 
 *
22
 
 * Detection window code for Linux/X11, based on Gtkmm. Includes unit test
23
 
 * code.
24
 
 */
25
 
 
26
 
#include "dragDetWnd.h"
27
 
 
28
 
/**
29
 
 *
30
 
 * Constructor.
31
 
 */
32
 
 
33
 
extern "C" {
34
 
#include "debug.h"
35
 
}
36
 
 
37
 
#include "dndUI.h"
38
 
#include <list>
39
 
 
40
 
/**
41
 
 *
42
 
 * Constructor.
43
 
 */
44
 
 
45
 
DragDetWnd::DragDetWnd() :
46
 
   m_isVisible(false)
47
 
{
48
 
#if defined(DETWNDDEBUG)
49
 
   DebugSetAttributes();
50
 
#endif
51
 
}
52
 
 
53
 
 
54
 
/**
55
 
 *
56
 
 * Destructor.
57
 
 */
58
 
 
59
 
DragDetWnd::~DragDetWnd()
60
 
{
61
 
}
62
 
 
63
 
 
64
 
/**
65
 
 * Flush the X connection.
66
 
 */
67
 
 
68
 
void
69
 
DragDetWnd::Flush()
70
 
{
71
 
   Glib::RefPtr<Gdk::Display> gdkdisplay = Gdk::Display::get_default();
72
 
   if (gdkdisplay) {
73
 
      gdkdisplay->sync();
74
 
      gdkdisplay->flush();
75
 
   }
76
 
}
77
 
 
78
 
 
79
 
/**
80
 
 *
81
 
 * Show the window.
82
 
 */
83
 
 
84
 
void
85
 
DragDetWnd::Show(void)
86
 
{
87
 
   show();
88
 
   Flush();
89
 
}
90
 
 
91
 
 
92
 
/**
93
 
 *
94
 
 * Hide the window.
95
 
 */
96
 
 
97
 
void
98
 
DragDetWnd::Hide(void)
99
 
{
100
 
   hide();
101
 
   Flush();
102
 
}
103
 
 
104
 
 
105
 
/**
106
 
 *
107
 
 * Raise the window.
108
 
 */
109
 
 
110
 
void
111
 
DragDetWnd::Raise(void)
112
 
{
113
 
   Glib::RefPtr<Gdk::Window> gdkwin = get_window();
114
 
   if (gdkwin) {
115
 
      gdkwin->raise();
116
 
   }
117
 
   Flush();
118
 
}
119
 
 
120
 
 
121
 
/**
122
 
 *
123
 
 * Lower the window.
124
 
 */
125
 
 
126
 
void
127
 
DragDetWnd::Lower(void)
128
 
{
129
 
   Glib::RefPtr<Gdk::Window> gdkwin = get_window();
130
 
   if (gdkwin) {
131
 
      gdkwin->lower();
132
 
   }
133
 
   Flush();
134
 
}
135
 
 
136
 
 
137
 
/**
138
 
 *
139
 
 * Get the width of the screen associated with this window.
140
 
 *
141
 
 * @return width of screen, in pixels.
142
 
 */
143
 
 
144
 
int
145
 
DragDetWnd::GetScreenWidth(void)
146
 
{
147
 
   Glib::RefPtr<Gdk::Screen> gdkscreen = get_screen();
148
 
   return gdkscreen->get_width();
149
 
}
150
 
 
151
 
 
152
 
/**
153
 
 *
154
 
 * Get the height of the screen associated with this window.
155
 
 *
156
 
 * @return height of screen, in pixels.
157
 
 */
158
 
 
159
 
int
160
 
DragDetWnd::GetScreenHeight(void)
161
 
{
162
 
   Glib::RefPtr<Gdk::Screen> gdkscreen = get_screen();
163
 
   return gdkscreen->get_height();
164
 
}
165
 
 
166
 
 
167
 
#if defined(DETWNDDEBUG)
168
 
/**
169
 
 *
170
 
 * Set default window attributes appropriate for debugging detection windows.
171
 
 *
172
 
 * @note This only applies to instances of DragDetWnd that are derived from
173
 
 * GTK::Window.
174
 
 */
175
 
 
176
 
void
177
 
DragDetWnd::DebugSetAttributes(void)
178
 
{
179
 
   set_default_size(1, 1);
180
 
   set_resizable(true);
181
 
   set_decorated(false);
182
 
   set_type_hint(Gdk::WINDOW_TYPE_HINT_DOCK);
183
 
}
184
 
#endif
185
 
 
186
 
 
187
 
/**
188
 
 *
189
 
 * Set the geometry of the window.
190
 
 *
191
 
 * @param[in] x desired x-coordinate of the window.
192
 
 * @param[in] y desired y-coordinate of the window.
193
 
 * @param[in] width desired width of the window.
194
 
 * @param[in] height desired height of the window.
195
 
 */
196
 
 
197
 
void
198
 
DragDetWnd::SetGeometry(const int x,
199
 
                        const int y,
200
 
                        const int width,
201
 
                        const int height)
202
 
{
203
 
   Glib::RefPtr<Gdk::Window> gdkwin = get_window();
204
 
 
205
 
   if (gdkwin) {
206
 
      gdkwin->move_resize(x, y, width, height);
207
 
      Flush();
208
 
   }
209
 
}
210
 
 
211
 
 
212
 
/**
213
 
 *
214
 
 * Get the current geometry of the window.
215
 
 *
216
 
 * @param[out] x current x-coordinate of the window.
217
 
 * @param[out] y current y-coordinate of the window.
218
 
 * @param[out] width current width of the window.
219
 
 * @param[out] height current height of the window.
220
 
 *
221
 
 * @note The current geometry may be inaccurate if retrieved too quickly
222
 
 * after a change made by SetGeometry(). This is due to the realities of
223
 
 * X and window managers. Some of this is mitigated by the use of flush()
224
 
 * and sync() calls in SetGeometry(), but these are no guarantee.
225
 
 */
226
 
 
227
 
void
228
 
DragDetWnd::GetGeometry(int &x, int &y, int &width, int &height)
229
 
{
230
 
   int dummy;
231
 
 
232
 
   Glib::RefPtr<Gdk::Window> gdkwin = get_window();
233
 
   if (gdkwin) {
234
 
      gdkwin->get_geometry(x, y, width, height, dummy);
235
 
#if defined(DETWNDTEST)
236
 
      Flush();
237
 
#endif
238
 
   }
239
 
}
240
 
 
241
 
/*
242
 
 * Code below here is for unit tests.
243
 
 */
244
 
 
245
 
#if defined(DETWNDTEST)
246
 
 
247
 
/**
248
 
 *
249
 
 * Add a button to launch unit tests to the drag detection window.
250
 
 */
251
 
 
252
 
void
253
 
DragDetWndTest::CreateTestUI()
254
 
{
255
 
   m_button.set_label("Start Unit Tests");
256
 
   add(m_button);
257
 
   m_button.signal_clicked().connect(sigc::mem_fun(*this, &DragDetWndTest::RunUnitTests));
258
 
   m_button.show();
259
 
}
260
 
 
261
 
 
262
 
/**
263
 
 *
264
 
 * Run some unit tests, then exit. Requires a main program, refer to
265
 
 * bora-vmsoft/toolbox/linux/vmwareuser/detWndTest/main.cpp for an
266
 
 * example.
267
 
 */
268
 
 
269
 
void
270
 
DragDetWndTest::RunUnitTests()
271
 
{
272
 
   DragDetWnd testWnd;
273
 
   int testCount = 0;
274
 
   int failCount = 0;
275
 
 
276
 
#if defined(DETWNDDEBUG)
277
 
   testWnd.SetAttributes();
278
 
#endif
279
 
   testWnd.Show();
280
 
   int x, y, width, height;
281
 
   testWnd.GetGeometry(x, y, width, height);
282
 
   printf("Geometry is x %d y %d width %d height %d\n", x, y, width, height);
283
 
 
284
 
   for (int i = 10; i < 50; Gtk::Main::iteration(), i++) {
285
 
      testCount++;
286
 
      printf("Setting geometry to x %d y %d w %d h %d\n", i * 10, i * 10, i * 10, i * 10);
287
 
      testWnd.SetGeometry(i * 10, i * 10, i * 10, i * 10);
288
 
      sleep(1);
289
 
      testWnd.GetGeometry(x, y, width, height);
290
 
      printf("Geometry is x %d y %d width %d height %d\n", x, y, width, height);
291
 
      if (x != i * 10 || y != i * 10 || width != i * 10) {
292
 
         printf("FAIL x or y not correct\n");
293
 
         failCount++;
294
 
      }
295
 
   }
296
 
 
297
 
   for (int i = 49; i > 0; Gtk::Main::iteration(), i--) {
298
 
      testCount++;
299
 
      printf("Setting geometry to x %d y %d w %d h %d\n", i * 10, i * 10, i * 10, i * 10);
300
 
      testWnd.SetGeometry(i * 10, i * 10, i * 10, i * 10);
301
 
      sleep(1);
302
 
      testWnd.GetGeometry(x, y, width, height);
303
 
      printf("Geometry is x %d y %d width %d height %d\n", x, y, width, height);
304
 
      if (x != i * 10 || y != i * 10 || width != i * 10) {
305
 
         printf("FAIL width or height not correct\n");
306
 
         failCount++;
307
 
      }
308
 
   }
309
 
 
310
 
   testWnd.SetGeometry(500, 500, 300, 300);
311
 
 
312
 
   for (int i = 0; i < 60; Gtk::Main::iteration(), i++) {
313
 
      if (i % 2) {
314
 
         printf("Hide\n");
315
 
         testWnd.Hide();
316
 
      } else {
317
 
         printf("Show\n");
318
 
         testWnd.Show();
319
 
         testWnd.Raise();
320
 
      }
321
 
      sleep(1);
322
 
   }
323
 
 
324
 
   printf("Done fail count %d (%.2f%%)\n", failCount, 100.0 * failCount/testCount);
325
 
   Gtk::Main::quit();
326
 
}
327
 
#endif