diff options
author | Louis-Francis Ratté-Boulianne <lfrb@collabora.com> | 2017-11-13 16:20:55 -0500 |
---|---|---|
committer | Daniel Stone <daniels@collabora.com> | 2017-12-05 14:09:24 +0000 |
commit | 864e39bf96edd86906239f6c079fab2550df41f7 (patch) | |
tree | 63f02ad72917ef7765c22a23c19567f902383e4f /shared | |
parent | e5d655c4840ff96e45e8faead55be944f45c4f47 (diff) | |
download | weston-864e39bf96edd86906239f6c079fab2550df41f7.tar.gz weston-864e39bf96edd86906239f6c079fab2550df41f7.tar.bz2 weston-864e39bf96edd86906239f6c079fab2550df41f7.zip |
xwm: Deal with title in a smarter way when there isn't enough space
The title in X11 windows and Wayland application using Weston toy
toolkit were placing the title in a very naive fashion. It was
only try to center the string in the title bar. This patch:
* Makes sure the title isn't renderer underneath buttons;
* Move the title to the left if the titlebar isn't large enough;
* Clip the end of the title if needed.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Diffstat (limited to 'shared')
-rw-r--r-- | shared/cairo-util.c | 26 | ||||
-rw-r--r-- | shared/cairo-util.h | 4 | ||||
-rw-r--r-- | shared/frame.c | 10 |
3 files changed, 26 insertions, 14 deletions
diff --git a/shared/cairo-util.c b/shared/cairo-util.c index 21fcbea5..fd8cc7ce 100644 --- a/shared/cairo-util.c +++ b/shared/cairo-util.c @@ -454,13 +454,14 @@ theme_destroy(struct theme *t) void theme_render_frame(struct theme *t, cairo_t *cr, int width, int height, - const char *title, struct wl_list *buttons, - uint32_t flags) + const char *title, cairo_rectangle_int_t *title_rect, + struct wl_list *buttons, uint32_t flags) { cairo_text_extents_t extents; cairo_font_extents_t font_extents; cairo_surface_t *source; int x, y, margin, top_margin; + int text_width, text_height; cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0, 0, 0, 0); @@ -491,11 +492,10 @@ theme_render_frame(struct theme *t, t->width, top_margin); if (title || !wl_list_empty(buttons)) { - cairo_rectangle (cr, margin + t->width, margin, - width - (margin + t->width) * 2, - t->titlebar_height - t->width); - cairo_clip(cr); + cairo_rectangle (cr, title_rect->x, title_rect->y, + title_rect->width, title_rect->height); + cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_select_font_face(cr, "sans", CAIRO_FONT_SLANT_NORMAL, @@ -503,11 +503,15 @@ theme_render_frame(struct theme *t, cairo_set_font_size(cr, 14); cairo_text_extents(cr, title, &extents); cairo_font_extents (cr, &font_extents); - x = (width - extents.width) / 2; - y = margin + - (t->titlebar_height - - font_extents.ascent - font_extents.descent) / 2 + - font_extents.ascent; + text_width = extents.width; + text_height = font_extents.descent - font_extents.ascent; + + x = (width - text_width) / 2; + y = margin + (t->titlebar_height - text_height) / 2; + if (x < title_rect->x) + x = title_rect->x; + else if (x + text_width > (title_rect->x + title_rect->width)) + x = (title_rect->x + title_rect->width) - text_width; if (flags & THEME_FRAME_ACTIVE) { cairo_move_to(cr, x + 1, y + 1); diff --git a/shared/cairo-util.h b/shared/cairo-util.h index 84cf005e..9481e58c 100644 --- a/shared/cairo-util.h +++ b/shared/cairo-util.h @@ -75,8 +75,8 @@ theme_set_background_source(struct theme *t, cairo_t *cr, uint32_t flags); void theme_render_frame(struct theme *t, cairo_t *cr, int width, int height, - const char *title, struct wl_list *buttons, - uint32_t flags); + const char *title, cairo_rectangle_int_t *title_rect, + struct wl_list *buttons, uint32_t flags); enum theme_location { THEME_LOCATION_INTERIOR = 0, diff --git a/shared/frame.c b/shared/frame.c index eb0cd77a..5ca7e08b 100644 --- a/shared/frame.c +++ b/shared/frame.c @@ -98,6 +98,8 @@ struct frame { int opaque_margin; int geometry_dirty; + cairo_rectangle_int_t title_rect; + uint32_t status; struct wl_list buttons; @@ -532,6 +534,11 @@ frame_refresh_geometry(struct frame *frame) } } + frame->title_rect.x = x_l; + frame->title_rect.y = y; + frame->title_rect.width = x_r - x_l; + frame->title_rect.height = titlebar_height; + frame->geometry_dirty = 0; } @@ -938,7 +945,8 @@ frame_repaint(struct frame *frame, cairo_t *cr) cairo_save(cr); theme_render_frame(frame->theme, cr, frame->width, frame->height, - frame->title, &frame->buttons, flags); + frame->title, &frame->title_rect, + &frame->buttons, flags); cairo_restore(cr); wl_list_for_each(button, &frame->buttons, link) |