Skip to content

Commit

Permalink
windows: fix mouse-button-down encoding
Browse files Browse the repository at this point in the history
Previously, pressing the left mouse button incorrectly reported that
X11MOUSE_BUTTON3 (right button) was pressed, and right or middle
buttons were incorrectly reported as modifiers (ctrl/shift/etc), as
they ended up outside the 2-bits which x11 mouse uses for button id.

Now left/middle/right are reported as x11 BUTTON 1/2/3, respectively.

This doesn't have any visible impact, because currently there's only
mouse-button-up binding, and less doesn't care which button it was.

However, the next commit will add right-mouse-button binding, so
ensure the windows mouse handling doesn't become broken.
  • Loading branch information
avih authored and gwsw committed Sep 25, 2023
1 parent fdaee1f commit adfe1fb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2861,14 +2861,19 @@ static int win32_mouse_event(XINPUT_RECORD *xip)
return (FALSE);

/* Generate an X11 mouse sequence from the mouse event. */
/* TODO: switch to the 1006 protocol to allow specific-button-up reports */
switch (xip->ir.Event.MouseEvent.dwEventFlags)
{
case 0: /* press or release */
if (xip->ir.Event.MouseEvent.dwButtonState == 0)
b = X11MOUSE_OFFSET + X11MOUSE_BUTTON_REL;
else if (!(xip->ir.Event.MouseEvent.dwButtonState & (FROM_LEFT_3RD_BUTTON_PRESSED | FROM_LEFT_4TH_BUTTON_PRESSED)))
b = X11MOUSE_OFFSET + X11MOUSE_BUTTON1 + ((int)xip->ir.Event.MouseEvent.dwButtonState << 1);
else
else if (xip->ir.Event.MouseEvent.dwButtonState == 1) /* leftmost */
b = X11MOUSE_OFFSET + X11MOUSE_BUTTON1;
else if (xip->ir.Event.MouseEvent.dwButtonState == 2) /* rightmost */
b = X11MOUSE_OFFSET + X11MOUSE_BUTTON3;
else if (xip->ir.Event.MouseEvent.dwButtonState == 4) /* middle ("next-to-leftmost") */
b = X11MOUSE_OFFSET + X11MOUSE_BUTTON2;
else /* don't bother to figure out what changed */
return (FALSE);
break;
case MOUSE_WHEELED:
Expand Down

0 comments on commit adfe1fb

Please sign in to comment.