From 58f511fe8d8df9d33018dd34d357f46ce9046d3e Mon Sep 17 00:00:00 2001 From: "alexey.skladnoy" Date: Tue, 22 Jul 2008 14:05:26 +0000 Subject: Dzen is now able to get font and color settings from X resources - Order of initialization changed: 1. connect to X server 2. Read X resources 3. Parse command line options - README files updated - x_read_resources may contain bugs git-svn-id: http://dzen.googlecode.com/svn/trunk@230 f2baff5b-bf2c-0410-a398-912abdc3d8b2 --- README | 12 ++++++++++++ README.dzen | 12 ++++++++++++ dzen.h | 1 + main.c | 38 +++++++++++++++++++++++++++++++++----- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/README b/README index 40adf13..e8c279c 100644 --- a/README +++ b/README @@ -97,6 +97,18 @@ dzen accepts a couple of options: +X resources +----------- + +Dzen is able to read font and color setting from X resources. +As an example you can add following lines to ~/.Xresources + +dzen2.font: -*-fixed-*-*-*-*-*-*-*-*-*-*-*-* +dzen2.foreground: #22EE11 +dzen2.background: black + + + Window layout ------------- diff --git a/README.dzen b/README.dzen index 9332164..43f9a50 100644 --- a/README.dzen +++ b/README.dzen @@ -97,6 +97,18 @@ dzen accepts a couple of options: +^fg(#6fbf47)X resources +^fg(#6fbf47)----------- + +Dzen is able to read font and color setting from X resources. +As an example you can add following lines to ~/.Xresources + +^fg(Khaki)dzen2.font: -*-fixed-*-*-*-*-*-*-*-*-*-*-*-* +^fg(Khaki)dzen2.foreground: #22EE11 +^fg(Khaki)dzen2.background: black + + + ^fg(#6fbf47)Window layout ^fg(#6fbf47)------------- diff --git a/dzen.h b/dzen.h index ba4107e..625cfbf 100644 --- a/dzen.h +++ b/dzen.h @@ -6,6 +6,7 @@ #include #include +#include #ifdef DZEN_XINERAMA #include #endif diff --git a/main.c b/main.c index 981f757..954d5c2 100644 --- a/main.c +++ b/main.c @@ -384,6 +384,35 @@ x_create_gcs(void) { dzen.tgc = XCreateGC(dzen.dpy, RootWindow(dzen.dpy, dzen.screen), GCGraphicsExposures, &gcv); } +static void +x_connect(void) { + dzen.dpy = XOpenDisplay(0); + if(!dzen.dpy) + eprint("dzen: cannot open display\n"); + dzen.screen = DefaultScreen(dzen.dpy); +} + +/* Read display styles from X resources. */ +static void +x_read_resources(void) { + XrmDatabase xdb; + char* xrm; + char* datatype[20]; + XrmValue xvalue; + + xrm = XResourceManagerString(dzen.dpy); + if( xrm != NULL ) { + xdb = XrmGetStringDatabase(xrm); + if( XrmGetResource(xdb, "dzen2.font", "*", datatype, &xvalue) == True ) + dzen.fnt = estrdup(xvalue.addr); + if( XrmGetResource(xdb, "dzen2.foreground", "*", datatype, &xvalue) == True ) + dzen.fg = estrdup(xvalue.addr); + if( XrmGetResource(xdb, "dzen2.background", "*", datatype, &xvalue) == True ) + dzen.bg = estrdup(xvalue.addr); + XrmDestroyDatabase(xdb); + } +} + static void x_create_windows(int use_ewmh_dock) { XSetWindowAttributes wa; @@ -391,11 +420,6 @@ x_create_windows(int use_ewmh_dock) { int i; XRectangle si; - dzen.dpy = XOpenDisplay(0); - if(!dzen.dpy) - eprint("dzen: cannot open display\n"); - - dzen.screen = DefaultScreen(dzen.dpy); root = RootWindow(dzen.dpy, dzen.screen); /* style */ @@ -797,6 +821,10 @@ main(int argc, char *argv[]) { dzen.line_height = 0; dzen.title_win.expand = noexpand; + /* Connect to X server */ + x_connect(); + x_read_resources(); + /* cmdline args */ for(i = 1; i < argc; i++) if(!strncmp(argv[i], "-l", 3)){ -- cgit v1.2.3-54-g00ecf