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

« back to all changes in this revision

Viewing changes to vmware-user/pointer.c

  • 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) 2005 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
 
 * pointer.c --
21
 
 *
22
 
 *     Set of functions for pointer (mouse) grab/ungrab.
23
 
 */
24
 
 
25
 
#include "vmwareuserInt.h"
26
 
#include <stdlib.h>
27
 
#include <string.h>
28
 
 
29
 
#include "vm_assert.h"
30
 
#include "debug.h"
31
 
#include "str.h"
32
 
#include "strutil.h"
33
 
#include "guestApp.h"
34
 
#include "eventManager.h"
35
 
#include "vmware/guestrpc/tclodefs.h"
36
 
 
37
 
static GuestAppAbsoluteMouseState absoluteMouseState = GUESTAPP_ABSMOUSE_UNKNOWN;
38
 
static Bool mouseIsGrabbed;
39
 
static uint8 gHostClipboardTries = 0;
40
 
 
41
 
/*
42
 
 * Forward Declarations
43
 
 */
44
 
void PointerGrabbed(void);
45
 
void PointerUngrabbed(void);
46
 
void PointerGetXCursorPos(int *x, int *y);
47
 
static Bool PointerUpdatePointerLoop(void* clientData);
48
 
 
49
 
/*
50
 
 *-----------------------------------------------------------------------------
51
 
 *
52
 
 * PointerGetXCursorPos --
53
 
 *
54
 
 *      Return the position in pixels of the X (mouse) pointer in the root
55
 
 *      window.
56
 
 *
57
 
 * Results:
58
 
 *      x and y coordinates.
59
 
 *
60
 
 * Side effects:
61
 
 *      None.
62
 
 *-----------------------------------------------------------------------------
63
 
 */
64
 
 
65
 
void
66
 
PointerGetXCursorPos(int *rootX, int *rootY)
67
 
{
68
 
   Window rootWin;
69
 
   Window childWin;
70
 
   int x;
71
 
   int y;
72
 
   unsigned int mask;
73
 
 
74
 
   XQueryPointer(gXDisplay, gXRoot, &rootWin, &childWin, rootX, rootY, &x, &y, &mask);
75
 
}
76
 
 
77
 
 
78
 
/*
79
 
 *-----------------------------------------------------------------------------
80
 
 *
81
 
 * PointerSetXCursorPos
82
 
 *
83
 
 *      Set the position in pixels of the X (mouse) pointer in the root window
84
 
 *
85
 
 * Results:
86
 
 *      None.
87
 
 *
88
 
 * Side effects:
89
 
 *      None.
90
 
 *
91
 
 *-----------------------------------------------------------------------------
92
 
 */
93
 
 
94
 
void
95
 
PointerSetXCursorPos(int x, int y)
96
 
{
97
 
   XWarpPointer(gXDisplay, None, gXRoot, 0, 0, 0, 0, x, y);
98
 
}
99
 
 
100
 
 
101
 
/*
102
 
 *-----------------------------------------------------------------------------
103
 
 *
104
 
 * PointerGrabbed --
105
 
 *
106
 
 *      Called when the pointer's state switches from released to grabbed.
107
 
 *      We warp the cursor to whatever position the vmx tells us, and then
108
 
 *      setup the loop which attempts to get the host clipboard.
109
 
 *
110
 
 * Results:
111
 
 *      None.
112
 
 *
113
 
 * Side effects:
114
 
 *      None.
115
 
 *
116
 
 *-----------------------------------------------------------------------------
117
 
 */
118
 
 
119
 
void
120
 
PointerGrabbed()
121
 
{
122
 
   short hostPosX;
123
 
   short hostPosY;
124
 
 
125
 
   GuestApp_GetPos(&hostPosX, &hostPosY);
126
 
 
127
 
   PointerSetXCursorPos(hostPosX, hostPosY);
128
 
   gHostClipboardTries = 9;
129
 
}
130
 
 
131
 
 
132
 
/*
133
 
 *-----------------------------------------------------------------------------
134
 
 *
135
 
 * PointerUngrabbed --
136
 
 *
137
 
 *      Called when the pointer's state switches from grabbed to release.
138
 
 *
139
 
 * Results:
140
 
 *      None.
141
 
 *
142
 
 * Side effects:
143
 
 *      None.
144
 
 *
145
 
 *-----------------------------------------------------------------------------
146
 
 */
