ref: a8873f75169ddcb7d280f23e834926ef577b2530
parent: 8207a74723d9f6cff10323623b782baa090411b1
author: qwx <[email protected]>
date: Thu Apr 15 13:07:58 EDT 2021
properly initialize mouse state
--- a/cpick.c
+++ b/cpick.c
@@ -56,7 +56,7 @@
threadmain(int, char **)
{
int fd;
- Mouse m, om;
+ Mouse om;
Rune r;
if(initdraw(nil, nil, "cpick") < 0)
@@ -75,9 +75,10 @@
sysfatal("initkeyboard: %r");
if((mc = initmouse(nil, _screen->display->image)) == nil)
sysfatal("initmouse: %r");
+ om.xy = ZP;
Alt a[] = {
{mc->resizec, nil, CHANRCV},
- {mc->c, &m, CHANRCV},
+ {mc->c, &mc->Mouse, CHANRCV},
{kc->c, &r, CHANRCV},
{nil, nil, CHANEND}
};
@@ -86,16 +87,19 @@
case 0:
if(getwindow(display, Refnone) < 0)
sysfatal("getwindow: %r");
+ om = mc->Mouse;
redraw();
break;
case 1:
- if((m.buttons & 4) == 4){
- pan.x += m.xy.x - om.xy.x;
- pan.y += m.xy.y - om.xy.y;
+ if(eqpt(om.xy, ZP))
+ om = mc->Mouse;
+ if((mc->buttons & 4) == 4){
+ pan.x += mc->xy.x - om.xy.x;
+ pan.y += mc->xy.y - om.xy.y;
redraw();
}else
- putcol(m.xy);
- om = m;
+ putcol(mc->xy);
+ om = mc->Mouse;
break;
case 2:
switch(r){
--- a/rfx.c
+++ b/rfx.c
@@ -337,7 +337,6 @@
{
Rectangle d;
Rune r;
- Mouse m;
ARGBEGIN{
case 'd':
@@ -402,7 +401,7 @@
enum{ATIC, AMOUSE, ARESIZE, AKEY, AEND};
Alt a[AEND+1] = {
[ATIC] {ticc, nil, CHANRCV},
- [AMOUSE] {mctl->c, &m, CHANRCV},
+ [AMOUSE] {mctl->c, &mctl->Mouse, CHANRCV},
[ARESIZE] {mctl->resizec, nil, CHANRCV},
[AKEY] {kctl->c, &r, CHANRCV},
[AEND] {nil, nil, CHANEND}
@@ -416,9 +415,9 @@
plaster();
break;
case AMOUSE:
- if(!done && m.buttons & bmask && m.buttons & ~oldb)
- check(m.buttons, m.xy);
- oldb = m.buttons;
+ if(!done && mctl->buttons & bmask && mctl->buttons & ~oldb)
+ check(mctl->buttons, mctl->xy);
+ oldb = mctl->buttons;
break;
case ARESIZE:
if(getwindow(display, Refnone) < 0)
--- a/spd.c
+++ b/spd.c
@@ -324,7 +324,6 @@
double d;
Rectangle r;
Rune k;
- Mouse m;
ARGBEGIN{
case 'd':
@@ -383,7 +382,7 @@
enum{ATIC, AMOUSE, ARESIZE, AKEY, AEND};
Alt a[AEND+1] = {
[ATIC] {tc, nil, CHANRCV},
- [AMOUSE] {mc->c, &m, CHANRCV},
+ [AMOUSE] {mc->c, &mc->Mouse, CHANRCV},
[ARESIZE] {mc->resizec, nil, CHANRCV},
[AKEY] {kc->c, &k, CHANRCV},
[AEND] {nil, nil, CHANEND}
@@ -397,7 +396,7 @@
plaster();
break;
case AMOUSE:
- if(m.buttons & 4)
+ if(mc->buttons & 4)
menu();
break;
case ARESIZE: