From f857aea8f4c86cdff0c6c2e5687cb129af0ad325 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Sat, 7 Aug 2021 09:35:53 +0100 Subject: [PATCH] ssd: add application title to title bar --- include/labwc.h | 1 + include/ssd.h | 2 ++ src/cursor.c | 4 ++-- src/foreign.c | 7 +++++++ src/output.c | 2 +- src/ssd.c | 45 +++++++++++++++++++++++++++++++++++++++++---- src/view.c | 1 + 7 files changed, 55 insertions(+), 7 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index bf33ff3a..7b01ce94 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -222,6 +222,7 @@ struct view { struct wl_list parts; struct wlr_box box; /* remember geo so we know when to update */ } ssd; + struct wlr_texture *title; struct wlr_foreign_toplevel_handle_v1 *toplevel_handle; struct wl_listener toplevel_handle_request_maximize; diff --git a/include/ssd.h b/include/ssd.h index 8effe4d5..c38caa59 100644 --- a/include/ssd.h +++ b/include/ssd.h @@ -11,6 +11,7 @@ enum ssd_part_type { LAB_SSD_BUTTON_CLOSE, LAB_SSD_BUTTON_MAXIMIZE, LAB_SSD_BUTTON_ICONIFY, + LAB_SSD_PART_TITLEBAR, LAB_SSD_PART_TITLE, LAB_SSD_PART_CORNER_TOP_LEFT, LAB_SSD_PART_CORNER_TOP_RIGHT, @@ -56,6 +57,7 @@ struct wlr_box ssd_max_extents(struct view *view); struct wlr_box ssd_box(struct view *view, enum ssd_part_type type); enum ssd_part_type ssd_at(struct view *view, double lx, double ly); uint32_t ssd_resize_edges(enum ssd_part_type type); +void ssd_update_title(struct view *view); void ssd_create(struct view *view); void ssd_destroy(struct view *view); void ssd_update_geometry(struct view *view); diff --git a/src/cursor.c b/src/cursor.c index fe50d19a..c0d80254 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -321,7 +321,7 @@ cursor_button(struct wl_listener *listener, void *data) desktop_focus_view(&server->seat, view); damage_all_outputs(server); - if (is_double_click(500) && view_area == LAB_SSD_PART_TITLE) { + if (is_double_click(500) && view_area == LAB_SSD_PART_TITLEBAR) { view_toggle_maximize(view); return; } @@ -339,7 +339,7 @@ cursor_button(struct wl_listener *listener, void *data) case LAB_SSD_BUTTON_ICONIFY: view_minimize(view, true); break; - case LAB_SSD_PART_TITLE: + case LAB_SSD_PART_TITLEBAR: interactive_begin(view, LAB_INPUT_STATE_MOVE, 0); break; case LAB_SSD_BUTTON_MAXIMIZE: diff --git a/src/foreign.c b/src/foreign.c index 82eb28e8..ccab98b9 100644 --- a/src/foreign.c +++ b/src/foreign.c @@ -23,6 +23,12 @@ foreign_toplevel_handle_create(struct view *view) { view->toplevel_handle = wlr_foreign_toplevel_handle_v1_create( view->server->foreign_toplevel_manager); + if (!view->toplevel_handle) { + wlr_log(WLR_ERROR, "cannot create foreign toplevel handle for (%s)", + view->impl->get_string_prop(view, "title")); + return; + } + view_update_title(view); wlr_foreign_toplevel_handle_v1_output_enter(view->toplevel_handle, view_wlr_output(view)); @@ -35,4 +41,5 @@ foreign_toplevel_handle_create(struct view *view) handle_toplevel_handle_request_minimize; wl_signal_add(&view->toplevel_handle->events.request_minimize, &view->toplevel_handle_request_minimize); + // TODO: hook up remaining signals } diff --git a/src/output.c b/src/output.c index e207fe3c..d8738763 100644 --- a/src/output.c +++ b/src/output.c @@ -488,7 +488,7 @@ render_deco(struct view *view, struct output *output, *(part->texture.inactive); render_texture_helper(output, output_damage, &part->box, texture); - } else { + } else if (part->color.active && part->color.inactive) { float *color = focused ? part->color.active : part->color.inactive; diff --git a/src/ssd.c b/src/ssd.c index c2e2c89c..f034b09e 100644 --- a/src/ssd.c +++ b/src/ssd.c @@ -6,6 +6,7 @@ #include #include "config/rcxml.h" +#include "common/font.h" #include "labwc.h" #include "theme.h" #include "ssd.h" @@ -63,7 +64,7 @@ ssd_interactive_box(struct view *view, enum ssd_part_type type) box.width = theme->title_height; box.height = theme->title_height; break; - case LAB_SSD_PART_TITLE: + case LAB_SSD_PART_TITLEBAR: box.x = view->x; box.y = view->y - theme->title_height; box.width = view->w; @@ -138,11 +139,20 @@ ssd_box(struct view *view, enum ssd_part_type type) case LAB_SSD_BUTTON_ICONIFY: box = ssd_interactive_box(view, type); break; - case LAB_SSD_PART_TITLE: + case LAB_SSD_PART_TITLEBAR: box = ssd_interactive_box(view, type); box.x += theme->title_height; box.width -= 2 * theme->title_height; break; + case LAB_SSD_PART_TITLE: + box = ssd_box(view, LAB_SSD_PART_TITLEBAR); + if (view->title) { + /* center align title vertically within allocated box */ + box.y += (box.height - view->title->height) / 2; + box.width = view->title->width; + box.height = view->title->height; + } + break; case LAB_SSD_PART_CORNER_TOP_LEFT: box = ssd_interactive_box(view, type); box.x += INVISIBLE_MARGIN; @@ -231,6 +241,27 @@ add_part(struct view *view, enum ssd_part_type type) return part; } +void +ssd_update_title(struct view *view) +{ + struct theme *theme = view->server->theme; + + /* TODO: use window.active.label.text.color here */ + /* TODO: set max_width propertly */ + font_texture_create(view->server, &view->title, 200, + view->impl->get_string_prop(view, "title"), + rc.font_name_activewindow, + theme->menu_items_active_text_color); + + struct ssd_part *part; + wl_list_for_each(part, &view->ssd.parts, link) { + if (part->type == LAB_SSD_PART_TITLE) { + part->box = ssd_box(view, part->type); + break; + } + } +} + void ssd_create(struct view *view) { @@ -257,11 +288,17 @@ ssd_create(struct view *view) } /* titlebar */ - part = add_part(view, LAB_SSD_PART_TITLE); - part->box = ssd_box(view, LAB_SSD_PART_TITLE); + part = add_part(view, LAB_SSD_PART_TITLEBAR); + part->box = ssd_box(view, LAB_SSD_PART_TITLEBAR); part->color.active = theme->window_active_title_bg_color; part->color.inactive = theme->window_inactive_title_bg_color; + /* title text */ + part = add_part(view, LAB_SSD_PART_TITLE); + ssd_update_title(view); + part->texture.active = &view->title; + part->texture.inactive = &view->title; + /* titlebar top-left corner */ part = add_part(view, LAB_SSD_PART_CORNER_TOP_LEFT); part->box = ssd_box(view, part->type); diff --git a/src/view.c b/src/view.c index 0b71c743..a311e142 100644 --- a/src/view.c +++ b/src/view.c @@ -173,5 +173,6 @@ view_update_title(struct view *view) if (!view->toplevel_handle || !title) { return; } + ssd_update_title(view); wlr_foreign_toplevel_handle_v1_set_title(view->toplevel_handle, title); }