147
 
void
148
 
PointerUngrabbed(void)
149
 
{
150
 
   CopyPaste_RequestSelection();
151
 
}
152
 
 
153
 
 
154
 
/*
155
 
 *-----------------------------------------------------------------------------
156
 
 *
157
 
 * PointerUpdatePointerLoop  --
158
 
 *
159
 
 *      Event Manager function for tracking the mouse/pointer/clipboard state.
160
 
 *      Manage grabbed/ungrab state based on x/y data from backdoor. On the
161
 
 *      transition to grabbed, call PointerHasBeenGrabbed(). While grabbed,
162
 
 *      send guest pointer coordinates thru the backdoor. Also, make several
163
 
 *      attempts to get the host clipboard from the backdoor. When changing
164
 
 *      to ungrabbed, call PointerHasBeenUngrabbed, which will push our
165
 
 *      clipboard thru the backdoor. While ungrabbed, don't do a thing.
166
 
 *
167
 
 *      This function is queued in Event Manager only when vmx doesn't support 
168
 
 *      RPC copy/paste because newer vmx initiates copy/paste from UI through 
169
 
 *      RPC, and doesn't need cursor grab/ungrab state to start copy/paste.
170
 
 *
171
 
 * Results:
172
 
 *      TRUE.
173
 
 *
174
 
 * Side effects:
175
 
 *      Lots. The vmx's notion of guest cursor position could change, the
176
 
 *      vmx's clipboard could change, and the guest's clipboard could change.
177
 
 *
178
 
 *-----------------------------------------------------------------------------
179
 
 */
180
 
 
181
 
static Bool
182
 
PointerUpdatePointerLoop(void* clientData) // IN: unused
183
 
{
184
 
   int16 hostX, hostY;
185
 
   int guestX, guestY;
186
 
 
187
 
   GuestApp_GetPos(&hostX, &hostY);
188
 
   if (mouseIsGrabbed) {
189
 
      if (hostX == UNGRABBED_POS) {
190
 
         /* We transitioned from grabbed to ungrabbed */
191
 
         mouseIsGrabbed = FALSE;
192
 
         PointerUngrabbed();
193
 
      } else {
194
 
         PointerGetXCursorPos(&guestX, &guestY);
195
 
         if (hostX != guestX || hostY != guestY) {
196
 
            GuestApp_SetPos(guestX,guestY);
197
 
         }
198
 
         if (gHostClipboardTries-- > 0) {
199
 
            if (gHostClipboardTries < 6 &&
200
 
                CopyPaste_GetBackdoorSelections()) {
201
 
               gHostClipboardTries = 0;
202
 
            }
203
 
         }
204
 
      }
205
 
   } else {
206
 
      if (hostX != UNGRABBED_POS) {
207
 
         mouseIsGrabbed = TRUE;
208
 
         PointerGrabbed();
209
 
      }
210
 
 
211
 
   }
212
 
 
213
 
   if (!CopyPaste_IsRpcCPSupported() ||
214
 
       (absoluteMouseState == GUESTAPP_ABSMOUSE_UNAVAILABLE)) {
215
 
      EventManager_Add(gEventQueue, POINTER_POLL_TIME, PointerUpdatePointerLoop,
216
 
                       clientData);
217
 
   }
218
 
   return TRUE;
219
 
}
220
 
 
221
 
 
222
 
/*
223
 
 *-----------------------------------------------------------------------------
224
 
 *
225
 
 * Pointer_Register --
226
 
 *
227
 
 *      Initialize Pointer.
228
 
 *
229
 
 * Results:
230
 
 *      Always TRUE.
231
 
 *
232
 
 * Side effects:
233
 
 *      None
234
 
 *
235
 
 *-----------------------------------------------------------------------------
236
 
 */
237
 
 
238
 
Bool
239
 
Pointer_Register(GtkWidget* mainWnd)
240
 
{
241
 
   absoluteMouseState = GuestApp_GetAbsoluteMouseState();
242
 
   PointerUpdatePointerLoop(mainWnd);
243
 
   mouseIsGrabbed = FALSE;
244
 
   return TRUE;
245
 
}