Implement <resize><drawContents>

<resize><drawContents>[yes|no] configures whether to let the clients
redraw its window content content while resizing.

When <resize><drawContents> is set to no, a multi-rect is shown to
indicate the geometry of the resized window.
This commit is contained in:
tokyo4j 2024-05-29 11:06:39 +09:00 committed by Johan Malm
parent 25415eb7ab
commit bb1d0b4352
10 changed files with 113 additions and 12 deletions

View file

@ -456,6 +456,11 @@ extending outward from the snapped edge.
Default is Never. Default is Never.
*<resize><drawContents>* [yes|no]
Let the application redraw its contents while resizing. If disabled, an
outlined rectangle is shown to indicate the geometry of resized window.
Default is yes.
## KEYBOARD ## KEYBOARD
*<keyboard><numlock>* [on|off] *<keyboard><numlock>* [on|off]

View file

@ -103,8 +103,12 @@
<windowEdgeStrength>20</windowEdgeStrength> <windowEdgeStrength>20</windowEdgeStrength>
</resistance> </resistance>
<!-- Show a simple resize and move indicator --> <resize>
<resize popupShow="Never" /> <!-- Show a simple resize and move indicator -->
<popupShow>Never</popupShow>
<!-- Let client redraw its contents while resizing -->
<drawContents>yes</drawContents>
</resize>
<focus> <focus>
<followMouse>no</followMouse> <followMouse>no</followMouse>

View file

