adding changes according to review

- adding default to config.h#defaults
- changing naming from content_* to vertical_*
- replacing switch-case with if-else-if
This commit is contained in:
chronus 2020-01-29 23:02:00 +01:00
parent e665eea97e
commit 4c09883ef6
8 changed files with 34 additions and 47 deletions

View File

@ -33,6 +33,7 @@ struct settings defaults = {
.idle_threshold = 0, /* don't timeout notifications when idle for x seconds */ .idle_threshold = 0, /* don't timeout notifications when idle for x seconds */
.show_age_threshold = -1, /* show age of notification, when notification is older than x seconds */ .show_age_threshold = -1, /* show age of notification, when notification is older than x seconds */
.align = ALIGN_LEFT, /* text alignment ALIGN_[LEFT|CENTER|RIGHT] */ .align = ALIGN_LEFT, /* text alignment ALIGN_[LEFT|CENTER|RIGHT] */
.vertical_alignment = VERTICAL_CENTER, /* vertical content alignment VERTICAL_[TOP|CENTER|BOTTOM] */
.sticky_history = true, .sticky_history = true,
.history_length = 20, /* max amount of notifications kept in history */ .history_length = 20, /* max amount of notifications kept in history */
.show_indicators = true, .show_indicators = true,

View File

@ -337,7 +337,7 @@ removed from the format.
Defines how the text should be aligned within the notification. Defines how the text should be aligned within the notification.
=item B<content_alignment> (values: [top/center/bottom], default: center) =item B<vertical_alignment> (values: [top/center/bottom], default: center)
Defines how the text and icon should be aligned vertically within the Defines how the text and icon should be aligned vertically within the
notification. If icons are disabled, this option has no effect. notification. If icons are disabled, this option has no effect.

View File

@ -134,7 +134,7 @@
# Vertical alignment of message text and icon. # Vertical alignment of message text and icon.
# Possible values are "top", "center" and "bottom". # Possible values are "top", "center" and "bottom".
content_alignment = center vertical_alignment = center
# Show age of message if message is older than show_age_threshold # Show age of message if message is older than show_age_threshold
# seconds. # seconds.

View File

@ -517,25 +517,18 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width)
// text positioning // text positioning
if (cl->icon) { if (cl->icon) {
// vertical alignment // vertical alignment
switch (settings.content_alignment) { if (settings.vertical_alignment == VERTICAL_TOP) {
case CONTENT_TOP:
text_y = settings.padding; text_y = settings.padding;
break; } else if (settings.vertical_alignment == VERTICAL_BOTTOM) {
case CONTENT_BOTTOM:
text_y = h + settings.padding - h_text; text_y = h + settings.padding - h_text;
if (text_y < 0) text_y = settings.padding; if (text_y < 0)
break; text_y = settings.padding;
default: // CONTENT_CENTER } // else VERTICAL_CENTER
break;
}
// icon position // icon position
switch (settings.icon_position) { if (settings.icon_position == ICON_LEFT) {
case ICON_LEFT:
text_x = cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding; text_x = cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding;
break; } // else ICON_RIGHT
default: // ICON_RIGHT
break;
}
} }
cairo_move_to(c, text_x, text_y); cairo_move_to(c, text_x, text_y);
@ -552,25 +545,18 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width)
image_y = settings.padding + h/2 - image_height/2; image_y = settings.padding + h/2 - image_height/2;
// vertical alignment // vertical alignment
switch (settings.content_alignment) { if (settings.vertical_alignment == VERTICAL_TOP) {
case CONTENT_TOP:
image_y = settings.padding; image_y = settings.padding;
break; } else if (settings.vertical_alignment == VERTICAL_BOTTOM) {
case CONTENT_BOTTOM:
image_y = h + settings.padding - image_height; image_y = h + settings.padding - image_height;
if (image_y < settings.padding || image_y > h) image_y = settings.padding; if (image_y < settings.padding || image_y > h)
break; image_y = settings.padding;
default: // CONTENT_CENTER } // else VERTICAL_CENTER
break;
}
// icon position // icon position
switch (settings.icon_position) { if (settings.icon_position == ICON_LEFT) {
case ICON_LEFT:
image_x = settings.h_padding; image_x = settings.h_padding;
break; } // else ICON_RIGHT
default: // ICON_RIGHT
break;
}
cairo_set_source_surface(c, cl->icon, image_x, image_y); cairo_set_source_surface(c, cl->icon, image_x, image_y);
cairo_rectangle(c, image_x, image_y, image_width, image_height); cairo_rectangle(c, image_x, image_y, image_width, image_height);

View File

@ -103,14 +103,14 @@ bool string_parse_icon_position(const char *s, enum icon_position *ret)
return false; return false;
} }
bool string_parse_content_alignment(const char *s, enum content_alignment *ret) bool string_parse_vertical_alignment(const char *s, enum vertical_alignment *ret)
{ {
ASSERT_OR_RET(STR_FULL(s), false); ASSERT_OR_RET(STR_FULL(s), false);
ASSERT_OR_RET(ret, false); ASSERT_OR_RET(ret, false);
STRING_PARSE_RET("top", CONTENT_TOP); STRING_PARSE_RET("top", VERTICAL_TOP);
STRING_PARSE_RET("center", CONTENT_CENTER); STRING_PARSE_RET("center", VERTICAL_CENTER);
STRING_PARSE_RET("bottom", CONTENT_BOTTOM); STRING_PARSE_RET("bottom", VERTICAL_BOTTOM);
return false; return false;
} }

