]> git.mdlowis.com Git - proto/anvil.git/commitdiff
barebones setup. empty event handlers
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 10 Mar 2020 13:07:24 +0000 (09:07 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 10 Mar 2020 13:07:24 +0000 (09:07 -0400)
.gitignore [new file with mode: 0644]
anvil.c
anvil.h [new file with mode: 0644]
build.sh [new file with mode: 0755]
tiny.c [deleted file]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b4bd510
--- /dev/null
@@ -0,0 +1,2 @@
+anvil
+tags
diff --git a/anvil.c b/anvil.c
index 01d07d1b5eb423df1155786353e943250672bd9b..62cb43fe1d6dde55d3fe512b6bf07b92f604d1e8 100644 (file)
--- a/anvil.c
+++ b/anvil.c
@@ -1,16 +1,6 @@
-#include <X11/Xlib.h>
-#include <stdlib.h>
-#include <stdint.h>
+#include "anvil.h"
 
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-
-struct {
-    Display* disp;
-    Window root;
-    void (*eventfns[LASTEvent])(XEvent*);
-} X;
-XWindowAttributes attr;
-XButtonEvent start;
+XConf X;
 
 static void check(intptr_t stat)
 {
@@ -20,66 +10,84 @@ static void check(intptr_t stat)
     }
 }
 
-void xkeypress(XEvent* ev)
+static void xbtnpress(XEvent* e)
 {
-    if (ev->xbutton.subwindow != None)
-    {
-        XRaiseWindow(X.disp, ev->xkey.subwindow);
-    }
+    (void)e;
 }
 
-void xbtnpress(XEvent* ev)
+static void xbtnrelease(XEvent* e)
 {
-    if (ev->xbutton.subwindow != None)
-    {
-        XGrabPointer(X.disp, ev->xbutton.subwindow, True,
-                PointerMotionMask|ButtonReleaseMask, GrabModeAsync,
-                GrabModeAsync, None, None, CurrentTime);
-        XGetWindowAttributes(X.disp, ev->xbutton.subwindow, &attr);
-        start = ev->xbutton;
-    }
+    (void)e;
+}
+
+static void xconfigrequest(XEvent* e)
+{
+    (void)e;
+}
+
+static void xmaprequest(XEvent* e)
+{
+    (void)e;
+}
+
+static void xunmapnotify(XEvent* e)
+{
+    (void)e;
 }
 
-void xbtnrelease(XEvent* ev)
+static void xdestroynotify(XEvent* e)
 {
-    XUngrabPointer(X.disp, CurrentTime);
+    (void)e;
 }
 
-void xmotionnotify(XEvent* ev)
+static void xclientmsg(XEvent* e)
 {
-    int xdiff, ydiff;
-    while (XCheckTypedEvent(X.disp, MotionNotify, ev));
-    xdiff = ev->xbutton.x_root - start.x_root;
-    ydiff = ev->xbutton.y_root - start.y_root;
-    XMoveResizeWindow(X.disp, ev->xmotion.window,
-        attr.x + (start.button==1 ? xdiff : 0),
-        attr.y + (start.button==1 ? ydiff : 0),
-        MAX(1, attr.width + (start.button==3 ? xdiff : 0)),
-        MAX(1, attr.height + (start.button==3 ? ydiff : 0)));
+    (void)e;
 }
 
-int main(int argc, char** argv)
+static void xpropnotify(XEvent* e)
 {
-    XWindowAttributes attr;
-    XButtonEvent start;
-    XEvent ev;
+    (void)e;
+}
+
+static void xenternotify(XEvent* e)
+{
+    (void)e;
+}
+
+static void xexpose(XEvent* e)
+{
+    (void)e;
+}
 
