1
/*********************************************************
2
* Copyright (C) 2005 VMware, Inc. All rights reserved.
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.
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.
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.
17
*********************************************************/
22
* Set of functions for pointer (mouse) grab/ungrab.
25
#include "vmwareuserInt.h"
29
#include "vm_assert.h"
34
#include "eventManager.h"
35
#include "vmware/guestrpc/tclodefs.h"
37
static GuestAppAbsoluteMouseState absoluteMouseState = GUESTAPP_ABSMOUSE_UNKNOWN;
38
static Bool mouseIsGrabbed;
39
static uint8 gHostClipboardTries = 0;
42
* Forward Declarations
44
void PointerGrabbed(void);
45
void PointerUngrabbed(void);
46
void PointerGetXCursorPos(int *x, int *y);
47
static Bool PointerUpdatePointerLoop(void* clientData);
50
*-----------------------------------------------------------------------------
52
* PointerGetXCursorPos --
54
* Return the position in pixels of the X (mouse) pointer in the root
58
* x and y coordinates.
62
*-----------------------------------------------------------------------------
66
PointerGetXCursorPos(int *rootX, int *rootY)
74
XQueryPointer(gXDisplay, gXRoot, &rootWin, &childWin, rootX, rootY, &x, &y, &mask);
79
*-----------------------------------------------------------------------------
81
* PointerSetXCursorPos
83
* Set the position in pixels of the X (mouse) pointer in the root window
91
*-----------------------------------------------------------------------------
95
PointerSetXCursorPos(int x, int y)
97
XWarpPointer(gXDisplay, None, gXRoot, 0, 0, 0, 0, x, y);
102
*-----------------------------------------------------------------------------
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.
116
*-----------------------------------------------------------------------------
125
GuestApp_GetPos(&hostPosX, &hostPosY);
127
PointerSetXCursorPos(hostPosX, hostPosY);
128
gHostClipboardTries = 9;
133
*-----------------------------------------------------------------------------
135
* PointerUngrabbed --
137
* Called when the pointer's state switches from grabbed to release.
145
*-----------------------------------------------------------------------------
148
PointerUngrabbed(void)
150
CopyPaste_RequestSelection();
155
*-----------------------------------------------------------------------------
157
* PointerUpdatePointerLoop --
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.
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.
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.
178
*-----------------------------------------------------------------------------
182
PointerUpdatePointerLoop(void* clientData) // IN: unused
187
GuestApp_GetPos(&hostX, &hostY);
188
if (mouseIsGrabbed) {
189
if (hostX == UNGRABBED_POS) {
190
/* We transitioned from grabbed to ungrabbed */
191
mouseIsGrabbed = FALSE;
194
PointerGetXCursorPos(&guestX, &guestY);
195
if (hostX != guestX || hostY != guestY) {
196
GuestApp_SetPos(guestX,guestY);
198
if (gHostClipboardTries-- > 0) {
199
if (gHostClipboardTries < 6 &&
200
CopyPaste_GetBackdoorSelections()) {
201
gHostClipboardTries = 0;
206
if (hostX != UNGRABBED_POS) {
207
mouseIsGrabbed = TRUE;
213
if (!CopyPaste_IsRpcCPSupported() ||
214
(absoluteMouseState == GUESTAPP_ABSMOUSE_UNAVAILABLE)) {
215
EventManager_Add(gEventQueue, POINTER_POLL_TIME, PointerUpdatePointerLoop,
223
*-----------------------------------------------------------------------------
225
* Pointer_Register --
227
* Initialize Pointer.
235
*-----------------------------------------------------------------------------
239
Pointer_Register(GtkWidget* mainWnd)
241
absoluteMouseState = GuestApp_GetAbsoluteMouseState();
242
PointerUpdatePointerLoop(mainWnd);
243
mouseIsGrabbed = FALSE;