From 2d59a77e0caf309d329f74663b2c35559087c5fc Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Tue, 23 Apr 2013 20:58:19 +0200 Subject: [PATCH 1/8] wrap the text if it's wider than the screen width (Fixes #53) --- x.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/x.c b/x.c index 2ad74d3..30bb6da 100644 --- a/x.c +++ b/x.c @@ -210,6 +210,28 @@ static dimension_t calculate_dimensions(GSList *layouts) pango_layout_get_pixel_size(cl->l, &w, &h); dim.h += h; text_width = MAX(w, text_width); + + if (dim.w <= 0) { + /* dynamic width */ + if ((text_width + 2 * settings.h_padding) > scr.dim.w) { + /* it's bigger than the screen */ + /* subtract height from the unwrapped text */ + dim.h -= h; + /* set width to screen width */ + dim.w = scr.dim.w - xctx.geometry.y * 2; + + /* re-setup the layout */ + int width = dim.w; + width -= 2 * settings.h_padding; + width -= 2 * settings.frame_width; + r_setup_pango_layout(cl->l, width); + + /* re-read information */ + pango_layout_get_pixel_size(cl->l, &w, &h); + dim.h += h; + text_width = MAX(w, text_width); + } + } } if (dim.w <= 0) { From 844186b77db5913983a871bef9a0c984e0e8c995 Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Tue, 30 Apr 2013 13:45:34 +0200 Subject: [PATCH 2/8] =?UTF-8?q?fixed=20"warning:=20=E2=80=98g=5Ftype=5Fini?= =?UTF-8?q?t=E2=80=99=20is=20deprecated"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbus.c | 4 +++- dunstify.c | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dbus.c b/dbus.c index 39f92dd..729cab1 100644 --- a/dbus.c +++ b/dbus.c @@ -389,7 +389,9 @@ int initdbus(void) { guint owner_id; - g_type_init(); + #if !GLIB_CHECK_VERSION(2,35,0) + g_type_init(); + #endif introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); diff --git a/dunstify.c b/dunstify.c index 9209c87..7958cd6 100644 --- a/dunstify.c +++ b/dunstify.c @@ -249,8 +249,9 @@ void add_hint(NotifyNotification *n, char *str) int main(int argc, char *argv[]) { - - g_type_init(); + #if !GLIB_CHECK_VERSION(2,35,0) + g_type_init(); + #endif parse_commandline(argc, argv); if (!notify_init(appname)) { From a25954f8a6cedc7f0f8757e9af914c695f211c13 Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Tue, 30 Apr 2013 14:54:55 +0200 Subject: [PATCH 3/8] added shrink option --- README.pod | 6 +++++- config.def.h | 1 + dunstrc | 3 +++ settings.c | 4 ++++ settings.h | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.pod b/README.pod index 2ede7cf..ab2eeea 100644 --- a/README.pod +++ b/README.pod @@ -4,7 +4,7 @@ dunst - A customizable and lightweight notification-daemon =head1 SYNOPSIS -dunst [-geometry geom] [-fn font] [-nf/nb/lf/lb/cf/cb color] +dunst [-geometry geom] [-shrink shrink] [-fn font] [-nf/nb/lf/lb/cf/cb color] [-to/nto/lto/cto secs] [-format fmt] [-key key] [-mod mod] [-mon n] [-v] =head1 DESCRIPTION @@ -84,6 +84,10 @@ a negative from the right side of the screen. Y is measured from the top and down respectevly. see also EXAMPLES show the notification on monitor n. +=item B<-shrink> + +TODO + =item B<-lh/-line_height> height The height of a single line in pixel. If the height is smaller than the font height, it will get raised to the font height. diff --git a/config.def.h b/config.def.h index 9cfc2b5..e4be36d 100644 --- a/config.def.h +++ b/config.def.h @@ -14,6 +14,7 @@ int timeouts[] = { 10, 10, 0 }; /* low, normal, critical */ unsigned int transparency = 0; /* transparency */ char *geom = "0x0"; /* geometry */ +int shrink = False; /* shrinking */ int sort = True; /* sort messages by urgency */ int indicate_hidden = True; /* show count of hidden messages */ int idle_threshold = 0; /* don't timeout notifications when idle for x seconds */ diff --git a/dunstrc b/dunstrc index df23c16..ece15f0 100644 --- a/dunstrc +++ b/dunstrc @@ -61,6 +61,9 @@ # screen width minus the width defined in within the geometry option. geometry = "300x5-30+20" + # TODO + shrink = no + # The transparency of the window. range: [0; 100] # This option will only work if a compositing windowmanager is present (e.g. xcompmgr, compiz, etc..) transparency = 0 diff --git a/settings.c b/settings.c index 7d4066d..47a5924 100644 --- a/settings.c +++ b/settings.c @@ -101,6 +101,10 @@ void load_settings(char *cmdline_config_path) settings.geom = option_get_string("global", "geometry", "-geom/-geometry", geom, "Geometry for the window"); + settings.shrink = + option_get_bool("global", "shrink", "-shrink", + shrink, + ""); // TODO settings.line_height = option_get_int("global", "line_height", "-lh/-line_height", line_height, diff --git a/settings.h b/settings.h index ec3554d..fed0a70 100644 --- a/settings.h +++ b/settings.h @@ -15,6 +15,7 @@ typedef struct _settings { int timeouts[3]; unsigned int transparency; char *geom; + int shrink; int sort; int indicate_hidden; int idle_threshold; From dd047ccd2000b9447be62998f2b1e6047020cf97 Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Tue, 30 Apr 2013 14:55:50 +0200 Subject: [PATCH 4/8] implemented shrink option --- x.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/x.c b/x.c index 30bb6da..4a80509 100644 --- a/x.c +++ b/x.c @@ -203,7 +203,7 @@ static dimension_t calculate_dimensions(GSList *layouts) dim.h += (g_slist_length(layouts) - 1) * settings.separator_height; dim.h += g_slist_length(layouts) * settings.padding * 2; - int text_width = 0; + int text_width = 0, total_width = 0; for (GSList *iter = layouts; iter; iter = iter->next) { colored_layout *cl = iter->data; int w,h; @@ -211,26 +211,31 @@ static dimension_t calculate_dimensions(GSList *layouts) dim.h += h; text_width = MAX(w, text_width); - if (dim.w <= 0) { + if (dim.w <= 0 || settings.shrink) { /* dynamic width */ - if ((text_width + 2 * settings.h_padding) > scr.dim.w) { - /* it's bigger than the screen */ - /* subtract height from the unwrapped text */ - dim.h -= h; + total_width = MAX(text_width + 2 * settings.h_padding, total_width); + + /* subtract height from the unwrapped text */ + dim.h -= h; + + if (total_width > scr.dim.w) { /* set width to screen width */ dim.w = scr.dim.w - xctx.geometry.y * 2; - - /* re-setup the layout */ - int width = dim.w; - width -= 2 * settings.h_padding; - width -= 2 * settings.frame_width; - r_setup_pango_layout(cl->l, width); - - /* re-read information */ - pango_layout_get_pixel_size(cl->l, &w, &h); - dim.h += h; - text_width = MAX(w, text_width); + } else if (total_width < xctx.geometry.w && settings.shrink) { + /* set width to text width */ + dim.w = total_width + 2 * settings.frame_width; } + + /* re-setup the layout */ + int width = dim.w; + width -= 2 * settings.h_padding; + width -= 2 * settings.frame_width; + r_setup_pango_layout(cl->l, width); + + /* re-read information */ + pango_layout_get_pixel_size(cl->l, &w, &h); + dim.h += h; + text_width = MAX(w, text_width); } } From a25e810b679b2a4b4ae5b70e52b9b4c5ae70685c Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Tue, 30 Apr 2013 15:01:07 +0200 Subject: [PATCH 5/8] =?UTF-8?q?fixed=20"warning:=20assignment=20discards?= =?UTF-8?q?=20=E2=80=98const=E2=80=99=20qualifier=20from=20pointer=20targe?= =?UTF-8?q?t=20type"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- notification.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notification.h b/notification.h index a58b74b..5c7a202 100644 --- a/notification.h +++ b/notification.h @@ -30,7 +30,7 @@ typedef struct _notification { int id; int dup_count; int displayed_height; - char *color_strings[2]; + const char *color_strings[2]; int progress; /* percentage + 1, 0 to hide */ int line_count; From e92e36a2d9bcf5e0285c0780e80e3bbdfd78e8eb Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Tue, 30 Apr 2013 15:16:35 +0200 Subject: [PATCH 6/8] added documentation --- README.pod | 2 +- dunstrc | 2 +- settings.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.pod b/README.pod index ab2eeea..22d87b3 100644 --- a/README.pod +++ b/README.pod @@ -86,7 +86,7 @@ see also EXAMPLES show the notification on monitor n. =item B<-shrink> -TODO +Shrink window if it's smaller than the width. Will be ignored if width is 0. =item B<-lh/-line_height> height diff --git a/dunstrc b/dunstrc index ece15f0..52e1261 100644 --- a/dunstrc +++ b/dunstrc @@ -61,7 +61,7 @@ # screen width minus the width defined in within the geometry option. geometry = "300x5-30+20" - # TODO + # Shrink window if it's smaller than the width. Will be ignored if width is 0. shrink = no # The transparency of the window. range: [0; 100] diff --git a/settings.c b/settings.c index 47a5924..0e0218f 100644 --- a/settings.c +++ b/settings.c @@ -104,7 +104,7 @@ void load_settings(char *cmdline_config_path) settings.shrink = option_get_bool("global", "shrink", "-shrink", shrink, - ""); // TODO + "Shrink window if it's smaller than the width"); settings.line_height = option_get_int("global", "line_height", "-lh/-line_height", line_height, From 24d9179e4de45ae18a4a951f3c1338002a161fa4 Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Wed, 1 May 2013 12:00:35 +0200 Subject: [PATCH 7/8] xctx.geometry.y -> xctx.geometry.x --- x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x.c b/x.c index 4a80509..d9fa7bc 100644 --- a/x.c +++ b/x.c @@ -220,7 +220,7 @@ static dimension_t calculate_dimensions(GSList *layouts) if (total_width > scr.dim.w) { /* set width to screen width */ - dim.w = scr.dim.w - xctx.geometry.y * 2; + dim.w = scr.dim.w - xctx.geometry.x * 2; } else if (total_width < xctx.geometry.w && settings.shrink) { /* set width to text width */ dim.w = total_width + 2 * settings.frame_width; From 718c07a9ebb973283730592f2f433070f244a539 Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Wed, 1 May 2013 12:08:13 +0200 Subject: [PATCH 8/8] removed unopened closing bracket --- dunstrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dunstrc b/dunstrc index 52e1261..500f9cc 100644 --- a/dunstrc +++ b/dunstrc @@ -49,7 +49,7 @@ # the geometry of the window - # geometry [{width}]x{height}][+/-{x}+/-{y}] + # geometry [{width}]x{height}[+/-{x}+/-{y}] # The geometry of the message window. # The height is measured in number of notifications everything else in pixels. If the width # is omitted but the height is given ("-geometry x2"), the message window