commit 668dc11
chld
·
2026-07-14 15:13:58 +0000 UTC
parent 668dc11
init
5 files changed,
+189,
-0
+6,
-0
1@@ -0,0 +1,6 @@
2+*.out
3+*.a
4+*.so
5+*.core
6+xl
7+config.h
A
Makefile
+29,
-0
1@@ -0,0 +1,29 @@
2+.POSIX:
3+SRC = xtr
4+PREFIX = /usr/pkg
5+
6+CC = cc
7+PKG_CONFIG = pkg-config
8+
9+CFLAGS += -std=c99 -Wall -Wextra -Oz -Wno-unused-parameter
10+
11+PKG_CFLAGS != ${PKG_CONFIG} --cflags x11
12+PKG_LIBS != ${PKG_CONFIG} --libs x11
13+
14+CPPFLAGS += ${WLD_CFLAGS} -I. -I/usr/local/include -I${PREFIX}/include
15+SRCS = ${SRC}.c
16+
17+.PHONY: all clean install
18+all: ${SRC}
19+
20+${SRC}: ${SRC}.c config.h
21+ ${CC} -o $@ ${CFLAGS} ${LDFLAGS} ${PKG_CFLAGS} ${SRCS} ${PKG_LIBS}
22+
23+clean:
24+ rm -f ${SRC} *.o ${PROTO}
25+install: ${SRC}
26+ cp ${SRC} ${PREFIX}/bin/${SRC}
27+uninstall:
28+ rm ${PREFIX}/bin/${SRC}
29+config.h: config.def.h
30+ cp config.def.h config.h
+13,
-0
1@@ -0,0 +1,13 @@
2+#ifndef XLND_CONFIG_H
3+#define XLND_CONFIG_H
4+
5+/* colors */
6+char *cols[] = {"#222222", /* border */
7+ "#080808", /* bg */
8+ "#aaaaaa", /* font */
9+ "#e74c3c", /* selected bg */
10+ "#080808", /* selected font */
11+ "#111111", /* title */
12+ NULL};
13+
14+#endif
A
xtr
+0,
-0
A
xtr.c
+141,
-0
1@@ -0,0 +1,141 @@
2+#include <X11/Xlib.h>
3+#include <X11/keysym.h>
4+
5+#include <stdbool.h>
6+#include <stdio.h>
7+#include <stdlib.h>
8+#include <string.h>
9+
10+#include <getopt.h>
11+
12+#include "config.h"
13+
14+int main(int ac, char **av) {
15+ int wi = 600, hi = 150, x = 0, y = 0;
16+
17+ char path[128];
18+ snprintf(path, sizeof path, "%s/%s", getenv("HOME"), ".xlrc");
19+
20+ char *fnt = NULL;
21+
22+ int opt;
23+ while ((opt = getopt(ac, av, "f:h ")) != -1) {
24+ switch (opt) {
25+ case 'f':
26+ fnt = optarg;
27+ break;
28+ case 'h':
29+ fprintf(stderr,
30+ "usage: %s [-c file] [-g WxH] [-f fontname]\nusage: %s "
31+ "[-h]\nusage: %s\n",
32+ av[0], av[0], av[0]);
33+ return 0;
34+ break;
35+ case ':':
36+ fprintf(stderr, "-%c needs a argument!\n", optopt);
37+ return 1;
38+ break;
39+ case '?':
40+ fprintf(stderr, "unknown flag: -%c\n", optopt);
41+ return 1;
42+ break;
43+ }
44+ }
45+
46+ Display *d = XOpenDisplay(NULL);
47+ if (!d) {
48+ fprintf(stderr, "couldnt open display\n");
49+ return 1;
50+ }
51+
52+ int s = DefaultScreen(d);
53+ int swi = DisplayWidth(d, s);
54+ int shi = DisplayHeight(d, s);
55+
56+ Window r = DefaultRootWindow(d);
57+ Window w_r;
58+ unsigned int m_r;
59+ int d1, d2;
60+
61+ if (XQueryPointer(d, r, &w_r, &w_r, &x, &y, &d1, &d2, &m_r)) {
62+ }
63+
64+ XColor col[6];
65+ for (size_t c = 0; cols[c] != NULL; c++) {
66+ XParseColor(d, DefaultColormap(d, s), cols[c], &col[c]);
67+ XAllocColor(d, DefaultColormap(d, s), &col[c]);
68+ }
69+
70+ Window w = XCreateSimpleWindow(d, RootWindow(d, s), (swi / 2) - (wi / 2),
71+ (shi / 2) - (hi / 2), wi, hi, 1, col[0].pixel,
72+ WhitePixel(d, s));
73+ XStoreName(d, w, "xlnd");
74+ XSelectInput(d, w,
75+ ExposureMask | KeyPressMask | StructureNotifyMask |
76+ ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
77+ /*
78+ * dont make it a regular window
79+ * kinda like rofi or layer-shell
80+ */
81+ XSetWindowAttributes at;
82+ at.override_redirect = True;
83+ XChangeWindowAttributes(d, w, CWOverrideRedirect, &at);
84+
85+ XMapWindow(d, w);
86+ XMapRaised(d, w);
87+ XSetInputFocus(d, w, RevertToPointerRoot, CurrentTime);
88+ XGrabKeyboard(d, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
89+ XGrabPointer(d, w, True, ButtonPressMask | PointerMotionMask, GrabModeAsync,
90+ GrabModeAsync, None, None, CurrentTime);
91+
92+ GC gc = XCreateGC(d, w, 0, NULL);
93+ XSetForeground(d, gc, WhitePixel(d, s));
94+ XFillRectangle(d, w, gc, 0, 0, wi, hi);
95+ XSetForeground(d, gc, BlackPixel(d, s));
96+
97+ XFontStruct *font = XLoadQueryFont(d, fnt ? fnt : "fixed");
98+ if (!font)
99+ font = XLoadQueryFont(d, "fixed");
100+ XSetFont(d, gc, font->fid);
101+
102+ while (1) {
103+ XEvent ev;
104+ XNextEvent(d, &ev);
105+
106+ switch (ev.type) {
107+ case Expose:
108+ if (ev.xexpose.count != 0)
109+ break;
110+
111+ XSetForeground(d, gc, col[1].pixel);
112+ XFillRectangle(d, w, gc, 0, 0, wi, hi);
113+
114+ break;
115+ case ConfigureNotify:
116+ break;
117+ case ButtonPress:
118+ break;
119+ case ButtonRelease:
120+ break;
121+ case MotionNotify: {
122+ break;
123+ }
124+ case KeyPress: {
125+ KeySym k = XLookupKeysym(&ev.xkey, 0);
126+ if (k == XK_Escape)
127+ goto q;
128+
129+ break;
130+ }
131+ }
132+ }
133+
134+q:
135+ XFreeFont(d, font);
136+ XUngrabKeyboard(d, CurrentTime);
137+ XUngrabPointer(d, CurrentTime);
138+ XFreeGC(d, gc);
139+ XDestroyWindow(d, w);
140+ XCloseDisplay(d);
141+ return 0;
142+}