]> git.mdlowis.com Git - proto/aos.git/commitdiff
fleshed out uitest to test new UI approach
authorMike Lowis <mike.lowis@gentex.com>
Wed, 10 Jan 2024 21:32:17 +0000 (16:32 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Wed, 10 Jan 2024 21:32:17 +0000 (16:32 -0500)
bin/rules.mk
bin/uitest/main.c [new file with mode: 0644]
inc/impl/libui.h
inc/libui.h
lib/a/Job.c.bak [new file with mode: 0644]
lib/ui/ui_begin.c [deleted file]
lib/ui/window_create.c
lib/ui/window_repaint.c [moved from lib/ui/ui_end.c with 66% similarity]
lib/ui/window_show.c
rules.mk

index e9dbda0986656ceee5bbf40297e949fc364d7317..33ce09dd5552faccad168527c6649f3773e7c8f2 100644 (file)
@@ -4,3 +4,4 @@ $(BINDIR)/pick:       LIBS += -lx11 -lX11 -lXft -lfontconfig -lXinerama
 $(BINDIR)/screenlock: LIBS += -lui -lX11 -lXft -lfontconfig -lcrypt -lXrandr
 $(BINDIR)/terminal:   LIBS += -lui -lX11 -lXft -lfontconfig
 $(BINDIR)/winmgr:     LIBS += -lX11 -lXft -lfontconfig -lXinerama
+$(BINDIR)/uitest:     LIBS += -lui -lX11 -lXft -lfontconfig -lXinerama
diff --git a/bin/uitest/main.c b/bin/uitest/main.c
new file mode 100644 (file)
index 0000000..16cf741
--- /dev/null
@@ -0,0 +1,84 @@
+#include "liba.h"
+#include "libui.h"
+#include <unistd.h>
+
+#include <impl/libui.h>
+
+#define COLOR(c) ((c) | ((c) >> 8))
+
+void SetBackground(UIWin* win, int c)
+{
+    XftColorFree(X.display, X.visual, X.colormap, &(win->bg));
+    win->bg.color.alpha = 0xFFFF;
+    win->bg.color.red   = COLOR((c & 0x00FF0000) >> 8);
+    win->bg.color.green = COLOR((c & 0x0000FF00));
+    win->bg.color.blue  = COLOR((c & 0x000000FF) << 8);
+    XftColorAllocValue(X.display, X.visual, X.colormap, &(win->bg.color), &(win->bg));
+}
+
+void SetForeground(UIWin* win, int c)
+{
+    XftColorFree(X.display, X.visual, X.colormap, &(win->fg));
+    win->fg.color.alpha = 0xFFFF;
+    win->fg.color.red   = COLOR((c & 0x00FF0000) >> 8);
+    win->fg.color.green = COLOR((c & 0x0000FF00));
+    win->fg.color.blue  = COLOR((c & 0x000000FF) << 8);
+    XftColorAllocValue(X.display, X.visual, X.colormap, &(win->fg.color), &(win->fg));
+}
+
+void DrawRectangle(UIWin* win, int px, int py, int width, int height)
+{
+    XftDrawRect(win->xft, &(win->fg), px, py, width, height);
+}
+
+void DrawGlyphs(UIWin* win, XftFont* font, XftGlyphSpec* specs, long nspecs)
+{
+    XftDrawGlyphSpec(win->xft, &(win->fg), font, specs, nspecs);
+}
+
+void DrawString(UIWin* win, XftFont* font, int posx, int posy, char* str)
+{
+    XftDrawStringUtf8(win->xft, &(win->fg), font, posx, posy, (const FcChar8*)str, strlen(str));
+}
+
+
+
+void update(UIWin* win)
+{
+    SetForeground(win, 0xFF0000);
+    DrawRectangle(win, 0, 0, 100, 100);
+    win_repaint(win);
+}
+
+
+int main(int argc, char** argv)
+{
+    UIWin* win = win_create("UI Test");
+    win_show(win);
+
+    XEvent ev;
+    while (1)
+    {
+        XNextEvent(X.display, &ev);
+        update(win);
+    }
+
+    return 0;
+}
+
+
+typedef struct WidgetClass WidgetClass;
+typedef struct Widget Widget;
+
+struct WidgetClass {
+    void (*onresize)();
+    void (*onredraw)();
+    void (*onaction)();
+};
+
+struct Widget {
+    WidgetClass* class;
+    Widget* first;
+    Widget* last;
+};
+
index 06a97619a0bfb7e7ddcd91f2650e6d4f65f98ac4..129766bb7212dd3d563a6cfcc929af153397fcd3 100644 (file)
@@ -16,6 +16,9 @@ struct UIWin
     GC gc;
     XftDraw* xft;
     XftFont* font;
+
+    XftColor bg;
+    XftColor fg;
 };
 
 struct XConf
index 2e2ed3e174ae40da24f131d15a8374a4243b4a60..f4a783bea116d4cfa2aa639e081319224f5d65b9 100644 (file)
@@ -1,25 +1,40 @@
 typedef struct UIFont UIFont;
 typedef struct UIWin UIWin;
 
+typedef struct {
+    /* keyboard events */
+    void (*onkeyup)();
+    void (*onkeydown)();
+
+    /* mouse events */
+    void (*onclick)();
+    void (*onmousemove)();
+} UIEventHandlers;
+
 UIWin* win_create(char* title);
 void win_delete(UIWin* win);
 void win_show(UIWin* win);
 void win_hide(UIWin* win);
+void win_repaint(UIWin* win);
+
 
 UIFont font_load(char* patt);
 void font_close(UIFont font);
 
-void ui_begin(UIWin* win);
-void ui_end(UIWin* win);
-
-
-typedef struct Attr {
-    struct Attr* next;
-    char* name;
-    char* value;
-} Attr;
+//typedef struct Attr {
+//    struct Attr* next;
+//    char* name;
+//    char* value;
+//} Attr;
+//
+//typedef struct Widget {
+//    Attr* attributes;
+//    void (*render)(struct Widget* w);
+//} Widget;
 
-typedef struct Widget {
-    Attr* attributes;
-    void (*render)(struct Widget* w);
-} Widget;
+//
+//typdef stuct UIWindow {
+//    void* model;
+//    void (*update)(struct UIWindow*, struct UIEvent*);
+//    void (*redraw)(struct UIWindow*);
+//} UIWindow;
\ No newline at end of file
diff --git a/lib/a/Job.c.bak b/lib/a/Job.c.bak
new file mode 100644 (file)
index 0000000..506297c
--- /dev/null
@@ -0,0 +1,14 @@
+typedef struct JobManager_T JobManager_T;
+
+typedef enum {
+    JOB_EVENT_WRRDY,
+    JOB_EVENT_RDRDY,
+    JOB_EVENT_CLOSED,
+    JOB_EVENT_ERROR
+} JobEventType_T;
+
+void JobManager_Init(JobManager_T* jm);
+void JobManager_Poll(JobManager_T* jm, int ms);
+void JobManager_JoinAll(JobManager_T* jm);
+int JobManager_Fork(JobManager_T* jm, int fd, void (*readfn)(JobEventType_T, int, void*), void* data);
+int JobManager_Exec(JobManager_T* jm, char** cmd);
diff --git a/lib/ui/ui_begin.c b/lib/ui/ui_begin.c
deleted file mode 100644 (file)
index 46fae72..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <liba.h>
-#include <libui.h>
-#include <impl/libui.h>
-
-void ui_begin(UIWin* win)
-{
-    XSetForeground(X.display, win->gc, 0xEAEAEA);
-    XFillRectangle(X.display, win->pixmap, win->gc, 0, 0, win->width, win->height);
-}
index 83db56aa326d87787466e734808518f35c33e951..7f96723676da0f3479bf3760ea9416086945a3c8 100644 (file)
@@ -31,7 +31,15 @@ UIWin* win_create(char* title)
     X.colormap = wa.colormap;
     win->width = 640;
     win->height = 480;
-    win->self = XCreateSimpleWindow(X.display, X.root, 0, 0, win->width, win->height, 0, 0, 0xEAEAEA);
+
+    XSetWindowAttributes attr;
+    attr.background_pixel = 0xEAEAEA;
+    attr.bit_gravity = NorthWestGravity;
+    attr.backing_store = WhenMapped;
+    win->self = XCreateWindow(
+        X.display, X.root, 0, 0, win->width, win->height, 0, X.depth, InputOutput, X.visual,
+        CWBackPixel | CWBitGravity | CWBackingStore,
+        &attr);
     XStoreName(X.display, win->self, title);
 
     /* initialize the graphics */
