Permalink
Browse files

Read configuration values from X resources

Configuration values can now be specified as X resources (e.g.
~/.Xdefaults, xrdb -load ~/.Xdefaults, man 1 xrdb).
Name or Instance is 'simpleswitcher', Class is 'Simpleswitcher'.

Possible values are:

	key
	dkey
	width
	lines
	font
	foreground
	background
	alternatebg
	highlightfg
	highlightbg
	bordercolor
	release
	startindex
	borderwidth
	opacity

E.g.:
	Simpleswitcher.key: F12
	Simpleswitcher.width: 50
	etc.
  • Loading branch information...
1 parent 84aaf17 commit 18511a797ce45cdd885a7316bf4c5bbc55fb9abd @jotrk jotrk committed Apr 11, 2013
Showing with 30 additions and 1 deletion.
  1. +1 −1 Makefile
  2. +29 −0 simpleswitcher.c
View
@@ -1,5 +1,5 @@
CFLAGS?=-Wall -Os
-LDADD?=`pkg-config --cflags --libs x11 xinerama xft`
+LDADD?=`pkg-config --cflags --libs x11 xinerama xft xres`
PREFIX?=$(DESTDIR)/usr
BINDIR?=$(PREFIX)/bin
View
@@ -34,6 +34,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <X11/Xft/Xft.h>
+#include <X11/Xresource.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1068,6 +1069,34 @@ int main(int argc, char *argv[])
// X atom values
for (i = 0; i < NETATOMS; i++) netatoms[i] = XInternAtom(display, netatom_names[i], False);
+ XrmInitialize();
+ char * xRMS = XResourceManagerString ( display );
+ XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
+
+ char * xrmType;
+ XrmValue xrmValue;
+
+ const char * namePrefix = "simpleswitcher";
+ const char * classPrefix = "Simpleswitcher";
+
+ for ( i = 0; i < sizeof ( xrmOptions ) / sizeof ( *xrmOptions ); ++i ) {
+ char * name = (char *) malloc ( ( 1 + strlen ( namePrefix ) + strlen ( xrmOptions[i].name ) ) * sizeof ( char ) );
+ char * class = (char *) malloc ( ( 1 + strlen ( classPrefix ) + strlen ( xrmOptions[i].name ) ) * sizeof ( char ) );
+ sprintf ( name, "%s.%s", namePrefix, xrmOptions[i].name );
+ sprintf ( class, "%s.%s", classPrefix, xrmOptions[i].name );
+
+ if ( XrmGetResource ( xDB, name, class, &xrmType, &xrmValue ) ) {
+
+ if ( xrmOptions[i].type == xrm_String ) {
+ *xrmOptions[i].str = (char *) malloc ( xrmValue.size * sizeof ( char ) );
+ strncpy ( *xrmOptions[i].str, xrmValue.addr, xrmValue.size );
+ } else if ( xrmOptions[i].type == xrm_Number ) {
+ *xrmOptions[i].num = strtol ( xrmValue.addr, NULL, 10 );
+ }
+ }
+
+ free ( name ); free ( class );
+ }
find_arg_str(ac, av, "-key", &config_menu_key );
find_arg_str(ac, av, "-dkey", &config_menu_dkey );

0 comments on commit 18511a7

Please sign in to comment.