Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhalim committed Sep 24, 2024
1 parent 27295ed commit 0ec216e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
4 changes: 2 additions & 2 deletions common/rfb/CMsgWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void CMsgWriter::writePointerEvent(const Point& pos, uint16_t buttonMask)
if (p.y >= server->height()) p.y = server->height() - 1;

// Only send extended pointerEvent message when needed
extendedMouseButtons = buttonMask >= 0x80;
extendedMouseButtons = buttonMask & 0x180;

startMsg(msgTypePointerEvent);
if (server->supportsExtendedMouseButtons && extendedMouseButtons) {
Expand All @@ -195,7 +195,7 @@ void CMsgWriter::writePointerEvent(const Point& pos, uint16_t buttonMask)
lowerBits = buttonMask & 0x7f;
lowerBits |= 0x80; // Set marker bit to 1

higherBits &= 0x3; // Clear reserved bits
higherBits &= 0x03; // Clear reserved bits

os->writeU8(lowerBits);
os->writeU16(p.x);
Expand Down
10 changes: 5 additions & 5 deletions common/rfb/SMsgReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -279,25 +279,25 @@ bool SMsgReader::readPointerEvent()
if (!is->hasData(1 + 2 + 2))
return false;

is->setRestorePoint();

mask = is->readU8();
x = is->readU16();
y = is->readU16();

if (handler->client.supportsExtendedMouseButtons() && mask & 0x80 ) {
if (handler->client.supportsExtendedMouseButtons() && mask & 0x180 ) {
int highBits;
int lowBits;

if (!is->hasData(1))
if (!is->hasDataOrRestore(1))
return false;

highBits = is->readU8();
lowBits = mask & 0x7f; // Clear marker bit
mask = (highBits << 7) | lowBits;
} else {
// Ignore marker bit
mask &= ~(0x7f);
}

is->clearRestorePoint();
handler->pointerEvent(Point(x, y), mask);
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions common/rfb/SMsgWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ SMsgWriter::SMsgWriter(ClientParams* client_, rdr::OutStream* os_)
nRectsInUpdate(0), nRectsInHeader(0),
needSetDesktopName(false), needCursor(false),
needCursorPos(false), needLEDState(false),
needQEMUKeyEvent(false)
,needExtMouseButtonsEvent(false)
needQEMUKeyEvent(false) ,needExtMouseButtonsEvent(false)
{
}

Expand Down
17 changes: 17 additions & 0 deletions unix/xserver/hw/vnc/vncInput.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,23 @@ static int vncPointerProc(DeviceIntPtr pDevice, int onoff)
btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);

/*
* The labels BTN_LABEL_PROP_BTN_SIDE and BTN_LABEL_PROP_BTN_EXTRA
* represent the side buttons on mice that are typically used to
* navigate back/forward respectively in web browsers (and other
* applications).
*
* There are also two similar labels:
* BTN_LABEL_PROP_BTN_BACK and BTN_LABEL_PROP_BTN_FORWARD,
* which are also used by *some* X applications to indicate
* back/forward navigation. The SIDE/EXTRA labels seem to be more
* widely spread by X applications, and some applications even
* detect both labels.
*
* Most modern mice seem to label the side buttons
* (back / forward) with SIDE/EXTRA.
*/
btn_labels[7] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_SIDE);
btn_labels[8] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_EXTRA);

Expand Down
31 changes: 24 additions & 7 deletions vncviewer/Viewport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,19 @@ int Viewport::handle(int event)
case FL_MOVE:
case FL_MOUSEWHEEL:

// Reset state for left, right, middle
mouseButtonMask &= ~(0x7);
// FIXME: FLTK is not consistent in how it sends FL_PUSH/FL_RELEASE
// events:
// * https://github.com/fltk/fltk/issues/1076
// * https://github.com/fltk/fltk/issues/1077.
// For LMB/MMB/RMB, we can get the button states consistently.
// We can't get the state for back/forward, and have to keep track
// of them ourselves. Unfortunately as FLTK has these
// inconsistencies, we could end up in a scenario where the
// mouseButtonMask state is out of sync with reality
// (for forward/back). There isn't much we can do until the bug is
// resolved in FLTK.

mouseButtonMask &= ~(0x7);
if (Fl::event_button1())
mouseButtonMask |= 1 << 0;
if (Fl::event_button2())
Expand All @@ -614,15 +624,15 @@ int Viewport::handle(int event)
switch (event) {
case FL_PUSH:
case FL_DRAG:
if (Fl::event_button() == MOUSE_FORWARD)
if (Fl::event_button() == 8)
mouseButtonMask |= 1 << 7;
else if (Fl::event_button() == MOUSE_BACK)
else if (Fl::event_button() == 9)
mouseButtonMask |= 1 << 8;
break;
case FL_RELEASE:
if (Fl::event_button() == MOUSE_FORWARD)
if (Fl::event_button() == 8)
mouseButtonMask &= ~(1 << 7);
else if (Fl::event_button() == MOUSE_BACK)
else if (Fl::event_button() == 9)
mouseButtonMask &= ~(1 << 8);
break;
}
Expand Down Expand Up @@ -944,8 +954,15 @@ int Viewport::handleSystemEvent(void *event, void *data)

assert(self);

if (!self->hasFocus())
if (!self->hasFocus()) {

#if !defined (WIN32) && !defined(__APPLE__)
if (fl_xevent->type == 8)
fprintf(stderr, "MISSED LEAVE\n");
#endif

return 0;
}

assert(event);

Expand Down

0 comments on commit 0ec216e

Please sign in to comment.