]> git.mdlowis.com Git - proto/labwc.git/commitdiff
deco: refactor button code
authorJohan Malm <jgm323@gmail.com>
Mon, 21 Sep 2020 18:24:27 +0000 (19:24 +0100)
committerJohan Malm <jgm323@gmail.com>
Mon, 21 Sep 2020 18:24:27 +0000 (19:24 +0100)
- Make the height+width of buttons the same as the title bar.
- Center icons within the 'button space'
- Show button background color on hover (just hard-coded grey for now)

src/cursor.c
src/deco.c
src/output.c

index faa75e10aa57a6abac28e4d69d06c16735499cc8..14604310ebac14d64274130cc24861ae107cd6d3 100644 (file)
@@ -90,9 +90,7 @@ static void process_cursor_motion(struct server *server, uint32_t time)
 
        /* TODO: Could we use wlr_xcursor_get_resize_name() here?? */
        switch (view_area) {
-       case LAB_DECO_PART_TITLE:
-               wlr_xcursor_manager_set_cursor_image(
-                       server->cursor_mgr, XCURSOR_DEFAULT, server->cursor);
+       case LAB_DECO_NONE:
                break;
        case LAB_DECO_PART_TOP:
                wlr_xcursor_manager_set_cursor_image(
@@ -110,6 +108,10 @@ static void process_cursor_motion(struct server *server, uint32_t time)
                wlr_xcursor_manager_set_cursor_image(
                        server->cursor_mgr, "left_side", server->cursor);
                break;
+       default:
+               wlr_xcursor_manager_set_cursor_image(
+                       server->cursor_mgr, XCURSOR_DEFAULT, server->cursor);
+               break;
        }
        if (surface) {
                bool focus_changed = seat->pointer_state.focused_surface !=
index 6974003bb1f1cb2e9cc9c1de5c56d95e45e4e750..8bba5d6510d465c98fc4c83589641e75ba6a4686 100644 (file)
@@ -37,31 +37,26 @@ struct wlr_box deco_max_extents(struct view *view)
 
 struct wlr_box deco_box(struct view *view, enum deco_part deco_part)
 {
-       int margin;
-
        struct wlr_box box = { .x = 0, .y = 0, .width = 0, .height = 0 };
        BUG_ON(!view);
        switch (deco_part) {
        case LAB_DECO_BUTTON_CLOSE:
-               wlr_texture_get_size(theme.xbm_close_active_unpressed,
-                                    &box.width, &box.height);
-               margin = (rc.title_height - box.height) / 2;
-               box.x = view->x + view->w + margin - rc.title_height;
-               box.y = view->y - rc.title_height + margin;
+               box.width = rc.title_height;
+               box.height = rc.title_height;
+               box.x = view->x + view->w - rc.title_height;
+               box.y = view->y - rc.title_height;
                break;
        case LAB_DECO_BUTTON_MAXIMIZE:
-               wlr_texture_get_size(theme.xbm_maximize_active_unpressed,
-                                    &box.width, &box.height);
-               margin = (rc.title_height - box.height) / 2;
-               box.x = view->x + view->w + margin - rc.title_height * 2;
-               box.y = view->y - rc.title_height + margin;
+               box.width = rc.title_height;
+               box.height = rc.title_height;
+               box.x = view->x + view->w - rc.title_height * 2;
+               box.y = view->y - rc.title_height;
                break;
        case LAB_DECO_BUTTON_ICONIFY:
-               wlr_texture_get_size(theme.xbm_iconify_active_unpressed,
-                                    &box.width, &box.height);
-               margin = (rc.title_height - box.height) / 2;
-               box.x = view->x + view->w + margin - rc.title_height * 3;
-               box.y = view->y - rc.title_height + margin;
+               box.width = rc.title_height;
+               box.height = rc.title_height;
+               box.x = view->x + view->w - rc.title_height * 3;
+               box.y = view->y - rc.title_height;
                break;
        case LAB_DECO_PART_TITLE:
                box.x = view->x;
index b51fad0b1e79ff43b5ebff1d8b9aafe0261cf018..773cbe2954d4f49c9f272d767e5e7638764c6616 100644 (file)
@@ -79,11 +79,35 @@ static void render_icon(struct draw_data *d, struct wlr_box box,
        if (!texture)
                return;
        float matrix[9];
-       wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
+
+       /* centre-align icon if smaller than designated box */
+       struct wlr_box button;
+       wlr_texture_get_size(texture, &button.width, &button.height);
+       if (box.width > button.width) {
+               button.x = box.x + (box.width - button.width) / 2;
+       } else {
+               button.x = box.x;
+               button.width = box.width;
+       }
+       if (box.height > button.height) {
+               button.y = box.y + (box.height - button.height) / 2;
+       } else {
+               button.y = box.y;
+               button.height = box.height;
+       }
+
+       wlr_matrix_project_box(matrix, &button, WL_OUTPUT_TRANSFORM_NORMAL, 0,
                               d->transform_matrix);
        wlr_render_texture_with_matrix(d->renderer, texture, matrix, 1);
 }
 
+static bool isbutton(enum deco_part deco_part)
+{
+       return deco_part == LAB_DECO_BUTTON_CLOSE ||
+              deco_part == LAB_DECO_BUTTON_MAXIMIZE ||
+              deco_part == LAB_DECO_BUTTON_ICONIFY;
+}
+
 static void render_decorations(struct wlr_output *output, struct view *view)
 {
        if (!view->server_side_deco)
@@ -93,18 +117,32 @@ static void render_decorations(struct wlr_output *output, struct view *view)
                .transform_matrix = output->transform_matrix,
        };
 
+       /* border */
        ddata.rgba = theme.window_active_handle_bg_color;
        draw_rect(&ddata, deco_box(view, LAB_DECO_PART_TOP));
        draw_rect(&ddata, deco_box(view, LAB_DECO_PART_RIGHT));
        draw_rect(&ddata, deco_box(view, LAB_DECO_PART_BOTTOM));
        draw_rect(&ddata, deco_box(view, LAB_DECO_PART_LEFT));
 
+       /* title */
        if (view->surface == seat_focused_surface())
                ddata.rgba = theme.window_active_title_bg_color;
        else
                ddata.rgba = theme.window_inactive_title_bg_color;
        draw_rect(&ddata, deco_box(view, LAB_DECO_PART_TITLE));
 
+       /* button background */
+       struct wlr_cursor *cur = view->server->cursor;
+       enum deco_part deco_part = deco_at(view, cur->x, cur->y);
+
+       struct wlr_box box = deco_box(view, deco_part);
+       if (isbutton(deco_part) &&
+           wlr_box_contains_point(&box, cur->x, cur->y)) {
+               ddata.rgba = (float[4]){ 0.5, 0.5, 0.5, 0.5 };
+               draw_rect(&ddata, deco_box(view, deco_part));
+       }
+
+       /* buttons */
        if (view->surface == seat_focused_surface()) {
                render_icon(&ddata, deco_box(view, LAB_DECO_BUTTON_CLOSE),
                            theme.xbm_close_active_unpressed);