-
-
Save akokshar/b1a3c0d9b51652feaf1b940c6a5018ce to your computer and use it in GitHub Desktop.
Xresource example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* $CC -o xresources_test xresources_test.c -lX11 */ | |
| #include <X11/Xresource.h> | |
| #include <string.h> | |
| #include <stdio.h> | |
| #define XRESOURCE_LOAD_STRING(NAME, DST) \ | |
| XrmGetResource(db, NAME, "String", &type, &ret); \ | |
| if (ret.addr != NULL && !strncmp("String", type, 64)) \ | |
| DST = ret.addr; | |
| int | |
| main(void) { | |
| XrmDatabase db; /* Xresources database */ | |
| XrmValue ret; /* structure that holds pointer to string */ | |
| Display *dpy; /* X connection */ | |
| char *resource_manager; | |
| char *type; /* class of returned variable */ | |
| char *var; /* pointer to the resource */ | |
| /* connect to X */ | |
| if (!(dpy = XOpenDisplay(NULL))) | |
| return -1; | |
| /* initialize xresources */ | |
| XrmInitialize(); | |
| resource_manager = XResourceManagerString(dpy); | |
| if (resource_manager == NULL) | |
| return -2; | |
| /* load the database */ | |
| db = XrmGetStringDatabase(resource_manager); | |
| if (db == NULL) | |
| return -3; | |
| /* use macro to get pointer string */ | |
| XRESOURCE_LOAD_STRING("my.var", var); | |
| printf("my.var = '%s'\n", var); | |
| /* remember to clean up */ | |
| XCloseDisplay(dpy); | |
| /* NOTE: you're being given pointers to the xresource database | |
| * DON'T free() THE MEMORY ! | |
| */ | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment