shithub: libacme

Download patch

ref: cdd8844c69f9e0848fc9e3e8ac8e73adca59d44d
parent: b26a8fbbb6d332c0da8bbfce89eb2fbda6e606eb
author: james palmer <[email protected]>
date: Mon Jul 19 14:20:43 EDT 2021

events: better naming for event functions. added aeventopen, aeventclose.

- this naming makes more sense.
- open and close functions mean the program does not
  need to manually set w->eventfd.

--- a/acme.h
+++ b/acme.h
@@ -13,8 +13,8 @@
 	int ctlfd;
 	int addrfd;
 	int datafd;
-	int eventfd;
 	int bodyfd;
+	int eventfd;
 
 	char buf[512];
 	char *bufp;
@@ -50,5 +50,7 @@
 int		awinaddtag(AWin *, char *);
 int		awinsettag(AWin *, char *);
 
-int		aeventnext(AWin *, AEvent *);
-int		aeventsend(AWin *, AEvent *);
+void	aeventopen(AWin *);
+int		aeventread(AWin *, AEvent *);
+int		aeventwrite(AWin *, AEvent *);
+void	aeventclose(AWin *w);
--- a/event.c
+++ b/event.c
@@ -77,8 +77,15 @@
 	return o;
 }
 
+void
+aeventopen(AWin *w)
+{
+	if(w->eventfd < 0)
+		w->eventfd = awinfsopen(w, "event", ORDWR);
+}
+
 int
-aeventnext(AWin *w, AEvent *e)
+aeventread(AWin *w, AEvent *e)
 {
 	int flags;
 	
@@ -107,10 +114,17 @@
 }
 
 int
-aeventsend(AWin *w, AEvent *e)
+aeventwrite(AWin *w, AEvent *e)
 {
 	if(e->flags & 0x2)
 		return fprint(w->eventfd, "%c%c%d %d\n", e->origin, e->type, e->p, e->p);
 	else
 		return fprint(w->eventfd, "%c%c%d %d\n", e->origin, e->type, e->q0, e->q1);
+}
+
+void
+aeventclose(AWin *w)
+{
+	close(w->eventfd);
+	w->eventfd = -1;
 }
--- a/libacme.man
+++ b/libacme.man
@@ -28,9 +28,13 @@
 .B void		awinsettag(AWin *w, char *tag);
 .br
 .PP
-.B void		aeventstop(AWin *w);
+.B void		aeventlisten(AWin *w);
 .br
+.B void		aeventnext(AWin *w);
+.br
 .B void		aeventsend(AWin *w, AEvent *ev);
+.br
+.B void		aeventstop(AWin *w);
 .SH DESCRIPTION
 .PP
 These routines provide a C interface to
@@ -63,15 +67,19 @@
 to the end of the window tag.
 .I Awinsettag replaces the current window tag.
 .PP
-.I Aeventnext reads the next event into
+.I Aeventopen
+opens the window event file. It should be called before using
+.IR aeventnext .
+.I Aeventread
+reads the next event into
 .BR ev .
-.I Aventsend writes the event
+.I Aventwrite
+writes the event
 .B ev
 to the events file.
-They require 
-.B w->eventfd
-to be a file descriptor reffering to
-the event file in the window\'s directory.
+.I Aeventclose
+closes the event file. It should be called when the program
+no longer wishes to process events.
 .SH FILES
 .PP
 .B /sys/include/acme.h
--- a/window.c
+++ b/window.c
@@ -36,6 +36,7 @@
 	w->addrfd = awinfsopen(w, "addr", ORDWR);
 	w->datafd = awinfsopen(w, "data", ORDWR);
 	w->bodyfd = awinfsopen(w, "body", OWRITE);
+	w->eventfd = -1;
 
 	w->next = awins;
 	awins = w;