Skip to content

Commit

Permalink
devdraw: handle shift of real mouse buttons correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Jun 17, 2024
1 parent e9cbe46 commit a2567fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/cmd/devdraw/mac-screen.m
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ - (void)flagsChanged:(NSEvent*)e
x = 2;
if(m & ~omod & NSEventModifierFlagCommand)
x = 4;
if(m & NSEventModifierFlagShift)
x <<= 5;
b |= x;
if(m & NSEventModifierFlagShift)
b <<= 5;
[self sendmouse:b];
}else if(m & ~omod & NSEventModifierFlagOption)
gfx_keystroke(self.client, Kalt);
Expand Down Expand Up @@ -698,17 +698,17 @@ - (void)getmouse:(NSEvent *)e
b = b&~6 | (b&4)>>1 | (b&2)<<1;
b = mouseswap(b);

m = [e modifierFlags];
if(b == 1){
m = [e modifierFlags];
if(m & NSEventModifierFlagOption){
gfx_abortcompose(self.client);
b = 2;
}else
if(m & NSEventModifierFlagCommand)
b = 4;
if(m & NSEventModifierFlagShift)
b <<= 5;
}
if(m & NSEventModifierFlagShift)
b <<= 5;
[self sendmouse:b];
}

Expand Down
23 changes: 18 additions & 5 deletions src/cmd/devdraw/x11-screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ runxevent(XEvent *xev)
if(w == nil)
w = _x.windows;

int shift;
switch(xev->type){
case Expose:
_xexpose(w, xev);
Expand Down Expand Up @@ -406,7 +407,10 @@ runxevent(XEvent *xev)
case MotionNotify:
if(_xtoplan9mouse(w, xev, &m) < 0)
return;
gfx_mousetrack(w->client, m.xy.x, m.xy.y, m.buttons|_x.kbuttons, m.msec);
shift = 0;
if(_x.kstate & ShiftMask)
shift = 5;
gfx_mousetrack(w->client, m.xy.x, m.xy.y, (m.buttons|_x.kbuttons)<<shift, m.msec);
break;

case KeyRelease:
Expand Down Expand Up @@ -440,32 +444,41 @@ runxevent(XEvent *xev)
case XK_Alt_L:
case XK_Alt_R:
kcodealt = ke->keycode;
// fall through
c |= Mod1Mask;
modp = 1;
break;
case XK_Shift_L:
case XK_Shift_R:
kcodeshift = ke->keycode;
c |= Mod1Mask;
c |= ShiftMask;
modp = 1;
break;
}
else {
if(ke->keycode == kcodecontrol){
c &= ~ControlMask;
modp = 1;
} else if(ke->keycode == kcodealt || ke->keycode == kcodeshift){
} else if(ke->keycode == kcodealt){
c &= ~Mod1Mask;
modp = 1;
} else if(ke->keycode == kcodeshift) {
c &= ~ShiftMask;
modp = 1;
}
}
if(modp){
_x.kstate = c;
if(m.buttons || _x.kbuttons) {
int shift = 0;
_x.altdown = 0; // used alt
_x.kbuttons = 0;
if(c & ControlMask)
_x.kbuttons |= 2;
if(c & Mod1Mask)
_x.kbuttons |= 4;
gfx_mousetrack(w->client, m.xy.x, m.xy.y, m.buttons|_x.kbuttons, m.msec);
if(c & ShiftMask)
shift = 5;
gfx_mousetrack(w->client, m.xy.x, m.xy.y, (m.buttons|_x.kbuttons)<<shift, m.msec);
}
modp = 0;
}
Expand Down

0 comments on commit a2567fc

Please sign in to comment.