ref: 58363833ce933924ef340eb53f0caa4d0d1f6ae5
parent: 3a0e0b8bb6e7fd9bcf510167980d9715e3faeb7b
author: Peter Mikkelsen <petermikkelsen10@gmail.com>
date: Thu Feb 15 17:20:34 EST 2024
implement mousedown, mouseup, mouseclick, and mousescroll events
--- a/graphics.c
+++ b/graphics.c
@@ -172,7 +172,7 @@
mousexy = mouse->Mouse.xy;
if(!root)
break;
- if(mouseevent(mouse->Mouse.buttons))
+ if(mouseevent(mouse->Mouse))
resized(0);
break;
case Akeyboard:
@@ -179,7 +179,7 @@
if(!root)
break;
if(keyboardevent(r))
- resized(1);
+ resized(0);
break;
}
}
--- a/guifs.h
+++ b/guifs.h
@@ -23,8 +23,19 @@
enum {
Horizontal,
Vertical,
+ Up,
+ Down,
};
+enum {
+ Xmousedown,
+ Xmouseup,
+ Xmouseclick,
+ Xmousescroll,
+ Xkeyboard,
+ Xmax,
+};
+
typedef struct Colour Colour;
typedef struct Spacing Spacing;
typedef union PropVal PropVal;
@@ -67,7 +78,12 @@
};
struct Event {
- Rune r;
+ int type;
+ union {
+ Mouse m;
+ Rune r;
+ int direction;
+ };
};
struct GuiSpec {
@@ -90,7 +106,6 @@
Qid qevent;
Qid qtype;
Qid qprops;
- Qid qwait;
int nchildren;
GuiElement **children;
@@ -100,9 +115,10 @@
int nprops;
Prop *props;
- int listening; /* the user is reading from the 'event' file */
+ uvlong listening; /* the user is reading from the 'event' file. Bitmask of which events are wanted */
Channel *events;
char *currentevents;
+ int buttons;
Rectangle border;
Rectangle rect;
@@ -131,5 +147,5 @@
PropVal getprop(GuiElement *, int, int);
void setprop(GuiElement *, int, PropVal, int);
-int mouseevent(int);
+int mouseevent(Mouse);
int keyboardevent(Rune);
\ No newline at end of file
--- a/guispec.c
+++ b/guispec.c
@@ -2,6 +2,7 @@
#include <libc.h>
#include <draw.h>
#include <thread.h>
+#include <mouse.h>
#include "guifs.h"
--- a/layout.c
+++ b/layout.c
@@ -2,6 +2,7 @@
#include <libc.h>
#include <draw.h>
#include <thread.h>
+#include <mouse.h>
#include "guifs.h"
--- a/main.c
+++ b/main.c
@@ -4,6 +4,7 @@
#include <thread.h>
#include <9p.h>
#include <draw.h>
+#include <mouse.h>
#include "guifs.h"
@@ -23,7 +24,6 @@
Qclone,
Qevent,
Qtype,
- Qwait,
Qprops,
Qprop,
@@ -33,7 +33,6 @@
Fclone,
Fevent,
Ftype,
- Fwait,
Fprops,
Fmax,
};
@@ -101,7 +100,6 @@
case Qclone:
case Qevent:
case Qtype:
- case Qwait:
q.type = QTFILE;
break;
}
@@ -159,7 +157,6 @@
g->qevent = mkqid(Qevent);
g->qtype = mkqid(Qtype);
g->qprops = mkqid(Qprops);
- g->qwait = mkqid(Qwait);
g->events = chancreate(sizeof(char *), 0);
@@ -239,8 +236,6 @@
*qid = g->qtype;
else if(strcmp(name, "props") == 0)
*qid = g->qprops;
- else if(strcmp(name, "wait") == 0)
- *qid = g->qwait;
else if(child = findchild(g, name)){
fid->aux = child;
*qid = child->qid;
@@ -290,7 +285,6 @@
case Qevent:
case Qclone:
case Qprops:
- case Qwait:
if(r->ifcall.mode != OREAD){
err = Eperm;
goto Lend;
@@ -379,11 +373,6 @@
d->name = estrdup9p("type");
d->qid = g->qtype;
break;
- case Fwait:
- d->mode = 0444;
- d->name = estrdup9p("wait");
- d->qid = g->qwait;
- break;
case Fprops:
d->mode = 0555|DMDIR;
d->name = estrdup9p("props");
@@ -500,9 +489,6 @@
runlock(&g->lock);
readstr(r, buf);
break;
- case Qwait:
- /* intentionally left blank */
- return;
case Qprops:
dirread9p(r, proptreegen, g);
break;
--- a/props.c
+++ b/props.c
@@ -5,6 +5,7 @@
#include <fcall.h>
#include <thread.h>
#include <9p.h>
+#include <mouse.h>
#include "guifs.h"