From 9a62fed33d568cc725fb7b50912e8f5e00bf7350 Mon Sep 17 00:00:00 2001 From: Stanislav Seletskiy Date: Tue, 11 Apr 2017 15:11:38 +0700 Subject: [PATCH] Add --centering option -geometry option can be used to set relative offset against center. --- src/settings.c | 21 +++++++++++++++++++++ src/settings.h | 2 ++ src/x11/x.c | 8 ++++++++ 3 files changed, 31 insertions(+) diff --git a/src/settings.c b/src/settings.c index fe6aff4..5b61507 100644 --- a/src/settings.c +++ b/src/settings.c @@ -599,6 +599,27 @@ void load_settings(char *cmdline_config_path) "Always run rule-defined scripts, even if the notification is suppressed with format = \"\"." ); + { + char *c = option_get_string( + "global", + "centering", "-centering", "off", + "Align notifications on screen off/horizontal/vertical/both" + ); + + if (strcmp(c, "off") == 0) + settings.centering = CENTERING_OFF; + else if (strcmp(c, "horizontal") == 0) + settings.centering = CENTERING_HORIZONTAL; + else if (strcmp(c, "vertical") == 0) + settings.centering = CENTERING_VERTICAL; + else if (strcmp(c, "both") == 0) + settings.centering = CENTERING_BOTH; + else + fprintf(stderr, + "Warning: unknown centering option: %s\n", c); + g_free(c); + } + /* push hardcoded default rules into rules list */ for (int i = 0; i < G_N_ELEMENTS(default_rules); i++) { rules = g_slist_insert(rules, &(default_rules[i]), -1); diff --git a/src/settings.h b/src/settings.h index 0577f42..62e6f15 100644 --- a/src/settings.h +++ b/src/settings.h @@ -12,6 +12,7 @@ enum icon_position_t { icons_left, icons_right, icons_off }; enum separator_color { FOREGROUND, AUTO, FRAME, CUSTOM }; enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD }; enum markup_mode { MARKUP_NULL, MARKUP_NO, MARKUP_STRIP, MARKUP_FULL }; +enum centering { CENTERING_OFF, CENTERING_HORIZONTAL, CENTERING_VERTICAL, CENTERING_BOTH }; typedef struct _settings { bool print_notifications; @@ -34,6 +35,7 @@ typedef struct _settings { char *icons[3]; unsigned int transparency; char *geom; + enum centering centering; char *title; char *class; int shrink; diff --git a/src/x11/x.c b/src/x11/x.c index 9a6c23a..552f5d5 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -724,6 +724,14 @@ static void x_win_move(int width, int height) y = scr->dim.y + xctx.geometry.y; } + if (settings.centering == CENTERING_HORIZONTAL || settings.centering == CENTERING_BOTH) { + x = scr->dim.x + (scr->dim.w - width) / 2 + xctx.geometry.x; + } + + if (settings.centering == CENTERING_VERTICAL || settings.centering == CENTERING_BOTH) { + y = scr->dim.y + (scr->dim.h - height) / 2 + xctx.geometry.y; + } + /* move and resize */ if (x != xctx.window_dim.x || y != xctx.window_dim.y) { XMoveWindow(xctx.dpy, xctx.win, x, y);