Merge pull request #100 from gs93/dynamic_wordwrap

wrap the text if it's wider than the screen width (Fixes #53)
This commit is contained in:
Sascha Kruse 2013-05-04 13:03:54 -07:00
commit 9d981e1fd7
9 changed files with 50 additions and 7 deletions

View File

@ -4,7 +4,7 @@ dunst - A customizable and lightweight notification-daemon
=head1 SYNOPSIS =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] [-to/nto/lto/cto secs] [-format fmt] [-key key] [-mod mod] [-mon n] [-v]
=head1 DESCRIPTION =head1 DESCRIPTION
@ -84,6 +84,10 @@ a negative from the right side of the screen.
Y is measured from the top and down respectevly. Y is measured from the top and down respectevly.
see also EXAMPLES show the notification on monitor n. 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 =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. 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.

View File

@ -14,6 +14,7 @@ int timeouts[] = { 10, 10, 0 }; /* low, normal, critical */
unsigned int transparency = 0; /* transparency */ unsigned int transparency = 0; /* transparency */
char *geom = "0x0"; /* geometry */ char *geom = "0x0"; /* geometry */
int shrink = False; /* shrinking */
int sort = True; /* sort messages by urgency */ int sort = True; /* sort messages by urgency */
int indicate_hidden = True; /* show count of hidden messages */ int indicate_hidden = True; /* show count of hidden messages */
int idle_threshold = 0; /* don't timeout notifications when idle for x seconds */ int idle_threshold = 0; /* don't timeout notifications when idle for x seconds */

4
dbus.c
View File

@ -389,7 +389,9 @@ int initdbus(void)
{ {
guint owner_id; 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, introspection_data = g_dbus_node_info_new_for_xml(introspection_xml,
NULL); NULL);

View File

@ -249,8 +249,9 @@ void add_hint(NotifyNotification *n, char *str)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#if !GLIB_CHECK_VERSION(2,35,0)
g_type_init(); g_type_init();
#endif
parse_commandline(argc, argv); parse_commandline(argc, argv);
if (!notify_init(appname)) { if (!notify_init(appname)) {

View File

@ -49,7 +49,7 @@
# the geometry of the window # the geometry of the window
# geometry [{width}]x{height}][+/-{x}+/-{y}] # geometry [{width}]x{height}[+/-{x}+/-{y}]
# The geometry of the message window. # The geometry of the message window.
# The height is measured in number of notifications everything else in pixels. If the width # 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 # 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. # screen width minus the width defined in within the geometry option.
geometry = "300x5-30+20" 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] # The transparency of the window. range: [0; 100]
# This option will only work if a compositing windowmanager is present (e.g. xcompmgr, compiz, etc..) # This option will only work if a compositing windowmanager is present (e.g. xcompmgr, compiz, etc..)
transparency = 0 transparency = 0

View File

@ -30,7 +30,7 @@ typedef struct _notification {
int id; int id;
int dup_count; int dup_count;
int displayed_height; int displayed_height;
char *color_strings[2]; const char *color_strings[2];
int progress; /* percentage + 1, 0 to hide */ int progress; /* percentage + 1, 0 to hide */
int line_count; int line_count;

View File

@ -101,6 +101,10 @@ void load_settings(char *cmdline_config_path)
settings.geom = settings.geom =
option_get_string("global", "geometry", "-geom/-geometry", geom, option_get_string("global", "geometry", "-geom/-geometry", geom,
"Geometry for the window"); "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 = settings.line_height =
option_get_int("global", "line_height", "-lh/-line_height", option_get_int("global", "line_height", "-lh/-line_height",
line_height, line_height,

View File

@ -15,6 +15,7 @@ typedef struct _settings {
int timeouts[3]; int timeouts[3];
unsigned int transparency; unsigned int transparency;
char *geom; char *geom;
int shrink;
int sort; int sort;
int indicate_hidden; int indicate_hidden;
int idle_threshold; int idle_threshold;

29
x.c
View File

@ -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) - 1) * settings.separator_height;
dim.h += g_slist_length(layouts) * settings.padding * 2; 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) { for (GSList *iter = layouts; iter; iter = iter->next) {
colored_layout *cl = iter->data; colored_layout *cl = iter->data;
int w,h; int w,h;
pango_layout_get_pixel_size(cl->l, &w, &h); pango_layout_get_pixel_size(cl->l, &w, &h);
dim.h += h; dim.h += h;
text_width = MAX(w, text_width); 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) { if (dim.w <= 0) {