aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--experimental/Makefile54
-rw-r--r--experimental/status.c40
2 files changed, 94 insertions, 0 deletions
diff --git a/experimental/Makefile b/experimental/Makefile
new file mode 100644
index 0000000..27d84c4
--- /dev/null
+++ b/experimental/Makefile
@@ -0,0 +1,54 @@
+# References:
+# BUILD_DIR and per-.cpp file https://spin.atomicobject.com/2016/08/26/makefile-c-projects/
+# https://bgstack15.ddns.net/blog/posts/2019/11/04/sample-makefile/ 2022-09-28-4 15:34
+awkbin :=$(shell which awk)
+cpbin :=$(shell which cp)
+echobin :=$(shell which echo)
+findbin :=$(shell which find)
+grepbin :=$(shell which grep)
+installbin :=$(shell which install)
+rmbin :=$(shell which rm)
+sedbin :=$(shell which sed)
+sortbin :=$(shell which sort)
+truebin :=$(shell which true)
+
+CXX = g++
+CC = gcc
+
+# to get full debug symbols, add to both FLAGS: -g
+# to make all warnings act as errors: -Wall -Weffc++ -Wextra -Wsign-conversion -Werror
+CXXFLAGS = -g -std=c++17 -Wall -Weffc++ -Wextra -Wsign-conversion -Werror
+CCFLAGS = -g -Wall -Wextra -Wsign-conversion -Werror `pkg-config x11 --cflags`
+
+# to remove all debug symbols: -s
+# to add full debug symbols: -g
+LDFLAGS = -g `pkg-config x11 --libs`
+
+src = $(wildcard *.c)
+obj = $(src:.c=.o)
+
+BUILD_DIR ?= .
+
+OUTEXE = status
+
+all: $(OUTEXE)
+
+$(obj):
+
+$(BUILD_DIR)/%.o: %.c
+ $(CC) -c $(CCFLAGS) -o $@ $<
+
+# link
+$(OUTEXE): $(obj)
+ $(CC) -o $@ $^ $(LDFLAGS)
+
+.PHONY: clean cleanall list
+
+list:
+ @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | ${awkbin} -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | ${sortbin} | ${grepbin} -E -v -e '^[^[:alnum:]]' -e '^$@$$' -e '\.(cp*|o)'
+
+clean:
+ rm -f $(obj)
+
+cleanall:
+ rm -f $(obj) $(OUTEXE)
diff --git a/experimental/status.c b/experimental/status.c
new file mode 100644
index 0000000..6357b62
--- /dev/null
+++ b/experimental/status.c
@@ -0,0 +1,40 @@
+/*
+ * File: status.c
+ * Location: https://bgstack15.ddns.net/cgit/keyboard-leds-trayicons/
+ * Author: bgstack15
+ * Startdate: 2022-09-28-4 13:30
+ * SPDX-License-Identifier: GPL-3.0
+ * Title: Proof of Concept C utility for polling capslock and numlock
+ * Purpose: Demonstrate these can be done in C, with the eventual goal of rewriting keyboard-leds-trayicons entirely in C to avoid the "sleep 0.75" in ps output
+ * History:
+ * Usage:
+ * References:
+ * https://github.com/Cairo-Dock/cairo-dock-plug-ins/blob/master/keyboard-indicator/src/applet-xklavier.c#L124
+ * https://github.com/oco2000/xfce4-kbdleds-plugin/blob/fe753d9d0f8a720a35a32f5f556b8fbead798d20/panel-plugin/xkbleds.c
+ * Improvements:
+ * Write main keyboard-led-trayicons logic, which includes parsing config file (libconfig?)
+ * Write pipe connectivity to mktrayicon or integrate it entirely
+ * Dependencies: libx11-dev
+ */
+#include<stdio.h>
+#include<string.h>
+#include<X11/XKBlib.h>
+
+Display* dpy;
+
+int get_indicator(Display* dpy, char* indicator) {
+ // where indicator is one of ["Num Lock", "Caps Lock"]
+ Atom lockIndicator = XInternAtom(dpy, indicator, False);
+ int st;
+ XkbGetNamedIndicator(dpy, lockIndicator, NULL, &st, NULL, NULL);
+ return st;
+}
+
+int main() {
+ dpy = XOpenDisplay( NULL );
+ int status_capslock = get_indicator(dpy, "Caps Lock");
+ int status_numlock = get_indicator(dpy, "Num Lock");
+ printf("Capslock: %d\tNumlock: %d\n",status_capslock,status_numlock);
+ printf("done\n");
+ return 0;
+}
bgstack15