Skip to content

Commit

Permalink
Support the VMware Cursor Position extension on vncviewer
Browse files Browse the repository at this point in the history
This change makes it possible for re-synchronizing the remote cursor on
the vncviewer when in fullscreen mode. This is done by locally moving
the cursor position to what the server thinks it should be.

Now SDL games should work!
  • Loading branch information
lhchavez committed Mar 1, 2021
1 parent b151bbd commit ee0e0ef
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 2 deletions.
7 changes: 5 additions & 2 deletions common/rfb/CConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ static LogWriter vlog("CConnection");

CConnection::CConnection()
: csecurity(0),
supportsLocalCursor(false), supportsDesktopResize(false),
supportsLEDState(false),
supportsLocalCursor(false), supportsCursorPosition(false),
supportsDesktopResize(false), supportsLEDState(false),
is(0), os(0), reader_(0), writer_(0),
shared(false),
state_(RFBSTATE_UNINITIALISED),
Expand Down Expand Up @@ -805,6 +805,9 @@ void CConnection::updateEncodings()
encodings.push_back(pseudoEncodingCursor);
encodings.push_back(pseudoEncodingXCursor);
}
if (supportsCursorPosition) {
encodings.push_back(pseudoEncodingVMwareCursorPosition);
}
if (supportsDesktopResize) {
encodings.push_back(pseudoEncodingDesktopSize);
encodings.push_back(pseudoEncodingExtendedDesktopSize);
Expand Down
1 change: 1 addition & 0 deletions common/rfb/CConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ namespace rfb {
// Optional capabilities that a subclass is expected to set to true
// if supported
bool supportsLocalCursor;
bool supportsCursorPosition;
bool supportsDesktopResize;
bool supportsLEDState;

Expand Down
1 change: 1 addition & 0 deletions common/rfb/CMsgHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace rfb {
const ScreenSet& layout);
virtual void setCursor(int width, int height, const Point& hotspot,
const rdr::U8* data) = 0;
virtual void setCursorPos(const Point& pos) = 0;
virtual void setPixelFormat(const PixelFormat& pf);
virtual void setName(const char* name);
virtual void fence(rdr::U32 flags, unsigned len, const char data[]);
Expand Down
4 changes: 4 additions & 0 deletions common/rfb/CMsgReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ bool CMsgReader::readMsg()
case pseudoEncodingVMwareCursor:
ret = readSetVMwareCursor(dataRect.width(), dataRect.height(), dataRect.tl);
break;
case pseudoEncodingVMwareCursorPosition:
handler->setCursorPos(dataRect.tl);
ret = true;
break;
case pseudoEncodingDesktopName:
ret = readSetDesktopName(dataRect.tl.x, dataRect.tl.y,
dataRect.width(), dataRect.height());
Expand Down
5 changes: 5 additions & 0 deletions tests/perf/decperf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CConn : public rfb::CConnection {
virtual void initDone();
virtual void setPixelFormat(const rfb::PixelFormat& pf);
virtual void setCursor(int, int, const rfb::Point&, const rdr::U8*);
virtual void setCursorPos(const rfb::Point&);
virtual void framebufferUpdateStart();
virtual void framebufferUpdateEnd();
virtual void setColourMapEntries(int, int, rdr::U16*);
Expand Down Expand Up @@ -144,6 +145,10 @@ void CConn::setCursor(int, int, const rfb::Point&, const rdr::U8*)
{
}

void CConn::setCursorPos(const rfb::Point&)
{
}

void CConn::framebufferUpdateStart()
{
CConnection::framebufferUpdateStart();
Expand Down
5 changes: 5 additions & 0 deletions tests/perf/encperf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class CConn : public rfb::CConnection {
virtual void initDone() {};
virtual void resizeFramebuffer();
virtual void setCursor(int, int, const rfb::Point&, const rdr::U8*);
virtual void setCursorPos(const rfb::Point&);
virtual void framebufferUpdateStart();
virtual void framebufferUpdateEnd();
virtual bool dataRect(const rfb::Rect&, int);
Expand Down Expand Up @@ -216,6 +217,10 @@ void CConn::setCursor(int, int, const rfb::Point&, const rdr::U8*)
{
}

void CConn::setCursorPos(const rfb::Point&)
{
}

void CConn::framebufferUpdateStart()
{
CConnection::framebufferUpdateStart();
Expand Down
8 changes: 8 additions & 0 deletions unix/xserver/hw/vnc/vncHooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ typedef struct _vncHooksScreenRec {
CopyWindowProcPtr CopyWindow;
ClearToBackgroundProcPtr ClearToBackground;
DisplayCursorProcPtr DisplayCursor;
#if XORG >= 119
CursorWarpedToProcPtr CursorWarpedTo;
#endif
ScreenBlockHandlerProcPtr BlockHandler;
#ifdef RENDER
CompositeProcPtr Composite;
Expand Down Expand Up @@ -114,10 +116,12 @@ static void vncHooksClearToBackground(WindowPtr pWin, int x, int y, int w,
int h, Bool generateExposures);
static Bool vncHooksDisplayCursor(DeviceIntPtr pDev,
ScreenPtr pScreen, CursorPtr cursor);
#if XORG >= 119
static void vncHooksCursorWarpedTo(DeviceIntPtr pDev,
ScreenPtr pScreen_, ClientPtr pClient,
WindowPtr pWindow, SpritePtr pSprite,
int x, int y);
#endif
#if XORG <= 118
static void vncHooksBlockHandler(ScreenPtr pScreen, void * pTimeout,
void * pReadmask);
Expand Down Expand Up @@ -276,7 +280,9 @@ int vncHooksInit(int scrIdx)
wrap(vncHooksScreen, pScreen, CopyWindow, vncHooksCopyWindow);
wrap(vncHooksScreen, pScreen, ClearToBackground, vncHooksClearToBackground);
wrap(vncHooksScreen, pScreen, DisplayCursor, vncHooksDisplayCursor);
#if XORG >= 119
wrap(vncHooksScreen, pScreen, CursorWarpedTo, vncHooksCursorWarpedTo);
#endif
wrap(vncHooksScreen, pScreen, BlockHandler, vncHooksBlockHandler);
#ifdef RENDER
ps = GetPictureScreenIfSet(pScreen);
Expand Down Expand Up @@ -639,6 +645,7 @@ static Bool vncHooksDisplayCursor(DeviceIntPtr pDev,

// CursorWarpedTo - notify that the cursor was warped

#if XORG >= 119
static void vncHooksCursorWarpedTo(DeviceIntPtr pDev,
ScreenPtr pScreen_, ClientPtr pClient,
WindowPtr pWindow, SpritePtr pSprite,
Expand All @@ -648,6 +655,7 @@ static void vncHooksCursorWarpedTo(DeviceIntPtr pDev,
vncSetCursorPos(pScreen->myNum, x, y);
SCREEN_EPILOGUE(CursorWarpedTo);
}
#endif

// BlockHandler - ignore any changes during the block handler - it's likely
// these are just drawing the cursor.
Expand Down
6 changes: 6 additions & 0 deletions vncviewer/CConn.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ CConn::CConn(const char* vncServerName, network::Socket* socket=NULL)
sock = socket;

supportsLocalCursor = true;
supportsCursorPosition = true;
supportsDesktopResize = true;
supportsLEDState = false;

Expand Down Expand Up @@ -430,6 +431,11 @@ void CConn::setCursor(int width, int height, const Point& hotspot,
desktop->setCursor(width, height, hotspot, data);
}

void CConn::setCursorPos(const Point& pos)
{
desktop->setCursorPos(pos);
}

void CConn::fence(rdr::U32 flags, unsigned len, const char data[])
{
CMsgHandler::fence(flags, len, data);
Expand Down
1 change: 1 addition & 0 deletions vncviewer/CConn.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class CConn : public rfb::CConnection

void setCursor(int width, int height, const rfb::Point& hotspot,
const rdr::U8* data);
void setCursorPos(const rfb::Point& pos);

void fence(rdr::U32 flags, unsigned len, const char data[]);

Expand Down
23 changes: 23 additions & 0 deletions vncviewer/DesktopWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

#ifdef __APPLE__
#include "cocoa.h"
#include <CoreGraphics/CGGeometry.h>
#include <CoreGraphics/CGRemoteOperation.h>
#endif

#define EDGE_SCROLL_SIZE 32
Expand Down Expand Up @@ -322,6 +324,27 @@ void DesktopWindow::setCursor(int width, int height,
}


void DesktopWindow::setCursorPos(const rfb::Point& pos)
{
if (!mouseGrabbed) {
// Do nothing if we do not have the mouse captured.
return;
}
#if defined(WIN32)
SetCursorPos(pos.x + viewport->x(), pos.y + viewport->y());
#elif defined(__APPLE__)
CGPoint new_pos;
new_pos.x = pos.x + viewport->x();
new_pos.y = pos.y + viewport->y();
CGWarpMouseCursorPosition(new_pos);
#else // Assume this is Xlib
Window rootwindow = DefaultRootWindow(fl_display);
XWarpPointer(fl_display, rootwindow, rootwindow, 0, 0, 0, 0,
pos.x + viewport->x(), pos.y + viewport->y());
#endif
}


void DesktopWindow::show()
{
Fl_Window::show();
Expand Down
3 changes: 3 additions & 0 deletions vncviewer/DesktopWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class DesktopWindow : public Fl_Window {
void setCursor(int width, int height, const rfb::Point& hotspot,
const rdr::U8* data);

// Server-provided cursor position
void setCursorPos(const rfb::Point& pos);

// Change client LED state
void setLEDState(unsigned int state);

Expand Down

0 comments on commit ee0e0ef

Please sign in to comment.