similarity index 66%
rename from lib/ui/ui_end.c
rename to lib/ui/window_repaint.c
index 01dc0edd5b238aeaf874bf6de942f0f52221902e..3c518d0f0a83f904f8f3c6fb2da2262648ab91cb 100644 (file)
@@ -1,9 +1,8 @@
-#include <liba.h>
 #include <libui.h>
 #include <impl/libui.h>
 
-void ui_end(UIWin* win)
+void win_repaint(UIWin* win)
 {
     XCopyArea(X.display, win->pixmap, win->self, win->gc, 0, 0, win->width, win->height, 0, 0);
-    XSync(X.display, False);
+    XFlush(X.display);
 }
index 2eae6b9031e10e34e526e34a5ed2e920a0145b1c..d91898ae548d21ea0a77a05903e9b81b770df3e1 100644 (file)
@@ -5,5 +5,5 @@
 void win_show(UIWin* win)
 {
     XMapWindow(X.display, win->self);
-    XSync(X.display, False);
+    XSync(X.display, True);
 }
index b2d929c19ce360ff095fff1e1918b0f28faa3675..ccb5cb7f9684da5d87bcc66050283081814fb24a 100644 (file)
--- a/rules.mk
+++ b/rules.mk
@@ -112,18 +112,14 @@ $(OUTDIR)/obj/lib/ui/window_delete.o: lib/ui/window_delete.c config.mk
        $(OBJECT)
 $(OUTDIR)/lib/libui.a: $(OUTDIR)/obj/lib/ui/window_delete.o
 -include $(OUTDIR)/obj/lib/ui/window_delete.d
-$(OUTDIR)/obj/lib/ui/ui_end.o: lib/ui/ui_end.c config.mk
-       $(OBJECT)
-$(OUTDIR)/lib/libui.a: $(OUTDIR)/obj/lib/ui/ui_end.o
--include $(OUTDIR)/obj/lib/ui/ui_end.d
-$(OUTDIR)/obj/lib/ui/ui_begin.o: lib/ui/ui_begin.c config.mk
-       $(OBJECT)
-$(OUTDIR)/lib/libui.a: $(OUTDIR)/obj/lib/ui/ui_begin.o
--include $(OUTDIR)/obj/lib/ui/ui_begin.d
 $(OUTDIR)/obj/lib/ui/font_close.o: lib/ui/font_close.c config.mk
        $(OBJECT)
 $(OUTDIR)/lib/libui.a: $(OUTDIR)/obj/lib/ui/font_close.o
 -include $(OUTDIR)/obj/lib/ui/font_close.d
+$(OUTDIR)/obj/lib/ui/window_repaint.o: lib/ui/window_repaint.c config.mk
+       $(OBJECT)
+$(OUTDIR)/lib/libui.a: $(OUTDIR)/obj/lib/ui/window_repaint.o
+-include $(OUTDIR)/obj/lib/ui/window_repaint.d
 $(OUTDIR)/obj/lib/ui/window_create.o: lib/ui/window_create.c config.mk
        $(OBJECT)
 $(OUTDIR)/lib/libui.a: $(OUTDIR)/obj/lib/ui/window_create.o
@@ -248,6 +244,13 @@ $(OUTDIR)/bin/terminal: $(OUTDIR)/obj/bin/terminal/st.o
 $(OUTDIR)/bin/terminal: | $(libs)
        $(BINARY)
 bins: $(OUTDIR)/bin/terminal
+$(OUTDIR)/obj/bin/uitest/main.o: bin/uitest/main.c config.mk
+       $(OBJECT)
+$(OUTDIR)/bin/uitest: $(OUTDIR)/obj/bin/uitest/main.o
+-include $(OUTDIR)/obj/bin/uitest/main.d
+$(OUTDIR)/bin/uitest: | $(libs)
+       $(BINARY)
+bins: $(OUTDIR)/bin/uitest
 $(OUTDIR)/obj/bin/winmgr/client.o: bin/winmgr/client.c config.mk
        $(OBJECT)
 $(OUTDIR)/bin/winmgr: $(OUTDIR)/obj/bin/winmgr/client.o