Merge pull request #566 from bebehei/notification-colors

Notification colors
This commit is contained in:
Nikos Tsipinakis 2018-11-27 14:36:02 +02:00 committed by GitHub
commit 0a2802af75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 82 additions and 92 deletions

View File

@ -4,12 +4,12 @@ struct settings defaults = {
.font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*",
.markup = MARKUP_NO,
.normbgcolor = "#1793D1",
.normfgcolor = "#DDDDDD",
.critbgcolor = "#ffaaaa",
.critfgcolor = "#000000",
.lowbgcolor = "#aaaaff",
.lowfgcolor = "#000000",
.colors_norm.bg = "#1793D1",
.colors_norm.fg = "#DDDDDD",
.colors_crit.bg = "#ffaaaa",
.colors_crit.fg = "#000000",
.colors_low.bg = "#aaaaff",
.colors_low.fg = "#000000",
.format = "%s %b", /* default format */
.timeouts = { S2US(10), S2US(10), S2US(0) }, /* low, normal, critical */

View File

@ -192,19 +192,19 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV
dict_value = g_variant_lookup_value(content, "fgcolor", G_VARIANT_TYPE_STRING);
if (dict_value) {
n->colors[ColFG] = g_variant_dup_string(dict_value, NULL);
n->colors.fg = g_variant_dup_string(dict_value, NULL);
g_variant_unref(dict_value);
}
dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING);
if (dict_value) {
n->colors[ColBG] = g_variant_dup_string(dict_value, NULL);
n->colors.bg = g_variant_dup_string(dict_value, NULL);
g_variant_unref(dict_value);
}
dict_value = g_variant_lookup_value(content, "frcolor", G_VARIANT_TYPE_STRING);
if (dict_value) {
n->colors[ColFrame] = g_variant_dup_string(dict_value, NULL);
n->colors.frame = g_variant_dup_string(dict_value, NULL);
g_variant_unref(dict_value);
}

View File

@ -281,9 +281,9 @@ static struct colored_layout *layout_init_shared(cairo_t *c, const struct notifi
cl->icon = NULL;
}
cl->fg = string_to_color(n->colors[ColFG]);
cl->bg = string_to_color(n->colors[ColBG]);
cl->frame = string_to_color(n->colors[ColFrame]);
cl->fg = string_to_color(n->colors.fg);
cl->bg = string_to_color(n->colors.bg);
cl->frame = string_to_color(n->colors.frame);
cl->n = n;

View File

@ -10,11 +10,6 @@
#include "notification.h"
#define ColLast 3
#define ColFrame 2
#define ColFG 1
#define ColBG 0
//!< A structure to describe dunst's global window status
struct dunst_status {
bool fullscreen; //!< a fullscreen window is currently focused
@ -38,8 +33,6 @@ void dunst_status(const enum dunst_status_field field,
struct dunst_status dunst_status_get(void);
extern const char *colors[3][3];
void wake_up(void);
int dunst_main(int argc, char *argv[]);

View File

@ -2,7 +2,12 @@
#ifndef DUNST_MARKUP_H
#define DUNST_MARKUP_H
#include "settings.h"
enum markup_mode {
MARKUP_NULL,
MARKUP_NO,
MARKUP_STRIP,
MARKUP_FULL
};
/**
* Strip any markup from text; turn it in to plain text.

View File

@ -22,7 +22,6 @@
#include "rules.h"
#include "settings.h"
#include "utils.h"
#include "x11/x.h"
static void notification_extract_urls(struct notification *n);
static void notification_format_message(struct notification *n);
@ -61,9 +60,9 @@ void notification_print(const struct notification *n)
printf("\turgency: %s\n", notification_urgency_to_string(n->urgency));
printf("\ttransient: %d\n", n->transient);
printf("\tformatted: '%s'\n", n->msg);
printf("\tfg: %s\n", n->colors[ColFG]);
printf("\tbg: %s\n", n->colors[ColBG]);
printf("\tframe: %s\n", n->colors[ColFrame]);
printf("\tfg: %s\n", n->colors.fg);
printf("\tbg: %s\n", n->colors.bg);
printf("\tframe: %s\n", n->colors.frame);
printf("\tfullscreen: %s\n", enum_to_string_fullscreen(n->fullscreen));
printf("\tprogress: %d\n", n->progress);
printf("\tstack_tag: %s\n", (n->stack_tag ? n->stack_tag : ""));
@ -249,9 +248,9 @@ void notification_unref(struct notification *n)
g_free(n->category);
g_free(n->text_to_render);
g_free(n->urls);
g_free(n->colors[ColFG]);
g_free(n->colors[ColBG]);
g_free(n->colors[ColFrame]);
g_free(n->colors.fg);
g_free(n->colors.bg);
g_free(n->colors.frame);
g_free(n->stack_tag);
actions_free(n->actions);
@ -348,12 +347,26 @@ void notification_init(struct notification *n)
n->icon = g_strdup(settings.icons[n->urgency]);
/* Color hints */
if (!n->colors[ColFG])
n->colors[ColFG] = g_strdup(xctx.colors[ColFG][n->urgency]);
if (!n->colors[ColBG])
n->colors[ColBG] = g_strdup(xctx.colors[ColBG][n->urgency]);
if (!n->colors[ColFrame])
n->colors[ColFrame] = g_strdup(xctx.colors[ColFrame][n->urgency]);
struct notification_colors defcolors;
switch (n->urgency) {
case URG_LOW:
defcolors = settings.colors_low;
break;
case URG_NORM:
defcolors = settings.colors_norm;
break;
case URG_CRIT:
defcolors = settings.colors_crit;
break;
default:
g_error("Unhandled urgency type: %d", n->urgency);
}
if (!n->colors.fg)
n->colors.fg = g_strdup(defcolors.fg);
if (!n->colors.bg)
n->colors.bg = g_strdup(defcolors.bg);
if (!n->colors.frame)
n->colors.frame = g_strdup(defcolors.frame);
/* Sanitize misc hints */
if (n->progress < 0)

View File

@ -5,7 +5,7 @@
#include <glib.h>
#include <stdbool.h>
#include "settings.h"
#include "markup.h"
#define DUNST_NOTIF_MAX_CHARS 5000
@ -44,6 +44,12 @@ struct actions {
typedef struct _notification_private NotificationPrivate;
struct notification_colors {
char *frame;
char *bg;
char *fg;
};
struct notification {
NotificationPrivate *priv;
int id;
@ -68,7 +74,7 @@ struct notification {
enum markup_mode markup;
const char *format;
const char *script;
char *colors[3];
struct notification_colors colors;
char *stack_tag; /**< stack notifications by tag */

View File

@ -32,16 +32,16 @@ void rule_apply(struct rule *r, struct notification *n)
g_clear_pointer(&n->raw_icon, rawimage_free);
}
if (r->fg) {
g_free(n->colors[ColFG]);
n->colors[ColFG] = g_strdup(r->fg);
g_free(n->colors.fg);
n->colors.fg = g_strdup(r->fg);
}
if (r->bg) {
g_free(n->colors[ColBG]);
n->colors[ColBG] = g_strdup(r->bg);
g_free(n->colors.bg);
n->colors.bg = g_strdup(r->bg);
}
if (r->fc) {
g_free(n->colors[ColFrame]);
n->colors[ColFrame] = g_strdup(r->fc);
g_free(n->colors.frame);
n->colors.frame = g_strdup(r->fc);
}
if (r->format)
n->format = r->format;

View File

@ -621,21 +621,21 @@ void load_settings(char *cmdline_config_path)
g_free(c);
}
settings.lowbgcolor = option_get_string(
settings.colors_low.bg = option_get_string(
"urgency_low",
"background", "-lb", defaults.lowbgcolor,
"background", "-lb", defaults.colors_low.bg,
"Background color for notifications with low urgency"
);
settings.lowfgcolor = option_get_string(
settings.colors_low.fg = option_get_string(
"urgency_low",
"foreground", "-lf", defaults.lowfgcolor,
"foreground", "-lf", defaults.colors_low.fg,
"Foreground color for notifications with low urgency"
);
settings.lowframecolor = option_get_string(
settings.colors_low.frame = option_get_string(
"urgency_low",
"frame_color", "-lfr", NULL,
"frame_color", "-lfr", settings.frame_color ? settings.frame_color : defaults.colors_low.frame,
"Frame color for notifications with low urgency"
);
@ -651,21 +651,21 @@ void load_settings(char *cmdline_config_path)
"Icon for notifications with low urgency"
);
settings.normbgcolor = option_get_string(
settings.colors_norm.bg = option_get_string(
"urgency_normal",
"background", "-nb", defaults.normbgcolor,
"background", "-nb", defaults.colors_norm.bg,
"Background color for notifications with normal urgency"
);
settings.normfgcolor = option_get_string(
settings.colors_norm.fg = option_get_string(
"urgency_normal",
"foreground", "-nf", defaults.normfgcolor,
"foreground", "-nf", defaults.colors_norm.fg,
"Foreground color for notifications with normal urgency"
);
settings.normframecolor = option_get_string(
settings.colors_norm.frame = option_get_string(
"urgency_normal",
"frame_color", "-nfr", NULL,
"frame_color", "-nfr", settings.frame_color ? settings.frame_color : defaults.colors_norm.frame,
"Frame color for notifications with normal urgency"
);
@ -681,21 +681,21 @@ void load_settings(char *cmdline_config_path)
"Icon for notifications with normal urgency"
);
settings.critbgcolor = option_get_string(
settings.colors_crit.bg = option_get_string(
"urgency_critical",
"background", "-cb", defaults.critbgcolor,
"background", "-cb", defaults.colors_crit.bg,
"Background color for notifications with critical urgency"
);
settings.critfgcolor = option_get_string(
settings.colors_crit.fg = option_get_string(
"urgency_critical",
"foreground", "-cf", defaults.critfgcolor,
"Foreground color for notifications with critical urgency"
"foreground", "-cf", defaults.colors_crit.fg,
"Foreground color for notifications with ciritical urgency"
);
settings.critframecolor = option_get_string(
settings.colors_crit.frame = option_get_string(
"urgency_critical",
"frame_color", "-cfr", NULL,
"frame_color", "-cfr", settings.frame_color ? settings.frame_color : defaults.colors_crit.frame,
"Frame color for notifications with critical urgency"
);

View File

@ -4,6 +4,8 @@
#include <stdbool.h>
#include "markup.h"
#include "notification.h"
#include "x11/x.h"
enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT };
@ -11,7 +13,6 @@ enum ellipsize { ELLIPSE_START, ELLIPSE_MIDDLE, ELLIPSE_END };
enum icon_position { ICON_LEFT, ICON_RIGHT, ICON_OFF };
enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM };
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
enum markup_mode { MARKUP_NULL, MARKUP_NO, MARKUP_STRIP, MARKUP_FULL };
enum mouse_action { MOUSE_NONE, MOUSE_DO_ACTION, MOUSE_CLOSE_CURRENT, MOUSE_CLOSE_ALL };
struct geometry {
@ -33,15 +34,9 @@ struct settings {
bool stack_duplicates;
bool hide_duplicate_count;
char *font;
char *normbgcolor;
char *normfgcolor;
char *normframecolor;
char *critbgcolor;
char *critfgcolor;
char *critframecolor;
char *lowbgcolor;
char *lowfgcolor;
char *lowframecolor;
struct notification_colors colors_low;
struct notification_colors colors_norm;
struct notification_colors colors_crit;
char *format;
gint64 timeouts[3];
char *icons[3];

View File

@ -464,27 +464,6 @@ void x_setup(void)
x_shortcut_grab(&settings.context_ks);
x_shortcut_ungrab(&settings.context_ks);
xctx.colors[ColFG][URG_LOW] = settings.lowfgcolor;
xctx.colors[ColFG][URG_NORM] = settings.normfgcolor;
xctx.colors[ColFG][URG_CRIT] = settings.critfgcolor;
xctx.colors[ColBG][URG_LOW] = settings.lowbgcolor;
xctx.colors[ColBG][URG_NORM] = settings.normbgcolor;
xctx.colors[ColBG][URG_CRIT] = settings.critbgcolor;
if (settings.lowframecolor)
xctx.colors[ColFrame][URG_LOW] = settings.lowframecolor;
else
xctx.colors[ColFrame][URG_LOW] = settings.frame_color;
if (settings.normframecolor)
xctx.colors[ColFrame][URG_NORM] = settings.normframecolor;
else
xctx.colors[ColFrame][URG_NORM] = settings.frame_color;
if (settings.critframecolor)
xctx.colors[ColFrame][URG_CRIT] = settings.critframecolor;
else
xctx.colors[ColFrame][URG_CRIT] = settings.frame_color;
xctx.screensaver_info = XScreenSaverAllocInfo();
init_screens();

View File

@ -37,7 +37,6 @@ struct dimensions {
struct x_context {
Display *dpy;
const char *colors[3][3];
XScreenSaverInfo *screensaver_info;
};