From a091c00c00c1d5ae5e3da7ef31b98293c76d479f Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:16:59 -0700 Subject: init --- src/xnvctrl.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/xnvctrl.c (limited to 'src/xnvctrl.c') diff --git a/src/xnvctrl.c b/src/xnvctrl.c new file mode 100644 index 0000000..af46493 --- /dev/null +++ b/src/xnvctrl.c @@ -0,0 +1,46 @@ +#include "../include/xnvctrl.h" +#include "../include/library_loader.h" +#include +#include +#include + +bool gsr_xnvctrl_load(gsr_xnvctrl *self, Display *display) { + memset(self, 0, sizeof(gsr_xnvctrl)); + self->display = display; + + dlerror(); /* clear */ + void *lib = dlopen("libXNVCtrl.so.0", RTLD_LAZY); + if(!lib) { + fprintf(stderr, "gsr error: gsr_xnvctrl_load failed: failed to load libXNVCtrl.so.0, error: %s\n", dlerror()); + return false; + } + + const dlsym_assign required_dlsym[] = { + { (void**)&self->XNVCTRLQueryExtension, "XNVCTRLQueryExtension" }, + { (void**)&self->XNVCTRLSetTargetAttributeAndGetStatus, "XNVCTRLSetTargetAttributeAndGetStatus" }, + { (void**)&self->XNVCTRLQueryValidTargetAttributeValues, "XNVCTRLQueryValidTargetAttributeValues" }, + { (void**)&self->XNVCTRLQueryTargetStringAttribute, "XNVCTRLQueryTargetStringAttribute" }, + + { NULL, NULL } + }; + + if(!dlsym_load_list(lib, required_dlsym)) { + fprintf(stderr, "gsr error: gsr_xnvctrl_load failed: missing required symbols in libXNVCtrl.so.0\n"); + goto fail; + } + + self->library = lib; + return true; + + fail: + dlclose(lib); + memset(self, 0, sizeof(gsr_xnvctrl)); + return false; +} + +void gsr_xnvctrl_unload(gsr_xnvctrl *self) { + if(self->library) { + dlclose(self->library); + memset(self, 0, sizeof(gsr_xnvctrl)); + } +} -- cgit v1.2.3