@ -118,6 +118,7 @@ struct rcxml {
enum tiling_events_mode snap_tiling_events_mode; enum tiling_events_mode snap_tiling_events_mode;
enum resize_indicator_mode resize_indicator; enum resize_indicator_mode resize_indicator;
bool resize_draw_contents;
struct { struct {
int popuptime; int popuptime;

13
include/resize-outlines.h Normal file
View file

@ -0,0 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_RESIZE_OUTLINES_H
#define LABWC_RESIZE_OUTLINES_H
#include <wlr/util/box.h>
struct view;
void resize_outlines_update(struct view *view, struct wlr_box new_geo);
void resize_outlines_finish(struct view *view);
bool resize_outlines_enabled(struct view *view);
#endif /* LABWC_RESIZE_OUTLINES_H */

View file

@ -238,6 +238,10 @@ struct view {
struct wlr_scene_rect *background; struct wlr_scene_rect *background;
struct scaled_font_buffer *text; struct scaled_font_buffer *text;
} resize_indicator; } resize_indicator;
struct resize_outlines {
struct wlr_box view_geo;
struct multi_rect *rect;
} resize_outlines;
struct foreign_toplevel { struct foreign_toplevel {
struct wlr_foreign_toplevel_handle_v1 *handle; struct wlr_foreign_toplevel_handle_v1 *handle;

View file

@ -1032,6 +1032,8 @@ entry(xmlNode *node, char *nodename, char *content)
} else { } else {
wlr_log(WLR_ERROR, "Invalid value for <resize popupShow />"); wlr_log(WLR_ERROR, "Invalid value for <resize popupShow />");
} }
} else if (!strcasecmp(nodename, "drawContents.resize")) {
set_bool(content, &rc.resize_draw_contents);
} else if (!strcasecmp(nodename, "mouseEmulation.tablet")) { } else if (!strcasecmp(nodename, "mouseEmulation.tablet")) {
set_bool(content, &rc.tablet.force_mouse_emulation); set_bool(content, &rc.tablet.force_mouse_emulation);
} else if (!strcasecmp(nodename, "mapToOutput.tablet")) { } else if (!strcasecmp(nodename, "mapToOutput.tablet")) {
@ -1271,6 +1273,7 @@ rcxml_init(void)
| LAB_VIEW_CRITERIA_NO_SKIP_WINDOW_SWITCHER; | LAB_VIEW_CRITERIA_NO_SKIP_WINDOW_SWITCHER;
rc.resize_indicator = LAB_RESIZE_INDICATOR_NEVER; rc.resize_indicator = LAB_RESIZE_INDICATOR_NEVER;
rc.resize_draw_contents = true;
rc.workspace_config.popuptime = INT_MIN; rc.workspace_config.popuptime = INT_MIN;
rc.workspace_config.min_nr_workspaces = 1; rc.workspace_config.min_nr_workspaces = 1;

View file

@ -24,6 +24,7 @@
#include "menu/menu.h" #include "menu/menu.h"
#include "regions.h" #include "regions.h"
#include "resistance.h" #include "resistance.h"
#include "resize-outlines.h"
#include "ssd.h" #include "ssd.h"
#include "view.h" #include "view.h"
#include "xwayland.h" #include "xwayland.h"
@ -306,7 +307,11 @@ process_cursor_resize(struct server *server, uint32_t time)
server->grab_box.width - new_view_geo.width; server->grab_box.width - new_view_geo.width;
} }
view_move_resize(view, new_view_geo); if (rc.resize_draw_contents) {
view_move_resize(view, new_view_geo);
} else {
resize_outlines_update(view, new_view_geo);
}
} }
void void
@ -1134,6 +1139,9 @@ cursor_finish_button_release(struct seat *seat)
if (server->input_mode == LAB_INPUT_STATE_MOVE if (server->input_mode == LAB_INPUT_STATE_MOVE
|| server->input_mode == LAB_INPUT_STATE_RESIZE) { || server->input_mode == LAB_INPUT_STATE_RESIZE) {
if (resize_outlines_enabled(server->grabbed_view)) {
resize_outlines_finish(server->grabbed_view);
}
/* Exit interactive move/resize mode */ /* Exit interactive move/resize mode */
interactive_finish(server->grabbed_view); interactive_finish(server->grabbed_view);
return true; return true;

View file

@ -20,6 +20,7 @@ labwc_sources = files(
'placement.c', 'placement.c',
'regions.c', 'regions.c',
'resistance.c', 'resistance.c',
'resize-outlines.c',
'seat.c', 'seat.c',
'server.c', 'server.c',
'session-lock.c', 'session-lock.c',

56
src/resize-outlines.c Normal file
View file

@ -0,0 +1,56 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <wlr/types/wlr_scene.h>
#include "common/graphic-helpers.h"
#include "ssd.h"
#include "resize-outlines.h"
#include "labwc.h"
bool
resize_outlines_enabled(struct view *view)
{
return view->resize_outlines.rect
&& view->resize_outlines.rect->tree->node.enabled;
}
void
resize_outlines_update(struct view *view, struct wlr_box new_geo)
{
struct resize_outlines *outlines = &view->resize_outlines;
if (!outlines->rect) {
float *colors[3] = {
view->server->theme->osd_bg_color,
view->server->theme->osd_label_text_color,
view->server->theme->osd_bg_color,
};
int width = 1;
outlines->rect = multi_rect_create(
view->scene_tree, colors, width);
}
struct border margin = ssd_get_margin(view->ssd);
struct wlr_box box = {
.x = new_geo.x - margin.left,
.y = new_geo.y - margin.top,
.width = new_geo.width + margin.left + margin.right,
.height = new_geo.height + margin.top + margin.bottom,
};
multi_rect_set_size(outlines->rect, box.width, box.height);
wlr_scene_node_set_position(&outlines->rect->tree->node,
box.x - view->current.x, box.y - view->current.y);
wlr_scene_node_set_enabled(
&view->resize_outlines.rect->tree->node, true);
outlines->view_geo = new_geo;
resize_indicator_update(view);
}
void
resize_outlines_finish(struct view *view)
{
view_move_resize(view, view->resize_outlines.view_geo);
wlr_scene_node_set_enabled(
&view->resize_outlines.rect->tree->node, false);
}

View file

@ -7,6 +7,7 @@
#include "common/scaled-font-buffer.h" #include "common/scaled-font-buffer.h"
#include "labwc.h" #include "labwc.h"
#include "resize-indicator.h" #include "resize-indicator.h"
#include "resize-outlines.h"
#include "view.h" #include "view.h"
static void static void
@ -159,25 +160,30 @@ resize_indicator_update(struct view *view)
char text[32]; /* 12345 x 12345 would be 13 chars + 1 null byte */ char text[32]; /* 12345 x 12345 would be 13 chars + 1 null byte */
int eff_height = view_effective_height(view, /* use_pending */ false); struct wlr_box view_box;
int eff_width = view->current.width; if (resize_outlines_enabled(view)) {
view_box = view->resize_outlines.view_geo;
} else {
view_box = view->current;
view_box.height = view_effective_height(view, /* use_pending */ false);
}
switch (view->server->input_mode) { switch (view->server->input_mode) {
case LAB_INPUT_STATE_RESIZE: case LAB_INPUT_STATE_RESIZE:
; /* works around "a label can only be part of a statement" */ ; /* works around "a label can only be part of a statement" */
struct view_size_hints hints = view_get_size_hints(view); struct view_size_hints hints = view_get_size_hints(view);
snprintf(text, sizeof(text), "%d x %d", snprintf(text, sizeof(text), "%d x %d",
MAX(0, eff_width - hints.base_width) MAX(0, view_box.width - hints.base_width)
/ MAX(1, hints.width_inc), / MAX(1, hints.width_inc),
MAX(0, eff_height - hints.base_height) MAX(0, view_box.height - hints.base_height)
/ MAX(1, hints.height_inc)); / MAX(1, hints.height_inc));
break; break;
case LAB_INPUT_STATE_MOVE: case LAB_INPUT_STATE_MOVE:
; /* works around "a label can only be part of a statement" */ ; /* works around "a label can only be part of a statement" */
struct border margin = ssd_get_margin(view->ssd); struct border margin = ssd_get_margin(view->ssd);
snprintf(text, sizeof(text), "%d , %d", snprintf(text, sizeof(text), "%d , %d",
view->current.x - margin.left, view_box.x - margin.left,
view->current.y - margin.top); view_box.y - margin.top);
break; break;
default: default:
wlr_log(WLR_ERROR, "Invalid input mode for indicator update %u", wlr_log(WLR_ERROR, "Invalid input mode for indicator update %u",
@ -194,9 +200,9 @@ resize_indicator_update(struct view *view)
resize_indicator_set_size(indicator, width); resize_indicator_set_size(indicator, width);
/* Center the indicator in the window */ /* Center the indicator in the window */
wlr_scene_node_set_position(&indicator->tree->node, int x = view_box.x - view->current.x + (view_box.width - indicator->width) / 2;
(eff_width - indicator->width) / 2, int y = view_box.y - view->current.y + (view_box.height - indicator->height) / 2;
(eff_height - indicator->height) / 2); wlr_scene_node_set_position(&indicator->tree->node, x, y);
scaled_font_buffer_update(indicator->text, text, width, &rc.font_osd, scaled_font_buffer_update(indicator->text, text, width, &rc.font_osd,
rc.theme->osd_label_text_color, rc.theme->osd_bg_color, rc.theme->osd_label_text_color, rc.theme->osd_bg_color,