Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch: Xresources #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ static const char *background_color = "#3e3e3e";
static const char *border_color = "#ececec";
static const char *font_color = "#ececec";
static const char *font_pattern = "monospace:size=10";
static const unsigned line_spacing = 5;
static const unsigned int padding = 15;
static unsigned line_spacing = 5;
static unsigned int padding = 15;

static const unsigned int width = 450;
static const unsigned int border_size = 2;
static const unsigned int pos_x = 30;
static const unsigned int pos_y = 60;
static unsigned int width = 450;
static unsigned int border_size = 2;
static unsigned int pos_x = 30;
static unsigned int pos_y = 60;

enum corners { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT };
enum corners corner = TOP_RIGHT;

static const unsigned int duration = 5; /* in seconds */
static unsigned int duration = 5; /* in seconds */

#define DISMISS_BUTTON Button1
#define ACTION_BUTTON Button3
33 changes: 32 additions & 1 deletion herbe.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
#include <X11/Xresource.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
Expand All @@ -15,6 +16,13 @@
#define EXIT_FAIL 1
#define EXIT_DISMISS 2

#define XRES_STR(name) \
if (XrmGetResource(db, "herbe." #name, "*", &type, &val)) \
name = val.addr
#define XRES_INT(name) \
if (XrmGetResource(db, "herbe." #name, "*", &type, &val)) \
name = strtoul(val.addr, 0, 10)

Display *display;
Window window;
int exit_code = EXIT_DISMISS;
Expand Down Expand Up @@ -107,6 +115,28 @@ int main(int argc, char *argv[])
if (!(display = XOpenDisplay(0)))
die("Cannot open display");

XrmInitialize();

char *res_man = XResourceManagerString(display);
XrmDatabase db = XrmGetStringDatabase(res_man);

char *type;
XrmValue val;

XRES_STR(background_color);
XRES_STR(border_color);
XRES_STR(font_color);
XRES_STR(font_pattern);

XRES_INT(line_spacing);
XRES_INT(padding);
XRES_INT(width);
XRES_INT(border_size);
XRES_INT(pos_x);
XRES_INT(pos_y);
XRES_INT(corner);
XRES_INT(duration);

int screen = DefaultScreen(display);
Visual *visual = DefaultVisual(display, screen);
Colormap colormap = DefaultColormap(display, screen);
Expand Down Expand Up @@ -214,7 +244,8 @@ int main(int argc, char *argv[])
XftDrawDestroy(draw);
XftColorFree(display, visual, colormap, &color);
XftFontClose(display, font);
XrmDestroyDatabase(db);
XCloseDisplay(display);

return exit_code;
}
}