From f90f64e16978b6eca9ff95c5d258b4a8fe2ad47c Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Wed, 10 Jan 2024 16:32:17 -0500 Subject: [PATCH] fleshed out uitest to test new UI approach --- bin/rules.mk | 1 + bin/uitest/main.c | 84 +++++++++++++++++++++++++++ inc/impl/libui.h | 3 + inc/libui.h | 41 ++++++++----- lib/a/Job.c.bak | 14 +++++ lib/ui/ui_begin.c | 9 --- lib/ui/window_create.c | 10 +++- lib/ui/{ui_end.c => window_repaint.c} | 5 +- lib/ui/window_show.c | 2 +- rules.mk | 19 +++--- 10 files changed, 153 insertions(+), 35 deletions(-) create mode 100644 bin/uitest/main.c create mode 100644 lib/a/Job.c.bak delete mode 100644 lib/ui/ui_begin.c rename lib/ui/{ui_end.c => window_repaint.c} (66%) diff --git a/bin/rules.mk b/bin/rules.mk index e9dbda0..33ce09d 100644 --- a/bin/rules.mk +++ b/bin/rules.mk @@ -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 index 0000000..16cf741 --- /dev/null +++ b/bin/uitest/main.c @@ -0,0 +1,84 @@ +#include "liba.h" +#include "libui.h" +#include + +#include + +#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; +}; + diff --git a/inc/impl/libui.h b/inc/impl/libui.h index 06a9761..129766b 100644 --- a/inc/impl/libui.h +++ b/inc/impl/libui.h @@ -16,6 +16,9 @@ struct UIWin GC gc; XftDraw* xft; XftFont* font; + + XftColor bg; + XftColor fg; }; struct XConf diff --git a/inc/libui.h b/inc/libui.h index 2e2ed3e..f4a783b 100644 --- a/inc/libui.h +++ b/inc/libui.h @@ -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 index 0000000..506297c --- /dev/null +++ b/lib/a/Job.c.bak @@ -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 index 46fae72..0000000 --- a/lib/ui/ui_begin.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include - -void ui_begin(UIWin* win) -{ - XSetForeground(X.display, win->gc, 0xEAEAEA); - XFillRectangle(X.display, win->pixmap, win->gc, 0, 0, win->width, win->height); -} diff --git a/lib/ui/window_create.c b/lib/ui/window_create.c index 83db56a..7f96723 100644 --- a/lib/ui/window_create.c +++ b/lib/ui/window_create.c @@ -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 */ diff --git a/lib/ui/ui_end.c b/lib/ui/window_repaint.c similarity index 66% rename from lib/ui/ui_end.c rename to lib/ui/window_repaint.c index 01dc0ed..3c518d0 100644 --- a/lib/ui/ui_end.c +++ b/lib/ui/window_repaint.c @@ -1,9 +1,8 @@ -#include #include #include -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); } diff --git a/lib/ui/window_show.c b/lib/ui/window_show.c index 2eae6b9..d91898a 100644 --- a/lib/ui/window_show.c +++ b/lib/ui/window_show.c @@ -5,5 +5,5 @@ void win_show(UIWin* win) { XMapWindow(X.display, win->self); - XSync(X.display, False); + XSync(X.display, True); } diff --git a/rules.mk b/rules.mk index b2d929c..ccb5cb7 100644 --- 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 -- 2.55.0