mirror of
https://github.com/labwc/labwc.git
synced 2025-11-02 09:01:47 -05:00
deco: refactor button code
- 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)
This commit is contained in:
parent
3c90cb7945
commit
4ecc5efa73
3 changed files with 56 additions and 21 deletions
|
|
@ -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 !=
|
||||
|
|
|
|||
29
src/deco.c
29
src/deco.c
|
|
@ -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;
|
||||
|
|
|
|||
40
src/output.c
40
src/output.c
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue