From: David Herrmann Date: Sun, 30 Sep 2012 21:01:24 +0000 (+0200) Subject: wlt: terminal: snap to console-size on resize X-Git-Tag: kmscon-7~445 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f198f28d028ef784c7532db1a31ca205b29f897a;p=platform%2Fupstream%2Fkmscon.git wlt: terminal: snap to console-size on resize Instead of resizing linearly, we now always resize only to the next possible console size. Signed-off-by: David Herrmann --- diff --git a/src/wlt_terminal.c b/src/wlt_terminal.c index 28b0892..db5d562 100644 --- a/src/wlt_terminal.c +++ b/src/wlt_terminal.c @@ -28,6 +28,7 @@ */ #include +#include #include #include #include @@ -216,12 +217,38 @@ static void widget_prepare_resize(struct wlt_widget *widget, unsigned int *new_height, void *data) { + static const bool do_snap = true; struct wlt_terminal *term = data; - - if (*new_width < width) - *new_width = width; - if (*new_height < height) - *new_height = height; + unsigned int w, h; + + /* TODO: allow disabling this via command-line */ + if (do_snap) { + if (*new_width >= width) { + *new_width += term->font_normal->attr.width; + } else { + w = width - *new_width; + w /= term->font_normal->attr.width; + if (!w) + w = 1; + w *= term->font_normal->attr.width; + *new_width += w; + } + if (*new_height >= height) { + *new_height += term->font_normal->attr.height; + } else { + h = height - *new_height; + h /= term->font_normal->attr.height; + if (!h) + h = 1; + h *= term->font_normal->attr.height; + *new_height += h; + } + } else { + if (*new_width < width) + *new_width = width; + if (*new_height < height) + *new_height = height; + } } static void widget_key(struct wlt_widget *widget, unsigned int mask,