+static void xkeypress(XEvent* e)
+{
+    (void)e;
+}
+
+int main(void)
+{
     /* Initialize X server*/
     check( !(X.disp = XOpenDisplay(0)) );
     X.root = DefaultRootWindow(X.disp);
-    XGrabKey(X.disp, XKeysymToKeycode(X.disp, XStringToKeysym("F1")), Mod1Mask, X.root,
-            True, GrabModeAsync, GrabModeAsync);
-    XGrabButton(X.disp, 1, Mod1Mask, X.root, True, ButtonPressMask, GrabModeAsync,
-            GrabModeAsync, None, None);
-    XGrabButton(X.disp, 3, Mod1Mask, X.root, True, ButtonPressMask, GrabModeAsync,
-            GrabModeAsync, None, None);
-    X.eventfns[KeyPress] = xkeypress;
+
+    /* setup event handlers */
     X.eventfns[ButtonPress] = xbtnpress;
     X.eventfns[ButtonRelease] = xbtnrelease;
-    X.eventfns[MotionNotify] = xmotionnotify;
+    X.eventfns[KeyPress] = xkeypress;
+    X.eventfns[ConfigureRequest] = xconfigrequest;
+    X.eventfns[MapRequest] = xmaprequest;
+    X.eventfns[UnmapNotify] = xunmapnotify;
+    X.eventfns[DestroyNotify] = xdestroynotify;
+    X.eventfns[ClientMessage] = xclientmsg;
+    X.eventfns[PropertyNotify] = xpropnotify;
+    X.eventfns[EnterNotify] = xenternotify;
+    X.eventfns[Expose] = xexpose;
 
+    /* main event loop */
     for (;;)
     {
+        XEvent ev;
         XNextEvent(X.disp, &ev);
         if (X.eventfns[ev.type])
         {
diff --git a/anvil.h b/anvil.h
new file mode 100644 (file)
index 0000000..3fe8c4d
--- /dev/null
+++ b/anvil.h
@@ -0,0 +1,19 @@
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+typedef struct {
+    Display* disp;
+    Window root;
+    void (*eventfns[LASTEvent])(XEvent*);
+} XConf;
+
+typedef struct Client {
+    struct Client* next;
+    char* name;
+    Window win;
+    int x, y, w, h;
+} Client;
+
+extern XConf X;
diff --git a/build.sh b/build.sh
new file mode 100755 (executable)
index 0000000..f141ac3
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+cc -Wall -Wextra -Werror -o anvil *.c -lX11
+ctags *
diff --git a/tiny.c b/tiny.c
deleted file mode 100644 (file)
index 01d07d1..0000000
--- a/tiny.c
+++ /dev/null
@@ -1,89 +0,0 @@
-#include <X11/Xlib.h>
-#include <stdlib.h>
-#include <stdint.h>
-
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-
-struct {
-    Display* disp;
-    Window root;
-    void (*eventfns[LASTEvent])(XEvent*);
-} X;
-XWindowAttributes attr;
-XButtonEvent start;
-
-static void check(intptr_t stat)
-{
-    if (!stat)
-    {
-        exit(1);
-    }
-}
-
-void xkeypress(XEvent* ev)
-{
-    if (ev->xbutton.subwindow != None)
-    {
-        XRaiseWindow(X.disp, ev->xkey.subwindow);
-    }
-}
-
-void xbtnpress(XEvent* ev)
-{
-    if (ev->xbutton.subwindow != None)
-    {
-        XGrabPointer(X.disp, ev->xbutton.subwindow, True,
-                PointerMotionMask|ButtonReleaseMask, GrabModeAsync,
-                GrabModeAsync, None, None, CurrentTime);
-        XGetWindowAttributes(X.disp, ev->xbutton.subwindow, &attr);
-        start = ev->xbutton;
-    }
-}
-
-void xbtnrelease(XEvent* ev)
-{
-    XUngrabPointer(X.disp, CurrentTime);
-}
-
-void xmotionnotify(XEvent* ev)
-{
-    int xdiff, ydiff;
-    while (XCheckTypedEvent(X.disp, MotionNotify, ev));
-    xdiff = ev->xbutton.x_root - start.x_root;
-    ydiff = ev->xbutton.y_root - start.y_root;
-    XMoveResizeWindow(X.disp, ev->xmotion.window,
-        attr.x + (start.button==1 ? xdiff : 0),
-        attr.y + (start.button==1 ? ydiff : 0),
-        MAX(1, attr.width + (start.button==3 ? xdiff : 0)),
-        MAX(1, attr.height + (start.button==3 ? ydiff : 0)));
-}
-
-int main(int argc, char** argv)
-{
-    XWindowAttributes attr;
-    XButtonEvent start;
-    XEvent ev;
-
-    /* Initialize X server*/
-    check( !(X.disp = XOpenDisplay(0)) );
-    X.root = DefaultRootWindow(X.disp);
-    XGrabKey(X.disp, XKeysymToKeycode(X.disp, XStringToKeysym("F1")), Mod1Mask, X.root,
-            True, GrabModeAsync, GrabModeAsync);
-    XGrabButton(X.disp, 1, Mod1Mask, X.root, True, ButtonPressMask, GrabModeAsync,
-            GrabModeAsync, None, None);
-    XGrabButton(X.disp, 3, Mod1Mask, X.root, True, ButtonPressMask, GrabModeAsync,
-            GrabModeAsync, None, None);
-    X.eventfns[KeyPress] = xkeypress;
-    X.eventfns[ButtonPress] = xbtnpress;
-    X.eventfns[ButtonRelease] = xbtnrelease;
-    X.eventfns[MotionNotify] = xmotionnotify;
-
-    for (;;)
-    {
-        XNextEvent(X.disp, &ev);
-        if (X.eventfns[ev.type])
-        {
-            X.eventfns[ev.type](&ev);
-        }
-    }
-}
\ No newline at end of file