overlay: add snap-to-edge overlay (PR #1652)

...and unify region overlay and snap-to-edge overlay into overlay.c.

Snap-to-edge overlay is delayed for 500ms to prevent flickering when
the view is dragged from an output to another (demo in discussion labwc#1613).

This also fixes a bug that region overlay is not shown when a modifier
key is re-pressed.
This commit is contained in:
Hiroaki Yamamoto 2024-04-05 11:35:31 +09:00 committed by GitHub
parent 67669dcf1e
commit 5cc0757390
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 361 additions and 152 deletions

View file

@ -125,6 +125,9 @@ struct rcxml {
/* window snapping */
int snap_edge_range;
bool snap_preview_enabled;
int snap_preview_delay_inner;
int snap_preview_delay_outer;
bool snap_top_maximize;
enum tiling_events_mode snap_tiling_events_mode;

View file

@ -47,6 +47,7 @@
#include "config/rcxml.h"
#include "input/cursor.h"
#include "input/ime.h"
#include "overlay.h"
#include "regions.h"
#include "session-lock.h"
#if HAVE_NLS
@ -159,9 +160,7 @@ struct seat {
struct wlr_scene_tree *icons;
} drag;
/* Private use by regions.c */
struct region *region_active;
struct region_overlay region_overlay;
struct overlay overlay;
/* Used to prevent region snapping when starting a move with A-Left */
bool region_prevent_snap;
@ -479,6 +478,8 @@ void seat_output_layout_changed(struct seat *seat);
void interactive_begin(struct view *view, enum input_mode mode, uint32_t edges);
void interactive_finish(struct view *view);
void interactive_cancel(struct view *view);
/* Possibly returns VIEW_EDGE_CENTER if <topMaximize> is yes */
enum view_edge edge_from_cursor(struct seat *seat, struct output **dest_output);
void output_init(struct server *server);
void output_manager_init(struct server *server);

36
include/overlay.h Normal file
View file

@ -0,0 +1,36 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_OVERLAY_H
#define LABWC_OVERLAY_H
#include <wlr/util/box.h>
#include "common/graphic-helpers.h"
#include "regions.h"
#include "view.h"
struct overlay {
struct wlr_scene_tree *tree;
union {
struct wlr_scene_rect *rect;
struct multi_rect *pixman_rect;
};
/* Represents currently shown or delayed overlay */
struct {
/* Region overlay */
struct region *region;
/* Snap-to-edge overlay */
enum view_edge edge;
struct output *output;
} active;
/* For delayed snap-to-edge overlay */
struct wl_event_source *timer;
};
/* Calls overlay_hide() internally if there's no overlay to show */
void overlay_update(struct seat *seat);
/* This function must be called when server->grabbed_view is destroyed */
void overlay_hide(struct seat *seat);
#endif

View file

@ -25,14 +25,6 @@ struct region {
} center;
};
struct region_overlay {
struct wlr_scene_tree *tree;
union {
struct wlr_scene_rect *overlay;
struct multi_rect *pixman_overlay;
};
};
/* Returns true if we should show the region overlay or snap to region */
bool regions_should_snap(struct server *server);
@ -73,7 +65,4 @@ void regions_destroy(struct seat *seat, struct wl_list *regions);
struct region *regions_from_cursor(struct server *server);
struct region *regions_from_name(const char *region_name, struct output *output);
void regions_show_overlay(struct view *view, struct seat *seat, struct region *region);
void regions_hide_overlay(struct seat *seat);
#endif /* LABWC_REGIONS_H */