Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the VMware Cursor Position extension on vncviewer #1212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 13 additions & 1 deletion common/rfb/ClientParams.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ClientParams::ClientParams()
compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
subsampling(subsampleUndefined),
width_(0), height_(0), name_(0),
ledState_(ledUnknown)
cursorPos_(0, 0), ledState_(ledUnknown)
{
setName("");

Expand Down Expand Up @@ -85,6 +85,11 @@ void ClientParams::setCursor(const Cursor& other)
cursor_ = new Cursor(other);
}

void ClientParams::setCursorPos(const Point& pos)
{
cursorPos_ = pos;
}

bool ClientParams::supportsEncoding(rdr::S32 encoding) const
{
return encodings_.count(encoding) != 0;
Expand Down Expand Up @@ -182,6 +187,13 @@ bool ClientParams::supportsLocalCursor() const
return false;
}

bool ClientParams::supportsCursorPosition() const
{
if (supportsEncoding(pseudoEncodingVMwareCursorPosition))
return true;
return false;
}

bool ClientParams::supportsDesktopSize() const
{
if (supportsEncoding(pseudoEncodingExtendedDesktopSize))
Expand Down
5 changes: 5 additions & 0 deletions common/rfb/ClientParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ namespace rfb {
const Cursor& cursor() const { return *cursor_; }
void setCursor(const Cursor& cursor);

const Point& cursorPos() const { return cursorPos_; }
void setCursorPos(const Point& pos);

bool supportsEncoding(rdr::S32 encoding) const;

void setEncodings(int nEncodings, const rdr::S32* encodings);
Expand All @@ -91,6 +94,7 @@ namespace rfb {
// Wrappers to check for functionality rather than specific
// encodings
bool supportsLocalCursor() const;
bool supportsCursorPosition() const;
bool supportsDesktopSize() const;
bool supportsLEDState() const;
bool supportsFence() const;
Expand All @@ -110,6 +114,7 @@ namespace rfb {
PixelFormat pf_;
char* name_;
Cursor* cursor_;
Point cursorPos_;
std::set<rdr::S32> encodings_;
unsigned int ledState_;
rdr::U32 clipFlags;
Expand Down
1 change: 1 addition & 0 deletions common/rfb/encodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace rfb {

// VMware-specific
const int pseudoEncodingVMwareCursor = 0x574d5664;
const int pseudoEncodingVMwareCursorPosition = 0x574d5666;
const int pseudoEncodingVMwareLEDState = 0x574d5668;

// UltraVNC-specific
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
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
32 changes: 32 additions & 0 deletions vncviewer/DesktopWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

#ifdef __APPLE__
#include "cocoa.h"
#include <Carbon/Carbon.h>
#endif

#define EDGE_SCROLL_SIZE 32
Expand Down Expand Up @@ -186,6 +187,14 @@ DesktopWindow::DesktopWindow(int w, int h, const char *name,

// Show hint about menu key
Fl::add_timeout(0.5, menuOverlay, this);

// By default we get a slight delay when we warp the pointer, something
// we don't want or we'll get jerky movement
#ifdef __APPLE__
CGEventSourceRef event = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventSourceSetLocalEventsSuppressionInterval(event, 0);
CFRelease(event);
#endif
}


Expand Down Expand Up @@ -322,6 +331,29 @@ void DesktopWindow::setCursor(int width, int height,
}


void DesktopWindow::setCursorPos(const rfb::Point& pos)
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i take the mouse-grabbing comment back, this worked!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The grab check was fine and much welcome. My point was to also check focus. But then again, I guess grab implies focus so I guess that isn't needed...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! got it, i didn't quite grok the meaning of the other comment. Restored the grab check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really restored the grab check.

if (!mouseGrabbed) {
// Do nothing if we do not have the mouse captured.
return;
}
#if defined(WIN32)
SetCursorPos(pos.x + x_root() + viewport->x(),
pos.y + y_root() + viewport->y());
#elif defined(__APPLE__)
CGPoint new_pos;
new_pos.x = pos.x + x_root() + viewport->x();
new_pos.y = pos.y + y_root() + 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 + x_root() + viewport->x(),
pos.y + y_root() + 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