From 864e39bf96edd86906239f6c079fab2550df41f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis-Francis=20Ratt=C3=A9-Boulianne?= Date: Mon, 13 Nov 2017 16:20:55 -0500 Subject: xwm: Deal with title in a smarter way when there isn't enough space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Daniel Stone --- shared/cairo-util.c | 26 +++++++++++++++----------- shared/cairo-util.h | 4 ++-- shared/frame.c | 10 +++++++++- 3 files changed, 26 insertions(+), 14 deletions(-) (limited to 'shared') 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) -- cgit v1.2.3