mirror of
https://github.com/labwc/labwc.git
synced 2026-03-10 05:33:47 -04:00
Allow mouse movements to trigger SnapToEdge
This commit is contained in:
parent
4e3a03586a
commit
87f4a60e38
5 changed files with 53 additions and 2 deletions
|
|
@ -29,6 +29,14 @@
|
||||||
<raiseOnFocus>no</raiseOnFocus>
|
<raiseOnFocus>no</raiseOnFocus>
|
||||||
</focus>
|
</focus>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Set range to 0 to disable window snapping completely
|
||||||
|
-->
|
||||||
|
<snapping>
|
||||||
|
<range>1</range>
|
||||||
|
<topMaximize>yes</topMaximize>
|
||||||
|
</snapping>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Keybind actions are specified in labwc-actions(5)
|
Keybind actions are specified in labwc-actions(5)
|
||||||
The following keybind modifiers are supported:
|
The following keybind modifiers are supported:
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,10 @@ struct rcxml {
|
||||||
|
|
||||||
/* resistance */
|
/* resistance */
|
||||||
int screen_edge_strength;
|
int screen_edge_strength;
|
||||||
|
|
||||||
|
/* window snapping */
|
||||||
|
int snap_edge_range;
|
||||||
|
bool snap_top_maximize;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct rcxml rc;
|
extern struct rcxml rc;
|
||||||
|
|
|
||||||
|
|
@ -374,6 +374,10 @@ entry(xmlNode *node, char *nodename, char *content)
|
||||||
rc.repeat_delay = atoi(content);
|
rc.repeat_delay = atoi(content);
|
||||||
} else if (!strcasecmp(nodename, "screenEdgeStrength.resistance")) {
|
} else if (!strcasecmp(nodename, "screenEdgeStrength.resistance")) {
|
||||||
rc.screen_edge_strength = atoi(content);
|
rc.screen_edge_strength = atoi(content);
|
||||||
|
} else if (!strcasecmp(nodename, "range.snapping")) {
|
||||||
|
rc.snap_edge_range = atoi(content);
|
||||||
|
} else if (!strcasecmp(nodename, "topMaximize.snapping")) {
|
||||||
|
rc.snap_top_maximize = get_bool(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -470,6 +474,8 @@ rcxml_init()
|
||||||
rc.repeat_rate = 25;
|
rc.repeat_rate = 25;
|
||||||
rc.repeat_delay = 600;
|
rc.repeat_delay = 600;
|
||||||
rc.screen_edge_strength = 20;
|
rc.screen_edge_strength = 20;
|
||||||
|
rc.snap_edge_range = 1;
|
||||||
|
rc.snap_top_maximize = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
|
|
|
||||||
|
|
@ -607,8 +607,12 @@ cursor_button(struct wl_listener *listener, void *data)
|
||||||
damage_all_outputs(server);
|
damage_all_outputs(server);
|
||||||
if (server->input_mode != LAB_INPUT_STATE_PASSTHROUGH) {
|
if (server->input_mode != LAB_INPUT_STATE_PASSTHROUGH) {
|
||||||
/* Exit interactive move/resize/menu mode. */
|
/* Exit interactive move/resize/menu mode. */
|
||||||
server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
|
if (server->grabbed_view == view) {
|
||||||
server->grabbed_view = NULL;
|
interactive_end(view);
|
||||||
|
} else {
|
||||||
|
server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
|
||||||
|
server->grabbed_view = NULL;
|
||||||
|
}
|
||||||
cursor_rebase(&server->seat, event->time_msec);
|
cursor_rebase(&server->seat, event->time_msec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,36 @@ void
|
||||||
interactive_end(struct view *view)
|
interactive_end(struct view *view)
|
||||||
{
|
{
|
||||||
if (view->server->grabbed_view == view) {
|
if (view->server->grabbed_view == view) {
|
||||||
|
bool should_snap = view->server->input_mode == LAB_INPUT_STATE_MOVE
|
||||||
|
&& rc.snap_edge_range;
|
||||||
view->server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
|
view->server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
|
||||||
view->server->grabbed_view = NULL;
|
view->server->grabbed_view = NULL;
|
||||||
|
if (should_snap) {
|
||||||
|
int snap_range = rc.snap_edge_range;
|
||||||
|
struct wlr_box *area = &view->output->usable_area;
|
||||||
|
|
||||||
|
/* Translate into output local coordinates */
|
||||||
|
double cursor_x = view->server->seat.cursor->x;
|
||||||
|
double cursor_y = view->server->seat.cursor->y;
|
||||||
|
wlr_output_layout_output_coords(view->server->output_layout,
|
||||||
|
view->output->wlr_output, &cursor_x, &cursor_y);
|
||||||
|
|
||||||
|
if (cursor_x <= area->x + snap_range) {
|
||||||
|
view_snap_to_edge(view, "left");
|
||||||
|
} else if (cursor_x >= area->x + area->width - snap_range) {
|
||||||
|
view_snap_to_edge(view, "right");
|
||||||
|
} else if (cursor_y <= area->y + snap_range) {
|
||||||
|
if (rc.snap_top_maximize) {
|
||||||
|
view_maximize(view, true);
|
||||||
|
/* When unmaximizing later on restore original position */
|
||||||
|
view->unmaximized_geometry.x = view->server->grab_box.x;
|
||||||
|
view->unmaximized_geometry.y = view->server->grab_box.y;
|
||||||
|
} else {
|
||||||
|
view_snap_to_edge(view, "up");
|
||||||
|
}
|
||||||
|
} else if (cursor_y >= area->y + area->height - snap_range) {
|
||||||
|
view_snap_to_edge(view, "down");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue