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>
dev
Louis-Francis Ratté-Boulianne 7 years ago committed by Daniel Stone
parent e5d655c484
commit 864e39bf96
  1. 26
      shared/cairo-util.c
  2. 4
      shared/cairo-util.h
  3. 10
      shared/frame.c

@ -454,13 +454,14 @@ theme_destroy(struct theme *t)
void void
theme_render_frame(struct theme *t, theme_render_frame(struct theme *t,
cairo_t *cr, int width, int height, cairo_t *cr, int width, int height,
const char *title, struct wl_list *buttons, const char *title, cairo_rectangle_int_t *title_rect,
uint32_t flags) struct wl_list *buttons, uint32_t flags)
{ {
cairo_text_extents_t extents; cairo_text_extents_t extents;
cairo_font_extents_t font_extents; cairo_font_extents_t font_extents;
cairo_surface_t *source; cairo_surface_t *source;
int x, y, margin, top_margin; int x, y, margin, top_margin;
int text_width, text_height;
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba(cr, 0, 0, 0, 0); cairo_set_source_rgba(cr, 0, 0, 0, 0);
@ -491,11 +492,10 @@ theme_render_frame(struct theme *t,
t->width, top_margin); t->width, top_margin);
if (title || !wl_list_empty(buttons)) { 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_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_select_font_face(cr, "sans", cairo_select_font_face(cr, "sans",
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_SLANT_NORMAL,
@ -503,11 +503,15 @@ theme_render_frame(struct theme *t,
cairo_set_font_size(cr, 14); cairo_set_font_size(cr, 14);
cairo_text_extents(cr, title, &extents); cairo_text_extents(cr, title, &extents);
cairo_font_extents (cr, &font_extents); cairo_font_extents (cr, &font_extents);
x = (width - extents.width) / 2; text_width = extents.width;
y = margin + text_height = font_extents.descent - font_extents.ascent;
(t->titlebar_height -
font_extents.ascent - font_extents.descent) / 2 + x = (width - text_width) / 2;
font_extents.ascent; 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) { if (flags & THEME_FRAME_ACTIVE) {
cairo_move_to(cr, x + 1, y + 1); cairo_move_to(cr, x + 1, y + 1);

@ -75,8 +75,8 @@ theme_set_background_source(struct theme *t, cairo_t *cr, uint32_t flags);
void void
theme_render_frame(struct theme *t, theme_render_frame(struct theme *t,
cairo_t *cr, int width, int height, cairo_t *cr, int width, int height,
const char *title, struct wl_list *buttons, const char *title, cairo_rectangle_int_t *title_rect,
uint32_t flags); struct wl_list *buttons, uint32_t flags);
enum theme_location { enum theme_location {
THEME_LOCATION_INTERIOR = 0, THEME_LOCATION_INTERIOR = 0,

@ -98,6 +98,8 @@ struct frame {
int opaque_margin; int opaque_margin;
int geometry_dirty; int geometry_dirty;
cairo_rectangle_int_t title_rect;
uint32_t status; uint32_t status;
struct wl_list buttons; 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; frame->geometry_dirty = 0;
} }
@ -938,7 +945,8 @@ frame_repaint(struct frame *frame, cairo_t *cr)
cairo_save(cr); cairo_save(cr);
theme_render_frame(frame->theme, cr, frame->width, frame->height, 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); cairo_restore(cr);
wl_list_for_each(button, &frame->buttons, link) wl_list_for_each(button, &frame->buttons, link)

Loading…
Cancel
Save