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-*-*-*-*-*-*-*", .font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*",
.markup = MARKUP_NO, .markup = MARKUP_NO,
.normbgcolor = "#1793D1", .colors_norm.bg = "#1793D1",
.normfgcolor = "#DDDDDD", .colors_norm.fg = "#DDDDDD",
.critbgcolor = "#ffaaaa", .colors_crit.bg = "#ffaaaa",
.critfgcolor = "#000000", .colors_crit.fg = "#000000",
.lowbgcolor = "#aaaaff", .colors_low.bg = "#aaaaff",
.lowfgcolor = "#000000", .colors_low.fg = "#000000",
.format = "%s %b", /* default format */ .format = "%s %b", /* default format */
.timeouts = { S2US(10), S2US(10), S2US(0) }, /* low, normal, critical */ .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); dict_value = g_variant_lookup_value(content, "fgcolor", G_VARIANT_TYPE_STRING);
if (dict_value) { 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); g_variant_unref(dict_value);
} }
dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING); dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING);
if (dict_value) { 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); g_variant_unref(dict_value);
} }
dict_value = g_variant_lookup_value(content, "frcolor", G_VARIANT_TYPE_STRING); dict_value = g_variant_lookup_value(content, "frcolor", G_VARIANT_TYPE_STRING);
if (dict_value) { 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); 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->icon = NULL;
} }
cl->fg = string_to_color(n->colors[ColFG]); cl->fg = string_to_color(n->colors.fg);
cl->bg = string_to_color(n->colors[ColBG]); cl->bg = string_to_color(n->colors.bg);
cl->frame = string_to_color(n->colors[ColFrame]); cl->frame = string_to_color(n->colors.frame);
cl->n = n; cl->n = n;

View File

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

View File

@ -2,7 +2,12 @@
#ifndef DUNST_MARKUP_H #ifndef DUNST_MARKUP_H
#define 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. * Strip any markup from text; turn it in to plain text.

View File

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

View File

@ -5,7 +5,7 @@
#include <glib.h> #include <glib.h>
#include <stdbool.h> #include <stdbool.h>
#include "settings.h" #include "markup.h"
#define DUNST_NOTIF_MAX_CHARS 5000 #define DUNST_NOTIF_MAX_CHARS 5000
@ -44,6 +44,12 @@ struct actions {
typedef struct _notification_private NotificationPrivate; typedef struct _notification_private NotificationPrivate;
struct notification_colors {
char *frame;
char *bg;
char *fg;
};
struct notification { struct notification {
NotificationPrivate *priv; NotificationPrivate *priv;
int id; int id;
@ -68,7 +74,7 @@ struct notification {
enum markup_mode markup; enum markup_mode markup;
const char *format; const char *format;
const char *script; const char *script;
char *colors[3]; struct notification_colors colors;
char *stack_tag; /**< stack notifications by tag */ 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); g_clear_pointer(&n->raw_icon, rawimage_free);
} }
if (r->fg) { if (r->fg) {
g_free(n->colors[ColFG]); g_free(n->colors.fg);
n->colors[ColFG] = g_strdup(r->fg); n->colors.fg = g_strdup(r->fg);
} }
if (r->bg) { if (r->bg) {
g_free(n->colors[ColBG]); g_free(n->colors.bg);
n->colors[ColBG] = g_strdup(r->bg); n->colors.bg = g_strdup(r->bg);
} }
if (r->fc) { if (r->fc) {
g_free(n->colors[ColFrame]); g_free(n->colors.frame);
n->colors[ColFrame] = g_strdup(r->fc); n->colors.frame = g_strdup(r->fc);
} }
if (r->format) if (r->format)
n->format = r->format; n->format = r->format;

View File

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

View File

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

View File

@ -464,27 +464,6 @@ void x_setup(void)
x_shortcut_grab(&settings.context_ks); x_shortcut_grab(&settings.context_ks);
x_shortcut_ungrab(&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(); xctx.screensaver_info = XScreenSaverAllocInfo();
init_screens(); init_screens();

View File

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