shithub: neindaw

Download patch

ref: c4e7743fc560f9c74539e21da8892d44cf7dfe20
parent: 22f7e9038ca004a322d82d3ee543eb8ed42dbec9
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Mar 19 09:18:17 EDT 2020

uiglue: add userdata support for ui controls

--- a/aux.h
+++ b/aux.h
@@ -14,9 +14,9 @@
 
 typedef struct Aux Aux;
 typedef struct Auxdsp Auxdsp;
-typedef struct Meta Meta;
-typedef struct UI UI;
 
+struct UI;
+
 struct Aux {
 	Auxtype type;
 	int id;
@@ -24,26 +24,6 @@
 	int data;
 	int metadata;
 
-	struct Auxdsp *dsp;
-	UI *ui;
-};
-
-struct Meta {
-	const char *k;
-	const char *v;
-};
-
-struct UI {
-	UItype type;
-	const char *label;
-	float *zone;
-	float init;
-	float min;
-	float max;
-	float step;
-	char *(*readstr)(UI *ui, int auxtype, char *s, int sz);
-	int (*writestr)(UI *ui, int auxtype, char *s);
-
-	Meta *meta;
-	int nummeta;
+	Auxdsp *dsp;
+	struct UI *ui;
 };
--- a/cfg/cfg.c
+++ b/cfg/cfg.c
@@ -15,7 +15,7 @@
 typedef struct UI UI;
 
 struct UI {
-	UItype type;
+	int type;
 	const char *label;
 	int index;
 
--- a/common.h
+++ b/common.h
@@ -1,4 +1,4 @@
-typedef enum {
+enum {
 	UITGroup,
 	UIHGroup,
 	UIVGroup,
@@ -10,6 +10,6 @@
 	UIHBarGraph,
 	UIVBarGraph,
 	UInum,
-}UItype;
+};
 
 extern char *uitypenames[UInum];
--- a/uiglue.c
+++ b/uiglue.c
@@ -3,8 +3,8 @@
 #include <fcall.h>
 #include <thread.h>
 #include <9p.h>
-#include "uiglue.h"
 #include "common.h"
+#include "uiglue.h"
 #include "aux.h"
 
 static struct {
@@ -112,7 +112,7 @@
 {
 	Aux *a;
 
-	a = calloc(1, sizeof(*a)+sizeof(UI) + sizeof(Meta)*decl.nummeta);
+	a = calloc(1, sizeof(*a) + sizeof(UI) + sizeof(Meta)*decl.nummeta);
 	a->type = Xui;
 	a->ui = (UI*)(a+1);
 	a->ui->type = type;
@@ -125,6 +125,7 @@
 	a->ui->label = label;
 	a->ui->readstr = uiglue.readstr != nil ? uiglue.readstr : ui_readstr;
 	a->ui->writestr = uiglue.writestr != nil ? uiglue.writestr : ui_writestr;
+	a->ui->userdata = uiglue.userdata;
 	if ((uiglue.f = createfile(f, label, nil, DMDIR|0775, a)) == nil)
 		sysfatal("failed to create ui: %r");
 	if ((f = createfile(uiglue.f, "ctl", nil, 0664, &a->ctl)) == nil)
--- a/uiglue.h
+++ b/uiglue.h
@@ -2,8 +2,31 @@
 typedef struct MetaGlue MetaGlue;
 
 struct File;
-struct UI;
 
+typedef struct Meta Meta;
+typedef struct UI UI;
+
+struct Meta {
+	const char *k;
+	const char *v;
+};
+
+struct UI {
+	int type;
+	const char *label;
+	float *zone;
+	float init;
+	float min;
+	float max;
+	float step;
+	char *(*readstr)(UI *ui, int auxtype, char *s, int sz);
+	int (*writestr)(UI *ui, int auxtype, char *s);
+
+	void *userdata;
+	Meta *meta;
+	int nummeta;
+};
+
 struct UIGlue {
 	union {
 		void *uiInterface;
@@ -22,8 +45,10 @@
 	void (*addVerticalBargraph)(void *uiInterface, const char *label, float *zone, float min, float max);
 	void (*declare)(void *uiInterface, float *zone, const char *key, const char *value);
 
-	char *(*readstr)(struct UI *ui, int auxtype, char *s, int sz);
-	int (*writestr)(struct UI *ui, int auxtype, char *s);
+	char *(*readstr)(UI *ui, int auxtype, char *s, int sz);
+	int (*writestr)(UI *ui, int auxtype, char *s);
+
+	void *userdata;
 };
 
 struct MetaGlue {
@@ -33,5 +58,5 @@
 
 extern UIGlue uiglue;
 
-char *ui_readstr(struct UI *ui, int type, char *s, int sz);
-int ui_writestr(struct UI *ui, int type, char *s);
+char *ui_readstr(UI *ui, int auxtype, char *s, int sz);
+int ui_writestr(UI *ui, int auxtype, char *s);