From c07acc9ee6ab9c337394bb8c32df789ea93f97fc Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Sat, 30 May 2020 21:28:17 +0100 Subject: [PATCH] Add deco parts top, right and bottom --- README.md | 5 +++++ include/labwc.h | 11 +++++++++-- src/cursor.c | 28 ++++++++++++++++++++++++++-- src/deco.c | 25 ++++++++++++++++++++++--- src/output.c | 43 +++++++++++++++++++++++++++++-------------- src/view.c | 12 ++++++++++++ src/xwl.c | 2 +- 7 files changed, 104 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 820bb7b0..e988473d 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,11 @@ This software is in early development. - wayland-protocols - xwayland +Will soon depend on + +- libxml2 +- cairo, pango, glib + ## Aim - [x] Support xwayland diff --git a/include/labwc.h b/include/labwc.h index 872feec2..bf591710 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -93,8 +93,15 @@ struct output { enum view_type { LAB_XDG_SHELL_VIEW, LAB_XWAYLAND_VIEW }; -/* Keep LAB_DECO_NONE last for the purpose of iterating */ -enum deco_part { LAB_DECO_PART_TOP = 0, LAB_DECO_PART_LEFT, LAB_DECO_NONE }; +enum deco_part { + LAB_DECO_PART_TITLE = 0, + LAB_DECO_PART_TOP, + LAB_DECO_PART_RIGHT, + LAB_DECO_PART_BOTTOM, + LAB_DECO_PART_LEFT, + LAB_DECO_NONE + /* Keep LAB_DECO_NONE last as iteration end-marker */ +}; struct view { enum view_type type; diff --git a/src/cursor.c b/src/cursor.c index 78b466c9..bde81839 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -84,10 +84,22 @@ static void process_cursor_motion(struct server *server, uint32_t time) server->cursor_mgr, XCURSOR_DEFAULT, server->cursor); } switch (view_area) { - case LAB_DECO_PART_TOP: + case LAB_DECO_PART_TITLE: wlr_xcursor_manager_set_cursor_image( server->cursor_mgr, XCURSOR_DEFAULT, server->cursor); break; + case LAB_DECO_PART_TOP: + wlr_xcursor_manager_set_cursor_image( + server->cursor_mgr, "top_side", server->cursor); + break; + case LAB_DECO_PART_RIGHT: + wlr_xcursor_manager_set_cursor_image( + server->cursor_mgr, "right_side", server->cursor); + break; + case LAB_DECO_PART_BOTTOM: + wlr_xcursor_manager_set_cursor_image( + server->cursor_mgr, "bottom_side", server->cursor); + break; case LAB_DECO_PART_LEFT: wlr_xcursor_manager_set_cursor_image( server->cursor_mgr, "left_side", server->cursor); @@ -186,9 +198,21 @@ void cursor_button(struct wl_listener *listener, void *data) /* Focus that client if the button was _pressed_ */ view_focus(view); switch (view_area) { - case LAB_DECO_PART_TOP: + case LAB_DECO_PART_TITLE: interactive_begin(view, LAB_CURSOR_MOVE, 0); break; + case LAB_DECO_PART_TOP: + interactive_begin(view, LAB_CURSOR_RESIZE, + WLR_EDGE_TOP); + break; + case LAB_DECO_PART_RIGHT: + interactive_begin(view, LAB_CURSOR_RESIZE, + WLR_EDGE_RIGHT); + break; + case LAB_DECO_PART_BOTTOM: + interactive_begin(view, LAB_CURSOR_RESIZE, + WLR_EDGE_BOTTOM); + break; case LAB_DECO_PART_LEFT: interactive_begin(view, LAB_CURSOR_RESIZE, WLR_EDGE_LEFT); diff --git a/src/deco.c b/src/deco.c index f5029688..485f6e98 100644 --- a/src/deco.c +++ b/src/deco.c @@ -18,18 +18,37 @@ struct wlr_box deco_box(struct view *view, enum deco_part deco_part) if (!view || !view->surface) return box; switch (deco_part) { + case LAB_DECO_PART_TITLE: + box.x = view->x; + box.y = view->y - XWL_TITLEBAR_HEIGHT; + box.width = view->surface->current.width; + box.height = XWL_TITLEBAR_HEIGHT; + break; case LAB_DECO_PART_TOP: box.x = view->x - XWL_WINDOW_BORDER; box.y = view->y - XWL_TITLEBAR_HEIGHT - XWL_WINDOW_BORDER; box.width = view->surface->current.width + 2 * XWL_WINDOW_BORDER; - box.height = XWL_TITLEBAR_HEIGHT + XWL_WINDOW_BORDER; + box.height = + XWL_WINDOW_BORDER; + break; + case LAB_DECO_PART_RIGHT: + box.x = view->x + view->surface->current.width; + box.y = view->y - XWL_TITLEBAR_HEIGHT; + box.width = XWL_WINDOW_BORDER; + box.height = view->surface->current.height + XWL_TITLEBAR_HEIGHT; + break; + case LAB_DECO_PART_BOTTOM: + box.x = view->x - XWL_WINDOW_BORDER; + box.y = view->y + view->surface->current.height; + box.width = + view->surface->current.width + 2 * XWL_WINDOW_BORDER; + box.height = + XWL_WINDOW_BORDER; break; case LAB_DECO_PART_LEFT: box.x = view->x - XWL_WINDOW_BORDER; - box.y = view->y; + box.y = view->y - XWL_TITLEBAR_HEIGHT; box.width = XWL_WINDOW_BORDER; - box.height = view->surface->current.height; + box.height = view->surface->current.height + XWL_TITLEBAR_HEIGHT; break; default: break; diff --git a/src/output.c b/src/output.c index d89185ac..8e577fa6 100644 --- a/src/output.c +++ b/src/output.c @@ -1,12 +1,19 @@ #include "labwc.h" -struct render_data { - struct wlr_output *output; +static float window_active_title_bg[] = { 0.29, 0.55, 0.78, 1.0 }; +static float window_active_handle_bg[] = { 0.21, 0.49, 0.71, 1.0 }; + +struct draw_data { struct wlr_renderer *renderer; - struct view *view; - struct timespec *when; + float *transform_matrix; + float *rgba; }; +static void draw_rect(struct draw_data *d, struct wlr_box box) +{ + wlr_render_rect(d->renderer, &box, d->rgba, d->transform_matrix); +} + static void render_cycle_box(struct output *output) { if (!output->server->cycle_view) @@ -34,20 +41,28 @@ static void render_decorations(struct wlr_output *output, struct view *view) { if (!view_want_deco(view)) return; + struct draw_data ddata = { + .renderer = view->server->renderer, + .transform_matrix = output->transform_matrix, + }; - struct wlr_box box = deco_max_extents(view); - float matrix[9]; - wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, - output->transform_matrix); - float color[] = { 0.2, 0.2, 0.7, 0.9 }; - wlr_render_quad_with_matrix(view->server->renderer, color, matrix); + ddata.rgba = window_active_handle_bg; + 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)); - box = deco_box(view, LAB_DECO_PART_TOP); - float color2[] = { 0.7, 0.2, 0.2, 0.9 }; - wlr_render_rect(view->server->renderer, &box, color2, - output->transform_matrix); + ddata.rgba = window_active_title_bg; + draw_rect(&ddata, deco_box(view, LAB_DECO_PART_TITLE)); } +struct render_data { + struct wlr_output *output; + struct wlr_renderer *renderer; + struct view *view; + struct timespec *when; +}; + static void render_surface(struct wlr_surface *surface, int sx, int sy, void *data) { diff --git a/src/view.c b/src/view.c index 3dc03070..22de3465 100644 --- a/src/view.c +++ b/src/view.c @@ -207,10 +207,22 @@ struct view *view_at(struct server *server, double lx, double ly, return view; if (!view_want_deco(view)) continue; + if (deco_at(view, lx, ly) == LAB_DECO_PART_TITLE) { + *view_area = LAB_DECO_PART_TITLE; + return view; + } if (deco_at(view, lx, ly) == LAB_DECO_PART_TOP) { *view_area = LAB_DECO_PART_TOP; return view; } + if (deco_at(view, lx, ly) == LAB_DECO_PART_RIGHT) { + *view_area = LAB_DECO_PART_RIGHT; + return view; + } + if (deco_at(view, lx, ly) == LAB_DECO_PART_BOTTOM) { + *view_area = LAB_DECO_PART_BOTTOM; + return view; + } if (deco_at(view, lx, ly) == LAB_DECO_PART_LEFT) { *view_area = LAB_DECO_PART_LEFT; return view; diff --git a/src/xwl.c b/src/xwl.c index c6e7806f..45995352 100644 --- a/src/xwl.c +++ b/src/xwl.c @@ -23,7 +23,7 @@ static void position(struct view *view) return; if (view->x || view->y) return; - box = deco_box(view, LAB_DECO_PART_TOP); + box = deco_box(view, LAB_DECO_PART_TITLE); view->y = box.height; box = deco_box(view, LAB_DECO_PART_LEFT); view->x = box.width;