Skip to content

Commit

Permalink
Use bit shifts when tracking mouse button state
Browse files Browse the repository at this point in the history
I think it makes more sense to use bit shifts instead of decimals for
each button.
  • Loading branch information
CendioHalim committed Sep 24, 2024
1 parent 6495d44 commit d62899d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions vncviewer/Viewport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -614,37 +614,37 @@ int Viewport::handle(int event)
// resolved in FLTK.
mouseButtonMask &= ~(0x07);
if (Fl::event_button1())
mouseButtonMask |= 1;
mouseButtonMask |= 1 << 0;
if (Fl::event_button2())
mouseButtonMask |= 2;
mouseButtonMask |= 1 << 1;
if (Fl::event_button3())
mouseButtonMask |= 4;
mouseButtonMask |= 1 << 2;

switch (event) {
case FL_PUSH:
if (Fl::event_button() == 8)
mouseButtonMask |= 128;
mouseButtonMask |= 1 << 7;
else if (Fl::event_button() == 9)
mouseButtonMask |= 256;
mouseButtonMask |= 1 << 8;
break;
case FL_RELEASE:
if (Fl::event_button() == 8)
mouseButtonMask &= ~(128);
mouseButtonMask &= ~(1 << 7);
else if (Fl::event_button() == 9)
mouseButtonMask &= ~(256);
mouseButtonMask &= ~(1 << 8);
break;
}

if (event == FL_MOUSEWHEEL) {
wheelMask = 0;
if (Fl::event_dy() < 0)
wheelMask |= 8;
wheelMask |= 1 << 3;
if (Fl::event_dy() > 0)
wheelMask |= 16;
wheelMask |= 1 << 4;
if (Fl::event_dx() < 0)
wheelMask |= 32;
wheelMask |= 1 << 5;
if (Fl::event_dx() > 0)
wheelMask |= 64;
wheelMask |= 1 << 6;

// A quick press of the wheel "button", followed by a immediate
// release below
Expand Down

0 comments on commit d62899d

Please sign in to comment.