diff --git a/README.pod b/README.pod index 2ede7cf..22d87b3 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> + +Shrink window if it's smaller than the width. Will be ignored if width is 0. + =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/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)) { diff --git a/dunstrc b/dunstrc index df23c16..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 @@ -61,6 +61,9 @@ # screen width minus the width defined in within the geometry option. geometry = "300x5-30+20" + # 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] # This option will only work if a compositing windowmanager is present (e.g. xcompmgr, compiz, etc..) transparency = 0 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; diff --git a/settings.c b/settings.c index 7d4066d..0e0218f 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, + "Shrink window if it's smaller than the width"); 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; diff --git a/x.c b/x.c index 2ad74d3..d9fa7bc 100644 --- a/x.c +++ b/x.c @@ -203,13 +203,40 @@ 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; pango_layout_get_pixel_size(cl->l, &w, &h); dim.h += h; text_width = MAX(w, text_width); + + if (dim.w <= 0 || settings.shrink) { + /* dynamic width */ + 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.x * 2; + } 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); + } } if (dim.w <= 0) {