summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-15 22:20:34 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-15 22:20:34 +0000
commit58363833ce933924ef340eb53f0caa4d0d1f6ae5 (patch)
tree777ac4b6c20002798a15f494db7c300606c1efe7
parent3a0e0b8bb6e7fd9bcf510167980d9715e3faeb7b (diff)
implement mousedown, mouseup, mouseclick, and mousescroll events
-rw-r--r--graphics.c4
-rw-r--r--guifs.h24
-rw-r--r--guispec.c1
-rw-r--r--layout.c1
-rw-r--r--main.c16
-rw-r--r--props.c1
6 files changed, 26 insertions, 21 deletions
diff --git a/graphics.c b/graphics.c
index c300f7a..64641ba 100644
--- a/graphics.c
+++ b/graphics.c
@@ -172,14 +172,14 @@ guiproc(void *)
mousexy = mouse->Mouse.xy;
if(!root)
break;
- if(mouseevent(mouse->Mouse.buttons))
+ if(mouseevent(mouse->Mouse))
resized(0);
break;
case Akeyboard:
if(!root)
break;
if(keyboardevent(r))
- resized(1);
+ resized(0);
break;
}
}
diff --git a/guifs.h b/guifs.h
index abfb81e..1121c3c 100644
--- a/guifs.h
+++ b/guifs.h
@@ -23,6 +23,17 @@ enum {
enum {
Horizontal,
Vertical,
+ Up,
+ Down,
+};
+
+enum {
+ Xmousedown,
+ Xmouseup,
+ Xmouseclick,
+ Xmousescroll,
+ Xkeyboard,
+ Xmax,
};
typedef struct Colour Colour;
@@ -67,7 +78,12 @@ struct Prop {
};
struct Event {
- Rune r;
+ int type;
+ union {
+ Mouse m;
+ Rune r;
+ int direction;
+ };
};
struct GuiSpec {
@@ -90,7 +106,6 @@ struct GuiElement {
Qid qevent;
Qid qtype;
Qid qprops;
- Qid qwait;
int nchildren;
GuiElement **children;
@@ -100,9 +115,10 @@ struct GuiElement {
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 @@ void layouttextbox(GuiElement *, Rectangle);
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
diff --git a/guispec.c b/guispec.c
index 0c59ea7..a2f22c1 100644
--- 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"
diff --git a/layout.c b/layout.c
index 17aa2ef..ab5e7c6 100644
--- 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"
diff --git a/main.c b/main.c
index 4ef93f1..dda6af1 100644
--- 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 @@ enum {
Qclone,
Qevent,
Qtype,
- Qwait,
Qprops,
Qprop,
@@ -33,7 +33,6 @@ enum {
Fclone,
Fevent,
Ftype,
- Fwait,
Fprops,
Fmax,
};
@@ -101,7 +100,6 @@ mkqid(int type)
case Qclone:
case Qevent:
case Qtype:
- case Qwait:
q.type = QTFILE;
break;
}
@@ -159,7 +157,6 @@ newgui(GuiElement *parent)
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 @@ fswalk1(Fid *fid, char *name, Qid *qid)
*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 @@ fsopen(Req *r)
case Qevent:
case Qclone:
case Qprops:
- case Qwait:
if(r->ifcall.mode != OREAD){
err = Eperm;
goto Lend;
@@ -379,11 +373,6 @@ dirtreegen(int n, Dir *d, void *aux)
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 @@ Lgotevent: currentsize = g->currentevents ? strlen(g->currentevents) : 0;
runlock(&g->lock);
readstr(r, buf);
break;
- case Qwait:
- /* intentionally left blank */
- return;
case Qprops:
dirread9p(r, proptreegen, g);
break;
diff --git a/props.c b/props.c
index 0bbd48e..fecf9ef 100644
--- 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"