Merge pull request #1684 from swaywm/follow-warp

Implement focus_follows_mouse, mouse_warping
This commit is contained in:
Drew DeVault 2018-03-31 15:32:29 -04:00 committed by GitHub
commit 122b96abed
Failed to generate hash of commit
9 changed files with 95 additions and 34 deletions

View file

@ -304,7 +304,6 @@ struct sway_config {
bool reloading;
bool reading;
bool auto_back_and_forth;
bool seamless_mouse;
bool show_marks;
bool edge_gaps;

View file

@ -56,6 +56,9 @@ void sway_seat_configure_xcursor(struct sway_seat *seat);
void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *container);
void sway_seat_set_focus_warp(struct sway_seat *seat,
struct sway_container *container, bool warp);
struct sway_container *sway_seat_get_focus(struct sway_seat *seat);
/**

View file

@ -98,9 +98,11 @@ static struct cmd_handler handlers[] = {
{ "bindsym", cmd_bindsym },
{ "exec", cmd_exec },
{ "exec_always", cmd_exec_always },
{ "focus_follows_mouse", cmd_focus_follows_mouse },
{ "include", cmd_include },
{ "input", cmd_input },
{ "mode", cmd_mode },
{ "mouse_warping", cmd_mouse_warping },
{ "output", cmd_output },
{ "seat", cmd_seat },
{ "workspace", cmd_workspace },

View file

@ -0,0 +1,12 @@
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) {
return error;
}
config->focus_follows_mouse = !strcasecmp(argv[0], "yes");
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -0,0 +1,19 @@
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) {
return error;
} else if (strcasecmp(argv[0], "output") == 0) {
config->mouse_warping = true;
} else if (strcasecmp(argv[0], "none") == 0) {
config->mouse_warping = false;
} else {
return cmd_results_new(CMD_FAILURE, "mouse_warping",
"Expected 'mouse_warping output|none'");
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -178,7 +178,6 @@ static void config_defaults(struct sway_config *config) {
config->active = false;
config->failed = false;
config->auto_back_and_forth = false;
config->seamless_mouse = true;
config->reading = false;
config->show_marks = true;

View file

@ -127,7 +127,10 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
struct wlr_seat *seat = cursor->seat->wlr_seat;
struct wlr_surface *surface = NULL;
double sx, sy;
container_at_cursor(cursor, &surface, &sx, &sy);
struct sway_container *c = container_at_cursor(cursor, &surface, &sx, &sy);
if (c && config->focus_follows_mouse) {
sway_seat_set_focus_warp(cursor->seat, c, false);
}
// reset cursor if switching between clients
struct wl_client *client = NULL;
@ -158,8 +161,8 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) {
cursor_send_pointer_motion(cursor, event->time_msec);
}
static void handle_cursor_motion_absolute(struct wl_listener *listener,
void *data) {
static void handle_cursor_motion_absolute(
struct wl_listener *listener, void *data) {
struct sway_cursor *cursor =
wl_container_of(listener, cursor, motion_absolute);
struct wlr_event_pointer_motion_absolute *event = data;
@ -172,7 +175,6 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
struct wlr_event_pointer_button *event = data;
if (event->button == BTN_LEFT) {
struct wlr_surface *surface = NULL;
double sx, sy;
struct sway_container *cont =
@ -199,7 +201,6 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
} else {
sway_seat_set_focus(cursor->seat, cont);
}
}
wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec,
event->button, event->state);

View file

@ -1,5 +1,6 @@
#define _XOPEN_SOURCE 700
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include "sway/tree/container.h"
#include "sway/input/seat.h"
@ -291,8 +292,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
seat->cursor->cursor->y);
}
void sway_seat_set_focus(struct sway_seat *seat,
struct sway_container *container) {
void sway_seat_set_focus_warp(struct sway_seat *seat,
struct sway_container *container, bool warp) {
struct sway_container *last_focus = sway_seat_get_focus(seat);
if (container && last_focus == container) {
@ -333,15 +334,33 @@ void sway_seat_set_focus(struct sway_seat *seat,
if (last_focus) {
struct sway_container *last_ws = last_focus;
if (last_ws && last_ws->type != C_WORKSPACE) {
last_ws = container_parent(last_focus, C_WORKSPACE);
last_ws = container_parent(last_ws, C_WORKSPACE);
}
if (last_ws) {
wlr_log(L_DEBUG, "sending workspace event");
ipc_event_workspace(last_ws, container, "focus");
if (last_ws->children->length == 0) {
container_workspace_destroy(last_ws);
}
}
struct sway_container *last_output = last_focus;
if (last_output && last_output->type != C_OUTPUT) {
last_output = container_parent(last_output, C_OUTPUT);
}
struct sway_container *new_output = container;
if (new_output && new_output->type != C_OUTPUT) {
new_output = container_parent(new_output, C_OUTPUT);
}
if (new_output && last_output && new_output != last_output
&& config->mouse_warping && warp) {
struct wlr_output *output = new_output->sway_output->wlr_output;
double x = container->x + output->lx + container->width / 2.0;
double y = container->y + output->ly + container->height / 2.0;
if (!wlr_output_layout_contains_point(
root_container.sway_root->output_layout,
output, seat->cursor->cursor->x, seat->cursor->cursor->y)) {
wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
}
}
}
if (last_focus && last_focus->type == C_VIEW &&
@ -353,6 +372,11 @@ void sway_seat_set_focus(struct sway_seat *seat,
seat->has_focus = (container != NULL);
}
void sway_seat_set_focus(struct sway_seat *seat,
struct sway_container *container) {
sway_seat_set_focus_warp(seat, container, true);
}
struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *container) {
struct sway_seat_container *current = NULL;
struct sway_container *parent = NULL;

View file

@ -13,6 +13,7 @@ sway_sources = files(
'commands/exec.c',
'commands/exec_always.c',
'commands/focus.c',
'commands/focus_follows_mouse.c',
'commands/kill.c',
'commands/include.c',
'commands/input.c',
@ -63,6 +64,7 @@ sway_sources = files(
'commands/input/xkb_options.c',
'commands/input/xkb_rules.c',
'commands/input/xkb_variant.c',
'commands/mouse_warping.c',
'commands/output.c',
'commands/reload.c',
'commands/workspace.c',