View File

@ -14,7 +14,7 @@ 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_follow_mode(const char *s, enum follow_mode *ret);
bool string_parse_fullscreen(const char *s, enum behavior_fullscreen *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_icon_position(const char *s, enum icon_position *ret);
bool string_parse_content_alignment(const char *s, enum content_alignment *ret); bool string_parse_vertical_alignment(const char *s, enum vertical_alignment *ret);
bool string_parse_markup_mode(const char *s, enum markup_mode *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_mouse_action(const char *s, enum mouse_action *ret);
bool string_parse_sepcolor(const char *s, struct separator_color_data *ret); bool string_parse_sepcolor(const char *s, struct separator_color_data *ret);

View File

@ -426,13 +426,13 @@ void load_settings(char *cmdline_config_path)
{ {
char *c = option_get_string( char *c = option_get_string(
"global", "global",
"content_alignment", "-content_alignment", "center", "vertical_alignment", "-vertical_alignment", "center",
"Align icon and text top/center/bottom" "Align icon and text top/center/bottom"
); );
if (!string_parse_content_alignment(c, &settings.content_alignment)) { if (!string_parse_vertical_alignment(c, &settings.vertical_alignment)) {
if (c) if (c)
LOG_W("Unknown content alignment: '%s'", c); LOG_W("Unknown vertical alignment: '%s'", c);
settings.content_alignment = defaults.content_alignment; settings.vertical_alignment = defaults.vertical_alignment;
} }
g_free(c); g_free(c);

View File

@ -11,7 +11,7 @@
enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT }; enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT };
enum ellipsize { ELLIPSE_START, ELLIPSE_MIDDLE, ELLIPSE_END }; 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 content_alignment { CONTENT_TOP, CONTENT_CENTER, CONTENT_BOTTOM }; enum vertical_alignment { VERTICAL_TOP, VERTICAL_CENTER, VERTICAL_BOTTOM };
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 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 };
@ -76,7 +76,7 @@ struct settings {
char *browser; char *browser;
char **browser_cmd; char **browser_cmd;
enum icon_position icon_position; enum icon_position icon_position;
enum content_alignment content_alignment; enum vertical_alignment vertical_alignment;
int min_icon_size; int min_icon_size;
int max_icon_size; int max_icon_size;
char *icon_path; char *icon_path;