commit 47271552b0f5ae5dbba6efd3882e5cce2d83070e
parent 204e1f47122d5a48865802dd1fb94fe0f05c2401
Author: Drew DeVault <sir@cmpwn.com>
Date: Fri, 1 Feb 2019 09:26:30 +0100
Merge pull request #3550 from RedSoxFan/seat-pointer-constraint
pointer_constraint: change to a seat subcommand
Diffstat:
11 files changed, 79 insertions(+), 62 deletions(-)
diff --git a/include/sway/commands.h b/include/sway/commands.h
@@ -153,7 +153,6 @@ sway_cmd cmd_new_window;
sway_cmd cmd_no_focus;
sway_cmd cmd_output;
sway_cmd cmd_permit;
-sway_cmd cmd_pointer_constraint;
sway_cmd cmd_popup_during_fullscreen;
sway_cmd cmd_reject;
sway_cmd cmd_reload;
@@ -268,6 +267,7 @@ sway_cmd seat_cmd_attach;
sway_cmd seat_cmd_cursor;
sway_cmd seat_cmd_fallback;
sway_cmd seat_cmd_hide_cursor;
+sway_cmd seat_cmd_pointer_constraint;
sway_cmd cmd_ipc_cmd;
sway_cmd cmd_ipc_events;
diff --git a/include/sway/config.h b/include/sway/config.h
@@ -135,6 +135,12 @@ struct seat_attachment_config {
// TODO other things are configured here for some reason
};
+enum seat_config_allow_constrain {
+ CONSTRAIN_DEFAULT, // the default is currently enabled
+ CONSTRAIN_ENABLE,
+ CONSTRAIN_DISABLE
+};
+
/**
* Options for multiseat and other misc device configurations
*/
@@ -143,7 +149,7 @@ struct seat_config {
int fallback; // -1 means not set
list_t *attachments; // list of seat_attachment configs
int hide_cursor_timeout;
- bool allow_constrain;
+ enum seat_config_allow_constrain allow_constrain;
};
enum config_dpms {
diff --git a/sway/commands.c b/sway/commands.c
@@ -81,7 +81,6 @@ static struct cmd_handler handlers[] = {
{ "no_focus", cmd_no_focus },
{ "output", cmd_output },
{ "popup_during_fullscreen", cmd_popup_during_fullscreen },
- { "pointer_constraint", cmd_pointer_constraint },
{ "seat", cmd_seat },
{ "set", cmd_set },
{ "show_marks", cmd_show_marks },
diff --git a/sway/commands/pointer_constraint.c b/sway/commands/pointer_constraint.c
@@ -1,51 +0,0 @@
-#include <string.h>
-#include <wlr/types/wlr_pointer_constraints_v1.h>
-#include "sway/commands.h"
-#include "sway/config.h"
-#include "sway/input/cursor.h"
-#include "sway/input/seat.h"
-
-enum operation {
- OP_ENABLE,
- OP_DISABLE,
- OP_ESCAPE,
-};
-
-// pointer_constraint [enable|disable|escape]
-struct cmd_results *cmd_pointer_constraint(int argc, char **argv) {
- struct cmd_results *error = NULL;
- if ((error = checkarg(argc, "pointer_constraint", EXPECTED_EQUAL_TO, 1))) {
- return error;
- }
-
- enum operation op;
- if (strcmp(argv[0], "enable") == 0) {
- op = OP_ENABLE;
- } else if (strcmp(argv[0], "disable") == 0) {
- op = OP_DISABLE;
- } else if (strcmp(argv[0], "escape") == 0) {
- op = OP_ESCAPE;
- } else {
- return cmd_results_new(CMD_FAILURE, "Expected enable|disable|escape");
- }
-
- if (op == OP_ESCAPE && config->reading) {
- return cmd_results_new(CMD_FAILURE, "Can only escape at runtime.");
- }
-
- struct sway_cursor *cursor = config->handler_context.seat->cursor;
- struct seat_config *seat_config = seat_get_config(cursor->seat);
- switch (op) {
- case OP_ENABLE:
- seat_config->allow_constrain = true;
- break;
- case OP_DISABLE:
- seat_config->allow_constrain = false;
- /* fallthrough */
- case OP_ESCAPE:
- sway_cursor_constrain(cursor, NULL);
- break;
- }
-
- return cmd_results_new(CMD_SUCCESS, NULL);
-}
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
@@ -11,6 +11,7 @@ static struct cmd_handler seat_handlers[] = {
{ "cursor", seat_cmd_cursor },
{ "fallback", seat_cmd_fallback },
{ "hide_cursor", seat_cmd_hide_cursor },
+ { "pointer_constraint", seat_cmd_pointer_constraint },
};
struct cmd_results *cmd_seat(int argc, char **argv) {
diff --git a/sway/commands/seat/pointer_constraint.c b/sway/commands/seat/pointer_constraint.c
@@ -0,0 +1,58 @@
+#include <string.h>
+#include <wlr/types/wlr_pointer_constraints_v1.h>
+#include "sway/commands.h"
+#include "sway/config.h"
+#include "sway/input/cursor.h"
+#include "sway/input/seat.h"
+
+enum operation {
+ OP_ENABLE,
+ OP_DISABLE,
+ OP_ESCAPE,
+};
+
+// pointer_constraint [enable|disable|escape]
+struct cmd_results *seat_cmd_pointer_constraint(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "pointer_constraint", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->handler_context.seat_config) {
+ return cmd_results_new(CMD_FAILURE, "No seat defined");
+ }
+
+ enum operation op;
+ if (strcmp(argv[0], "enable") == 0) {
+ op = OP_ENABLE;
+ } else if (strcmp(argv[0], "disable") == 0) {
+ op = OP_DISABLE;
+ } else if (strcmp(argv[0], "escape") == 0) {
+ op = OP_ESCAPE;
+ } else {
+ return cmd_results_new(CMD_FAILURE, "Expected enable|disable|escape");
+ }
+
+ if (op == OP_ESCAPE && config->reading) {
+ return cmd_results_new(CMD_FAILURE, "Can only escape at runtime.");
+ }
+
+ struct seat_config *seat_config = config->handler_context.seat_config;
+ switch (op) {
+ case OP_ENABLE:
+ seat_config->allow_constrain = CONSTRAIN_ENABLE;
+ break;
+ case OP_DISABLE:
+ seat_config->allow_constrain = CONSTRAIN_DISABLE;
+ /* fallthrough */
+ case OP_ESCAPE:;
+ bool wildcard = !strcmp(seat_config->name, "*");
+ struct sway_seat *seat = NULL;
+ wl_list_for_each(seat, &server.input->seats, link) {
+ if (wildcard || !strcmp(seat->wlr_seat->name, seat_config->name)) {
+ sway_cursor_constrain(seat->cursor, NULL);
+ }
+ }
+ break;
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL);
+}
diff --git a/sway/config/seat.c b/sway/config/seat.c
@@ -26,7 +26,7 @@ struct seat_config *new_seat_config(const char* name) {
return NULL;
}
seat->hide_cursor_timeout = -1;
- seat->allow_constrain = true;
+ seat->allow_constrain = CONSTRAIN_DEFAULT;
return seat;
}
@@ -143,6 +143,10 @@ void merge_seat_config(struct seat_config *dest, struct seat_config *source) {
if (source->hide_cursor_timeout != -1) {
dest->hide_cursor_timeout = source->hide_cursor_timeout;
}
+
+ if (source->allow_constrain != CONSTRAIN_DEFAULT) {
+ dest->allow_constrain = source->allow_constrain;
+ }
}
struct seat_config *copy_seat_config(struct seat_config *seat) {
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
@@ -1458,7 +1458,7 @@ void handle_pointer_constraint(struct wl_listener *listener, void *data) {
void sway_cursor_constrain(struct sway_cursor *cursor,
struct wlr_pointer_constraint_v1 *constraint) {
struct seat_config *config = seat_get_config(cursor->seat);
- if (!config->allow_constrain) {
+ if (config->allow_constrain == CONSTRAIN_DISABLE) {
return;
}
diff --git a/sway/meson.build b/sway/meson.build
@@ -75,7 +75,6 @@ sway_sources = files(
'commands/nop.c',
'commands/output.c',
'commands/popup_during_fullscreen.c',
- 'commands/pointer_constraint.c',
'commands/reload.c',
'commands/rename.c',
'commands/resize.c',
@@ -85,6 +84,7 @@ sway_sources = files(
'commands/seat/cursor.c',
'commands/seat/fallback.c',
'commands/seat/hide_cursor.c',
+ 'commands/seat/pointer_constraint.c',
'commands/set.c',
'commands/show_marks.c',
'commands/smart_borders.c',
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd
@@ -172,6 +172,11 @@ in their own "seat").
disables hiding the cursor. The minimal timeout is 100 and any value less
than that (aside from 0), will be increased to 100.
+*seat* <name> pointer_constraint enable|disable|escape
+ Enables or disables the ability for clients to capture the cursor (enabled
+ by default) for the seat. This is primarily useful for video games. The
+ "escape" command can be used at runtime to escape from a captured client.
+
# SEE ALSO
*sway*(5) *sway-output*(5)
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
@@ -552,11 +552,6 @@ The default colors are:
\* may be used in lieu of a specific output name to configure all outputs.
A list of output names may be obtained via *swaymsg -t get_outputs*.
-*pointer_constraint* enable|disable|escape
- Enables or disables the ability for clients to capture the cursor (enabled
- by default). This is primarily useful for video games. The "escape" command
- can be used at runtime to escape from a captured client.
-
*popup_during_fullscreen* smart|ignore|leave_fullscreen
Determines what to do when a fullscreen view opens a dialog.
If _smart_ (the default), the dialog will be displayed. If _ignore_, the