Change how icons are loaded
- use several icon_folders instead of a single icon_path - check all paths for the icon
This commit is contained in:
parent
c6ef8ecaed
commit
a02ab4cf70
@ -50,8 +50,8 @@ char *dmenu = "/usr/bin/dmenu";
|
||||
|
||||
char *browser = "/usr/bin/firefox";
|
||||
|
||||
/* path to default icons */
|
||||
char *icon_path = "/usr/share/icons/gnome/16x16/status/";
|
||||
/* paths to default icons */
|
||||
char *icon_folders = "/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/";
|
||||
|
||||
/* follow focus to different monitor and display notifications there?
|
||||
* possible values:
|
||||
|
4
dunstrc
4
dunstrc
@ -141,8 +141,8 @@
|
||||
# Align icons left/right/off
|
||||
icon_position = off
|
||||
|
||||
# Path to default icons.
|
||||
icon_path = /usr/share/icons/gnome/16x16/status/
|
||||
# Paths to default icons.
|
||||
icon_folders = /usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/
|
||||
|
||||
[frame]
|
||||
width = 3
|
||||
|
@ -281,13 +281,6 @@ int notification_init(notification * n, int id)
|
||||
|
||||
n->urls = notification_extract_markup_urls(&(n->body));
|
||||
|
||||
/* Add icon path if relative */
|
||||
if (strlen(n->icon) > 0 && n->icon[0] != '/' && n->icon[0] != '~') {
|
||||
char *new = g_strconcat(settings.icon_path, n->icon, ".png", NULL);
|
||||
free(n->icon);
|
||||
n->icon = new;
|
||||
}
|
||||
|
||||
n->msg = string_replace("%a", n->appname, g_strdup(n->format));
|
||||
n->msg = string_replace("%s", n->summary, n->msg);
|
||||
if (n->icon) {
|
||||
|
@ -210,9 +210,9 @@ void load_settings(char *cmdline_config_path)
|
||||
}
|
||||
}
|
||||
|
||||
settings.icon_path =
|
||||
option_get_string("global", "icon_path", "-icon_path", icon_path,
|
||||
"path to default icons");
|
||||
settings.icon_folders =
|
||||
option_get_string("global", "icon_folders", "-icon_folders", icon_folders,
|
||||
"paths to default icons");
|
||||
|
||||
settings.frame_width =
|
||||
option_get_int("frame", "width", "-frame_width", frame_width,
|
||||
|
@ -43,7 +43,7 @@ typedef struct _settings {
|
||||
char **dmenu_cmd;
|
||||
char *browser;
|
||||
enum icon_position_t icon_position;
|
||||
char *icon_path;
|
||||
char *icon_folders;
|
||||
enum follow_mode f_mode;
|
||||
keyboard_shortcut close_ks;
|
||||
keyboard_shortcut close_all_ks;
|
||||
|
54
x.c
54
x.c
@ -258,6 +258,49 @@ static dimension_t calculate_dimensions(GSList *layouts)
|
||||
return dim;
|
||||
}
|
||||
|
||||
static cairo_t *get_icon_surface(char *icon_path)
|
||||
{
|
||||
cairo_t *icon_surface = NULL;
|
||||
if (strlen(icon_path) > 0 && settings.icon_position != icons_off) {
|
||||
/* absolute path? */
|
||||
if (icon_path[0] == '/' || icon_path[0] == '~') {
|
||||
icon_surface = cairo_image_surface_create_from_png(icon_path);
|
||||
if (cairo_surface_status(icon_surface) != CAIRO_STATUS_SUCCESS) {
|
||||
cairo_surface_destroy(icon_surface);
|
||||
icon_surface = NULL;
|
||||
}
|
||||
}
|
||||
/* search in icon_folders */
|
||||
if (icon_surface == NULL) {
|
||||
char *start = settings.icon_folders,
|
||||
*end, *current_folder, *maybe_icon_path;
|
||||
do {
|
||||
end = strchr(start, ':');
|
||||
if (end == NULL) end = strchr(settings.icon_folders, '\0'); /* end = end of string */
|
||||
|
||||
current_folder = strndup(start, end - start);
|
||||
maybe_icon_path = g_strconcat(current_folder, "/", icon_path, ".png", NULL);
|
||||
free(current_folder);
|
||||
|
||||
icon_surface = cairo_image_surface_create_from_png(maybe_icon_path);
|
||||
free(maybe_icon_path);
|
||||
if (cairo_surface_status(icon_surface) == CAIRO_STATUS_SUCCESS) {
|
||||
return icon_surface;
|
||||
} else {
|
||||
cairo_surface_destroy(icon_surface);
|
||||
icon_surface = NULL;
|
||||
}
|
||||
|
||||
start = end + 1;
|
||||
} while (*(end) != '\0');
|
||||
}
|
||||
if (icon_surface == NULL)
|
||||
fprintf(stderr,
|
||||
"Could not load icon: '%s'\n", icon_path);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static colored_layout *r_init_shared(cairo_t *c, notification *n)
|
||||
{
|
||||
colored_layout *cl = malloc(sizeof(colored_layout));
|
||||
@ -267,16 +310,7 @@ static colored_layout *r_init_shared(cairo_t *c, notification *n)
|
||||
pango_layout_set_ellipsize(cl->l, PANGO_ELLIPSIZE_MIDDLE);
|
||||
}
|
||||
|
||||
cl->icon = NULL;
|
||||
if (strlen(n->icon) > 0 && settings.icon_position != icons_off) {
|
||||
cl->icon = cairo_image_surface_create_from_png(n->icon);
|
||||
if (cairo_surface_status(cl->icon) != CAIRO_STATUS_SUCCESS) {
|
||||
cairo_surface_destroy(cl->icon);
|
||||
cl->icon = NULL;
|
||||
fprintf(stderr,
|
||||
"Could not load icon: %s\n", n->icon);
|
||||
}
|
||||
}
|
||||
cl->icon = get_icon_surface(n->icon);
|
||||
|
||||
cl->fg = x_string_to_color_t(n->color_strings[ColFG]);
|
||||
cl->bg = x_string_to_color_t(n->color_strings[ColBG]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user