summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-26 16:24:00 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-26 16:24:00 -0400
commitfc8f01587cafa361e97abc30234094859b262307 (patch)
tree6dca103e6ecfb36d63c14b4c7deaae0a3edd1499
initial commit
-rw-r--r--.gitignore2
-rw-r--r--LICENSE21
-rw-r--r--Makefile34
-rw-r--r--xbar.c55
4 files changed, 112 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..aa406a3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.o
+xbar
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..2c4ec25
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 Jakob Kaivo <jkk@ung.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d73399a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,34 @@
+.POSIX:
+
+# This Makefile was generated by maje
+# See https://src.kaivo.net/dev/maje/ for more information
+# Do not edit this Makefile by hand
+
+CC=c99
+LD=$(CC)
+CFLAGS=-Wall -Wextra -Wpedantic -Werror -g
+LDFLAGS=
+LDLIBS= -lX11
+SRCDIR=.
+OBJDIR=.
+BINDIR=$(OBJDIR)
+LIBDIR=$(OBJDIR)
+DESTDIR=/usr/local
+
+all: $(BINDIR)/xbar
+
+clean:
+ rm -f $(BINDIR)/xbar $(OBJDIR)/*.o
+
+install: $(BINDIR)/xbar
+ mkdir -p $(DESTDIR)/bin
+ cp $(BINDIR)/xbar $(DESTDIR)/bin
+
+$(BINDIR)/xbar: $(OBJDIR)/xbar.o
+$(OBJDIR)/xbar.o: $(SRCDIR)/xbar.c
+ @mkdir -p $(@D)
+ $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/xbar.c
+
+$(BINDIR)/xbar:
+ @mkdir -p $(@D)
+ $(LD) $(LDFLAGS) -o $@ $(OBJDIR)/*.o $(LDLIBS)
diff --git a/xbar.c b/xbar.c
new file mode 100644
index 0000000..01090fa
--- /dev/null
+++ b/xbar.c
@@ -0,0 +1,55 @@
+/* MAJE_LDLIB=-lX11 */
+
+#define _POSIX_C_SOURCE 200809L
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <X11/Xlib.h>
+
+int main(int argc, char *argv[])
+{
+ int c = 0;
+ while ((c = getopt(argc, argv, "")) != -1) {
+ switch (c) {
+ default:
+ return 1;
+ }
+ }
+
+ Display *dpy = XOpenDisplay("");
+ if (dpy == NULL) {
+ fprintf(stderr, "xbar: can't open display\n");
+ return 1;
+ }
+
+ int screen = DefaultScreen(dpy);
+ int width = DisplayWidth(dpy, screen);
+ int height = 20;
+
+ Window win = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy),
+ 0, 0, width, height, 0,
+ BlackPixel(dpy, screen), BlackPixel(dpy, screen));
+ XSelectInput(dpy, win, ExposureMask | KeyPressMask);
+ XMapWindow(dpy, win);
+
+ for (;;) {
+ XEvent e;
+ XNextEvent(dpy, &e);
+ switch (e.type) {
+ case Expose:
+ XDrawString(dpy, win, DefaultGC(dpy, screen), 0, 0,
+ "hello", strlen("hello"));
+ break;
+
+ case KeyPress:
+ printf("keypress\n");
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return 0;
+}