From f81c9e531fba1831397e4c319ba352c07b24f564 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 30 Aug 2022 16:00:36 +0200 Subject: gbrightness --- .gitignore | 1 + .gitmodules | 3 +++ Makefile | 15 ++++++++++----- gbrightness.cpp | 22 ++++++++++++++++++++++ got-gui | 1 + 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 .gitmodules create mode 100644 gbrightness.cpp create mode 160000 got-gui diff --git a/.gitignore b/.gitignore index 71ba227..751b0a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .ccls-cache/ brightness +gbrightness diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f90e8ab --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "got-gui"] + path = got-gui + url = https://git.tomsmeding.com/got-gui diff --git a/Makefile b/Makefile index 8584d48..35b351a 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,25 @@ CXX = g++ -CXXFLAGS = -Wall -Wextra -O2 -std=c++11 +CXXFLAGS = -Wall -Wextra -O2 -std=c++17 INSTALL_DIR = $(HOME)/prefix/bin -BIN = brightness +BINS = brightness gbrightness .PHONY: all clean install -all: $(BIN) +all: $(BINS) clean: - rm -f $(BIN) + rm -f $(BINS) install: sudo install -o root brightness $(INSTALL_DIR) sudo chmod +s $(INSTALL_DIR)/brightness -$(BIN): brightness.cpp $(wildcard *.h) +brightness: brightness.cpp $(CXX) $(CXXFLAGS) $(filter %.cpp,$^) -o $@ + +UTILS = $(patsubst %,got-gui/%,gui.cpp gui.h xutil.cpp xutil.h command.cpp command.h) + +gbrightness: gbrightness.cpp $(UTILS) + $(CXX) $(CXXFLAGS) $(filter %.cpp,$^) -o $@ -lX11 diff --git a/gbrightness.cpp b/gbrightness.cpp new file mode 100644 index 0000000..985d159 --- /dev/null +++ b/gbrightness.cpp @@ -0,0 +1,22 @@ +#include +#include +#include "got-gui/command.h" +#include "got-gui/xutil.h" + + +int main() { + auto display = x::XOpenDisplayRAII(nullptr); + Display *dpy = display.first; + + x::globalKeyboardGrab(dpy, [dpy](const XKeyEvent &ev) -> bool { + x::Keycode kc{ev.keycode}; + if (kc == x::Keysym{XK_Up}.toCode(dpy)) { + runCommand({"brightness", "+"}); + } else if (kc == x::Keysym{XK_Down}.toCode(dpy)) { + runCommand({"brightness", "-"}); + } else { + return true; + } + return false; + }); +} diff --git a/got-gui b/got-gui new file mode 160000 index 0000000..7c6c2aa --- /dev/null +++ b/got-gui @@ -0,0 +1 @@ +Subproject commit 7c6c2aad9ba78f780f0c0513aef3f14a2e6fd3ab -- cgit v1.2.3