commit
6a8f1c52c3
3
config.h
3
config.h
@ -46,8 +46,7 @@ struct settings defaults = {
|
|||||||
.separator_height = 2, /* height of the separator line between two notifications */
|
.separator_height = 2, /* height of the separator line between two notifications */
|
||||||
.padding = 0,
|
.padding = 0,
|
||||||
.h_padding = 0, /* horizontal padding */
|
.h_padding = 0, /* horizontal padding */
|
||||||
.sep_color = SEP_AUTO, /* SEP_AUTO, SEP_FOREGROUND, SEP_FRAME, SEP_CUSTOM */
|
.sep_color = {SEP_AUTO}, /* SEP_AUTO, SEP_FOREGROUND, SEP_FRAME, SEP_CUSTOM */
|
||||||
.sep_custom_color_str = NULL,/* custom color if sep_color is set to CUSTOM */
|
|
||||||
|
|
||||||
.frame_width = 0,
|
.frame_width = 0,
|
||||||
.frame_color = "#888888",
|
.frame_color = "#888888",
|
||||||
|
@ -463,8 +463,8 @@ static bool dbus_get_fdn_daemon_info(GDBusConnection *connection,
|
|||||||
char **name,
|
char **name,
|
||||||
char **vendor)
|
char **vendor)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(pid, false);
|
ASSERT_OR_RET(pid, false);
|
||||||
g_return_val_if_fail(connection, false);
|
ASSERT_OR_RET(connection, false);
|
||||||
|
|
||||||
char *owner = NULL;
|
char *owner = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
@ -93,14 +93,14 @@ static struct color calculate_foreground_color(struct color bg)
|
|||||||
static struct color layout_get_sepcolor(struct colored_layout *cl,
|
static struct color layout_get_sepcolor(struct colored_layout *cl,
|
||||||
struct colored_layout *cl_next)
|
struct colored_layout *cl_next)
|
||||||
{
|
{
|
||||||
switch (settings.sep_color) {
|
switch (settings.sep_color.type) {
|
||||||
case SEP_FRAME:
|
case SEP_FRAME:
|
||||||
if (cl_next->n->urgency > cl->n->urgency)
|
if (cl_next->n->urgency > cl->n->urgency)
|
||||||
return cl_next->frame;
|
return cl_next->frame;
|
||||||
else
|
else
|
||||||
return cl->frame;
|
return cl->frame;
|
||||||
case SEP_CUSTOM:
|
case SEP_CUSTOM:
|
||||||
return string_to_color(settings.sep_custom_color_str);
|
return string_to_color(settings.sep_color.sep_color);
|
||||||
case SEP_FOREGROUND:
|
case SEP_FOREGROUND:
|
||||||
return cl->fg;
|
return cl->fg;
|
||||||
case SEP_AUTO:
|
case SEP_AUTO:
|
||||||
@ -486,7 +486,7 @@ static cairo_surface_t *render_background(cairo_surface_t *srf,
|
|||||||
draw_rounded_rect(c, x, y, width, height, corner_radius, first, last);
|
draw_rounded_rect(c, x, y, width, height, corner_radius, first, last);
|
||||||
cairo_fill(c);
|
cairo_fill(c);
|
||||||
|
|
||||||
if ( settings.sep_color != SEP_FRAME
|
if ( settings.sep_color.type != SEP_FRAME
|
||||||
&& settings.separator_height > 0
|
&& settings.separator_height > 0
|
||||||
&& !last) {
|
&& !last) {
|
||||||
struct color sep_color = layout_get_sepcolor(cl, cl_next);
|
struct color sep_color = layout_get_sepcolor(cl, cl_next);
|
||||||
|
@ -206,8 +206,7 @@ cairo_surface_t *icon_get_for_notification(const struct notification *n)
|
|||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!pixbuf)
|
ASSERT_OR_RET(pixbuf, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
int w = gdk_pixbuf_get_width(pixbuf);
|
int w = gdk_pixbuf_get_width(pixbuf);
|
||||||
int h = gdk_pixbuf_get_height(pixbuf);
|
int h = gdk_pixbuf_get_height(pixbuf);
|
||||||
|
@ -30,8 +30,7 @@ static const char *log_level_to_string(GLogLevelFlags level)
|
|||||||
/* see log.h */
|
/* see log.h */
|
||||||
void log_set_level_from_string(const char *level)
|
void log_set_level_from_string(const char *level)
|
||||||
{
|
{
|
||||||
if (!level)
|
ASSERT_OR_RET(level,);
|
||||||
return;
|
|
||||||
|
|
||||||
if (STR_CASEQ(level, "critical"))
|
if (STR_CASEQ(level, "critical"))
|
||||||
log_level = G_LOG_LEVEL_CRITICAL;
|
log_level = G_LOG_LEVEL_CRITICAL;
|
||||||
|
21
src/markup.c
21
src/markup.c
@ -18,8 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
static char *markup_quote(char *str)
|
static char *markup_quote(char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
ASSERT_OR_RET(str, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
str = string_replace_all("&", "&", str);
|
str = string_replace_all("&", "&", str);
|
||||||
str = string_replace_all("\"", """, str);
|
str = string_replace_all("\"", """, str);
|
||||||
@ -36,8 +35,7 @@ static char *markup_quote(char *str)
|
|||||||
*/
|
*/
|
||||||
static char *markup_unquote(char *str)
|
static char *markup_unquote(char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
ASSERT_OR_RET(str, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
str = string_replace_all(""", "\"", str);
|
str = string_replace_all(""", "\"", str);
|
||||||
str = string_replace_all("'", "'", str);
|
str = string_replace_all("'", "'", str);
|
||||||
@ -54,8 +52,7 @@ static char *markup_unquote(char *str)
|
|||||||
*/
|
*/
|
||||||
static char *markup_br2nl(char *str)
|
static char *markup_br2nl(char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
ASSERT_OR_RET(str, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
str = string_replace_all("<br>", "\n", str);
|
str = string_replace_all("<br>", "\n", str);
|
||||||
str = string_replace_all("<br/>", "\n", str);
|
str = string_replace_all("<br/>", "\n", str);
|
||||||
@ -224,8 +221,7 @@ void markup_strip_img(char **str, char **urls)
|
|||||||
/* see markup.h */
|
/* see markup.h */
|
||||||
char *markup_strip(char *str)
|
char *markup_strip(char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
ASSERT_OR_RET(str, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* strip all tags */
|
/* strip all tags */
|
||||||
string_strip_delimited(str, '<', '>');
|
string_strip_delimited(str, '<', '>');
|
||||||
@ -248,8 +244,7 @@ static bool markup_is_entity(const char *str)
|
|||||||
assert(*str == '&');
|
assert(*str == '&');
|
||||||
|
|
||||||
char *end = strchr(str, ';');
|
char *end = strchr(str, ';');
|
||||||
if (!end)
|
ASSERT_OR_RET(end, false);
|
||||||
return false;
|
|
||||||
|
|
||||||
// Parse (hexa)decimal entities with the format Ӓ or ઼
|
// Parse (hexa)decimal entities with the format Ӓ or ઼
|
||||||
if (str[1] == '#') {
|
if (str[1] == '#') {
|
||||||
@ -293,8 +288,7 @@ static bool markup_is_entity(const char *str)
|
|||||||
*/
|
*/
|
||||||
static char *markup_escape_unsupported(char *str)
|
static char *markup_escape_unsupported(char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
ASSERT_OR_RET(str, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
char *match = str;
|
char *match = str;
|
||||||
while ((match = strchr(match, '&'))) {
|
while ((match = strchr(match, '&'))) {
|
||||||
@ -313,8 +307,7 @@ static char *markup_escape_unsupported(char *str)
|
|||||||
/* see markup.h */
|
/* see markup.h */
|
||||||
char *markup_transform(char *str, enum markup_mode markup_mode)
|
char *markup_transform(char *str, enum markup_mode markup_mode)
|
||||||
{
|
{
|
||||||
if (!str)
|
ASSERT_OR_RET(str, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
switch (markup_mode) {
|
switch (markup_mode) {
|
||||||
case MARKUP_NULL:
|
case MARKUP_NULL:
|
||||||
|
@ -222,8 +222,7 @@ void invoke_action(const char *action)
|
|||||||
*/
|
*/
|
||||||
void dispatch_menu_result(const char *input)
|
void dispatch_menu_result(const char *input)
|
||||||
{
|
{
|
||||||
if (!input)
|
ASSERT_OR_RET(input,);
|
||||||
return;
|
|
||||||
|
|
||||||
char *in = g_strdup(input);
|
char *in = g_strdup(input);
|
||||||
g_strstrip(in);
|
g_strstrip(in);
|
||||||
@ -248,8 +247,7 @@ char *invoke_dmenu(const char *dmenu_input)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dmenu_input || *dmenu_input == '\0')
|
ASSERT_OR_RET(STR_FULL(dmenu_input), NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
gint dunst_to_dmenu;
|
gint dunst_to_dmenu;
|
||||||
gint dmenu_to_dunst;
|
gint dmenu_to_dunst;
|
||||||
|
@ -168,8 +168,7 @@ int notification_cmp_data(const void *va, const void *vb, void *data)
|
|||||||
struct notification *a = (struct notification *) va;
|
struct notification *a = (struct notification *) va;
|
||||||
struct notification *b = (struct notification *) vb;
|
struct notification *b = (struct notification *) vb;
|
||||||
|
|
||||||
if (!settings.sort)
|
ASSERT_OR_RET(settings.sort, 1);
|
||||||
return 1;
|
|
||||||
|
|
||||||
return notification_cmp(a, b);
|
return notification_cmp(a, b);
|
||||||
}
|
}
|
||||||
@ -191,8 +190,7 @@ int notification_is_duplicate(const struct notification *a, const struct notific
|
|||||||
/* see notification.h */
|
/* see notification.h */
|
||||||
void rawimage_free(struct raw_image *i)
|
void rawimage_free(struct raw_image *i)
|
||||||
{
|
{
|
||||||
if (!i)
|
ASSERT_OR_RET(i,);
|
||||||
return;
|
|
||||||
|
|
||||||
g_free(i->data);
|
g_free(i->data);
|
||||||
g_free(i);
|
g_free(i);
|
||||||
@ -220,8 +218,7 @@ void notification_ref(struct notification *n)
|
|||||||
/* see notification.h */
|
/* see notification.h */
|
||||||
void notification_unref(struct notification *n)
|
void notification_unref(struct notification *n)
|
||||||
{
|
{
|
||||||
if (!n)
|
ASSERT_OR_RET(n,);
|
||||||
return;
|
|
||||||
|
|
||||||
assert(n->priv->refcount > 0);
|
assert(n->priv->refcount > 0);
|
||||||
if (!g_atomic_int_dec_and_test(&n->priv->refcount))
|
if (!g_atomic_int_dec_and_test(&n->priv->refcount))
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "dunst.h"
|
#include "dunst.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
struct entry {
|
struct entry {
|
||||||
char *key;
|
char *key;
|
||||||
@ -39,6 +40,122 @@ static void cmdline_usage_append(const char *key, const char *type, const char *
|
|||||||
|
|
||||||
static int cmdline_find_option(const char *key);
|
static int cmdline_find_option(const char *key);
|
||||||
|
|
||||||
|
#define STRING_PARSE_RET(string, value) if (STR_EQ(s, string)) { *ret = value; return true; }
|
||||||
|
|
||||||
|
bool string_parse_alignment(const char *s, enum alignment *ret)
|
||||||
|
{
|
||||||
|
ASSERT_OR_RET(s, false);
|
||||||
|
ASSERT_OR_RET(ret, false);
|
||||||
|
|
||||||
|
STRING_PARSE_RET("left", ALIGN_LEFT);
|
||||||
|
STRING_PARSE_RET("center", ALIGN_CENTER);
|
||||||
|
STRING_PARSE_RET("right", ALIGN_RIGHT);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string_parse_ellipsize(const char *s, enum ellipsize *ret)
|
||||||
|
{
|
||||||
|
ASSERT_OR_RET(s, false);
|
||||||
|
ASSERT_OR_RET(ret, false);
|
||||||
|
|
||||||
|
STRING_PARSE_RET("start", ELLIPSE_START);
|
||||||
|
STRING_PARSE_RET("middle", ELLIPSE_MIDDLE);
|
||||||
|
STRING_PARSE_RET("end", ELLIPSE_END);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string_parse_follow_mode(const char *s, enum follow_mode *ret)
|
||||||
|
{
|
||||||
|
ASSERT_OR_RET(s, false);
|
||||||
|
ASSERT_OR_RET(ret, false);
|
||||||
|
|
||||||
|
STRING_PARSE_RET("mouse", FOLLOW_MOUSE);
|
||||||
|
STRING_PARSE_RET("keyboard", FOLLOW_KEYBOARD);
|
||||||
|
STRING_PARSE_RET("none", FOLLOW_NONE);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool string_parse_fullscreen(const char *s, enum behavior_fullscreen *ret)
|
||||||
|
{
|
||||||
|
ASSERT_OR_RET(s, false);
|
||||||
|
ASSERT_OR_RET(ret, false);
|
||||||
|
|
||||||
|
STRING_PARSE_RET("show", FS_SHOW);
|
||||||
|
STRING_PARSE_RET("delay", FS_DELAY);
|
||||||
|
STRING_PARSE_RET("pushback", FS_PUSHBACK);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string_parse_icon_position(const char *s, enum icon_position *ret)
|
||||||
|
{
|
||||||
|
ASSERT_OR_RET(s, false);
|
||||||
|
ASSERT_OR_RET(ret, false);
|
||||||
|
|
||||||
|
STRING_PARSE_RET("left", ICON_LEFT);
|
||||||
|
STRING_PARSE_RET("right", ICON_RIGHT);
|
||||||
|
STRING_PARSE_RET("off", ICON_OFF);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string_parse_markup_mode(const char *s, enum markup_mode *ret)
|
||||||
|
{
|
||||||
|
ASSERT_OR_RET(s, false);
|
||||||
|
ASSERT_OR_RET(ret, false);
|
||||||
|
|
||||||
|
STRING_PARSE_RET("strip", MARKUP_STRIP);
|
||||||
|
STRING_PARSE_RET("no", MARKUP_NO);
|
||||||
|
STRING_PARSE_RET("full", MARKUP_FULL);
|
||||||
|
STRING_PARSE_RET("yes", MARKUP_FULL);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string_parse_mouse_action(const char *s, enum mouse_action *ret)
|
||||||
|
{
|
||||||
|
ASSERT_OR_RET(s, false);
|
||||||
|
ASSERT_OR_RET(ret, false);
|
||||||
|
|
||||||
|
STRING_PARSE_RET("none", MOUSE_NONE);
|
||||||
|
STRING_PARSE_RET("do_action", MOUSE_DO_ACTION);
|
||||||
|
STRING_PARSE_RET("close_current", MOUSE_CLOSE_CURRENT);
|
||||||
|
STRING_PARSE_RET("close_all", MOUSE_CLOSE_ALL);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string_parse_sepcolor(const char *s, struct separator_color_data *ret)
|
||||||
|
{
|
||||||
|
ASSERT_OR_RET(s, false);
|
||||||
|
ASSERT_OR_RET(ret, false);
|
||||||
|
|
||||||
|
STRING_PARSE_RET("auto", (struct separator_color_data){.type = SEP_AUTO});
|
||||||
|
STRING_PARSE_RET("foreground", (struct separator_color_data){.type = SEP_FOREGROUND});
|
||||||
|
STRING_PARSE_RET("frame", (struct separator_color_data){.type = SEP_FRAME});
|
||||||
|
|
||||||
|
ret->type = SEP_CUSTOM;
|
||||||
|
ret->sep_color = g_strdup(s);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string_parse_urgency(const char *s, enum urgency *ret)
|
||||||
|
{
|
||||||
|
ASSERT_OR_RET(s, false);
|
||||||
|
ASSERT_OR_RET(ret, false);
|
||||||
|
|
||||||
|
STRING_PARSE_RET("low", URG_LOW);
|
||||||
|
STRING_PARSE_RET("normal", URG_NORM);
|
||||||
|
STRING_PARSE_RET("critical", URG_CRIT);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
struct section *new_section(const char *name)
|
struct section *new_section(const char *name)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < section_count; i++) {
|
for (int i = 0; i < section_count; i++) {
|
||||||
@ -95,9 +212,7 @@ void add_entry(const char *section_name, const char *key, const char *value)
|
|||||||
const char *get_value(const char *section, const char *key)
|
const char *get_value(const char *section, const char *key)
|
||||||
{
|
{
|
||||||
struct section *s = get_section(section);
|
struct section *s = get_section(section);
|
||||||
if (!s) {
|
ASSERT_OR_RET(s, NULL);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < s->entry_count; i++) {
|
for (int i = 0; i < s->entry_count; i++) {
|
||||||
if (STR_EQ(s->entries[i].key, key)) {
|
if (STR_EQ(s->entries[i].key, key)) {
|
||||||
@ -158,11 +273,8 @@ bool ini_is_set(const char *ini_section, const char *ini_key)
|
|||||||
|
|
||||||
const char *next_section(const char *section)
|
const char *next_section(const char *section)
|
||||||
{
|
{
|
||||||
if (section_count == 0)
|
ASSERT_OR_RET(section_count > 0, NULL);
|
||||||
return NULL;
|
ASSERT_OR_RET(section, sections[0].name);
|
||||||
|
|
||||||
if (!section)
|
|
||||||
return sections[0].name;
|
|
||||||
|
|
||||||
for (int i = 0; i < section_count; i++) {
|
for (int i = 0; i < section_count; i++) {
|
||||||
if (STR_EQ(section, sections[i].name)) {
|
if (STR_EQ(section, sections[i].name)) {
|
||||||
@ -202,8 +314,7 @@ int ini_get_bool(const char *section, const char *key, int def)
|
|||||||
|
|
||||||
int load_ini_file(FILE *fp)
|
int load_ini_file(FILE *fp)
|
||||||
{
|
{
|
||||||
if (!fp)
|
ASSERT_OR_RET(fp, 1);
|
||||||
return 1;
|
|
||||||
|
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t line_len = 0;
|
size_t line_len = 0;
|
||||||
@ -277,9 +388,8 @@ void cmdline_load(int argc, char *argv[])
|
|||||||
|
|
||||||
int cmdline_find_option(const char *key)
|
int cmdline_find_option(const char *key)
|
||||||
{
|
{
|
||||||
if (!key) {
|
ASSERT_OR_RET(key, -1);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
char *key1 = g_strdup(key);
|
char *key1 = g_strdup(key);
|
||||||
char *key2 = strchr(key1, '/');
|
char *key2 = strchr(key1, '/');
|
||||||
|
|
||||||
@ -532,22 +642,4 @@ const char *cmdline_create_usage(void)
|
|||||||
return usage_str;
|
return usage_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see option_parser.h */
|
|
||||||
enum behavior_fullscreen parse_enum_fullscreen(const char *string, enum behavior_fullscreen def)
|
|
||||||
{
|
|
||||||
if (!string)
|
|
||||||
return def;
|
|
||||||
|
|
||||||
if (STR_EQ(string, "show"))
|
|
||||||
return FS_SHOW;
|
|
||||||
else if (STR_EQ(string, "delay"))
|
|
||||||
return FS_DELAY;
|
|
||||||
else if (STR_EQ(string, "pushback"))
|
|
||||||
return FS_PUSHBACK;
|
|
||||||
else {
|
|
||||||
LOG_W("Unknown fullscreen value: '%s'\n", string);
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
||||||
|
@ -7,6 +7,17 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "dunst.h"
|
#include "dunst.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
bool string_parse_alignment(const char *s, enum alignment *ret);
|
||||||
|
bool string_parse_ellipsize(const char *s, enum ellipsize *ret);
|
||||||
|
bool string_parse_follow_mode(const char *s, enum follow_mode *ret);
|
||||||
|
bool string_parse_fullscreen(const char *s, enum behavior_fullscreen *ret);
|
||||||
|
bool string_parse_icon_position(const char *s, enum icon_position *ret);
|
||||||
|
bool string_parse_markup_mode(const char *s, enum markup_mode *ret);
|
||||||
|
bool string_parse_mouse_action(const char *s, enum mouse_action *ret);
|
||||||
|
bool string_parse_sepcolor(const char *s, struct separator_color_data *ret);
|
||||||
|
bool string_parse_urgency(const char *s, enum urgency *ret);
|
||||||
|
|
||||||
int load_ini_file(FILE *);
|
int load_ini_file(FILE *);
|
||||||
char *ini_get_path(const char *section, const char *key, const char *def);
|
char *ini_get_path(const char *section, const char *key, const char *def);
|
||||||
@ -65,17 +76,5 @@ int option_get_bool(const char *ini_section,
|
|||||||
*/
|
*/
|
||||||
const char *next_section(const char *section);
|
const char *next_section(const char *section);
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the fullscreen behavior value of the given string
|
|
||||||
*
|
|
||||||
* @param string the string representation of #behavior_fullscreen.
|
|
||||||
* The string must not contain any waste characters.
|
|
||||||
* @param def value to return in case of errors
|
|
||||||
*
|
|
||||||
* @return the #behavior_fullscreen representation of `string`
|
|
||||||
* @return `def` if `string` is invalid or `NULL`
|
|
||||||
*/
|
|
||||||
enum behavior_fullscreen parse_enum_fullscreen(const char *string, enum behavior_fullscreen def);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
||||||
|
@ -113,8 +113,7 @@ static void queues_swap_notifications(GQueue *queueA,
|
|||||||
*/
|
*/
|
||||||
static bool queues_notification_is_ready(const struct notification *n, struct dunst_status status, bool shown)
|
static bool queues_notification_is_ready(const struct notification *n, struct dunst_status status, bool shown)
|
||||||
{
|
{
|
||||||
if (!status.running)
|
ASSERT_OR_RET(status.running, false);
|
||||||
return false;
|
|
||||||
if (status.fullscreen && shown)
|
if (status.fullscreen && shown)
|
||||||
return n && n->fullscreen != FS_PUSHBACK;
|
return n && n->fullscreen != FS_PUSHBACK;
|
||||||
else if (status.fullscreen && !shown)
|
else if (status.fullscreen && !shown)
|
||||||
@ -418,8 +417,7 @@ void queues_update(struct dunst_status status)
|
|||||||
struct notification *n = iter->data;
|
struct notification *n = iter->data;
|
||||||
nextiter = iter->next;
|
nextiter = iter->next;
|
||||||
|
|
||||||
if (!n)
|
ASSERT_OR_RET(n,);
|
||||||
return;
|
|
||||||
|
|
||||||
if (!queues_notification_is_ready(n, status, false)) {
|
if (!queues_notification_is_ready(n, status, false)) {
|
||||||
iter = nextiter;
|
iter = nextiter;
|
||||||
|
185
src/settings.c
185
src/settings.c
@ -18,80 +18,18 @@
|
|||||||
|
|
||||||
struct settings settings;
|
struct settings settings;
|
||||||
|
|
||||||
static const char *follow_mode_to_string(enum follow_mode f_mode)
|
static enum urgency ini_get_urgency(const char *section, const char *key, const enum urgency def)
|
||||||
{
|
{
|
||||||
switch(f_mode) {
|
enum urgency ret;
|
||||||
case FOLLOW_NONE: return "none";
|
char *c = ini_get_string(section, key, NULL);
|
||||||
case FOLLOW_MOUSE: return "mouse";
|
|
||||||
case FOLLOW_KEYBOARD: return "keyboard";
|
if (!string_parse_urgency(c, &ret)) {
|
||||||
default: return "";
|
if (c)
|
||||||
}
|
LOG_W("Unknown urgency: '%s'", c);
|
||||||
|
ret = def;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum follow_mode parse_follow_mode(const char *mode)
|
g_free(c);
|
||||||
{
|
|
||||||
if (!mode)
|
|
||||||
return FOLLOW_NONE;
|
|
||||||
|
|
||||||
if (STR_EQ(mode, "mouse"))
|
|
||||||
return FOLLOW_MOUSE;
|
|
||||||
else if (STR_EQ(mode, "keyboard"))
|
|
||||||
return FOLLOW_KEYBOARD;
|
|
||||||
else if (STR_EQ(mode, "none"))
|
|
||||||
return FOLLOW_NONE;
|
|
||||||
else {
|
|
||||||
LOG_W("Unknown follow mode: '%s'", mode);
|
|
||||||
return FOLLOW_NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum markup_mode parse_markup_mode(const char *mode)
|
|
||||||
{
|
|
||||||
if (STR_EQ(mode, "strip")) {
|
|
||||||
return MARKUP_STRIP;
|
|
||||||
} else if (STR_EQ(mode, "no")) {
|
|
||||||
return MARKUP_NO;
|
|
||||||
} else if (STR_EQ(mode, "full") || STR_EQ(mode, "yes")) {
|
|
||||||
return MARKUP_FULL;
|
|
||||||
} else {
|
|
||||||
LOG_W("Unknown markup mode: '%s'", mode);
|
|
||||||
return MARKUP_NO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum mouse_action parse_mouse_action(const char *action)
|
|
||||||
{
|
|
||||||
if (STR_EQ(action, "none"))
|
|
||||||
return MOUSE_NONE;
|
|
||||||
else if (STR_EQ(action, "do_action"))
|
|
||||||
return MOUSE_DO_ACTION;
|
|
||||||
else if (STR_EQ(action, "close_current"))
|
|
||||||
return MOUSE_CLOSE_CURRENT;
|
|
||||||
else if (STR_EQ(action, "close_all"))
|
|
||||||
return MOUSE_CLOSE_ALL;
|
|
||||||
else {
|
|
||||||
LOG_W("Unknown mouse action: '%s'", action);
|
|
||||||
return MOUSE_NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static enum urgency ini_get_urgency(const char *section, const char *key, const int def)
|
|
||||||
{
|
|
||||||
int ret = def;
|
|
||||||
char *urg = ini_get_string(section, key, "");
|
|
||||||
|
|
||||||
if (STR_FULL(urg)) {
|
|
||||||
if (STR_EQ(urg, "low"))
|
|
||||||
ret = URG_LOW;
|
|
||||||
else if (STR_EQ(urg, "normal"))
|
|
||||||
ret = URG_NORM;
|
|
||||||
else if (STR_EQ(urg, "critical"))
|
|
||||||
ret = URG_CRIT;
|
|
||||||
else
|
|
||||||
LOG_W("Unknown urgency: '%s'", urg);
|
|
||||||
}
|
|
||||||
g_free(urg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,12 +144,10 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"Specify how markup should be handled"
|
"Specify how markup should be handled"
|
||||||
);
|
);
|
||||||
|
|
||||||
//Use markup if set
|
if (!string_parse_markup_mode(c, &settings.markup)) {
|
||||||
//Use default if settings.markup not set yet
|
if (c)
|
||||||
// (=>c empty&&!allow_markup)
|
LOG_W("Cannot parse markup mode value: '%s'", c);
|
||||||
if (c) {
|
if (!settings.markup)
|
||||||
settings.markup = parse_markup_mode(c);
|
|
||||||
} else if (!settings.markup) {
|
|
||||||
settings.markup = defaults.markup;
|
settings.markup = defaults.markup;
|
||||||
}
|
}
|
||||||
g_free(c);
|
g_free(c);
|
||||||
@ -244,19 +180,12 @@ void load_settings(char *cmdline_config_path)
|
|||||||
{
|
{
|
||||||
char *c = option_get_string(
|
char *c = option_get_string(
|
||||||
"global",
|
"global",
|
||||||
"ellipsize", "-ellipsize", "",
|
"ellipsize", "-ellipsize", NULL,
|
||||||
"Ellipsize truncated lines on the start/middle/end"
|
"Ellipsize truncated lines on the start/middle/end"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (STR_EMPTY(c)) {
|
if (!string_parse_ellipsize(c, &settings.ellipsize)) {
|
||||||
settings.ellipsize = defaults.ellipsize;
|
if (c)
|
||||||
} else if (STR_EQ(c, "start")) {
|
|
||||||
settings.ellipsize = ELLIPSE_START;
|
|
||||||
} else if (STR_EQ(c, "middle")) {
|
|
||||||
settings.ellipsize = ELLIPSE_MIDDLE;
|
|
||||||
} else if (STR_EQ(c, "end")) {
|
|
||||||
settings.ellipsize = ELLIPSE_END;
|
|
||||||
} else {
|
|
||||||
LOG_W("Unknown ellipsize value: '%s'", c);
|
LOG_W("Unknown ellipsize value: '%s'", c);
|
||||||
settings.ellipsize = defaults.ellipsize;
|
settings.ellipsize = defaults.ellipsize;
|
||||||
}
|
}
|
||||||
@ -284,11 +213,15 @@ void load_settings(char *cmdline_config_path)
|
|||||||
{
|
{
|
||||||
char *c = option_get_string(
|
char *c = option_get_string(
|
||||||
"global",
|
"global",
|
||||||
"follow", "-follow", follow_mode_to_string(defaults.f_mode),
|
"follow", "-follow", NULL,
|
||||||
"Follow mouse, keyboard or none?"
|
"Follow mouse, keyboard or none?"
|
||||||
);
|
);
|
||||||
|
|
||||||
settings.f_mode = parse_follow_mode(c);
|
if (!string_parse_follow_mode(c, &settings.f_mode)) {
|
||||||
|
if (c)
|
||||||
|
LOG_W("Cannot parse follow mode: %s", c);
|
||||||
|
settings.f_mode = defaults.f_mode;
|
||||||
|
}
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,17 +280,14 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"alignment", "-align/-alignment", "",
|
"alignment", "-align/-alignment", "",
|
||||||
"Text alignment left/center/right"
|
"Text alignment left/center/right"
|
||||||
);
|
);
|
||||||
if (STR_FULL(c)) {
|
|
||||||
if (STR_EQ(c, "left"))
|
if (!string_parse_alignment(c, &settings.align)) {
|
||||||
settings.align = ALIGN_LEFT;
|
if (c)
|
||||||
else if (STR_EQ(c, "center"))
|
|
||||||
settings.align = ALIGN_CENTER;
|
|
||||||
else if (STR_EQ(c, "right"))
|
|
||||||
settings.align = ALIGN_RIGHT;
|
|
||||||
else
|
|
||||||
LOG_W("Unknown alignment value: '%s'", c);
|
LOG_W("Unknown alignment value: '%s'", c);
|
||||||
g_free(c);
|
settings.align = defaults.align;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.show_age_threshold = option_get_time(
|
settings.show_age_threshold = option_get_time(
|
||||||
@ -427,17 +357,8 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"Color of the separator line (or 'auto')"
|
"Color of the separator line (or 'auto')"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (STR_FULL(c)) {
|
if (!string_parse_sepcolor(c, &settings.sep_color)) {
|
||||||
if (STR_EQ(c, "auto"))
|
settings.sep_color = defaults.sep_color;
|
||||||
settings.sep_color = SEP_AUTO;
|
|
||||||
else if (STR_EQ(c, "foreground"))
|
|
||||||
settings.sep_color = SEP_FOREGROUND;
|
|
||||||
else if (STR_EQ(c, "frame"))
|
|
||||||
settings.sep_color = SEP_FRAME;
|
|
||||||
else {
|
|
||||||
settings.sep_color = SEP_CUSTOM;
|
|
||||||
settings.sep_custom_color_str = g_strdup(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
@ -494,17 +415,12 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"Align icons left/right/off"
|
"Align icons left/right/off"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (STR_FULL(c)) {
|
if (!string_parse_icon_position(c, &settings.icon_position)) {
|
||||||
if (STR_EQ(c, "left"))
|
if (c)
|
||||||
settings.icon_position = ICON_LEFT;
|
|
||||||
else if (STR_EQ(c, "right"))
|
|
||||||
settings.icon_position = ICON_RIGHT;
|
|
||||||
else if (STR_EQ(c, "off"))
|
|
||||||
settings.icon_position = ICON_OFF;
|
|
||||||
else
|
|
||||||
LOG_W("Unknown icon position: '%s'", c);
|
LOG_W("Unknown icon position: '%s'", c);
|
||||||
g_free(c);
|
settings.icon_position = defaults.icon_position;
|
||||||
}
|
}
|
||||||
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.max_icon_size = option_get_int(
|
settings.max_icon_size = option_get_int(
|
||||||
@ -580,12 +496,11 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"Action of Left click event"
|
"Action of Left click event"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (c) {
|
if (!string_parse_mouse_action(c, &settings.mouse_left_click)) {
|
||||||
settings.mouse_left_click = parse_mouse_action(c);
|
if (c)
|
||||||
} else {
|
LOG_W("Unknown mouse action value: '%s'", c);
|
||||||
settings.mouse_left_click = defaults.mouse_left_click;
|
settings.mouse_left_click = defaults.mouse_left_click;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,12 +511,11 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"Action of middle click event"
|
"Action of middle click event"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (c) {
|
if (!string_parse_mouse_action(c, &settings.mouse_middle_click)) {
|
||||||
settings.mouse_middle_click = parse_mouse_action(c);
|
if (c)
|
||||||
} else {
|
LOG_W("Unknown mouse action value: '%s'", c);
|
||||||
settings.mouse_middle_click = defaults.mouse_middle_click;
|
settings.mouse_middle_click = defaults.mouse_middle_click;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,12 +526,11 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"Action of right click event"
|
"Action of right click event"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (c) {
|
if (!string_parse_mouse_action(c, &settings.mouse_right_click)) {
|
||||||
settings.mouse_right_click = parse_mouse_action(c);
|
if (c)
|
||||||
} else {
|
LOG_W("Unknown mouse action value: '%s'", c);
|
||||||
settings.mouse_right_click = defaults.mouse_right_click;
|
settings.mouse_right_click = defaults.mouse_right_click;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -795,10 +708,11 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"markup", NULL
|
"markup", NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
if (c) {
|
if (!string_parse_markup_mode(c, &r->markup)) {
|
||||||
r->markup = parse_markup_mode(c);
|
if (c)
|
||||||
g_free(c);
|
LOG_W("Invalid markup mode value: %s", c);
|
||||||
}
|
}
|
||||||
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
r->urgency = ini_get_urgency(cur_section, "urgency", r->urgency);
|
r->urgency = ini_get_urgency(cur_section, "urgency", r->urgency);
|
||||||
@ -817,7 +731,10 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"fullscreen", NULL
|
"fullscreen", NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
r->fullscreen = parse_enum_fullscreen(c, r->fullscreen);
|
if (!string_parse_fullscreen(c, &r->fullscreen)) {
|
||||||
|
if (c)
|
||||||
|
LOG_W("Invalid fullscreen value: %s", c);
|
||||||
|
}
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
r->script = ini_get_path(cur_section, "script", NULL);
|
r->script = ini_get_path(cur_section, "script", NULL);
|
||||||
|
@ -15,6 +15,11 @@ 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 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 separator_color_data {
|
||||||
|
enum separator_color type;
|
||||||
|
char *sep_color;
|
||||||
|
};
|
||||||
|
|
||||||
struct geometry {
|
struct geometry {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
@ -24,7 +29,6 @@ struct geometry {
|
|||||||
bool negative_y;
|
bool negative_y;
|
||||||
bool negative_width;
|
bool negative_width;
|
||||||
bool width_set;
|
bool width_set;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct settings {
|
struct settings {
|
||||||
@ -61,8 +65,7 @@ struct settings {
|
|||||||
int separator_height;
|
int separator_height;
|
||||||
int padding;
|
int padding;
|
||||||
int h_padding;
|
int h_padding;
|
||||||
enum separator_color sep_color;
|
struct separator_color_data sep_color;
|
||||||
char *sep_custom_color_str;
|
|
||||||
int frame_width;
|
int frame_width;
|
||||||
char *frame_color;
|
char *frame_color;
|
||||||
int startup_notification;
|
int startup_notification;
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
/* see utils.h */
|
/* see utils.h */
|
||||||
char *string_replace_char(char needle, char replacement, char *haystack)
|
char *string_replace_char(char needle, char replacement, char *haystack)
|
||||||
{
|
{
|
||||||
if (!haystack)
|
ASSERT_OR_RET(haystack, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
char *current = haystack;
|
char *current = haystack;
|
||||||
while ((current = strchr(current, needle)))
|
while ((current = strchr(current, needle)))
|
||||||
@ -56,8 +55,7 @@ char *string_replace_at(char *buf, int pos, int len, const char *repl)
|
|||||||
/* see utils.h */
|
/* see utils.h */
|
||||||
char *string_replace_all(const char *needle, const char *replacement, char *haystack)
|
char *string_replace_all(const char *needle, const char *replacement, char *haystack)
|
||||||
{
|
{
|
||||||
if (!haystack)
|
ASSERT_OR_RET(haystack, NULL);
|
||||||
return NULL;
|
|
||||||
assert(needle);
|
assert(needle);
|
||||||
assert(replacement);
|
assert(replacement);
|
||||||
|
|
||||||
@ -104,8 +102,7 @@ char *string_append(char *a, const char *b, const char *sep)
|
|||||||
/* see utils.h */
|
/* see utils.h */
|
||||||
char *string_strip_quotes(const char *value)
|
char *string_strip_quotes(const char *value)
|
||||||
{
|
{
|
||||||
if (!value)
|
ASSERT_OR_RET(value, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
size_t len = strlen(value);
|
size_t len = strlen(value);
|
||||||
char *s;
|
char *s;
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
//! Test if string a and b are the same case-insensitively
|
//! Test if string a and b are the same case-insensitively
|
||||||
#define STR_CASEQ(a, b) (strcasecmp(a, b) == 0)
|
#define STR_CASEQ(a, b) (strcasecmp(a, b) == 0)
|
||||||
|
|
||||||
|
//! Assert that expr evaluates to true, if not return with val
|
||||||
|
#define ASSERT_OR_RET(expr, val) if (!(expr)) return val;
|
||||||
|
|
||||||
//! Convert a second into the internal time representation
|
//! Convert a second into the internal time representation
|
||||||
#define S2US(s) (((gint64)(s)) * 1000 * 1000)
|
#define S2US(s) (((gint64)(s)) * 1000 * 1000)
|
||||||
|
|
||||||
|
@ -221,8 +221,7 @@ bool window_is_fullscreen(Window window)
|
|||||||
{
|
{
|
||||||
bool fs = false;
|
bool fs = false;
|
||||||
|
|
||||||
if (!window)
|
ASSERT_OR_RET(window, false);
|
||||||
return false;
|
|
||||||
|
|
||||||
Atom has_wm_state = XInternAtom(xctx.dpy, "_NET_WM_STATE", True);
|
Atom has_wm_state = XInternAtom(xctx.dpy, "_NET_WM_STATE", True);
|
||||||
if (has_wm_state == None){
|
if (has_wm_state == None){
|
||||||
|
@ -674,8 +674,7 @@ void x_win_show(struct window_x11 *win)
|
|||||||
*/
|
*/
|
||||||
void x_win_hide(struct window_x11 *win)
|
void x_win_hide(struct window_x11 *win)
|
||||||
{
|
{
|
||||||
if (!win->visible)
|
ASSERT_OR_RET(win->visible,);
|
||||||
return;
|
|
||||||
|
|
||||||
x_shortcut_ungrab(&settings.close_ks);
|
x_shortcut_ungrab(&settings.close_ks);
|
||||||
x_shortcut_ungrab(&settings.close_all_ks);
|
x_shortcut_ungrab(&settings.close_all_ks);
|
||||||
@ -755,8 +754,7 @@ static int x_shortcut_tear_down_error_handler(void)
|
|||||||
*/
|
*/
|
||||||
static int x_shortcut_grab(struct keyboard_shortcut *ks)
|
static int x_shortcut_grab(struct keyboard_shortcut *ks)
|
||||||
{
|
{
|
||||||
if (!ks->is_valid)
|
ASSERT_OR_RET(ks->is_valid, 1);
|
||||||
return 1;
|
|
||||||
Window root;
|
Window root;
|
||||||
root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy));
|
root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy));
|
||||||
|
|
||||||
@ -805,8 +803,7 @@ static void x_shortcut_ungrab(struct keyboard_shortcut *ks)
|
|||||||
*/
|
*/
|
||||||
static void x_shortcut_init(struct keyboard_shortcut *ks)
|
static void x_shortcut_init(struct keyboard_shortcut *ks)
|
||||||
{
|
{
|
||||||
if (!ks|| !ks->str)
|
ASSERT_OR_RET(ks && ks->str,);
|
||||||
return;
|
|
||||||
|
|
||||||
if (STR_EQ(ks->str, "none") || (STR_EQ(ks->str, ""))) {
|
if (STR_EQ(ks->str, "none") || (STR_EQ(ks->str, ""))) {
|
||||||
ks->is_valid = false;
|
ks->is_valid = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user