mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 00:11:28 +00:00
Add pointer_constraint command
This commit is contained in:
parent
ee4b8a3938
commit
a6d41254c9
|
@ -153,6 +153,7 @@ sway_cmd cmd_new_window;
|
||||||
sway_cmd cmd_no_focus;
|
sway_cmd cmd_no_focus;
|
||||||
sway_cmd cmd_output;
|
sway_cmd cmd_output;
|
||||||
sway_cmd cmd_permit;
|
sway_cmd cmd_permit;
|
||||||
|
sway_cmd cmd_pointer_constraint;
|
||||||
sway_cmd cmd_popup_during_fullscreen;
|
sway_cmd cmd_popup_during_fullscreen;
|
||||||
sway_cmd cmd_reject;
|
sway_cmd cmd_reject;
|
||||||
sway_cmd cmd_reload;
|
sway_cmd cmd_reload;
|
||||||
|
|
|
@ -143,6 +143,7 @@ struct seat_config {
|
||||||
int fallback; // -1 means not set
|
int fallback; // -1 means not set
|
||||||
list_t *attachments; // list of seat_attachment configs
|
list_t *attachments; // list of seat_attachment configs
|
||||||
int hide_cursor_timeout;
|
int hide_cursor_timeout;
|
||||||
|
bool allow_constrain;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum config_dpms {
|
enum config_dpms {
|
||||||
|
|
|
@ -81,6 +81,7 @@ static struct cmd_handler handlers[] = {
|
||||||
{ "no_focus", cmd_no_focus },
|
{ "no_focus", cmd_no_focus },
|
||||||
{ "output", cmd_output },
|
{ "output", cmd_output },
|
||||||
{ "popup_during_fullscreen", cmd_popup_during_fullscreen },
|
{ "popup_during_fullscreen", cmd_popup_during_fullscreen },
|
||||||
|
{ "pointer_constraint", cmd_pointer_constraint },
|
||||||
{ "seat", cmd_seat },
|
{ "seat", cmd_seat },
|
||||||
{ "set", cmd_set },
|
{ "set", cmd_set },
|
||||||
{ "show_marks", cmd_show_marks },
|
{ "show_marks", cmd_show_marks },
|
||||||
|
|
51
sway/commands/pointer_constraint.c
Normal file
51
sway/commands/pointer_constraint.c
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#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);
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ struct seat_config *new_seat_config(const char* name) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
seat->hide_cursor_timeout = -1;
|
seat->hide_cursor_timeout = -1;
|
||||||
|
seat->allow_constrain = true;
|
||||||
|
|
||||||
return seat;
|
return seat;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1454,6 +1454,11 @@ void handle_pointer_constraint(struct wl_listener *listener, void *data) {
|
||||||
|
|
||||||
void sway_cursor_constrain(struct sway_cursor *cursor,
|
void sway_cursor_constrain(struct sway_cursor *cursor,
|
||||||
struct wlr_pointer_constraint_v1 *constraint) {
|
struct wlr_pointer_constraint_v1 *constraint) {
|
||||||
|
struct seat_config *config = seat_get_config(cursor->seat);
|
||||||
|
if (!config->allow_constrain) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (cursor->active_constraint == constraint) {
|
if (cursor->active_constraint == constraint) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ sway_sources = files(
|
||||||
'commands/nop.c',
|
'commands/nop.c',
|
||||||
'commands/output.c',
|
'commands/output.c',
|
||||||
'commands/popup_during_fullscreen.c',
|
'commands/popup_during_fullscreen.c',
|
||||||
|
'commands/pointer_constraint.c',
|
||||||
'commands/reload.c',
|
'commands/reload.c',
|
||||||
'commands/rename.c',
|
'commands/rename.c',
|
||||||
'commands/resize.c',
|
'commands/resize.c',
|
||||||
|
|
|
@ -539,6 +539,11 @@ The default colors are:
|
||||||
\* may be used in lieu of a specific output name to configure all outputs.
|
\* 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*.
|
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
|
*popup_during_fullscreen* smart|ignore|leave_fullscreen
|
||||||
Determines what to do when a fullscreen view opens a dialog.
|
Determines what to do when a fullscreen view opens a dialog.
|
||||||
If _smart_ (the default), the dialog will be displayed. If _ignore_, the
|
If _smart_ (the default), the dialog will be displayed. If _ignore_, the
|
||||||
|
|
Loading…
Reference in a new issue