]> git.mdlowis.com Git - proto/labwc.git/commitdiff
ssd: add application title to title bar
authorJohan Malm <jgm323@gmail.com>
Sat, 7 Aug 2021 08:35:53 +0000 (09:35 +0100)
committerJohan Malm <jgm323@gmail.com>
Sat, 7 Aug 2021 08:35:53 +0000 (09:35 +0100)
include/labwc.h
include/ssd.h
src/cursor.c
src/foreign.c
src/output.c
src/ssd.c
src/view.c

index bf33ff3afb2ff1c5393dc1a0a2257ce5afcb808f..7b01ce9495608d83d9a3673ffe5c8766fd041258 100644 (file)
@@ -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;
index 8effe4d5cdee4c954613aff311e9db87ab144176..c38caa59df59241a0fac490d69b74562df3a0f75 100644 (file)
@@ -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);
index fe50d19acb4e148baa56572303dc0e0f4ce1fe40..c0d8025408c10f62922a3852ba5ca5a249998b72 100644 (file)
@@ -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:
index 82eb28e852e43eac3eee7289765e9a264c50ed57..ccab98b9c1b1623e57fa6d5f837c5024f4b6f5f6 100644 (file)
@@ -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
 }
index e207fe3c2701eee471b17b7e05ccf2e2ec99b849..d8738763ae6ae5595f362d0f3bc940b36c6eeafc 100644 (file)
@@ -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;
index c2e2c89cc04594413d7d8e3cf4bfbc38e1195337..f034b09e28636196797ca29c35d33b1ff87f8574 100644 (file)
--- a/src/ssd.c
+++ b/src/ssd.c
@@ -6,6 +6,7 @@
 
 #include <assert.h>
 #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);
index 0b71c7434ac6c4b4472b11bc4fcea15e08b7c923..a311e1429dc75de525eb468468594f651a8e2ef4 100644 (file)
@@ -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);
 }