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>
This commit is contained in:
parent
e5d655c484
commit
864e39bf96
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue