]> git.mdlowis.com Git - projs/tide.git/commitdiff
fleshed out x11 init more
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 24 Mar 2022 02:57:44 +0000 (22:57 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 24 Mar 2022 02:57:44 +0000 (22:57 -0400)
src/uitest/ui.h
src/uitest/ui_window.c
src/uitest/x11.c

index 0863e5dc22cff5c83e3486b0ba4393b0a3731164..2f773817e4952fd2d9d763b37eb0d4da959d68f0 100644 (file)
@@ -21,18 +21,12 @@ typedef struct XConf {
     Visual* visual;
     Colormap colormap;
     unsigned depth;
-
-//    Window self;
-//    XftDraw* xft;
-//    XftFont *tagfont, *font;
-//    Pixmap pixmap;
-//    XIC xic;
-//    XIM xim;
-//    GC gc;
-//    void (*eventfns[LASTEvent])(struct XConf*, XEvent*);
+    void (*eventfns[LASTEvent])(XEvent*);
 //    Time now;
 } XConf;
 
+extern XConf X;
+
 ///* Selection identifiers */
 //enum {
 //    PRIMARY   = 0,
@@ -132,8 +126,6 @@ typedef struct XConf {
 //    char* arg;
 //} KeyBinding;
 
-extern struct XConf X;
-
 typedef struct {
     long width, height;
     Window winid;
@@ -141,15 +133,16 @@ typedef struct {
     XIC xic;
     XIM xim;
     GC gc;
+    XftDraw* xft;
 } XWindow;
 
-int X11_Init(XConf* x);
+int X11_Init(void);
 void X11_ClearError(void);
 XErrorEvent* X11_GetError(void);
-void X11_MakeWindow(XConf* x, XWindow* win, int width, int height);
-void X11_MakeDialog(XConf* x, XWindow* win, int width, int height);
-void X11_ShowWindow(XConf* x, XWindow* w);
-void X11_HideWindow(XConf* x, XWindow* w);
+void X11_MakeWindow(XWindow* win, int width, int height);
+void X11_MakeDialog(XWindow* win, int width, int height);
+void X11_ShowWindow(XWindow* w);
+void X11_HideWindow(XWindow* w);
 
 //void x11_resize(XConf* x, XEvent* e);
 //void x11_process_events(XConf* x);
index f35020c4f530b351cf6e4363a6fa418e7c4e9782..3a169f3c89ebc738aaa07a7a2179db04975d4d12 100644 (file)
@@ -11,7 +11,7 @@ UIWindow* WindowList = NULL;
 
 UIWindow* make_window(void)
 {
-    if (!WindowList) { X11_Init(&X); }
+    if (!WindowList) { X11_Init(); }
     UIWindow* win = calloc(1, sizeof(UIWindow));
     win->next = WindowList;
     WindowList = win;
@@ -21,14 +21,14 @@ UIWindow* make_window(void)
 UIWidget* UI_MakeWindow(long width, long height)
 {
     UIWindow* win = make_window();
-    X11_MakeWindow(&X, &(win->xwin), width, height);
+    X11_MakeWindow(&(win->xwin), width, height);
     return &(win->widget);
 }
 
 UIWidget* UI_MakeDialog(void)
 {
     UIWindow* win = make_window();
-    X11_MakeDialog(&X, &(win->xwin), 640, 480);
+    X11_MakeDialog(&(win->xwin), 640, 480);
     return &(win->widget);
 }
 
@@ -40,11 +40,11 @@ UIWidget* UI_MakeDialog(void)
 void UI_ShowWindow(UIWidget* w)
 {
     UIWindow* win = (UIWindow*)w;
-    X11_ShowWindow(&X, &(win->xwin));
+    X11_ShowWindow(&(win->xwin));
 }
 
 void UI_HideWindow(UIWidget* w)
 {
     UIWindow* win = (UIWindow*)w;
-    X11_HideWindow(&X, &(win->xwin));
+    X11_HideWindow(&(win->xwin));
 }
index 0255f6b827fc14571734b42aa4ad81f4d68e8769..a4154785b7c06d08b0231022c6dfbce5189e8953 100644 (file)
@@ -2,7 +2,7 @@
 #include "ui.h"
 #include "config.h"
 
-struct XConf X;
+XConf X;
 static Bool Has_Error = False;
 static XErrorEvent Error = {0};
 
@@ -13,27 +13,59 @@ static int onerror(Display* disp, XErrorEvent* ev)
     return 0;
 }
 
-int X11_Init(XConf* x)
+static void xkeypress(XEvent* e)
+{}
+
+static void xmousebtn(XEvent* e)
+{}
+
+static void xbtnmotion(XEvent* e)
+{}
+
+static void xclientmsg(XEvent* e)
+{}
+
+static void xresize(XEvent* e)
+{}
+
+static void xmapnotify(XEvent* e)
+{}
+
+static void xenternotify(XEvent* e)
+{}
+
+int X11_Init(void)
 {
     int ret = -1;
-//    signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
-//    setlocale(LC_CTYPE, "");
-//    XSetLocaleModifiers("");
+    signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
+    setlocale(LC_CTYPE, "");
+    XSetLocaleModifiers("");
 
     /* open the X display and get basic attributes */
-    if ( (x->display = XOpenDisplay(0)) )
+    if ( (X.display = XOpenDisplay(0)) )
     {
-        x->root = DefaultRootWindow(x->display);
+        X.root = DefaultRootWindow(X.display);
         XWindowAttributes wa;
-        XGetWindowAttributes(x->display, x->root, &wa);
-        x->visual   = wa.visual;
-        x->colormap = wa.colormap;
-        x->screen   = DefaultScreen(x->display);
-        x->depth    = DefaultDepth(x->display, x->screen);
-        x->state    = RUNNING;
+        XGetWindowAttributes(X.display, X.root, &wa);
+        X.visual   = wa.visual;
+        X.colormap = wa.colormap;
+        X.screen   = DefaultScreen(X.display);
+        X.depth    = DefaultDepth(X.display, X.screen);
+        X.state    = RUNNING;
         XSetErrorHandler(onerror);
+
+        /* register event handlers */
+        X.eventfns[KeyPress] = xkeypress;
+        X.eventfns[ButtonPress] = xmousebtn;
+        X.eventfns[ButtonRelease] = xmousebtn;
+        X.eventfns[MotionNotify] = xbtnmotion;
+        X.eventfns[ClientMessage] = xclientmsg;
+        X.eventfns[ConfigureNotify] = xresize;
+        X.eventfns[MapNotify] = xmapnotify;
+        X.eventfns[EnterNotify] = xenternotify;
         ret = 0;
     }
+
     return ret;
 }
 
@@ -48,7 +80,7 @@ XErrorEvent* X11_GetError(void)
     return (Has_Error ? &Error : NULL);
 }
 
-void X11_MakeWindow(XConf* x, XWindow* win, int width, int height)
+void X11_MakeWindow(XWindow* win, int width, int height)
 {
     /* create the main window */
     XSetWindowAttributes attr;
@@ -69,68 +101,67 @@ void X11_MakeWindow(XConf* x, XWindow* win, int width, int height)
     win->width = width;
     win->height = height;
     win->winid = XCreateWindow(
-        x->display, x->root, 0, 0, width, height, 0, x->depth, InputOutput, x->visual,
+        X.display, X.root, 0, 0, width, height, 0, X.depth, InputOutput, X.visual,
         CWBackPixel | CWBitGravity | CWBackingStore | CWEventMask,
         &attr);
 
     /* register interest in the delete window message */
-    Atom wmDeleteMessage = XInternAtom(x->display, "WM_DELETE_WINDOW", False);
-    XSetWMProtocols(x->display, win->winid, &wmDeleteMessage, 1);
-
-//    /* set input methods */
-//    if ((x->xim = XOpenIM(x->display, 0, 0, 0)))
-//        x->xic = XCreateIC(x->xim, XNInputStyle, XIMPreeditNothing|XIMStatusNothing, XNClientWindow, x->self, XNFocusWindow, x->self, NULL);
-//    /* initialize pixmap and drawing context */
-//    x->pixmap = XCreatePixmap(x->display, x->self, x->width, x->height, x->depth);
-//    x->xft    = XftDrawCreate(x->display, x->pixmap, x->visual, x->colormap);
-//    /* initialize the graphics context */
-//    XGCValues gcv;
-//    gcv.foreground = WhitePixel(x->display, x->screen);
-//    gcv.graphics_exposures = False;
-//    x->gc = XCreateGC(x->display, x->self, GCGraphicsExposures, &gcv);
-//    x->eventfns[ConfigureNotify] = x11_resize;
-//    x->eventfns[MapNotify] = x11_mapnotify;
-//    x->eventfns[EnterNotify] = x11_enternotify;
+    Atom wmDeleteMessage = XInternAtom(X.display, "WM_DELETE_WINDOW", False);
+    XSetWMProtocols(X.display, win->winid, &wmDeleteMessage, 1);
 
+    /* set input methods */
+    if ((win->xim = XOpenIM(X.display, 0, 0, 0)))
+    {
+        win->xic = XCreateIC(
+            win->xim, XNInputStyle, XIMPreeditNothing|XIMStatusNothing, XNClientWindow, win->winid, XNFocusWindow, win->winid, NULL);
+    }
+    /* initialize pixmap and drawing context */
+    win->pixmap = XCreatePixmap(X.display, win->winid, win->width, win->height, X.depth);
+    win->xft    = XftDrawCreate(X.display, win->pixmap, X.visual, X.colormap);
+    /* initialize the graphics context */
+    XGCValues gcv;
+    gcv.foreground = WhitePixel(X.display, X.screen);
+    gcv.graphics_exposures = False;
+    win->gc = XCreateGC(X.display, win->winid, GCGraphicsExposures, &gcv);
 }
 
-void X11_MakeDialog(XConf* x, XWindow* win, int width, int height)
+void X11_MakeDialog(XWindow* win, int width, int height)
 {
-    X11_MakeWindow(x, win, width, height);
-    Atom WindowType = XInternAtom(x->display, "_NET_WM_WINDOW_TYPE", False);
-    Atom DialogType = XInternAtom(x->display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
-    XChangeProperty(x->display, win->winid, WindowType, XA_ATOM, 32, PropModeReplace, (unsigned char*)&DialogType, 1);
+    X11_MakeWindow(win, width, height);
+    Atom WindowType = XInternAtom(X.display, "_NET_WM_WINDOW_TYPE", False);
+    Atom DialogType = XInternAtom(X.display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
+    XChangeProperty(X.display, win->winid, WindowType, XA_ATOM, 32, PropModeReplace, (unsigned char*)&DialogType, 1);
 }
 
-void X11_ShowWindow(XConf* x, XWindow* w)
+void X11_ShowWindow(XWindow* w)
 {
     /* simulate an initial resize and map the window */
     XConfigureEvent ce;
     ce.type   = ConfigureNotify;
     ce.width  = w->width;
     ce.height = w->height;
-    XSendEvent(x->display, w->winid, False, StructureNotifyMask, (XEvent *)&ce);
-    XMapWindow(x->display, w->winid);
-    XSync(x->display, False);
+    XSendEvent(X.display, w->winid, False, StructureNotifyMask, (XEvent *)&ce);
+    XMapWindow(X.display, w->winid);
+    XSync(X.display, False);
 
     /* Waiting for window mapping */
     XEvent ev;
     do
     {
-        XNextEvent(x->display, &ev);
+        XNextEvent(X.display, &ev);
         if (XFilterEvent(&ev, None))
         {
             continue;
         }
         if (ev.type == ConfigureNotify)
         {
-//            x11_resize(x, &ev);
+            xresize(&ev);
         }
     }
     while (ev.type != MapNotify);
 }
 
-void X11_HideWindow(XConf* x, XWindow* w)
+void X11_HideWindow(XWindow* w)
 {
     /* TODO: implement window hiding */
 }