Skip to content

Commit 6d1de4f

Browse files
committed
Support the VMware Cursor Position extension on vncviewer
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!
1 parent 4eda4c2 commit 6d1de4f

File tree

10 files changed

+52
-2
lines changed

10 files changed

+52
-2
lines changed

common/rfb/CConnection.cxx

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ static LogWriter vlog("CConnection");
4343

4444
CConnection::CConnection()
4545
: csecurity(0),
46-
supportsLocalCursor(false), supportsDesktopResize(false),
47-
supportsLEDState(false),
46+
supportsLocalCursor(false), supportsCursorPosition(false),
47+
supportsDesktopResize(false), supportsLEDState(false),
4848
is(0), os(0), reader_(0), writer_(0),
4949
shared(false),
5050
state_(RFBSTATE_UNINITIALISED),
@@ -805,6 +805,9 @@ void CConnection::updateEncodings()
805805
encodings.push_back(pseudoEncodingCursor);
806806
encodings.push_back(pseudoEncodingXCursor);
807807
}
808+
if (supportsCursorPosition) {
809+
encodings.push_back(pseudoEncodingVMwareCursorPosition);
810+
}
808811
if (supportsDesktopResize) {
809812
encodings.push_back(pseudoEncodingDesktopSize);
810813
encodings.push_back(pseudoEncodingExtendedDesktopSize);

common/rfb/CConnection.h

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ namespace rfb {
239239
// Optional capabilities that a subclass is expected to set to true
240240
// if supported
241241
bool supportsLocalCursor;
242+
bool supportsCursorPosition;
242243
bool supportsDesktopResize;
243244
bool supportsLEDState;
244245

common/rfb/CMsgHandler.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace rfb {
5252
const ScreenSet& layout);
5353
virtual void setCursor(int width, int height, const Point& hotspot,
5454
const rdr::U8* data) = 0;
55+
virtual void setCursorPos(const Point& pos) = 0;
5556
virtual void setPixelFormat(const PixelFormat& pf);
5657
virtual void setName(const char* name);
5758
virtual void fence(rdr::U32 flags, unsigned len, const char data[]);

common/rfb/CMsgReader.cxx

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ bool CMsgReader::readMsg()
165165
case pseudoEncodingVMwareCursor:
166166
ret = readSetVMwareCursor(dataRect.width(), dataRect.height(), dataRect.tl);
167167
break;
168+
case pseudoEncodingVMwareCursorPosition:
169+
handler->setCursorPos(dataRect.tl);
170+
ret = true;
171+
break;
168172
case pseudoEncodingDesktopName:
169173
ret = readSetDesktopName(dataRect.tl.x, dataRect.tl.y,
170174
dataRect.width(), dataRect.height());

tests/perf/decperf.cxx

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class CConn : public rfb::CConnection {
6666
virtual void initDone();
6767
virtual void setPixelFormat(const rfb::PixelFormat& pf);
6868
virtual void setCursor(int, int, const rfb::Point&, const rdr::U8*);
69+
virtual void setCursorPos(const rfb::Point&);
6970
virtual void framebufferUpdateStart();
7071
virtual void framebufferUpdateEnd();
7172
virtual void setColourMapEntries(int, int, rdr::U16*);
@@ -144,6 +145,10 @@ void CConn::setCursor(int, int, const rfb::Point&, const rdr::U8*)
144145
{
145146
}
146147

148+
void CConn::setCursorPos(const rfb::Point&)
149+
{
150+
}
151+
147152
void CConn::framebufferUpdateStart()
148153
{
149154
CConnection::framebufferUpdateStart();

tests/perf/encperf.cxx

+5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class CConn : public rfb::CConnection {
9595
virtual void initDone() {};
9696
virtual void resizeFramebuffer();
9797
virtual void setCursor(int, int, const rfb::Point&, const rdr::U8*);
98+
virtual void setCursorPos(const rfb::Point&);
9899
virtual void framebufferUpdateStart();
99100
virtual void framebufferUpdateEnd();
100101
virtual bool dataRect(const rfb::Rect&, int);
@@ -216,6 +217,10 @@ void CConn::setCursor(int, int, const rfb::Point&, const rdr::U8*)
216217
{
217218
}
218219

220+
void CConn::setCursorPos(const rfb::Point&)
221+
{
222+
}
223+
219224
void CConn::framebufferUpdateStart()
220225
{
221226
CConnection::framebufferUpdateStart();

vncviewer/CConn.cxx

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ CConn::CConn(const char* vncServerName, network::Socket* socket=NULL)
8484
sock = socket;
8585

8686
supportsLocalCursor = true;
87+
supportsCursorPosition = true;
8788
supportsDesktopResize = true;
8889
supportsLEDState = false;
8990

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

434+
void CConn::setCursorPos(const Point& pos)
435+
{
436+
desktop->setCursorPos(pos);
437+
}
438+
433439
void CConn::fence(rdr::U32 flags, unsigned len, const char data[])
434440
{
435441
CMsgHandler::fence(flags, len, data);

vncviewer/CConn.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CConn : public rfb::CConnection
6363

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

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

vncviewer/DesktopWindow.cxx

+21
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,27 @@ void DesktopWindow::setCursor(int width, int height,
322322
}
323323

324324

325+
void DesktopWindow::setCursorPos(const rfb::Point& pos)
326+
{
327+
if (!mouseGrabbed) {
328+
// Do nothing if we do not have the mouse captured.
329+
return;
330+
}
331+
#if defined(WIN32)
332+
SetCursorPos(pos.x, pos.y);
333+
#elif defined(__APPLE__)
334+
CGPoint new_pos;
335+
new_pos.x = pos.x;
336+
new_pos.y = pos.y;
337+
CGWarpMouseCursorPosition(new_pos);
338+
#else // Assume this is Xlib
339+
Window rootwindow = DefaultRootWindow(fl_display);
340+
XWarpPointer(fl_display, rootwindow, rootwindow, 0, 0, 0, 0,
341+
pos.x, pos.y);
342+
#endif
343+
}
344+
345+
325346
void DesktopWindow::show()
326347
{
327348
Fl_Window::show();

vncviewer/DesktopWindow.h

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class DesktopWindow : public Fl_Window {
6666
void setCursor(int width, int height, const rfb::Point& hotspot,
6767
const rdr::U8* data);
6868

69+
// Server-provided cursor position
70+
void setCursorPos(const rfb::Point& pos);
71+
6972
// Change client LED state
7073
void setLEDState(unsigned int state);
7174

0 commit comments

Comments
 (0)