diff options
54 files changed, 1640 insertions, 1417 deletions
diff --git a/completions/bash/swayidle b/completions/bash/swayidle deleted file mode 100644 index a0cdc8b2..00000000 --- a/completions/bash/swayidle +++ /dev/null @@ -1,48 +0,0 @@ -# swaymsg(1) completion - -_swayidle() -{ - local cur prev - _get_comp_words_by_ref -n : cur prev - local prev2=${COMP_WORDS[COMP_CWORD-2]} - local prev3=${COMP_WORDS[COMP_CWORD-3]} - - events=( - 'timeout' - 'before-sleep' - ) - - short=( - -h - -d - ) - - if [ "$prev" = timeout ]; then - # timeout <timeout> - return - elif [ "$prev2" = timeout ]; then - # timeout <timeout> <timeout command> - COMPREPLY=($(compgen -c -- "$cur")) - return - elif [ "$prev3" = timeout ]; then - # timeout <timeout> <timeout command> [resume <resume command>] - COMPREPLY=(resume) - # optional argument; no return here as user may skip 'resume' - fi - - case "$prev" in - resume) - COMPREPLY=($(compgen -c -- "$cur")) - return - ;; - before-sleep) - COMPREPLY=($(compgen -c -- "$cur")) - return - ;; - esac - - COMPREPLY+=($(compgen -W "${events[*]}" -- "$cur")) - COMPREPLY+=($(compgen -W "${short[*]}" -- "$cur")) - -} && -complete -F _swayidle swayidle diff --git a/completions/fish/swayidle.fish b/completions/fish/swayidle.fish deleted file mode 100644 index 71279925..00000000 --- a/completions/fish/swayidle.fish +++ /dev/null @@ -1,3 +0,0 @@ -# swayidle -complete -c swayidle -s h --description 'show help' -complete -c swayidle -s d --description 'debug' diff --git a/completions/zsh/_swayidle b/completions/zsh/_swayidle deleted file mode 100644 index b419bc2c..00000000 --- a/completions/zsh/_swayidle +++ /dev/null @@ -1,22 +0,0 @@ -#compdef swayidle -# -# Completion script for swayidle -# - -local events=('timeout:Execute timeout command if there is no activity for timeout seconds' - 'before-sleep:Execute before-sleep command before sleep') -local resume=('resume:Execute command when there is activity again') - -if (($#words <= 2)); then - _arguments -C \ - '(-h --help)'{-h,--help}'[Show help message and quit]' \ - '(-d)'-d'[Enable debug output]' - _describe -t "events" 'swayidle' events - -elif [[ "$words[-3]" == before-sleep || "$words[-3]" == resume ]]; then - _describe -t "events" 'swayidle' events - -elif [[ "$words[-4]" == timeout ]]; then - _describe -t "events" 'swayidle' events - _describe -t "resume" 'swayidle' resume -fi diff --git a/include/sway/commands.h b/include/sway/commands.h index ffc18789..ec21f4e1 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -199,6 +199,8 @@ sway_cmd bar_cmd_id; sway_cmd bar_cmd_position; sway_cmd bar_cmd_separator_symbol; sway_cmd bar_cmd_status_command; +sway_cmd bar_cmd_status_edge_padding; +sway_cmd bar_cmd_status_padding; sway_cmd bar_cmd_pango_markup; sway_cmd bar_cmd_strip_workspace_numbers; sway_cmd bar_cmd_strip_workspace_name; diff --git a/include/sway/config.h b/include/sway/config.h index 29c21afe..a667984d 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -232,6 +232,8 @@ struct bar_config { bool verbose; struct side_gaps gaps; pid_t pid; + int status_padding; + int status_edge_padding; struct { char *background; char *statusline; diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 4636bf6b..77aa0ea1 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -50,6 +50,12 @@ struct sway_cursor { size_t pressed_button_count; }; +struct sway_node; + +struct sway_node *node_at_coords( + struct sway_seat *seat, double lx, double ly, + struct wlr_surface **surface, double *sx, double *sy); + void sway_cursor_destroy(struct sway_cursor *cursor); struct sway_cursor *sway_cursor_create(struct sway_seat *seat); @@ -74,6 +80,9 @@ void dispatch_cursor_button(struct sway_cursor *cursor, struct wlr_input_device *device, uint32_t time_msec, uint32_t button, enum wlr_button_state state); +void dispatch_cursor_axis(struct sway_cursor *cursor, + struct wlr_event_pointer_axis *event); + void cursor_set_image(struct sway_cursor *cursor, const char *image, struct wl_client *client); diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index 08e749dc..8e8bf1f2 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -37,6 +37,10 @@ void input_manager_configure_xcursor(void); void input_manager_apply_input_config(struct input_config *input_config); +void input_manager_reset_input(struct sway_input_device *input_device); + +void input_manager_reset_all_inputs(); + void input_manager_apply_seat_config(struct seat_config *seat_config); struct sway_seat *input_manager_get_default_seat(void); diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index a3c20346..d2f14895 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -6,6 +6,17 @@ #include <wlr/util/edges.h> #include "sway/input/input-manager.h" +struct sway_seat; + +struct sway_seatop_impl { + void (*motion)(struct sway_seat *seat, uint32_t time_msec); + void (*finish)(struct sway_seat *seat); + void (*abort)(struct sway_seat *seat); + void (*unref)(struct sway_seat *seat, struct sway_container *con); + void (*render)(struct sway_seat *seat, struct sway_output *output, + pixman_region32_t *damage); +}; + struct sway_seat_device { struct sway_seat *sway_seat; struct sway_input_device *input_device; @@ -35,16 +46,6 @@ struct sway_drag_icon { struct wl_listener destroy; }; -enum sway_seat_operation { - OP_NONE, - OP_DOWN, - OP_MOVE_FLOATING, - OP_MOVE_TILING_THRESHOLD, - OP_MOVE_TILING, - OP_RESIZE_FLOATING, - OP_RESIZE_TILING, -}; - struct sway_seat { struct wlr_seat *wlr_seat; struct sway_cursor *cursor; @@ -64,19 +65,10 @@ struct sway_seat { int32_t touch_id; double touch_x, touch_y; - // Operations (drag and resize) - enum sway_seat_operation operation; - struct sway_container *op_container; - struct sway_node *op_target_node; // target for tiling move - enum wlr_edges op_target_edge; - struct wlr_box op_drop_box; - enum wlr_edges op_resize_edge; - uint32_t op_button; - bool op_resize_preserve_ratio; - double op_ref_lx, op_ref_ly; // cursor's x/y at start of op - double op_ref_width, op_ref_height; // container's size at start of op - double op_ref_con_lx, op_ref_con_ly; // container's x/y at start of op - bool op_moved; // if the mouse moved during a down op + // Seat operations (drag and resize) + const struct sway_seatop_impl *seatop_impl; + void *seatop_data; + uint32_t seatop_button; uint32_t last_button; uint32_t last_button_serial; @@ -100,6 +92,9 @@ void seat_add_device(struct sway_seat *seat, void seat_configure_device(struct sway_seat *seat, struct sway_input_device *device); +void seat_reset_device(struct sway_seat *seat, + struct sway_input_device *input_device); + void seat_remove_device(struct sway_seat *seat, struct sway_input_device *device); @@ -181,32 +176,59 @@ bool seat_is_input_allowed(struct sway_seat *seat, struct wlr_surface *surface); void drag_icon_update_position(struct sway_drag_icon *icon); -void seat_begin_down(struct sway_seat *seat, struct sway_container *con, - uint32_t button, double sx, double sy); +void seatop_begin_down(struct sway_seat *seat, + struct sway_container *con, uint32_t button, int sx, int sy); -void seat_begin_move_floating(struct sway_seat *seat, +void seatop_begin_move_floating(struct sway_seat *seat, struct sway_container *con, uint32_t button); -void seat_begin_move_tiling_threshold(struct sway_seat *seat, +void seatop_begin_move_tiling_threshold(struct sway_seat *seat, struct sway_container *con, uint32_t button); -void seat_begin_move_tiling(struct sway_seat *seat, +void seatop_begin_move_tiling(struct sway_seat *seat, struct sway_container *con, uint32_t button); -void seat_begin_resize_floating(struct sway_seat *seat, +void seatop_begin_resize_floating(struct sway_seat *seat, struct sway_container *con, uint32_t button, enum wlr_edges edge); -void seat_begin_resize_tiling(struct sway_seat *seat, +void seatop_begin_resize_tiling(struct sway_seat *seat, struct sway_container *con, uint32_t button, enum wlr_edges edge); struct sway_container *seat_get_focus_inactive_floating(struct sway_seat *seat, struct sway_workspace *workspace); -void seat_end_mouse_operation(struct sway_seat *seat); - void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec, uint32_t button, enum wlr_button_state state); void seat_consider_warp_to_focus(struct sway_seat *seat); +bool seat_doing_seatop(struct sway_seat *seat); + +void seatop_motion(struct sway_seat *seat, uint32_t time_msec); + +/** + * End a seatop and apply the affects. + */ +void seatop_finish(struct sway_seat *seat); + +/** + * End a seatop without applying the affects. + */ +void seatop_abort(struct sway_seat *seat); + +/** + * Instructs the seatop implementation to drop any references to the given + * container (eg. because the container is destroying). + * The seatop may choose to abort itself in response to this. + */ +void seatop_unref(struct sway_seat *seat, struct sway_container *con); + +/** + * Instructs a seatop to render anything that it needs to render + * (eg. dropzone for move-tiling) + */ +void seatop_render(struct sway_seat *seat, struct sway_output *output, + pixman_region32_t *damage); + + #endif diff --git a/include/sway/output.h b/include/sway/output.h index f7c5ceba..bdf9614d 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -146,4 +146,12 @@ enum sway_container_layout output_get_default_layout( void output_add_listeners(struct sway_output *output); +void render_rect(struct wlr_output *wlr_output, + pixman_region32_t *output_damage, const struct wlr_box *_box, + float color[static 4]); + +void premultiply_alpha(float color[4], float opacity); + +void scale_box(struct wlr_box *box, float scale); + #endif diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 1d0a0ad1..9a432cb2 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -333,4 +333,6 @@ void container_add_mark(struct sway_container *container, char *mark); void container_update_marks_textures(struct sway_container *container); +void container_raise_floating(struct sway_container *con); + #endif diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index e377b8de..2d9ba0d9 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -61,6 +61,7 @@ struct swaybar_output { struct wl_list hotspots; // swaybar_hotspot::link char *name; + char *identifier; bool focused; uint32_t width, height; diff --git a/include/swaybar/config.h b/include/swaybar/config.h index 1f6577bd..add0a1cf 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h @@ -43,6 +43,8 @@ struct swaybar_config { struct wl_list outputs; // config_output::link bool all_outputs; int height; + int status_padding; + int status_edge_padding; struct { int top; int right; diff --git a/include/swaylock/swaylock.h b/include/swaylock/swaylock.h index 18af7ab4..516a56f4 100644 --- a/include/swaylock/swaylock.h +++ b/include/swaylock/swaylock.h @@ -22,6 +22,7 @@ enum auth_state { struct swaylock_colorset { uint32_t input; uint32_t cleared; + uint32_t caps_lock; uint32_t verifying; uint32_t wrong; }; @@ -30,6 +31,8 @@ struct swaylock_colors { uint32_t background; uint32_t bs_highlight; uint32_t key_highlight; + uint32_t caps_lock_bs_highlight; + uint32_t caps_lock_key_highlight; uint32_t separator; struct swaylock_colorset inside; struct swaylock_colorset line; @@ -45,6 +48,8 @@ struct swaylock_args { uint32_t thickness; bool ignore_empty; bool show_indicator; + bool show_caps_lock_text; + bool show_caps_lock_indicator; bool daemonize; }; diff --git a/meson.build b/meson.build index b1353b59..bffbe312 100644 --- a/meson.build +++ b/meson.build @@ -86,7 +86,6 @@ if scdoc.found() 'sway/sway-output.5.scd', 'swaylock/swaylock.1.scd', 'swaymsg/swaymsg.1.scd', - 'swayidle/swayidle.1.scd', 'swaynag/swaynag.1.scd', 'swaynag/swaynag.5.scd', ] @@ -146,7 +145,6 @@ subdir('swaymsg') subdir('client') subdir('swaybg') subdir('swaybar') -subdir('swayidle') subdir('swaynag') subdir('swaylock') @@ -214,7 +212,6 @@ if (get_option('bash-completions')) bash_files = files( 'completions/bash/sway', 'completions/bash/swaybar', - 'completions/bash/swayidle', 'completions/bash/swaylock', 'completions/bash/swaymsg', ) @@ -226,7 +223,6 @@ endif if (get_option('fish-completions')) fish_files = files( 'completions/fish/sway.fish', - 'completions/fish/swayidle.fish', 'completions/fish/swaylock.fish', 'completions/fish/swaymsg.fish', 'completions/fish/swaynag.fish', diff --git a/sway/commands/bar.c b/sway/commands/bar.c index ee5a8ebf..2a82d508 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c @@ -24,6 +24,8 @@ static struct cmd_handler bar_handlers[] = { { "position", bar_cmd_position }, { "separator_symbol", bar_cmd_separator_symbol }, { "status_command", bar_cmd_status_command }, + { "status_edge_padding", bar_cmd_status_edge_padding }, + { "status_padding", bar_cmd_status_padding }, { "strip_workspace_name", bar_cmd_strip_workspace_name }, { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers }, { "tray_bindsym", bar_cmd_tray_bindsym }, diff --git a/sway/commands/bar/status_edge_padding.c b/sway/commands/bar/status_edge_padding.c new file mode 100644 index 00000000..f3b10631 --- /dev/null +++ b/sway/commands/bar/status_edge_padding.c @@ -0,0 +1,21 @@ +#include <stdlib.h> +#include <string.h> +#include "sway/commands.h" +#include "log.h" + +struct cmd_results *bar_cmd_status_edge_padding(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "status_edge_padding", EXPECTED_EQUAL_TO, 1))) { + return error; + } + char *end; + int padding = strtol(argv[0], &end, 10); + if (strlen(end) || padding < 0) { + return cmd_results_new(CMD_INVALID, "status_edge_padding", + "Padding must be a positive integer"); + } + config->current_bar->status_edge_padding = padding; + wlr_log(WLR_DEBUG, "Status edge padding on bar %s: %d", + config->current_bar->id, config->current_bar->status_edge_padding); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/bar/status_padding.c b/sway/commands/bar/status_padding.c new file mode 100644 index 00000000..13b8eb6b --- /dev/null +++ b/sway/commands/bar/status_padding.c @@ -0,0 +1,21 @@ +#include <stdlib.h> +#include <string.h> +#include "sway/commands.h" +#include "log.h" + +struct cmd_results *bar_cmd_status_padding(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "status_padding", EXPECTED_EQUAL_TO, 1))) { + return error; + } + char *end; + int padding = strtol(argv[0], &end, 10); + if (strlen(end) || padding < 0) { + return cmd_results_new(CMD_INVALID, "status_padding", + "Padding must be a positive integer"); + } + config->current_bar->status_padding = padding; + wlr_log(WLR_DEBUG, "Status padding on bar %s: %d", + config->current_bar->id, config->current_bar->status_padding); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index e7ed69c6..69f46269 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c @@ -1,10 +1,69 @@ +#include <limits.h> #include <string.h> #include <strings.h> +#include <wlr/backend/libinput.h> #include "sway/config.h" #include "sway/commands.h" #include "sway/input/input-manager.h" #include "log.h" +static void toggle_send_events_for_device(struct input_config *ic, + struct sway_input_device *input_device) { + struct wlr_input_device *wlr_device = input_device->wlr_device; + if (!wlr_input_device_is_libinput(wlr_device)) { + return; + } + struct libinput_device *libinput_dev + = wlr_libinput_get_device_handle(wlr_device); + + enum libinput_config_send_events_mode mode = + libinput_device_config_send_events_get_mode(libinput_dev); + uint32_t possible = + libinput_device_config_send_events_get_modes(libinput_dev); + + switch (mode) { + case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED: + mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; + if (possible & mode) { + break; + } + // fall through + case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE: + mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; + if (possible & mode) { + break; + } + // fall through + case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED: + default: + mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; + break; + } + + ic->send_events = mode; +} + +static void toggle_send_events(struct input_config *ic) { + struct sway_input_device *input_device = NULL; + wl_list_for_each(input_device, &server.input->devices, link) { + if (strcmp(input_device->identifier, ic->identifier) == 0) { + toggle_send_events_for_device(ic, input_device); + } + } +} + +static void toggle_wildcard_send_events() { + struct sway_input_device *input_device = NULL; + wl_list_for_each(input_device, &server.input->devices, link) { + struct input_config *ic = new_input_config(input_device->identifier); + if (!ic) { + break; + } + toggle_send_events_for_device(ic, input_device); + store_input_config(ic); + } +} + struct cmd_results *input_cmd_events(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { @@ -23,9 +82,24 @@ struct cmd_results *input_cmd_events(int argc, char **argv) { } else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { ic->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; - } else { + } else if (config->reading) { return cmd_results_new(CMD_INVALID, "events", "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); + } else if (strcasecmp(argv[0], "toggle") == 0) { + if (strcmp(ic->identifier, "*") == 0) { + // Update the device input configs and then reset the wildcard + // config send events mode so that is does not override the device + // ones. The device ones will be applied when attempting to apply + // the wildcard config + toggle_wildcard_send_events(); + ic->send_events = INT_MIN; + } else { + toggle_send_events(ic); + } + } else { + return cmd_results_new(CMD_INVALID, "events", + "Expected 'events <enabled|disabled|disabled_on_external_mouse|" + "toggle>'"); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/input/scroll_button.c b/sway/commands/input/scroll_button.c index 1958f23c..d82a1fe1 100644 --- a/sway/commands/input/scroll_button.c +++ b/sway/commands/input/scroll_button.c @@ -1,9 +1,7 @@ -#include <string.h> -#include <strings.h> -#include <errno.h> +#include <libevdev/libevdev.h> #include "sway/config.h" #include "sway/commands.h" -#include "sway/input/input-manager.h" +#include "sway/input/cursor.h" struct cmd_results *input_cmd_scroll_button(int argc, char **argv) { struct cmd_results *error = NULL; @@ -16,22 +14,26 @@ struct cmd_results *input_cmd_scroll_button(int argc, char **argv) { "No input device defined."); } - errno = 0; - char *endptr; - int scroll_button = strtol(*argv, &endptr, 10); - if (endptr == *argv && scroll_button == 0) { - return cmd_results_new(CMD_INVALID, "scroll_button", - "Scroll button identifier must be an integer."); + if (strcmp(*argv, "disable") == 0) { + ic->scroll_button = 0; + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } - if (errno == ERANGE) { + + char *message = NULL; + uint32_t button = get_mouse_button(*argv, &message); + if (message) { + error = cmd_results_new(CMD_INVALID, "scroll_button", message); + free(message); + return error; + } else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN + || button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) { return cmd_results_new(CMD_INVALID, "scroll_button", - "Scroll button identifier out of range."); - } - if (scroll_button < 0) { + "X11 axis buttons are not supported for scroll_button"); + } else if (!button) { return cmd_results_new(CMD_INVALID, "scroll_button", - "Scroll button identifier cannot be negative."); + "Unknown button %s", *argv); } - ic->scroll_button = scroll_button; + ic->scroll_button = button; return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 1fbc68a1..8d9e426a 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -3,6 +3,7 @@ #include <strings.h> #include <wlr/types/wlr_cursor.h> +#include <wlr/types/wlr_pointer.h> #include "sway/commands.h" #include "sway/input/cursor.h" @@ -11,7 +12,7 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " "'cursor <set> <x> <y>' or " - "'curor <press|release> <left|right|1|2|3...>'"; + "'curor <press|release> <button[1-9]|event-name-or-code>'"; static struct cmd_results *handle_command(struct sway_cursor *cursor, int argc, char **argv) { @@ -91,15 +92,35 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); } - if (strcasecmp(button_str, "left") == 0) { - button = BTN_LEFT; - } else if (strcasecmp(button_str, "right") == 0) { - button = BTN_RIGHT; - } else { - button = strtol(button_str, NULL, 10); - if (button == 0) { - return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); - } + char *message = NULL; + button = get_mouse_button(button_str, &message); + if (message) { + struct cmd_results *error = + cmd_results_new(CMD_INVALID, "cursor", message); + free(message); + return error; + } else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN + || button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) { + // Dispatch axis event + enum wlr_axis_orientation orientation = + (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN) + ? WLR_AXIS_ORIENTATION_VERTICAL + : WLR_AXIS_ORIENTATION_HORIZONTAL; + double delta = (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_LEFT) + ? -1 : 1; + struct wlr_event_pointer_axis event = { + .device = NULL, + .time_msec = 0, + .source = WLR_AXIS_SOURCE_WHEEL, + .orientation = orientation, + .delta = delta * 15, + .delta_discrete = delta + }; + dispatch_cursor_axis(cursor, &event); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); + } else if (!button) { + return cmd_results_new(CMD_INVALID, "curor", + "Unknown button %s", button_str); } dispatch_cursor_button(cursor, NULL, 0, button, state); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/config.c b/sway/config.c index ea9f23dd..5ca4806c 100644 --- a/sway/config.c +++ b/sway/config.c @@ -387,6 +387,8 @@ bool load_main_config(const char *file, bool is_active, bool validating) { memcpy(&config->swaynag_config_errors, &old_config->swaynag_config_errors, sizeof(struct swaynag_instance)); + + input_manager_reset_all_inputs(); } config->current_config_path = path; @@ -571,15 +573,18 @@ bool load_include_configs(const char *path, struct sway_config *config, } // get line, with backslash continuation -static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file) { +static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file, + int *nlines) { char *next_line = NULL; size_t next_line_size = 0; ssize_t nread = getline(lineptr, line_size, file); + *nlines = nread == -1 ? 0 : 1; while (nread >= 2 && strcmp(&(*lineptr)[nread - 2], "\\\n") == 0) { ssize_t next_nread = getline(&next_line, &next_line_size, file); if (next_nread == -1) { break; } + (*nlines)++; nread += next_nread - 2; if ((ssize_t) *line_size < nread + 1) { @@ -613,7 +618,9 @@ static int detect_brace(FILE *file) { } } free(line); - fseek(file, pos, SEEK_SET); + if (ret == 0) { + fseek(file, pos, SEEK_SET); + } return ret; } @@ -661,7 +668,8 @@ bool read_config(FILE *file, struct sway_config *config, ssize_t nread; list_t *stack = create_list(); size_t read = 0; - while ((nread = getline_with_cont(&line, &line_size, file)) != -1) { + int nlines = 0; + while ((nread = getline_with_cont(&line, &line_size, file, &nlines)) != -1) { if (reading_main_config) { if (read + nread > config_size) { wlr_log(WLR_ERROR, "Config file changed during reading"); @@ -677,7 +685,7 @@ bool read_config(FILE *file, struct sway_config *config, line[nread - 1] = '\0'; } - line_number++; + line_number += nlines; wlr_log(WLR_DEBUG, "Read line %d: %s", line_number, line); strip_whitespace(line); diff --git a/sway/config/bar.c b/sway/config/bar.c index 670219f1..701bf051 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c @@ -96,7 +96,7 @@ struct bar_config *default_bar_config(void) { bar->pango_markup = false; bar->swaybar_command = NULL; bar->font = NULL; - bar->height = -1; + bar->height = 0; bar->workspace_buttons = true; bar->wrap_scroll = false; bar->separator_symbol = NULL; @@ -106,6 +106,8 @@ struct bar_config *default_bar_config(void) { bar->verbose = false; bar->pid = 0; bar->modifier = get_modifier_mask_by_name("Mod4"); + bar->status_padding = 1; + bar->status_edge_padding = 3; if (!(bar->mode = strdup("dock"))) { goto cleanup; } diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 79ad7faa..04c9b4f6 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -300,7 +300,7 @@ static int scale_length(int length, int offset, float scale) { return round((offset + length) * scale) - round(offset * scale); } -static void scale_box(struct wlr_box *box, float scale) { +void scale_box(struct wlr_box *box, float scale) { box->width = scale_length(box->width, box->x, scale); box->height = scale_length(box->height, box->y, scale); box->x = round(box->x * scale); diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 6c9fe23c..a38c6a07 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -49,13 +49,6 @@ static int scale_length(int length, int offset, float scale) { return round((offset + length) * scale) - round(offset * scale); } -static void scale_box(struct wlr_box *box, float scale) { - box->width = scale_length(box->width, box->x, scale); - box->height = scale_length(box->height, box->y, scale); - box->x = round(box->x * scale); - box->y = round(box->y * scale); -} - static void scissor_output(struct wlr_output *wlr_output, pixman_box32_t *rect) { struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); @@ -164,7 +157,7 @@ static void render_drag_icons(struct sway_output *output, // _box.x and .y are expected to be layout-local // _box.width and .height are expected to be output-buffer-local -static void render_rect(struct wlr_output *wlr_output, +void render_rect(struct wlr_output *wlr_output, pixman_region32_t *output_damage, const struct wlr_box *_box, float color[static 4]) { struct wlr_renderer *renderer = @@ -197,7 +190,7 @@ damage_finish: pixman_region32_fini(&damage); } -static void premultiply_alpha(float color[4], float opacity) { +void premultiply_alpha(float color[4], float opacity) { color[3] *= opacity; color[0] *= color[3]; color[1] *= color[3]; @@ -949,21 +942,11 @@ static void render_floating(struct sway_output *soutput, } } -static void render_dropzones(struct sway_output *output, +static void render_seatops(struct sway_output *output, pixman_region32_t *damage) { struct sway_seat *seat; wl_list_for_each(seat, &server.input->seats, link) { - if (seat->operation == OP_MOVE_TILING && seat->op_target_node - && node_get_output(seat->op_target_node) == output) { - float color[4]; - memcpy(&color, config->border_colors.focused.indicator, - sizeof(float) * 4); - premultiply_alpha(color, 0.5); - struct wlr_box box; - memcpy(&box, &seat->op_drop_box, sizeof(struct wlr_box)); - scale_box(&box, output->wlr_output->scale); - render_rect(output->wlr_output, damage, &box, color); - } + seatop_render(seat, output, damage); } } @@ -1060,7 +1043,7 @@ void output_render(struct sway_output *output, struct timespec *when, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); } - render_dropzones(output, damage); + render_seatops(output, damage); struct sway_seat *seat = input_manager_current_seat(); struct sway_container *focus = seat_get_focused_container(seat); diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index f46938e2..1cdd7c6d 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -299,7 +299,7 @@ static void transaction_apply(struct sway_transaction *transaction) { if (root->outputs->length) { struct sway_seat *seat; wl_list_for_each(seat, &server.input->seats, link) { - if (seat->operation == OP_NONE) { + if (!seat_doing_seatop(seat)) { cursor_rebase(seat->cursor); } } diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 801dcee0..f05e156f 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -360,7 +360,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) { struct wlr_xdg_toplevel_move_event *e = data; struct sway_seat *seat = e->seat->seat->data; if (e->serial == seat->last_button_serial) { - seat_begin_move_floating(seat, view->container, seat->last_button); + seatop_begin_move_floating(seat, view->container, seat->last_button); } } @@ -374,7 +374,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { struct wlr_xdg_toplevel_resize_event *e = data; struct sway_seat *seat = e->seat->seat->data; if (e->serial == seat->last_button_serial) { - seat_begin_resize_floating(seat, view->container, + seatop_begin_resize_floating(seat, view->container, seat->last_button, e->edges); } } diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 4bc83b8e..9f6741c8 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -357,7 +357,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) { struct wlr_xdg_toplevel_v6_move_event *e = data; struct sway_seat *seat = e->seat->seat->data; if (e->serial == seat->last_button_serial) { - seat_begin_move_floating(seat, view->container, seat->last_button); + seatop_begin_move_floating(seat, view->container, seat->last_button); } } @@ -371,7 +371,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { struct wlr_xdg_toplevel_v6_resize_event *e = data; struct sway_seat *seat = e->seat->seat->data; if (e->serial == seat->last_button_serial) { - seat_begin_resize_floating(seat, view->container, + seatop_begin_resize_floating(seat, view->container, seat->last_button, e->edges); } } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 1838ad32..080f6c41 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -470,7 +470,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) { return; } struct sway_seat *seat = input_manager_current_seat(); - seat_begin_move_floating(seat, view->container, seat->last_button); + seatop_begin_move_floating(seat, view->container, seat->last_button); } static void handle_request_resize(struct wl_listener *listener, void *data) { @@ -486,7 +486,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { } struct wlr_xwayland_resize_event *e = data; struct sway_seat *seat = input_manager_current_seat(); - seat_begin_resize_floating(seat, view->container, + seatop_begin_resize_floating(seat, view->container, seat->last_button, e->edges); } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 9af7ef57..08222494 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -27,10 +27,6 @@ #include "sway/tree/workspace.h" #include "wlr-layer-shell-unstable-v1-protocol.h" -// When doing a tiling drag, this is the thickness of the dropzone -// when dragging to the edge of a layout container. -#define DROP_LAYOUT_BORDER 30 - static uint32_t get_current_time_msec(void) { struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); @@ -59,7 +55,7 @@ static struct wlr_surface *layer_surface_at(struct sway_output *output, * Returns the node at the cursor's position. If there is a surface at that * location, it is stored in **surface (it may not be a view). */ -static struct sway_node *node_at_coords( +struct sway_node *node_at_coords( struct sway_seat *seat, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { // check for unmanaged views first @@ -226,347 +222,6 @@ static enum wlr_edges find_resize_edge(struct sway_container *cont, return edge; } -static void handle_down_motion(struct sway_seat *seat, - struct sway_cursor *cursor, uint32_t time_msec) { - struct sway_container *con = seat->op_container; - if (seat_is_input_allowed(seat, con->view->surface)) { - double moved_x = cursor->cursor->x - seat->op_ref_lx; - double moved_y = cursor->cursor->y - seat->op_ref_ly; - double sx = seat->op_ref_con_lx + moved_x; - double sy = seat->op_ref_con_ly + moved_y; - wlr_seat_pointer_notify_motion(seat->wlr_seat, time_msec, sx, sy); - } - seat->op_moved = true; -} - -static void handle_move_floating_motion(struct sway_seat *seat, - struct sway_cursor *cursor) { - struct sway_container *con = seat->op_container; - desktop_damage_whole_container(con); - container_floating_translate(con, - cursor->cursor->x - cursor->previous.x, - cursor->cursor->y - cursor->previous.y); - desktop_damage_whole_container(con); -} - -static void resize_box(struct wlr_box *box, enum wlr_edges edge, - int thickness) { - switch (edge) { - case WLR_EDGE_TOP: - box->height = thickness; - break; - case WLR_EDGE_LEFT: - box->width = thickness; - break; - case WLR_EDGE_RIGHT: - box->x = box->x + box->width - thickness; - box->width = thickness; - break; - case WLR_EDGE_BOTTOM: - box->y = box->y + box->height - thickness; - box->height = thickness; - break; - case WLR_EDGE_NONE: - box->x += thickness; - box->y += thickness; - box->width -= thickness * 2; - box->height -= thickness * 2; - break; - } -} - -static void handle_move_tiling_motion(struct sway_seat *seat, - struct sway_cursor *cursor) { - struct wlr_surface *surface = NULL; - double sx, sy; - struct sway_node *node = node_at_coords(seat, - cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); - // Damage the old location - desktop_damage_box(&seat->op_drop_box); - - if (!node) { - // Eg. hovered over a layer surface such as swaybar - seat->op_target_node = NULL; - seat->op_target_edge = WLR_EDGE_NONE; - return; - } - - if (node->type == N_WORKSPACE) { - // Emtpy workspace - seat->op_target_node = node; - seat->op_target_edge = WLR_EDGE_NONE; - workspace_get_box(node->sway_workspace, &seat->op_drop_box); - desktop_damage_box(&seat->op_drop_box); - return; - } - - // Deny moving within own workspace if this is the only child - struct sway_container *con = node->sway_container; - if (workspace_num_tiling_views(seat->op_container->workspace) == 1 && - con->workspace == seat->op_container->workspace) { - seat->op_target_node = NULL; - seat->op_target_edge = WLR_EDGE_NONE; - return; - } - - // Traverse the ancestors, trying to find a layout container perpendicular - // to the edge. Eg. close to the top or bottom of a horiz layout. - while (con) { - enum wlr_edges edge = WLR_EDGE_NONE; - enum sway_container_layout layout = container_parent_layout(con); - struct wlr_box parent; - con->parent ? container_get_box(con->parent, &parent) : - workspace_get_box(con->workspace, &parent); - if (layout == L_HORIZ || layout == L_TABBED) { - if (cursor->cursor->y < parent.y + DROP_LAYOUT_BORDER) { - edge = WLR_EDGE_TOP; - } else if (cursor->cursor->y > parent.y + parent.height - - DROP_LAYOUT_BORDER) { - edge = WLR_EDGE_BOTTOM; - } - } else if (layout == L_VERT || layout == L_STACKED) { - if (cursor->cursor->x < parent.x + DROP_LAYOUT_BORDER) { - edge = WLR_EDGE_LEFT; - } else if (cursor->cursor->x > parent.x + parent.width - - DROP_LAYOUT_BORDER) { - edge = WLR_EDGE_RIGHT; - } - } - if (edge) { - seat->op_target_node = node_get_parent(&con->node); - seat->op_target_edge = edge; - node_get_box(seat->op_target_node, &seat->op_drop_box); - resize_box(&seat->op_drop_box, edge, DROP_LAYOUT_BORDER); - desktop_damage_box(&seat->op_drop_box); - return; - } - con = con->parent; - } - - // Use the hovered view - but we must be over the actual surface - con = node->sway_container; - if (!con->view->surface || node == &seat->op_container->node) { - seat->op_target_node = NULL; - seat->op_target_edge = WLR_EDGE_NONE; - return; - } - - // Find the closest edge - size_t thickness = fmin(con->content_width, con->content_height) * 0.3; - size_t closest_dist = INT_MAX; - size_t dist; - seat->op_target_edge = WLR_EDGE_NONE; - if ((dist = cursor->cursor->y - con->y) < closest_dist) { - closest_dist = dist; - seat->op_target_edge = WLR_EDGE_TOP; - } - if ((dist = cursor->cursor->x - con->x) < closest_dist) { - closest_dist = dist; - seat->op_target_edge = WLR_EDGE_LEFT; - } - if ((dist = con->x + con->width - cursor->cursor->x) < closest_dist) { - closest_dist = dist; - seat->op_target_edge = WLR_EDGE_RIGHT; - } - if ((dist = con->y + con->height - cursor->cursor->y) < closest_dist) { - closest_dist = dist; - seat->op_target_edge = WLR_EDGE_BOTTOM; - } - - if (closest_dist > thickness) { - seat->op_target_edge = WLR_EDGE_NONE; - } - - seat->op_target_node = node; - seat->op_drop_box.x = con->content_x; - seat->op_drop_box.y = con->content_y; - seat->op_drop_box.width = con->content_width; - seat->op_drop_box.height = con->content_height; - resize_box(&seat->op_drop_box, seat->op_target_edge, thickness); - desktop_damage_box(&seat->op_drop_box); -} - -static void handle_move_tiling_threshold_motion(struct sway_seat *seat, - struct sway_cursor *cursor) { - double cx = seat->cursor->cursor->x; - double cy = seat->cursor->cursor->y; - double sx = seat->op_ref_lx; - double sy = seat->op_ref_ly; - - // Get the scaled threshold for the output. Even if the operation goes - // across multiple outputs of varying scales, just use the scale for the - // output that the cursor is currently on for simplicity. - struct wlr_output *wlr_output = wlr_output_layout_output_at( - root->output_layout, cx, cy); - double output_scale = wlr_output ? wlr_output->scale : 1; - double threshold = config->tiling_drag_threshold * output_scale; - threshold *= threshold; - - // If the threshold has been exceeded, start the actual drag - if ((cx - sx) * (cx - sx) + (cy - sy) * (cy - sy) > threshold) { - seat->operation = OP_MOVE_TILING; - cursor_set_image(cursor, "grab", NULL); - handle_move_tiling_motion(seat, cursor); - } -} - -static void calculate_floating_constraints(struct sway_container *con, - int *min_width, int *max_width, int *min_height, int *max_height) { - if (config->floating_minimum_width == -1) { // no minimum - *min_width = 0; - } else if (config->floating_minimum_width == 0) { // automatic - *min_width = 75; - } else { - *min_width = config->floating_minimum_width; - } - - if (config->floating_minimum_height == -1) { // no minimum - *min_height = 0; - } else if (config->floating_minimum_height == 0) { // automatic - *min_height = 50; - } else { - *min_height = config->floating_minimum_height; - } - - if (config->floating_maximum_width == -1) { // no maximum - *max_width = INT_MAX; - } else if (config->floating_maximum_width == 0) { // automatic - *max_width = con->workspace->width; - } else { - *max_width = config->floating_maximum_width; - } - - if (config->floating_maximum_height == -1) { // no maximum - *max_height = INT_MAX; - } else if (config->floating_maximum_height == 0) { // automatic - *max_height = con->workspace->height; - } else { - *max_height = config->floating_maximum_height; - } -} - -static void handle_resize_floating_motion(struct sway_seat *seat, - struct sway_cursor *cursor) { - struct sway_container *con = seat->op_container; - enum wlr_edges edge = seat->op_resize_edge; - - // The amount the mouse has moved since the start of the resize operation - // Positive is down/right - double mouse_move_x = cursor->cursor->x - seat->op_ref_lx; - double mouse_move_y = cursor->cursor->y - seat->op_ref_ly; - - if (edge == WLR_EDGE_TOP || edge == WLR_EDGE_BOTTOM) { - mouse_move_x = 0; - } - if (edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT) { - mouse_move_y = 0; - } - - double grow_width = edge & WLR_EDGE_LEFT ? -mouse_move_x : mouse_move_x; - double grow_height = edge & WLR_EDGE_TOP ? -mouse_move_y : mouse_move_y; - - if (seat->op_resize_preserve_ratio) { - double x_multiplier = grow_width / seat->op_ref_width; - double y_multiplier = grow_height / seat->op_ref_height; - double max_multiplier = fmax(x_multiplier, y_multiplier); - grow_width = seat->op_ref_width * max_multiplier; - grow_height = seat->op_ref_height * max_multiplier; - } - - // Determine new width/height, and accommodate for floating min/max values - double width = seat->op_ref_width + grow_width; - double height = seat->op_ref_height + grow_height; - int min_width, max_width, min_height, max_height; - calculate_floating_constraints(con, &min_width, &max_width, - &min_height, &max_height); - width = fmax(min_width, fmin(width, max_width)); - height = fmax(min_height, fmin(height, max_height)); - - // Apply the view's min/max size - if (con->view) { - double view_min_width, view_max_width, view_min_height, view_max_height; - view_get_constraints(con->view, &view_min_width, &view_max_width, - &view_min_height, &view_max_height); - width = fmax(view_min_width, fmin(width, view_max_width)); - height = fmax(view_min_height, fmin(height, view_max_height)); - } - - // Recalculate these, in case we hit a min/max limit - grow_width = width - seat->op_ref_width; - grow_height = height - seat->op_ref_height; - - // Determine grow x/y values - these are relative to the container's x/y at - // the start of the resize operation. - double grow_x = 0, grow_y = 0; - if (edge & WLR_EDGE_LEFT) { - grow_x = -grow_width; - } else if (edge & WLR_EDGE_RIGHT) { - grow_x = 0; - } else { - grow_x = -grow_width / 2; - } - if (edge & WLR_EDGE_TOP) { - grow_y = -grow_height; - } else if (edge & WLR_EDGE_BOTTOM) { - grow_y = 0; - } else { - grow_y = -grow_height / 2; - } - - // Determine the amounts we need to bump everything relative to the current - // size. - int relative_grow_width = width - con->width; - int relative_grow_height = height - con->height; - int relative_grow_x = (seat->op_ref_con_lx + grow_x) - con->x; - int relative_grow_y = (seat->op_ref_con_ly + grow_y) - con->y; - - // Actually resize stuff - con->x += relative_grow_x; - con->y += relative_grow_y; - con->width += relative_grow_width; - con->height += relative_grow_height; - - con->content_x += relative_grow_x; - con->content_y += relative_grow_y; - con->content_width += relative_grow_width; - con->content_height += relative_grow_height; - - arrange_container(con); -} - -static void handle_resize_tiling_motion(struct sway_seat *seat, - struct sway_cursor *cursor) { - int amount_x = 0; - int amount_y = 0; - int moved_x = cursor->cursor->x - seat->op_ref_lx; - int moved_y = cursor->cursor->y - seat->op_ref_ly; - enum wlr_edges edge_x = WLR_EDGE_NONE; - enum wlr_edges edge_y = WLR_EDGE_NONE; - struct sway_container *con = seat->op_container; - - if (seat->op_resize_edge & WLR_EDGE_TOP) { - amount_y = (seat->op_ref_height - moved_y) - con->height; - edge_y = WLR_EDGE_TOP; - } else if (seat->op_resize_edge & WLR_EDGE_BOTTOM) { - amount_y = (seat->op_ref_height + moved_y) - con->height; - edge_y = WLR_EDGE_BOTTOM; - } - if (seat->op_resize_edge & WLR_EDGE_LEFT) { - amount_x = (seat->op_ref_width - moved_x) - con->width; - edge_x = WLR_EDGE_LEFT; - } else if (seat->op_resize_edge & WLR_EDGE_RIGHT) { - amount_x = (seat->op_ref_width + moved_x) - con->width; - edge_x = WLR_EDGE_RIGHT; - } - - if (amount_x != 0) { - container_resize_tiled(seat->op_container, edge_x, amount_x); - } - if (amount_y != 0) { - container_resize_tiled(seat->op_container, edge_y, amount_y); - } -} - static void cursor_do_rebase(struct sway_cursor *cursor, uint32_t time_msec, struct sway_node *node, struct wlr_surface *surface, double sx, double sy) { @@ -669,29 +324,8 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, struct sway_seat *seat = cursor->seat; struct wlr_seat *wlr_seat = seat->wlr_seat; - if (seat->operation != OP_NONE) { - switch (seat->operation) { - case OP_DOWN: - handle_down_motion(seat, cursor, time_msec); - break; - case OP_MOVE_FLOATING: - handle_move_floating_motion(seat, cursor); - break; - case OP_MOVE_TILING_THRESHOLD: - handle_move_tiling_threshold_motion(seat, cursor); - break; - case OP_MOVE_TILING: - handle_move_tiling_motion(seat, cursor); - break; - case OP_RESIZE_FLOATING: - handle_resize_floating_motion(seat, cursor); - break; - case OP_RESIZE_TILING: - handle_resize_tiling_motion(seat, cursor); - break; - case OP_NONE: - break; - } + if (seat_doing_seatop(seat)) { + seatop_motion(seat, time_msec); cursor->previous.x = cursor->cursor->x; cursor->previous.y = cursor->cursor->y; return; @@ -868,9 +502,9 @@ void dispatch_cursor_button(struct sway_cursor *cursor, struct sway_seat *seat = cursor->seat; // Handle existing seat operation - if (cursor->seat->operation != OP_NONE) { - if (button == cursor->seat->op_button && state == WLR_BUTTON_RELEASED) { - seat_end_mouse_operation(seat); + if (seat_doing_seatop(seat)) { + if (button == seat->seatop_button && state == WLR_BUTTON_RELEASED) { + seatop_finish(seat); seat_pointer_notify_button(seat, time_msec, button, state); } if (state == WLR_BUTTON_PRESSED) { @@ -943,7 +577,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, if (cont && resize_edge && button == BTN_LEFT && state == WLR_BUTTON_PRESSED && !is_floating) { seat_set_focus_container(seat, cont); - seat_begin_resize_tiling(seat, cont, button, edge); + seatop_begin_resize_tiling(seat, cont, button, edge); return; } @@ -973,7 +607,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, } cursor_set_image(seat->cursor, image, NULL); seat_set_focus_container(seat, cont); - seat_begin_resize_tiling(seat, cont, button, edge); + seatop_begin_resize_tiling(seat, cont, button, edge); return; } } @@ -988,7 +622,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, cont = cont->parent; } seat_set_focus_container(seat, cont); - seat_begin_move_floating(seat, cont, button); + seatop_begin_move_floating(seat, cont, button); return; } } @@ -998,7 +632,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, state == WLR_BUTTON_PRESSED) { // Via border if (button == BTN_LEFT && resize_edge != WLR_EDGE_NONE) { - seat_begin_resize_floating(seat, cont, button, resize_edge); + seatop_begin_resize_floating(seat, cont, button, resize_edge); return; } @@ -1015,7 +649,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, WLR_EDGE_RIGHT : WLR_EDGE_LEFT; edge |= cursor->cursor->y > floater->y + floater->height / 2 ? WLR_EDGE_BOTTOM : WLR_EDGE_TOP; - seat_begin_resize_floating(seat, floater, button, edge); + seatop_begin_resize_floating(seat, floater, button, edge); return; } } @@ -1035,9 +669,9 @@ void dispatch_cursor_button(struct sway_cursor *cursor, // If moving a container by it's title bar, use a threshold for the drag if (!mod_pressed && config->tiling_drag_threshold > 0) { - seat_begin_move_tiling_threshold(seat, cont, button); + seatop_begin_move_tiling_threshold(seat, cont, button); } else { - seat_begin_move_tiling(seat, cont, button); + seatop_begin_move_tiling(seat, cont, button); } return; } @@ -1046,7 +680,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, if (surface && cont && state == WLR_BUTTON_PRESSED) { seat_set_focus_container(seat, cont); seat_pointer_notify_button(seat, time_msec, button, state); - seat_begin_down(seat, cont, button, sx, sy); + seatop_begin_down(seat, cont, button, sx, sy); return; } @@ -1082,11 +716,13 @@ static uint32_t wl_axis_to_button(struct wlr_event_pointer_axis *event) { } } -static void dispatch_cursor_axis(struct sway_cursor *cursor, +void dispatch_cursor_axis(struct sway_cursor *cursor, struct wlr_event_pointer_axis *event) { struct sway_seat *seat = cursor->seat; - struct sway_input_device *input_device = event->device->data; - struct input_config *ic = input_device_get_config(input_device); + struct sway_input_device *input_device = + event->device ? event->device->data : NULL; + struct input_config *ic = + input_device ? input_device_get_config(input_device) : NULL; // Determine what's under the cursor struct wlr_surface *surface = NULL; @@ -1109,7 +745,8 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor, // Gather information needed for mouse bindings struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; - struct wlr_input_device *device = input_device->wlr_device; + struct wlr_input_device *device = + input_device ? input_device->wlr_device : NULL; char *dev_id = device ? input_device_get_identifier(device) : strdup("*"); uint32_t button = wl_axis_to_button(event); @@ -1350,7 +987,7 @@ static void handle_request_set_cursor(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, request_set_cursor); - if (cursor->seat->operation != OP_NONE) { + if (seat_doing_seatop(cursor->seat)) { return; } struct wlr_seat_pointer_request_set_cursor_event *event = data; @@ -1593,7 +1230,7 @@ uint32_t get_mouse_bindcode(const char *name, char **error) { uint32_t get_mouse_button(const char *name, char **error) { uint32_t button = get_mouse_bindsym(name, error); - if (!button && !error) { + if (!button && !*error) { button = get_mouse_bindcode(name, error); } return button; diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 04e14355..d90803f6 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -129,6 +129,24 @@ static void input_manager_libinput_config_keyboard( } } +static void input_manager_libinput_reset_keyboard( + struct sway_input_device *input_device) { + struct wlr_input_device *wlr_device = input_device->wlr_device; + struct libinput_device *libinput_device; + + if (!wlr_input_device_is_libinput(wlr_device)) { + return; + } + + libinput_device = wlr_libinput_get_device_handle(wlr_device); + + uint32_t send_events = + libinput_device_config_send_events_get_default_mode(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_keyboard(%s) send_events_set_mode(%d)", + input_device->identifier, send_events); + libinput_device_config_send_events_set_mode(libinput_device, send_events); +} + static void input_manager_libinput_config_touch( struct sway_input_device *input_device) { struct wlr_input_device *wlr_device = input_device->wlr_device; @@ -151,6 +169,24 @@ static void input_manager_libinput_config_touch( } } +static void input_manager_libinput_reset_touch( + struct sway_input_device *input_device) { + struct wlr_input_device *wlr_device = input_device->wlr_device; + struct libinput_device *libinput_device; + + if (!wlr_input_device_is_libinput(wlr_device)) { + return; + } + + libinput_device = wlr_libinput_get_device_handle(wlr_device); + + uint32_t send_events = + libinput_device_config_send_events_get_default_mode(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_touch(%s) send_events_set_mode(%d)", + input_device->identifier, send_events); + libinput_device_config_send_events_set_mode(libinput_device, send_events); +} + static void input_manager_libinput_config_pointer( struct sway_input_device *input_device) { struct wlr_input_device *wlr_device = input_device->wlr_device; @@ -180,14 +216,14 @@ static void input_manager_libinput_config_pointer( if (ic->drag != INT_MIN) { wlr_log(WLR_DEBUG, "libinput_config_pointer(%s) tap_set_drag_enabled(%d)", - ic->identifier, ic->click_method); + ic->identifier, ic->drag); libinput_device_config_tap_set_drag_enabled(libinput_device, ic->drag); } if (ic->drag_lock != INT_MIN) { wlr_log(WLR_DEBUG, "libinput_config_pointer(%s) tap_set_drag_lock_enabled(%d)", - ic->identifier, ic->click_method); + ic->identifier, ic->drag_lock); libinput_device_config_tap_set_drag_lock_enabled(libinput_device, ic->drag_lock); } @@ -248,12 +284,118 @@ static void input_manager_libinput_config_pointer( } if (ic->tap_button_map != INT_MIN) { wlr_log(WLR_DEBUG, "libinput_config_pointer(%s) tap_set_button_map(%d)", - ic->identifier, ic->tap); + ic->identifier, ic->tap_button_map); libinput_device_config_tap_set_button_map(libinput_device, ic->tap_button_map); } } +static void input_manager_libinput_reset_pointer( + struct sway_input_device *input_device) { + struct wlr_input_device *wlr_device = input_device->wlr_device; + + if (!wlr_input_device_is_libinput(wlr_device)) { + return; + } + + struct libinput_device *libinput_device = + wlr_libinput_get_device_handle(wlr_device); + + enum libinput_config_accel_profile accel_profile = + libinput_device_config_accel_get_default_profile(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) accel_set_profile(%d)", + input_device->identifier, accel_profile); + libinput_device_config_accel_set_profile(libinput_device, accel_profile); + + enum libinput_config_click_method click_method = + libinput_device_config_click_get_default_method(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) click_set_method(%d)", + input_device->identifier, click_method); + libinput_device_config_click_set_method(libinput_device, click_method); + + enum libinput_config_drag_state drag = + libinput_device_config_tap_get_default_drag_enabled(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) tap_set_drag_enabled(%d)", + input_device->identifier, drag); + libinput_device_config_tap_set_drag_enabled(libinput_device, drag); + + enum libinput_config_drag_lock_state drag_lock = + libinput_device_config_tap_get_default_drag_lock_enabled( + libinput_device); + wlr_log(WLR_DEBUG, + "libinput_reset_pointer(%s) tap_set_drag_lock_enabled(%d)", + input_device->identifier, drag_lock); + libinput_device_config_tap_set_drag_lock_enabled(libinput_device, + drag_lock); + + enum libinput_config_dwt_state dwt = + libinput_device_config_dwt_get_default_enabled(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) dwt_set_enabled(%d)", + input_device->identifier, dwt); + libinput_device_config_dwt_set_enabled(libinput_device, dwt); + + int left_handed = + libinput_device_config_left_handed_get_default(libinput_device); + wlr_log(WLR_DEBUG, + "libinput_reset_pointer(%s) left_handed_set_enabled(%d)", + input_device->identifier, left_handed); + libinput_device_config_left_handed_set(libinput_device, left_handed); + + enum libinput_config_middle_emulation_state middle_emulation = + libinput_device_config_middle_emulation_get_default_enabled( + libinput_device); + wlr_log(WLR_DEBUG, + "libinput_reset_pointer(%s) middle_emulation_set_enabled(%d)", + input_device->identifier, middle_emulation); + libinput_device_config_middle_emulation_set_enabled(libinput_device, + middle_emulation); + + int natural_scroll = + libinput_device_config_scroll_get_default_natural_scroll_enabled( + libinput_device); + wlr_log(WLR_DEBUG, + "libinput_reset_pointer(%s) natural_scroll_set_enabled(%d)", + input_device->identifier, natural_scroll); + libinput_device_config_scroll_set_natural_scroll_enabled( + libinput_device, natural_scroll); + + double pointer_accel = + libinput_device_config_accel_get_default_speed(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) accel_set_speed(%f)", + input_device->identifier, pointer_accel); + libinput_device_config_accel_set_speed(libinput_device, pointer_accel); + + uint32_t scroll_button = + libinput_device_config_scroll_get_default_button(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) scroll_set_button(%d)", + input_device->identifier, scroll_button); + libinput_device_config_scroll_set_button(libinput_device, scroll_button); + + enum libinput_config_scroll_method scroll_method = + libinput_device_config_scroll_get_default_method(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) scroll_set_method(%d)", + input_device->identifier, scroll_method); + libinput_device_config_scroll_set_method(libinput_device, scroll_method); + + uint32_t send_events = + libinput_device_config_send_events_get_default_mode(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) send_events_set_mode(%d)", + input_device->identifier, send_events); + libinput_device_config_send_events_set_mode(libinput_device, send_events); + + enum libinput_config_tap_state tap = + libinput_device_config_tap_get_default_enabled(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) tap_set_enabled(%d)", + input_device->identifier, tap); + libinput_device_config_tap_set_enabled(libinput_device, tap); + + enum libinput_config_tap_button_map tap_button_map = + libinput_device_config_tap_get_button_map(libinput_device); + wlr_log(WLR_DEBUG, "libinput_reset_pointer(%s) tap_set_button_map(%d)", + input_device->identifier, tap_button_map); + libinput_device_config_tap_set_button_map(libinput_device, tap_button_map); +} + static void handle_device_destroy(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; @@ -466,6 +608,30 @@ void input_manager_apply_input_config(struct input_config *input_config) { } } +void input_manager_reset_input(struct sway_input_device *input_device) { + if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER || + input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) { + input_manager_libinput_reset_pointer(input_device); + } else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) { + input_manager_libinput_reset_keyboard(input_device); + } else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_TOUCH) { + input_manager_libinput_reset_touch(input_device); + } + + struct sway_seat *seat = NULL; + wl_list_for_each(seat, &server.input->seats, link) { + seat_reset_device(seat, input_device); + } +} + +void input_manager_reset_all_inputs() { + struct sway_input_device *input_device = NULL; + wl_list_for_each(input_device, &server.input->devices, link) { + input_manager_reset_input(input_device); + } +} + + void input_manager_apply_seat_config(struct seat_config *seat_config) { wlr_log(WLR_DEBUG, "applying seat config for seat %s", seat_config->name); if (strcmp(seat_config->name, "*") == 0) { diff --git a/sway/input/seat.c b/sway/input/seat.c index a8df5b99..a63999b6 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -308,7 +308,7 @@ static void handle_new_drag_icon(struct wl_listener *listener, void *data) { wl_list_insert(&root->drag_icons, &icon->link); drag_icon_update_position(icon); - seat_end_mouse_operation(seat); + seatop_abort(seat); } static void collect_focus_iter(struct sway_node *node, void *data) { @@ -405,6 +405,14 @@ static void seat_update_capabilities(struct sway_seat *seat) { } } +static void seat_reset_input_config(struct sway_seat *seat, + struct sway_seat_device *sway_device) { + wlr_log(WLR_DEBUG, "Resetting output mapping for input device %s", + sway_device->input_device->identifier); + wlr_cursor_map_input_to_output(seat->cursor->cursor, + sway_device->input_device->wlr_device, NULL); +} + static void seat_apply_input_config(struct sway_seat *seat, struct sway_seat_device *sway_device) { const char *mapped_to_output = NULL; @@ -522,6 +530,35 @@ void seat_configure_device(struct sway_seat *seat, } } +void seat_reset_device(struct sway_seat *seat, + struct sway_input_device *input_device) { + struct sway_seat_device *seat_device = seat_get_device(seat, input_device); + if (!seat_device) { + return; + } + + switch (input_device->wlr_device->type) { + case WLR_INPUT_DEVICE_POINTER: + seat_reset_input_config(seat, seat_device); + break; + case WLR_INPUT_DEVICE_KEYBOARD: + sway_keyboard_configure(seat_device->keyboard); + break; + case WLR_INPUT_DEVICE_TOUCH: + seat_reset_input_config(seat, seat_device); + break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + seat_reset_input_config(seat, seat_device); + break; + case WLR_INPUT_DEVICE_TABLET_PAD: + wlr_log(WLR_DEBUG, "TODO: reset tablet pad"); + break; + case WLR_INPUT_DEVICE_SWITCH: + wlr_log(WLR_DEBUG, "TODO: reset switch device"); + break; + } +} + void seat_add_device(struct sway_seat *seat, struct sway_input_device *input_device) { if (seat_get_device(seat, input_device)) { @@ -625,18 +662,6 @@ static int handle_urgent_timeout(void *data) { return 0; } -static void container_raise_floating(struct sway_container *con) { - // Bring container to front by putting it at the end of the floating list. - struct sway_container *floater = con; - while (floater->parent) { - floater = floater->parent; - } - if (container_is_floating(floater)) { - list_move_to_end(floater->workspace->floating, floater); - node_set_dirty(&floater->workspace->node); - } -} - static void set_workspace(struct sway_seat *seat, struct sway_workspace *new_ws) { if (seat->workspace == new_ws) { @@ -1025,187 +1050,6 @@ struct seat_config *seat_get_config_by_name(const char *name) { return NULL; } -void seat_begin_down(struct sway_seat *seat, struct sway_container *con, - uint32_t button, double sx, double sy) { - seat->operation = OP_DOWN; - seat->op_container = con; - seat->op_button = button; - seat->op_ref_lx = seat->cursor->cursor->x; - seat->op_ref_ly = seat->cursor->cursor->y; - seat->op_ref_con_lx = sx; - seat->op_ref_con_ly = sy; - seat->op_moved = false; - - container_raise_floating(con); -} - -void seat_begin_move_floating(struct sway_seat *seat, - struct sway_container *con, uint32_t button) { - if (!seat->cursor) { - wlr_log(WLR_DEBUG, "Ignoring move request due to no cursor device"); - return; - } - seat->operation = OP_MOVE_FLOATING; - seat->op_container = con; - seat->op_button = button; - - container_raise_floating(con); - - cursor_set_image(seat->cursor, "grab", NULL); -} - -void seat_begin_move_tiling_threshold(struct sway_seat *seat, - struct sway_container *con, uint32_t button) { - seat->operation = OP_MOVE_TILING_THRESHOLD; - seat->op_container = con; - seat->op_button = button; - seat->op_target_node = NULL; - seat->op_target_edge = 0; - seat->op_ref_lx = seat->cursor->cursor->x; - seat->op_ref_ly = seat->cursor->cursor->y; -} - -void seat_begin_move_tiling(struct sway_seat *seat, - struct sway_container *con, uint32_t button) { - seat->operation = OP_MOVE_TILING; - seat->op_container = con; - seat->op_button = button; - seat->op_target_node = NULL; - seat->op_target_edge = 0; - cursor_set_image(seat->cursor, "grab", NULL); -} - -void seat_begin_resize_floating(struct sway_seat *seat, - struct sway_container *con, uint32_t button, enum wlr_edges edge) { - if (!seat->cursor) { - wlr_log(WLR_DEBUG, "Ignoring resize request due to no cursor device"); - return; - } - struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); - seat->operation = OP_RESIZE_FLOATING; - seat->op_container = con; - seat->op_resize_preserve_ratio = keyboard && - (wlr_keyboard_get_modifiers(keyboard) & WLR_MODIFIER_SHIFT); - seat->op_resize_edge = edge == WLR_EDGE_NONE ? - WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT : edge; - seat->op_button = button; - seat->op_ref_lx = seat->cursor->cursor->x; - seat->op_ref_ly = seat->cursor->cursor->y; - seat->op_ref_con_lx = con->x; - seat->op_ref_con_ly = con->y; - seat->op_ref_width = con->width; - seat->op_ref_height = con->height; - - container_raise_floating(con); - - const char *image = edge == WLR_EDGE_NONE ? - "se-resize" : wlr_xcursor_get_resize_name(edge); - cursor_set_image(seat->cursor, image, NULL); -} - -void seat_begin_resize_tiling(struct sway_seat *seat, - struct sway_container *con, uint32_t button, enum wlr_edges edge) { - seat->operation = OP_RESIZE_TILING; - seat->op_container = con; - seat->op_resize_edge = edge; - seat->op_button = button; - seat->op_ref_lx = seat->cursor->cursor->x; - seat->op_ref_ly = seat->cursor->cursor->y; - seat->op_ref_con_lx = con->x; - seat->op_ref_con_ly = con->y; - seat->op_ref_width = con->width; - seat->op_ref_height = con->height; -} - -static bool is_parallel(enum sway_container_layout layout, - enum wlr_edges edge) { - bool layout_is_horiz = layout == L_HORIZ || layout == L_TABBED; - bool edge_is_horiz = edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT; - return layout_is_horiz == edge_is_horiz; -} - -static void seat_end_move_tiling(struct sway_seat *seat) { - struct sway_container *con = seat->op_container; - struct sway_container *old_parent = con->parent; - struct sway_workspace *old_ws = con->workspace; - struct sway_node *target_node = seat->op_target_node; - struct sway_workspace *new_ws = target_node->type == N_WORKSPACE ? - target_node->sway_workspace : target_node->sway_container->workspace; - enum wlr_edges edge = seat->op_target_edge; - int after = edge != WLR_EDGE_TOP && edge != WLR_EDGE_LEFT; - - container_detach(con); - - // Moving container into empty workspace - if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) { - workspace_add_tiling(new_ws, con); - } else if (target_node->type == N_CONTAINER) { - // Moving container before/after another - struct sway_container *target = target_node->sway_container; - enum sway_container_layout layout = container_parent_layout(target); - if (edge && !is_parallel(layout, edge)) { - enum sway_container_layout new_layout = edge == WLR_EDGE_TOP || - edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ; - container_split(target, new_layout); - } - container_add_sibling(target, con, after); - } else { - // Target is a workspace which requires splitting - enum sway_container_layout new_layout = edge == WLR_EDGE_TOP || - edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ; - workspace_split(new_ws, new_layout); - workspace_insert_tiling(new_ws, con, after); - } - - if (old_parent) { - container_reap_empty(old_parent); - } - - // This is a bit dirty, but we'll set the dimensions to that of a sibling. - // I don't think there's any other way to make it consistent without - // changing how we auto-size containers. - list_t *siblings = container_get_siblings(con); - if (siblings->length > 1) { - int index = list_find(siblings, con); - struct sway_container *sibling = index == 0 ? - siblings->items[1] : siblings->items[index - 1]; - con->width = sibling->width; - con->height = sibling->height; - } - - arrange_workspace(old_ws); - if (new_ws != old_ws) { - arrange_workspace(new_ws); - } -} - -void seat_end_mouse_operation(struct sway_seat *seat) { - enum sway_seat_operation operation = seat->operation; - if (seat->operation == OP_MOVE_FLOATING) { - // We "move" the container to its own location so it discovers its - // output again. - struct sway_container *con = seat->op_container; - container_floating_move_to(con, con->x, con->y); - } else if (seat->operation == OP_MOVE_TILING && seat->op_target_node) { - seat_end_move_tiling(seat); - } - seat->operation = OP_NONE; - seat->op_container = NULL; - if (operation == OP_DOWN) { - // Set the cursor's previous coords to the x/y at the start of the - // operation, so the container change will be detected if using - // focus_follows_mouse and the cursor moved off the original container - // during the operation. - seat->cursor->previous.x = seat->op_ref_lx; - seat->cursor->previous.y = seat->op_ref_ly; - if (seat->op_moved) { - cursor_send_pointer_motion(seat->cursor, 0); - } - } else { - cursor_set_image(seat->cursor, "left_ptr", NULL); - } -} - void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec, uint32_t button, enum wlr_button_state state) { seat->last_button = button; @@ -1238,3 +1082,44 @@ void seat_consider_warp_to_focus(struct sway_seat *seat) { wl_event_source_timer_update(seat->cursor->hide_source, cursor_get_timeout(seat->cursor)); } } + +bool seat_doing_seatop(struct sway_seat *seat) { + return seat->seatop_impl != NULL; +} + +void seatop_unref(struct sway_seat *seat, struct sway_container *con) { + if (seat->seatop_impl && seat->seatop_impl->unref) { + seat->seatop_impl->unref(seat, con); + } +} + +void seatop_motion(struct sway_seat *seat, uint32_t time_msec) { + if (seat->seatop_impl && seat->seatop_impl->motion) { + seat->seatop_impl->motion(seat, time_msec); + } +} + +void seatop_finish(struct sway_seat *seat) { + if (seat->seatop_impl && seat->seatop_impl->finish) { + seat->seatop_impl->finish(seat); + } + free(seat->seatop_data); + seat->seatop_data = NULL; + seat->seatop_impl = NULL; +} + +void seatop_abort(struct sway_seat *seat) { + if (seat->seatop_impl && seat->seatop_impl->abort) { + seat->seatop_impl->abort(seat); + } + free(seat->seatop_data); + seat->seatop_data = NULL; + seat->seatop_impl = NULL; +} + +void seatop_render(struct sway_seat *seat, struct sway_output *output, + pixman_region32_t *damage) { + if (seat->seatop_impl && seat->seatop_impl->render) { + seat->seatop_impl->render(seat, output, damage); + } +} diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c new file mode 100644 index 00000000..ad11c5ca --- /dev/null +++ b/sway/input/seatop_down.c @@ -0,0 +1,77 @@ +#define _POSIX_C_SOURCE 200809L +#include <wlr/types/wlr_cursor.h> +#include "sway/input/cursor.h" +#include "sway/input/seat.h" +#include "sway/tree/view.h" + +struct seatop_down_event { + struct sway_container *con; + double ref_lx, ref_ly; // cursor's x/y at start of op + double ref_con_lx, ref_con_ly; // container's x/y at start of op + bool moved; +}; + +static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { + struct seatop_down_event *e = seat->seatop_data; + struct sway_container *con = e->con; + if (seat_is_input_allowed(seat, con->view->surface)) { + double moved_x = seat->cursor->cursor->x - e->ref_lx; + double moved_y = seat->cursor->cursor->y - e->ref_ly; + double sx = e->ref_con_lx + moved_x; + double sy = e->ref_con_ly + moved_y; + wlr_seat_pointer_notify_motion(seat->wlr_seat, time_msec, sx, sy); + } + e->moved = true; +} + +static void handle_finish(struct sway_seat *seat) { + struct seatop_down_event *e = seat->seatop_data; + // Set the cursor's previous coords to the x/y at the start of the + // operation, so the container change will be detected if using + // focus_follows_mouse and the cursor moved off the original container + // during the operation. + seat->cursor->previous.x = e->ref_lx; + seat->cursor->previous.y = e->ref_ly; + if (e->moved) { + cursor_send_pointer_motion(seat->cursor, 0); + } +} + +static void handle_abort(struct sway_seat *seat) { + cursor_set_image(seat->cursor, "left_ptr", NULL); +} + +static void handle_unref(struct sway_seat *seat, struct sway_container *con) { + struct seatop_down_event *e = seat->seatop_data; + if (e->con == con) { + seatop_abort(seat); + } +} + +static const struct sway_seatop_impl seatop_impl = { + .motion = handle_motion, + .finish = handle_finish, + .abort = handle_abort, + .unref = handle_unref, +}; + +void seatop_begin_down(struct sway_seat *seat, + struct sway_container *con, uint32_t button, int sx, int sy) { + seatop_abort(seat); + + struct seatop_down_event *e = + calloc(1, sizeof(struct seatop_down_event)); + if (!e) { + return; + } + e->con = con; + e->ref_lx = seat->cursor->cursor->x; + e->ref_ly = seat->cursor->cursor->y; + e->ref_con_lx = sx; + e->ref_con_ly = sy; + e->moved = false; + + seat->seatop_impl = &seatop_impl; + seat->seatop_data = e; + seat->seatop_button = button; +} diff --git a/sway/input/seatop_move_floating.c b/sway/input/seatop_move_floating.c new file mode 100644 index 00000000..08e3a5a4 --- /dev/null +++ b/sway/input/seatop_move_floating.c @@ -0,0 +1,65 @@ +#define _POSIX_C_SOURCE 200809L +#include <wlr/types/wlr_cursor.h> +#include "sway/desktop.h" +#include "sway/input/cursor.h" +#include "sway/input/seat.h" + +struct seatop_move_floating_event { + struct sway_container *con; +}; + +static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { + struct seatop_move_floating_event *e = seat->seatop_data; + desktop_damage_whole_container(e->con); + container_floating_translate(e->con, + seat->cursor->cursor->x - seat->cursor->previous.x, + seat->cursor->cursor->y - seat->cursor->previous.y); + desktop_damage_whole_container(e->con); +} + +static void handle_finish(struct sway_seat *seat) { + struct seatop_move_floating_event *e = seat->seatop_data; + + // We "move" the container to its own location + // so it discovers its output again. + container_floating_move_to(e->con, e->con->x, e->con->y); + cursor_set_image(seat->cursor, "left_ptr", NULL); +} + +static void handle_abort(struct sway_seat *seat) { + cursor_set_image(seat->cursor, "left_ptr", NULL); +} + +static void handle_unref(struct sway_seat *seat, struct sway_container *con) { + struct seatop_move_floating_event *e = seat->seatop_data; + if (e->con == con) { + seatop_abort(seat); + } +} + +static const struct sway_seatop_impl seatop_impl = { + .motion = handle_motion, + .finish = handle_finish, + .abort = handle_abort, + .unref = handle_unref, +}; + +void seatop_begin_move_floating(struct sway_seat *seat, + struct sway_container *con, uint32_t button) { + seatop_abort(seat); + + struct seatop_move_floating_event *e = + calloc(1, sizeof(struct seatop_move_floating_event)); + if (!e) { + return; + } + e->con = con; + + seat->seatop_impl = &seatop_impl; + seat->seatop_data = e; + seat->seatop_button = button; + + container_raise_floating(con); + + cursor_set_image(seat->cursor, "grab", NULL); +} diff --git a/sway/input/seatop_move_tiling.c b/sway/input/seatop_move_tiling.c new file mode 100644 index 00000000..8b541f80 --- /dev/null +++ b/sway/input/seatop_move_tiling.c @@ -0,0 +1,335 @@ +#define _POSIX_C_SOURCE 200809L +#include <limits.h> +#include <wlr/types/wlr_cursor.h> +#include <wlr/util/edges.h> +#include "sway/desktop.h" +#include "sway/input/cursor.h" +#include "sway/input/seat.h" +#include "sway/output.h" +#include "sway/tree/arrange.h" +#include "sway/tree/node.h" +#include "sway/tree/view.h" +#include "sway/tree/workspace.h" + +// Thickness of the dropzone when dragging to the edge of a layout container +#define DROP_LAYOUT_BORDER 30 + +struct seatop_move_tiling_event { + struct sway_container *con; + struct sway_node *target_node; + enum wlr_edges target_edge; + struct wlr_box drop_box; + double ref_lx, ref_ly; // cursor's x/y at start of op + bool threshold_reached; +}; + +static void handle_render(struct sway_seat *seat, + struct sway_output *output, pixman_region32_t *damage) { + struct seatop_move_tiling_event *e = seat->seatop_data; + if (!e->threshold_reached) { + return; + } + if (e->target_node && node_get_output(e->target_node) == output) { + float color[4]; + memcpy(&color, config->border_colors.focused.indicator, + sizeof(float) * 4); + premultiply_alpha(color, 0.5); + struct wlr_box box; + memcpy(&box, &e->drop_box, sizeof(struct wlr_box)); + scale_box(&box, output->wlr_output->scale); + render_rect(output->wlr_output, damage, &box, color); + } +} + +static void handle_motion_prethreshold(struct sway_seat *seat) { + struct seatop_move_tiling_event *e = seat->seatop_data; + double cx = seat->cursor->cursor->x; + double cy = seat->cursor->cursor->y; + double sx = e->ref_lx; + double sy = e->ref_ly; + + // Get the scaled threshold for the output. Even if the operation goes + // across multiple outputs of varying scales, just use the scale for the + // output that the cursor is currently on for simplicity. + struct wlr_output *wlr_output = wlr_output_layout_output_at( + root->output_layout, cx, cy); + double output_scale = wlr_output ? wlr_output->scale : 1; + double threshold = config->tiling_drag_threshold * output_scale; + threshold *= threshold; + + // If the threshold has been exceeded, start the actual drag + if ((cx - sx) * (cx - sx) + (cy - sy) * (cy - sy) > threshold) { + e->threshold_reached = true; + cursor_set_image(seat->cursor, "grab", NULL); + } +} + +static void resize_box(struct wlr_box *box, enum wlr_edges edge, + int thickness) { + switch (edge) { + case WLR_EDGE_TOP: + box->height = thickness; + break; + case WLR_EDGE_LEFT: + box->width = thickness; + break; + case WLR_EDGE_RIGHT: + box->x = box->x + box->width - thickness; + box->width = thickness; + break; + case WLR_EDGE_BOTTOM: + box->y = box->y + box->height - thickness; + box->height = thickness; + break; + case WLR_EDGE_NONE: + box->x += thickness; + box->y += thickness; + box->width -= thickness * 2; + box->height -= thickness * 2; + break; + } +} + +static void handle_motion_postthreshold(struct sway_seat *seat) { + struct seatop_move_tiling_event *e = seat->seatop_data; + struct wlr_surface *surface = NULL; + double sx, sy; + struct sway_cursor *cursor = seat->cursor; + struct sway_node *node = node_at_coords(seat, + cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); + // Damage the old location + desktop_damage_box(&e->drop_box); + + if (!node) { + // Eg. hovered over a layer surface such as swaybar + e->target_node = NULL; + e->target_edge = WLR_EDGE_NONE; + return; + } + + if (node->type == N_WORKSPACE) { + // Emtpy workspace + e->target_node = node; + e->target_edge = WLR_EDGE_NONE; + workspace_get_box(node->sway_workspace, &e->drop_box); + desktop_damage_box(&e->drop_box); + return; + } + + // Deny moving within own workspace if this is the only child + struct sway_container *con = node->sway_container; + if (workspace_num_tiling_views(e->con->workspace) == 1 && + con->workspace == e->con->workspace) { + e->target_node = NULL; + e->target_edge = WLR_EDGE_NONE; + return; + } + + // Traverse the ancestors, trying to find a layout container perpendicular + // to the edge. Eg. close to the top or bottom of a horiz layout. + while (con) { + enum wlr_edges edge = WLR_EDGE_NONE; + enum sway_container_layout layout = container_parent_layout(con); + struct wlr_box parent; + con->parent ? container_get_box(con->parent, &parent) : + workspace_get_box(con->workspace, &parent); + if (layout == L_HORIZ || layout == L_TABBED) { + if (cursor->cursor->y < parent.y + DROP_LAYOUT_BORDER) { + edge = WLR_EDGE_TOP; + } else if (cursor->cursor->y > parent.y + parent.height + - DROP_LAYOUT_BORDER) { + edge = WLR_EDGE_BOTTOM; + } + } else if (layout == L_VERT || layout == L_STACKED) { + if (cursor->cursor->x < parent.x + DROP_LAYOUT_BORDER) { + edge = WLR_EDGE_LEFT; + } else if (cursor->cursor->x > parent.x + parent.width + - DROP_LAYOUT_BORDER) { + edge = WLR_EDGE_RIGHT; + } + } + if (edge) { + e->target_node = node_get_parent(&con->node); + e->target_edge = edge; + node_get_box(e->target_node, &e->drop_box); + resize_box(&e->drop_box, edge, DROP_LAYOUT_BORDER); + desktop_damage_box(&e->drop_box); + return; + } + con = con->parent; + } + + // Use the hovered view - but we must be over the actual surface + con = node->sway_container; + if (!con->view->surface || node == &e->con->node) { + e->target_node = NULL; + e->target_edge = WLR_EDGE_NONE; + return; + } + + // Find the closest edge + size_t thickness = fmin(con->content_width, con->content_height) * 0.3; + size_t closest_dist = INT_MAX; + size_t dist; + e->target_edge = WLR_EDGE_NONE; + if ((dist = cursor->cursor->y - con->y) < closest_dist) { + closest_dist = dist; + e->target_edge = WLR_EDGE_TOP; + } + if ((dist = cursor->cursor->x - con->x) < closest_dist) { + closest_dist = dist; + e->target_edge = WLR_EDGE_LEFT; + } + if ((dist = con->x + con->width - cursor->cursor->x) < closest_dist) { + closest_dist = dist; + e->target_edge = WLR_EDGE_RIGHT; + } + if ((dist = con->y + con->height - cursor->cursor->y) < closest_dist) { + closest_dist = dist; + e->target_edge = WLR_EDGE_BOTTOM; + } + + if (closest_dist > thickness) { + e->target_edge = WLR_EDGE_NONE; + } + + e->target_node = node; + e->drop_box.x = con->content_x; + e->drop_box.y = con->content_y; + e->drop_box.width = con->content_width; + e->drop_box.height = con->content_height; + resize_box(&e->drop_box, e->target_edge, thickness); + desktop_damage_box(&e->drop_box); +} + +static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { + struct seatop_move_tiling_event *e = seat->seatop_data; + if (e->threshold_reached) { + handle_motion_postthreshold(seat); + } else { + handle_motion_prethreshold(seat); + } +} + +static void handle_abort(struct sway_seat *seat) { + cursor_set_image(seat->cursor, "left_ptr", NULL); +} + +static bool is_parallel(enum sway_container_layout layout, + enum wlr_edges edge) { + bool layout_is_horiz = layout == L_HORIZ || layout == L_TABBED; + bool edge_is_horiz = edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT; + return layout_is_horiz == edge_is_horiz; +} + +static void handle_finish(struct sway_seat *seat) { + struct seatop_move_tiling_event *e = seat->seatop_data; + + if (!e->target_node) { + handle_abort(seat); + return; + } + + struct sway_container *con = e->con; + struct sway_container *old_parent = con->parent; + struct sway_workspace *old_ws = con->workspace; + struct sway_node *target_node = e->target_node; + struct sway_workspace *new_ws = target_node->type == N_WORKSPACE ? + target_node->sway_workspace : target_node->sway_container->workspace; + enum wlr_edges edge = e->target_edge; + int after = edge != WLR_EDGE_TOP && edge != WLR_EDGE_LEFT; + + container_detach(con); + + // Moving container into empty workspace + if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) { + workspace_add_tiling(new_ws, con); + } else if (target_node->type == N_CONTAINER) { + // Moving container before/after another + struct sway_container *target = target_node->sway_container; + enum sway_container_layout layout = container_parent_layout(target); + if (edge && !is_parallel(layout, edge)) { + enum sway_container_layout new_layout = edge == WLR_EDGE_TOP || + edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ; + container_split(target, new_layout); + } + container_add_sibling(target, con, after); + } else { + // Target is a workspace which requires splitting + enum sway_container_layout new_layout = edge == WLR_EDGE_TOP || + edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ; + workspace_split(new_ws, new_layout); + workspace_insert_tiling(new_ws, con, after); + } + + if (old_parent) { + container_reap_empty(old_parent); + } + + // This is a bit dirty, but we'll set the dimensions to that of a sibling. + // I don't think there's any other way to make it consistent without + // changing how we auto-size containers. + list_t *siblings = container_get_siblings(con); + if (siblings->length > 1) { + int index = list_find(siblings, con); + struct sway_container *sibling = index == 0 ? + siblings->items[1] : siblings->items[index - 1]; + con->width = sibling->width; + con->height = sibling->height; + } + + arrange_workspace(old_ws); + if (new_ws != old_ws) { + arrange_workspace(new_ws); + } + + cursor_set_image(seat->cursor, "left_ptr", NULL); +} + +static void handle_unref(struct sway_seat *seat, struct sway_container *con) { + struct seatop_move_tiling_event *e = seat->seatop_data; + if (e->target_node == &con->node) { // Drop target + e->target_node = NULL; + } + if (e->con == con) { // The container being moved + seatop_abort(seat); + } +} + +static const struct sway_seatop_impl seatop_impl = { + .motion = handle_motion, + .finish = handle_finish, + .abort = handle_abort, + .unref = handle_unref, + .render = handle_render, +}; + +void seatop_begin_move_tiling_threshold(struct sway_seat *seat, + struct sway_container *con, uint32_t button) { + seatop_abort(seat); + + struct seatop_move_tiling_event *e = + calloc(1, sizeof(struct seatop_move_tiling_event)); + if (!e) { + return; + } + e->con = con; + e->ref_lx = seat->cursor->cursor->x; + e->ref_ly = seat->cursor->cursor->y; + + seat->seatop_impl = &seatop_impl; + seat->seatop_data = e; + seat->seatop_button = button; + + container_raise_floating(con); +} + +void seatop_begin_move_tiling(struct sway_seat *seat, + struct sway_container *con, uint32_t button) { + seatop_begin_move_tiling_threshold(seat, con, button); + struct seatop_move_tiling_event *e = seat->seatop_data; + if (e) { + e->threshold_reached = true; + cursor_set_image(seat->cursor, "grab", NULL); + } +} diff --git a/sway/input/seatop_resize_floating.c b/sway/input/seatop_resize_floating.c new file mode 100644 index 00000000..12851b40 --- /dev/null +++ b/sway/input/seatop_resize_floating.c @@ -0,0 +1,199 @@ +#define _POSIX_C_SOURCE 200809L +#include <limits.h> +#include <wlr/types/wlr_cursor.h> +#include <wlr/types/wlr_xcursor_manager.h> +#include "sway/input/cursor.h" +#include "sway/input/seat.h" +#include "sway/tree/arrange.h" +#include "sway/tree/view.h" +#include "sway/tree/workspace.h" + +struct seatop_resize_floating_event { + struct sway_container *con; + enum wlr_edges edge; + bool preserve_ratio; + double ref_lx, ref_ly; // cursor's x/y at start of op + double ref_width, ref_height; // container's size at start of op + double ref_con_lx, ref_con_ly; // container's x/y at start of op +}; + +static void calculate_floating_constraints(struct sway_container *con, + int *min_width, int *max_width, int *min_height, int *max_height) { + if (config->floating_minimum_width == -1) { // no minimum + *min_width = 0; + } else if (config->floating_minimum_width == 0) { // automatic + *min_width = 75; + } else { + *min_width = config->floating_minimum_width; + } + + if (config->floating_minimum_height == -1) { // no minimum + *min_height = 0; + } else if (config->floating_minimum_height == 0) { // automatic + *min_height = 50; + } else { + *min_height = config->floating_minimum_height; + } + + if (config->floating_maximum_width == -1) { // no maximum + *max_width = INT_MAX; + } else if (config->floating_maximum_width == 0) { // automatic + *max_width = con->workspace->width; + } else { + *max_width = config->floating_maximum_width; + } + + if (config->floating_maximum_height == -1) { // no maximum + *max_height = INT_MAX; + } else if (config->floating_maximum_height == 0) { // automatic + *max_height = con->workspace->height; + } else { + *max_height = config->floating_maximum_height; + } +} + +static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { + struct seatop_resize_floating_event *e = seat->seatop_data; + struct sway_container *con = e->con; + enum wlr_edges edge = e->edge; + struct sway_cursor *cursor = seat->cursor; + + // The amount the mouse has moved since the start of the resize operation + // Positive is down/right + double mouse_move_x = cursor->cursor->x - e->ref_lx; + double mouse_move_y = cursor->cursor->y - e->ref_ly; + + if (edge == WLR_EDGE_TOP || edge == WLR_EDGE_BOTTOM) { + mouse_move_x = 0; + } + if (edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT) { + mouse_move_y = 0; + } + + double grow_width = edge & WLR_EDGE_LEFT ? -mouse_move_x : mouse_move_x; + double grow_height = edge & WLR_EDGE_TOP ? -mouse_move_y : mouse_move_y; + + if (e->preserve_ratio) { + double x_multiplier = grow_width / e->ref_width; + double y_multiplier = grow_height / e->ref_height; + double max_multiplier = fmax(x_multiplier, y_multiplier); + grow_width = e->ref_width * max_multiplier; + grow_height = e->ref_height * max_multiplier; + } + + // Determine new width/height, and accommodate for floating min/max values + double width = e->ref_width + grow_width; + double height = e->ref_height + grow_height; + int min_width, max_width, min_height, max_height; + calculate_floating_constraints(con, &min_width, &max_width, + &min_height, &max_height); + width = fmax(min_width, fmin(width, max_width)); + height = fmax(min_height, fmin(height, max_height)); + + // Apply the view's min/max size + if (con->view) { + double view_min_width, view_max_width, view_min_height, view_max_height; + view_get_constraints(con->view, &view_min_width, &view_max_width, + &view_min_height, &view_max_height); + width = fmax(view_min_width, fmin(width, view_max_width)); + height = fmax(view_min_height, fmin(height, view_max_height)); + } + + // Recalculate these, in case we hit a min/max limit + grow_width = width - e->ref_width; + grow_height = height - e->ref_height; + + // Determine grow x/y values - these are relative to the container's x/y at + // the start of the resize operation. + double grow_x = 0, grow_y = 0; + if (edge & WLR_EDGE_LEFT) { + grow_x = -grow_width; + } else if (edge & WLR_EDGE_RIGHT) { + grow_x = 0; + } else { + grow_x = -grow_width / 2; + } + if (edge & WLR_EDGE_TOP) { + grow_y = -grow_height; + } else if (edge & WLR_EDGE_BOTTOM) { + grow_y = 0; + } else { + grow_y = -grow_height / 2; + } + + // Determine the amounts we need to bump everything relative to the current + // size. + int relative_grow_width = width - con->width; + int relative_grow_height = height - con->height; + int relative_grow_x = (e->ref_con_lx + grow_x) - con->x; + int relative_grow_y = (e->ref_con_ly + grow_y) - con->y; + + // Actually resize stuff + con->x += relative_grow_x; + con->y += relative_grow_y; + con->width += relative_grow_width; + con->height += relative_grow_height; + + con->content_x += relative_grow_x; + con->content_y += relative_grow_y; + con->content_width += relative_grow_width; + con->content_height += relative_grow_height; + + arrange_container(con); +} + +static void handle_finish(struct sway_seat *seat) { + cursor_set_image(seat->cursor, "left_ptr", NULL); +} + +static void handle_abort(struct sway_seat *seat) { + cursor_set_image(seat->cursor, "left_ptr", NULL); +} + +static void handle_unref(struct sway_seat *seat, struct sway_container *con) { + struct seatop_resize_floating_event *e = seat->seatop_data; + if (e->con == con) { + seatop_abort(seat); + } +} + +static const struct sway_seatop_impl seatop_impl = { + .motion = handle_motion, + .finish = handle_finish, + .abort = handle_abort, + .unref = handle_unref, +}; + +void seatop_begin_resize_floating(struct sway_seat *seat, + struct sway_container *con, uint32_t button, enum wlr_edges edge) { + seatop_abort(seat); + + struct seatop_resize_floating_event *e = + calloc(1, sizeof(struct seatop_resize_floating_event)); + if (!e) { + return; + } + e->con = con; + + struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); + e->preserve_ratio = keyboard && + (wlr_keyboard_get_modifiers(keyboard) & WLR_MODIFIER_SHIFT); + + e->edge = edge == WLR_EDGE_NONE ? WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT : edge; + e->ref_lx = seat->cursor->cursor->x; + e->ref_ly = seat->cursor->cursor->y; + e->ref_con_lx = con->x; + e->ref_con_ly = con->y; + e->ref_width = con->width; + e->ref_height = con->height; + + seat->seatop_impl = &seatop_impl; + seat->seatop_data = e; + seat->seatop_button = button; + + container_raise_floating(con); + + const char *image = edge == WLR_EDGE_NONE ? + "se-resize" : wlr_xcursor_get_resize_name(edge); + cursor_set_image(seat->cursor, image, NULL); +} diff --git a/sway/input/seatop_resize_tiling.c b/sway/input/seatop_resize_tiling.c new file mode 100644 index 00000000..30431f04 --- /dev/null +++ b/sway/input/seatop_resize_tiling.c @@ -0,0 +1,92 @@ +#define _POSIX_C_SOURCE 200809L +#include <wlr/types/wlr_cursor.h> +#include "sway/commands.h" +#include "sway/input/cursor.h" +#include "sway/input/seat.h" + +struct seatop_resize_tiling_event { + struct sway_container *con; + enum wlr_edges edge; + double ref_lx, ref_ly; // cursor's x/y at start of op + double ref_width, ref_height; // container's size at start of op + double ref_con_lx, ref_con_ly; // container's x/y at start of op +}; + +static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { + struct seatop_resize_tiling_event *e = seat->seatop_data; + int amount_x = 0; + int amount_y = 0; + int moved_x = seat->cursor->cursor->x - e->ref_lx; + int moved_y = seat->cursor->cursor->y - e->ref_ly; + enum wlr_edges edge_x = WLR_EDGE_NONE; + enum wlr_edges edge_y = WLR_EDGE_NONE; + struct sway_container *con = e->con; + + if (e->edge & WLR_EDGE_TOP) { + amount_y = (e->ref_height - moved_y) - con->height; + edge_y = WLR_EDGE_TOP; + } else if (e->edge & WLR_EDGE_BOTTOM) { + amount_y = (e->ref_height + moved_y) - con->height; + edge_y = WLR_EDGE_BOTTOM; + } + if (e->edge & WLR_EDGE_LEFT) { + amount_x = (e->ref_width - moved_x) - con->width; + edge_x = WLR_EDGE_LEFT; + } else if (e->edge & WLR_EDGE_RIGHT) { + amount_x = (e->ref_width + moved_x) - con->width; + edge_x = WLR_EDGE_RIGHT; + } + + if (amount_x != 0) { + container_resize_tiled(e->con, edge_x, amount_x); + } + if (amount_y != 0) { + container_resize_tiled(e->con, edge_y, amount_y); + } +} + +static void handle_finish(struct sway_seat *seat) { + cursor_set_image(seat->cursor, "left_ptr", NULL); +} + +static void handle_abort(struct sway_seat *seat) { + cursor_set_image(seat->cursor, "left_ptr", NULL); +} + +static void handle_unref(struct sway_seat *seat, struct sway_container *con) { + struct seatop_resize_tiling_event *e = seat->seatop_data; + if (e->con == con) { + seatop_abort(seat); + } +} + +static const struct sway_seatop_impl seatop_impl = { + .motion = handle_motion, + .finish = handle_finish, + .abort = handle_abort, + .unref = handle_unref, +}; + +void seatop_begin_resize_tiling(struct sway_seat *seat, + struct sway_container *con, uint32_t button, enum wlr_edges edge) { + seatop_abort(seat); + + struct seatop_resize_tiling_event *e = + calloc(1, sizeof(struct seatop_resize_tiling_event)); + if (!e) { + return; + } + e->con = con; + e->edge = edge; + + e->ref_lx = seat->cursor->cursor->x; + e->ref_ly = seat->cursor->cursor->y; + e->ref_con_lx = con->x; + e->ref_con_ly = con->y; + e->ref_width = con->width; + e->ref_height = con->height; + + seat->seatop_impl = &seatop_impl; + seat->seatop_data = e; + seat->seatop_button = button; +} diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 61602343..6e5ba4fd 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -13,6 +13,7 @@ #include "sway/input/input-manager.h" #include "sway/input/cursor.h" #include "sway/input/seat.h" +#include <wlr/backend/libinput.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_output.h> #include <xkbcommon/xkbcommon.h> @@ -600,6 +601,26 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) { } } + if (wlr_input_device_is_libinput(device->wlr_device)) { + struct libinput_device *libinput_dev; + libinput_dev = wlr_libinput_get_device_handle(device->wlr_device); + + const char *events = "unknown"; + switch (libinput_device_config_send_events_get_mode(libinput_dev)) { + case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED: + events = "enabled"; + break; + case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE: + events = "disabled_on_external_mouse"; + break; + case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED: + events = "disabled"; + break; + } + json_object_object_add(object, "libinput_send_events", + json_object_new_string(events)); + } + return object; } @@ -687,6 +708,10 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { } json_object_object_add(json, "bar_height", json_object_new_int(bar->height)); + json_object_object_add(json, "status_padding", + json_object_new_int(bar->status_padding)); + json_object_object_add(json, "status_edge_padding", + json_object_new_int(bar->status_edge_padding)); json_object_object_add(json, "wrap_scroll", json_object_new_boolean(bar->wrap_scroll)); json_object_object_add(json, "workspace_buttons", diff --git a/sway/meson.build b/sway/meson.build index 9518c62b..93858336 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -23,6 +23,11 @@ sway_sources = files( 'input/input-manager.c', 'input/seat.c', + 'input/seatop_down.c', + 'input/seatop_move_floating.c', + 'input/seatop_move_tiling.c', + 'input/seatop_resize_floating.c', + 'input/seatop_resize_tiling.c', 'input/cursor.c', 'input/keyboard.c', @@ -116,6 +121,8 @@ sway_sources = files( 'commands/bar/position.c', 'commands/bar/separator_symbol.c', 'commands/bar/status_command.c', + 'commands/bar/status_edge_padding.c', + 'commands/bar/status_padding.c', 'commands/bar/strip_workspace_numbers.c', 'commands/bar/strip_workspace_name.c', 'commands/bar/swaybar_command.c', diff --git a/sway/sway-bar.5.scd b/sway/sway-bar.5.scd index ac1949b7..3f6b4298 100644 --- a/sway/sway-bar.5.scd +++ b/sway/sway-bar.5.scd @@ -69,7 +69,7 @@ Sway allows configuring swaybar in the sway configuration file. use. *height* <height> - Sets the height of the bar. Default height will match the font size. + Sets the height of the bar. Default height (0) will match the font size. *bindcode* [--release] <event-code> <command> Executes _command_ when the mouse button has been pressed (or if _released_ @@ -100,6 +100,16 @@ Sway allows configuring swaybar in the sway configuration file. *modifier* <Modifier>|none Specifies the modifier key that shows a hidden bar. Default is _Mod4_. +*status\_padding* <padding> + Sets the vertical padding that is used for the status line. The default is + _1_. If _padding_ is _0_, blocks will be able to take up the full height of + the bar. This value will be multiplied by the output scale. + +*status\_edge\_padding* <padding> + Sets the padding that is used when the status line is at the right edge of + the bar. This value will be multiplied by the output scale. The default is + _3_. + ## TRAY Swaybar provides a system tray where third-party applications may place icons. diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index 820194a9..c2673f2a 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd @@ -82,9 +82,12 @@ The following commands may only be used in the configuration file. *input* <identifier> dwt enabled|disabled Enables or disables disable-while-typing for the specified input device. -*input* <identifier> events enabled|disabled|disabled\_on\_external\_mouse - Enables or disables send\_events for specified input device. (Disabling - send\_events disables the input device) +*input* <identifier> events enabled|disabled|disabled\_on\_external\_mouse|toggle + Enables or disables send\_events for specified input device. Disabling + send\_events disables the input device. The _toggle_ option cannot be used + in the config. The order is enabled, disabled\_on\_external\_mouse, + disabled, (loop back to enabled). Any mode which is not supported by the + device will be skipped during the toggle. *input* <identifier> left\_handed enabled|disabled Enables or disables left handed mode for specified input device. @@ -105,10 +108,11 @@ The following commands may only be used in the configuration file. *input* <identifier> repeat\_rate <characters per second> Sets the frequency of key repeats once the repeat\_delay has passed. -*input* <identifier> scroll\_button <button\_identifier> - Sets button used for scroll\_method on\_button\_down. The button identifier - can be obtained from `libinput debug-events`. - If set to 0, it disables the scroll\_button on\_button\_down. +*input* <identifier> scroll\_button disable|button[1-3,8,9]|<event-code-or-name> + Sets the button used for scroll\_method on\_button\_down. The button can + be given as an event name or code, which can be obtained from `libinput + debug-events`, or as a x11 mouse button (button[1-3,8,9]). If set to + _disable_, it disables the scroll\_method on\_button\_down. *input* <identifier> scroll\_factor <floating point value> Changes the scroll factor for the specified input device. Scroll speed will @@ -141,6 +145,19 @@ in their own "seat"). Attach an input device to this seat by its input identifier. A special value of "\*" will attach all devices to the seat. +*seat* <seat> cursor move|set <x> <y> + Move specified seat's cursor relative to current position or wrap to + absolute coordinates (with respect to the global coordinate space). + Specifying either value as 0 will not update that coordinate. + +*seat* <seat> cursor press|release button[1-9]|<event-name-or-code> + Simulate pressing (or releasing) the specified mouse button on the + specified seat. The button can either be provided as a button event name or + event code, which can be obtained from `libinput debug-events`, or as an x11 + mouse button (button[1-9]). If using button[4-7], which map to axes, an axis + event will be simulated, however _press_ and _release_ will be ignored and + both will occur. + *seat* <name> fallback true|false Set this seat as the fallback seat. A fallback seat will attach any device not explicitly attached to another seat (similar to a "default" seat). diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 3398ad58..a9f60c1b 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -491,15 +491,6 @@ The default colors are: *seat* <seat> <seat-subcommands...> For details on seat subcommands, see *sway-input*(5). -*seat* <seat> cursor move|set <x> <y> - Move specified seat's cursor relative to current position or wrap to - absolute coordinates (with respect to the global coordinate space). - Specifying either value as 0 will not update that coordinate. - -*seat* <seat> cursor press|release left|right|1|2|3... - Simulate pressing (or releasing) the specified mouse button on the - specified seat. - *kill* Kills (closes) the currently focused container and all of its children. diff --git a/sway/tree/container.c b/sway/tree/container.c index 99262356..d9c721f5 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -864,15 +864,7 @@ bool container_has_urgent_child(struct sway_container *container) { void container_end_mouse_operation(struct sway_container *container) { struct sway_seat *seat; wl_list_for_each(seat, &server.input->seats, link) { - if (seat->op_container == container) { - seat->op_target_node = NULL; // ensure tiling move doesn't apply - seat_end_mouse_operation(seat); - } - // If the user is doing a tiling drag over this container, - // keep the operation active but unset the target container. - if (seat->op_target_node == &container->node) { - seat->op_target_node = NULL; - } + seatop_unref(seat, container); } } @@ -1384,3 +1376,16 @@ void container_update_marks_textures(struct sway_container *con) { &config->border_colors.urgent); container_damage_whole(con); } + +void container_raise_floating(struct sway_container *con) { + // Bring container to front by putting it at the end of the floating list. + struct sway_container *floater = con; + while (floater->parent) { + floater = floater->parent; + } + if (container_is_floating(floater)) { + list_move_to_end(floater->workspace->floating, floater); + node_set_dirty(&floater->workspace->node); + } +} + diff --git a/swaybar/bar.c b/swaybar/bar.c index 7aed4dca..d36367fc 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -59,6 +59,7 @@ static void swaybar_output_free(struct swaybar_output *output) { free_workspaces(&output->workspaces); wl_list_remove(&output->link); free(output->name); + free(output->identifier); free(output); } @@ -166,13 +167,15 @@ bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) { return visible; } -static bool bar_uses_output(struct swaybar *bar, const char *name) { - if (bar->config->all_outputs) { +static bool bar_uses_output(struct swaybar_output *output) { + if (output->bar->config->all_outputs) { return true; } + char *identifier = output->identifier; struct config_output *coutput; - wl_list_for_each(coutput, &bar->config->outputs, link) { - if (strcmp(coutput->name, name) == 0) { + wl_list_for_each(coutput, &output->bar->config->outputs, link) { + if (strcmp(coutput->name, output->name) == 0 || + (identifier && strcmp(coutput->name, identifier) == 0)) { return true; } } @@ -233,7 +236,7 @@ static void xdg_output_handle_done(void *data, struct swaybar *bar = output->bar; assert(output->name != NULL); - if (!bar_uses_output(bar, output->name)) { + if (!bar_uses_output(output)) { swaybar_output_free(output); return; } @@ -258,7 +261,22 @@ static void xdg_output_handle_name(void *data, static void xdg_output_handle_description(void *data, struct zxdg_output_v1 *xdg_output, const char *description) { - // Who cares + // wlroots currently sets the description to `make model serial (name)` + // If this changes in the future, this will need to be modified. + struct swaybar_output *output = data; + free(output->identifier); + output->identifier = NULL; + char *paren = strrchr(description, '('); + if (paren) { + size_t length = paren - description; + output->identifier = malloc(length); + if (!output->identifier) { + wlr_log(WLR_ERROR, "Failed to allocate output identifier"); + return; + } + strncpy(output->identifier, description, length); + output->identifier[length - 1] = '\0'; + } } struct zxdg_output_v1_listener xdg_output_listener = { diff --git a/swaybar/config.c b/swaybar/config.c index 9cafe061..d4cc9b1a 100644 --- a/swaybar/config.c +++ b/swaybar/config.c @@ -37,6 +37,8 @@ struct swaybar_config *init_config(void) { config->workspace_buttons = true; config->bindings = create_list(); wl_list_init(&config->outputs); + config->status_padding = 1; + config->status_edge_padding = 3; /* height */ config->height = 0; diff --git a/swaybar/ipc.c b/swaybar/ipc.c index ba53d95d..097f9161 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -157,7 +157,7 @@ static bool ipc_parse_config( json_object *font, *gaps, *bar_height, *wrap_scroll, *workspace_buttons; json_object *strip_workspace_numbers, *strip_workspace_name; json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol; - json_object *outputs, *bindings; + json_object *outputs, *bindings, *status_padding, *status_edge_padding; json_object_object_get_ex(bar_config, "mode", &mode); json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); json_object_object_get_ex(bar_config, "position", &position); @@ -176,6 +176,9 @@ static bool ipc_parse_config( json_object_object_get_ex(bar_config, "outputs", &outputs); json_object_object_get_ex(bar_config, "pango_markup", &markup); json_object_object_get_ex(bar_config, "bindings", &bindings); + json_object_object_get_ex(bar_config, "status_padding", &status_padding); + json_object_object_get_ex(bar_config, "status_edge_padding", + &status_edge_padding); if (status_command) { free(config->status_command); config->status_command = strdup(json_object_get_string(status_command)); @@ -209,6 +212,12 @@ static bool ipc_parse_config( if (bar_height) { config->height = json_object_get_int(bar_height); } + if (status_padding) { + config->status_padding = json_object_get_int(status_padding); + } + if (status_edge_padding) { + config->status_edge_padding = json_object_get_int(status_edge_padding); + } if (gaps) { json_object *top = json_object_object_get(gaps, "top"); if (top) { diff --git a/swaybar/render.c b/swaybar/render.c index 670e8e74..55f680ed 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -36,7 +36,8 @@ static uint32_t render_status_line_error(cairo_t *cairo, cairo_set_source_u32(cairo, 0xFF0000FF); int margin = 3 * output->scale; - int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; + double ws_vertical_padding = + output->bar->config->status_padding * output->scale; char *font = output->bar->config->font; int text_width, text_height; @@ -45,7 +46,8 @@ static uint32_t render_status_line_error(cairo_t *cairo, uint32_t ideal_height = text_height + ws_vertical_padding * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } *x -= text_width + margin; @@ -72,12 +74,13 @@ static uint32_t render_status_line_text(cairo_t *cairo, get_text_size(cairo, config->font, &text_width, &text_height, NULL, output->scale, config->pango_markup, "%s", text); - int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; + double ws_vertical_padding = config->status_padding * output->scale; int margin = 3 * output->scale; uint32_t ideal_height = text_height + ws_vertical_padding * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } @@ -154,7 +157,7 @@ static uint32_t render_status_block(cairo_t *cairo, output->scale, block->markup, "%s", block->full_text); int margin = 3 * output->scale; - double ws_vertical_padding = WS_VERTICAL_PADDING * 2 * output->scale; + double ws_vertical_padding = config->status_padding * output->scale; int width = text_width; if (width < block->min_width) { @@ -164,7 +167,8 @@ static uint32_t render_status_block(cairo_t *cairo, double block_width = width; uint32_t ideal_height = text_height + ws_vertical_padding * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } @@ -186,7 +190,8 @@ static uint32_t render_status_block(cairo_t *cairo, output->scale, false, "%s", config->sep_symbol); uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; uint32_t _ideal_surface_height = _ideal_height / output->scale; - if (output->height < _ideal_surface_height) { + if (!output->bar->config->height && + output->height < _ideal_surface_height) { return _ideal_surface_height; } if (sep_width > sep_block_width) { @@ -194,8 +199,8 @@ static uint32_t render_status_block(cairo_t *cairo, } } *x -= sep_block_width; - } else { - *x -= margin; + } else if (config->status_edge_padding) { + *x -= config->status_edge_padding * output->scale; } uint32_t height = output->height * output->scale; @@ -213,8 +218,8 @@ static uint32_t render_status_block(cairo_t *cairo, } double x_pos = *x; - double y_pos = WS_VERTICAL_PADDING * output->scale; - double render_height = height - ws_vertical_padding + output->scale; + double y_pos = ws_vertical_padding; + double render_height = height - ws_vertical_padding * 2; uint32_t bg_color = block->urgent ? config->colors.urgent_workspace.background : block->background; @@ -287,7 +292,7 @@ static uint32_t render_status_block(cairo_t *cairo, static uint32_t render_status_line_i3bar(cairo_t *cairo, struct swaybar_output *output, double *x) { uint32_t max_height = 0; - bool edge = true; + bool edge = *x == output->width * output->scale; struct i3bar_block *block; wl_list_for_each(block, &output->bar->status->blocks, link) { uint32_t h = render_status_block(cairo, output, block, x, edge); @@ -333,7 +338,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, uint32_t ideal_height = text_height + ws_vertical_padding * 2 + border_width * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; @@ -399,7 +405,8 @@ static uint32_t render_workspace_button(cairo_t *cairo, uint32_t ideal_height = ws_vertical_padding * 2 + text_height + border_width * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } @@ -526,7 +533,7 @@ void render_frame(struct swaybar_output *output) { cairo_restore(cairo); uint32_t height = render_to_cairo(cairo, output); int config_height = output->bar->config->height; - if (config_height >= 0 && height < (uint32_t)config_height) { + if (config_height > 0) { height = config_height; } if (height != output->height || output->width == 0) { diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c index 0c3517cb..d5d0c84e 100644 --- a/swaybar/tray/tray.c +++ b/swaybar/tray/tray.c @@ -101,13 +101,17 @@ void tray_in(int fd, short mask, void *data) { } static int cmp_output(const void *item, const void *cmp_to) { - return strcmp(item, cmp_to); + const struct swaybar_output *output = cmp_to; + if (output->identifier && strcmp(item, output->identifier) == 0) { + return 0; + } + return strcmp(item, output->name); } uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) { struct swaybar_config *config = output->bar->config; if (config->tray_outputs) { - if (list_seq_find(config->tray_outputs, cmp_output, output->name) == -1) { + if (list_seq_find(config->tray_outputs, cmp_output, output) == -1) { return 0; } } // else display on all diff --git a/swayidle/main.c b/swayidle/main.c deleted file mode 100644 index 41eecc41..00000000 --- a/swayidle/main.c +++ /dev/null @@ -1,483 +0,0 @@ -#define _POSIX_C_SOURCE 200809L -#include <assert.h> -#include <errno.h> -#include <fcntl.h> -#include <getopt.h> -#include <pthread.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/wait.h> -#include <unistd.h> -#include <wayland-client-protocol.h> -#include <wayland-client.h> -#include <wayland-server.h> -#include <wayland-util.h> -#include <wlr/config.h> -#include <wlr/util/log.h> -#include "config.h" -#include "idle-client-protocol.h" -#include "list.h" -#if HAVE_SYSTEMD -#include <systemd/sd-bus.h> -#include <systemd/sd-login.h> -#elif HAVE_ELOGIND -#include <elogind/sd-bus.h> -#include <elogind/sd-login.h> -#endif - -static struct org_kde_kwin_idle *idle_manager = NULL; -static struct wl_seat *seat = NULL; - -struct swayidle_state { - struct wl_display *display; - struct wl_event_loop *event_loop; - list_t *timeout_cmds; // struct swayidle_timeout_cmd * - char *lock_cmd; -} state; - -struct swayidle_timeout_cmd { - int timeout, registered_timeout; - struct org_kde_kwin_idle_timeout *idle_timer; - char *idle_cmd; - char *resume_cmd; -}; - -void sway_terminate(int exit_code) { - wl_display_disconnect(state.display); - wl_event_loop_destroy(state.event_loop); - exit(exit_code); -} - -static void cmd_exec(char *param) { - wlr_log(WLR_DEBUG, "Cmd exec %s", param); - pid_t pid = fork(); - if (pid == 0) { - pid = fork(); - if (pid == 0) { - char *const cmd[] = { "sh", "-c", param, NULL, }; - execvp(cmd[0], cmd); - wlr_log_errno(WLR_ERROR, "execve failed!"); - exit(1); - } else if (pid < 0) { - wlr_log_errno(WLR_ERROR, "fork failed"); - exit(1); - } - exit(0); - } else if (pid < 0) { - wlr_log_errno(WLR_ERROR, "fork failed"); - } else { - wlr_log(WLR_DEBUG, "Spawned process %s", param); - waitpid(pid, NULL, 0); - } -} - -#if HAVE_SYSTEMD || HAVE_ELOGIND -static int lock_fd = -1; -static int ongoing_fd = -1; -static struct sd_bus *bus = NULL; - -static int release_lock(void *data) { - wlr_log(WLR_INFO, "Releasing sleep lock %d", ongoing_fd); - if (ongoing_fd >= 0) { - close(ongoing_fd); - } - ongoing_fd = -1; - return 0; -} - -static void acquire_sleep_lock(void) { - sd_bus_message *msg = NULL; - sd_bus_error error = SD_BUS_ERROR_NULL; - int ret = sd_bus_call_method(bus, "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", "Inhibit", - &error, &msg, "ssss", "sleep", "swayidle", - "Setup Up Lock Screen", "delay"); - if (ret < 0) { - wlr_log(WLR_ERROR, "Failed to send Inhibit signal: %s", error.message); - sd_bus_error_free(&error); - return; - } - - ret = sd_bus_message_read(msg, "h", &lock_fd); - if (ret < 0) { - wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s", - strerror(-ret)); - sd_bus_error_free(&error); - sd_bus_message_unref(msg); - return; - } else { - wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd); - } - - // sd_bus_message_unref closes the file descriptor so we need - // to copy it beforehand - lock_fd = fcntl(lock_fd, F_DUPFD_CLOEXEC, 3); - if (lock_fd < 0) { - wlr_log(WLR_ERROR, "Failed to copy sleep lock fd: %s", - strerror(errno)); - } - - sd_bus_error_free(&error); - sd_bus_message_unref(msg); -} - -static int prepare_for_sleep(sd_bus_message *msg, void *userdata, - sd_bus_error *ret_error) { - /* "b" apparently reads into an int, not a bool */ - int going_down = 1; - int ret = sd_bus_message_read(msg, "b", &going_down); - if (ret < 0) { - wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s", - strerror(-ret)); - } - wlr_log(WLR_DEBUG, "PrepareForSleep signal received %d", going_down); - if (!going_down) { - acquire_sleep_lock(); - return 0; - } - - ongoing_fd = lock_fd; - - if (state.lock_cmd) { - cmd_exec(state.lock_cmd); - } - - if (ongoing_fd >= 0) { - struct wl_event_source *source = - wl_event_loop_add_timer(state.event_loop, release_lock, NULL); - wl_event_source_timer_update(source, 1000); - } - - wlr_log(WLR_DEBUG, "Prepare for sleep done"); - return 0; -} - -static int dbus_event(int fd, uint32_t mask, void *data) { - sd_bus *bus = data; - - if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) { - sway_terminate(0); - } - - int count = 0; - if (mask & WL_EVENT_READABLE) { - count = sd_bus_process(bus, NULL); - } - if (mask & WL_EVENT_WRITABLE) { - sd_bus_flush(bus); - } - if (mask == 0) { - sd_bus_flush(bus); - } - - if (count < 0) { - wlr_log_errno(WLR_ERROR, "sd_bus_process failed, exiting"); - sway_terminate(0); - } - - return count; -} - -static void setup_sleep_listener(void) { - int ret = sd_bus_default_system(&bus); - if (ret < 0) { - wlr_log(WLR_ERROR, "Failed to open D-Bus connection: %s", - strerror(-ret)); - return; - } - - char str[256]; - const char *fmt = "type='signal'," - "sender='org.freedesktop.login1'," - "interface='org.freedesktop.login1.%s'," - "member='%s'," "path='%s'"; - - snprintf(str, sizeof(str), fmt, "Manager", "PrepareForSleep", - "/org/freedesktop/login1"); - ret = sd_bus_add_match(bus, NULL, str, prepare_for_sleep, NULL); - if (ret < 0) { - wlr_log(WLR_ERROR, "Failed to add D-Bus match: %s", strerror(-ret)); - return; - } - acquire_sleep_lock(); - - struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop, - sd_bus_get_fd(bus), WL_EVENT_READABLE, dbus_event, bus); - wl_event_source_check(source); -} -#endif - -static void handle_global(void *data, struct wl_registry *registry, - uint32_t name, const char *interface, uint32_t version) { - if (strcmp(interface, org_kde_kwin_idle_interface.name) == 0) { - idle_manager = - wl_registry_bind(registry, name, &org_kde_kwin_idle_interface, 1); - } else if (strcmp(interface, wl_seat_interface.name) == 0) { - seat = wl_registry_bind(registry, name, &wl_seat_interface, 1); - } -} - -static void handle_global_remove(void *data, struct wl_registry *registry, - uint32_t name) { - // Who cares -} - -static const struct wl_registry_listener registry_listener = { - .global = handle_global, - .global_remove = handle_global_remove, -}; - -static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener; - -static void register_timeout(struct swayidle_timeout_cmd *cmd, - int timeout) { - if (cmd->idle_timer != NULL) { - org_kde_kwin_idle_timeout_destroy(cmd->idle_timer); - cmd->idle_timer = NULL; - } - if (timeout < 0) { - wlr_log(WLR_DEBUG, "Not registering idle timeout"); - return; - } - wlr_log(WLR_DEBUG, "Register with timeout: %d", timeout); - cmd->idle_timer = - org_kde_kwin_idle_get_idle_timeout(idle_manager, seat, timeout); - org_kde_kwin_idle_timeout_add_listener(cmd->idle_timer, - &idle_timer_listener, cmd); - cmd->registered_timeout = timeout; -} - -static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) { - struct swayidle_timeout_cmd *cmd = data; - wlr_log(WLR_DEBUG, "idle state"); - if (cmd->idle_cmd) { - cmd_exec(cmd->idle_cmd); - } -} - -static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) { - struct swayidle_timeout_cmd *cmd = data; - wlr_log(WLR_DEBUG, "active state"); - if (cmd->registered_timeout != cmd->timeout) { - register_timeout(cmd, cmd->timeout); - } - if (cmd->resume_cmd) { - cmd_exec(cmd->resume_cmd); - } -} - -static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = { - .idle = handle_idle, - .resumed = handle_resume, -}; - -static char *parse_command(int argc, char **argv) { - if (argc < 1) { - wlr_log(WLR_ERROR, "Missing command"); - return NULL; - } - - wlr_log(WLR_DEBUG, "Command: %s", argv[0]); - return strdup(argv[0]); -} - -static int parse_timeout(int argc, char **argv) { - if (argc < 3) { - wlr_log(WLR_ERROR, "Too few parameters to timeout command. " - "Usage: timeout <seconds> <command>"); - exit(-1); - } - errno = 0; - char *endptr; - int seconds = strtoul(argv[1], &endptr, 10); - if (errno != 0 || *endptr != '\0') { - wlr_log(WLR_ERROR, "Invalid timeout parameter '%s', it should be a " - "numeric value representing seconds", optarg); - exit(-1); - } - - struct swayidle_timeout_cmd *cmd = - calloc(1, sizeof(struct swayidle_timeout_cmd)); - - if (seconds > 0) { - cmd->timeout = seconds * 1000; - } else { - cmd->timeout = -1; - } - - wlr_log(WLR_DEBUG, "Register idle timeout at %d ms", cmd->timeout); - wlr_log(WLR_DEBUG, "Setup idle"); - cmd->idle_cmd = parse_command(argc - 2, &argv[2]); - - int result = 3; - if (argc >= 5 && !strcmp("resume", argv[3])) { - wlr_log(WLR_DEBUG, "Setup resume"); - cmd->resume_cmd = parse_command(argc - 4, &argv[4]); - result = 5; - } - list_add(state.timeout_cmds, cmd); - return result; -} - -static int parse_sleep(int argc, char **argv) { - if (argc < 2) { - wlr_log(WLR_ERROR, "Too few parameters to before-sleep command. " - "Usage: before-sleep <command>"); - exit(-1); - } - - state.lock_cmd = parse_command(argc - 1, &argv[1]); - if (state.lock_cmd) { - wlr_log(WLR_DEBUG, "Setup sleep lock: %s", state.lock_cmd); - } - - return 2; -} - -static int parse_args(int argc, char *argv[]) { - bool debug = false; - - int c; - while ((c = getopt(argc, argv, "hd")) != -1) { - switch (c) { - case 'd': - debug = true; - break; - case 'h': - case '?': - printf("Usage: %s [OPTIONS]\n", argv[0]); - printf(" -d\tdebug\n"); - printf(" -h\tthis help menu\n"); - return 1; - default: - return 1; - } - } - - wlr_log_init(debug ? WLR_DEBUG : WLR_INFO, NULL); - - state.timeout_cmds = create_list(); - - int i = optind; - while (i < argc) { - if (!strcmp("timeout", argv[i])) { - wlr_log(WLR_DEBUG, "Got timeout"); - i += parse_timeout(argc - i, &argv[i]); - } else if (!strcmp("before-sleep", argv[i])) { - wlr_log(WLR_DEBUG, "Got before-sleep"); - i += parse_sleep(argc - i, &argv[i]); - } else { - wlr_log(WLR_ERROR, "Unsupported command '%s'", argv[i]); - return 1; - } - } - - return 0; -} - -static int handle_signal(int sig, void *data) { - switch (sig) { - case SIGINT: - case SIGTERM: - sway_terminate(0); - return 0; - case SIGUSR1: - wlr_log(WLR_DEBUG, "Got SIGUSR1"); - for (int i = 0; i < state.timeout_cmds->length; ++i) { - register_timeout(state.timeout_cmds->items[i], 0); - } - return 1; - } - assert(false); // not reached -} - -static int display_event(int fd, uint32_t mask, void *data) { - if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) { - sway_terminate(0); - } - - int count = 0; - if (mask & WL_EVENT_READABLE) { - count = wl_display_dispatch(state.display); - } - if (mask & WL_EVENT_WRITABLE) { - wl_display_flush(state.display); - } - if (mask == 0) { - count = wl_display_dispatch_pending(state.display); - wl_display_flush(state.display); - } - - if (count < 0) { - wlr_log_errno(WLR_ERROR, "wl_display_dispatch failed, exiting"); - sway_terminate(0); - } - - return count; -} - -int main(int argc, char *argv[]) { - if (parse_args(argc, argv) != 0) { - return -1; - } - - state.event_loop = wl_event_loop_create(); - - wl_event_loop_add_signal(state.event_loop, SIGINT, handle_signal, NULL); - wl_event_loop_add_signal(state.event_loop, SIGTERM, handle_signal, NULL); - wl_event_loop_add_signal(state.event_loop, SIGUSR1, handle_signal, NULL); - - state.display = wl_display_connect(NULL); - if (state.display == NULL) { - wlr_log(WLR_ERROR, "Unable to connect to the compositor. " - "If your compositor is running, check or set the " - "WAYLAND_DISPLAY environment variable."); - return -3; - } - - struct wl_registry *registry = wl_display_get_registry(state.display); - wl_registry_add_listener(registry, ®istry_listener, NULL); - wl_display_roundtrip(state.display); - - if (idle_manager == NULL) { - wlr_log(WLR_ERROR, "Display doesn't support idle protocol"); - return -4; - } - if (seat == NULL) { - wlr_log(WLR_ERROR, "Seat error"); - return -5; - } - - bool should_run = state.timeout_cmds->length > 0; -#if HAVE_SYSTEMD || HAVE_ELOGIND - if (state.lock_cmd) { - should_run = true; - setup_sleep_listener(); - } -#endif - if (!should_run) { - wlr_log(WLR_INFO, "No command specified! Nothing to do, will exit"); - sway_terminate(0); - } - - for (int i = 0; i < state.timeout_cmds->length; ++i) { - struct swayidle_timeout_cmd *cmd = state.timeout_cmds->items[i]; - register_timeout(cmd, cmd->timeout); - } - - wl_display_roundtrip(state.display); - - struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop, - wl_display_get_fd(state.display), WL_EVENT_READABLE, - display_event, NULL); - wl_event_source_check(source); - - while (wl_event_loop_dispatch(state.event_loop, -1) != 1) { - // This space intentionally left blank - } - - sway_terminate(0); -} diff --git a/swayidle/meson.build b/swayidle/meson.build deleted file mode 100644 index 79d2c5c4..00000000 --- a/swayidle/meson.build +++ /dev/null @@ -1,27 +0,0 @@ -threads = dependency('threads') - -swayidle_deps = [ - client_protos, - pixman, - wayland_client, - wayland_server, - wlroots, -] - -if systemd.found() - swayidle_deps += systemd -endif -if elogind.found() - swayidle_deps += elogind -endif - -executable( - 'swayidle', [ - 'main.c', - ], - include_directories: [sway_inc], - dependencies: swayidle_deps, - link_with: [lib_sway_common, lib_sway_client], - install_rpath : rpathdir, - install: true -) diff --git a/swayidle/swayidle.1.scd b/swayidle/swayidle.1.scd deleted file mode 100644 index 0e3b5c3c..00000000 --- a/swayidle/swayidle.1.scd +++ /dev/null @@ -1,63 +0,0 @@ -swayidle (1) - -# NAME - -swayidle - Idle manager for Wayland - -# SYNOPSIS - -*swayidle* [options] [events...] - -# OPTIONS - -*-h* - Show help message and quit. - -*-d* - Enable debug output. - -# DESCRIPTION - -swayidle listens for idle activity on your Wayland compositor and executes tasks -on various idle-related events. You can specify any number of events at the -command line. - -Sending SIGUSR1 to swayidle will immediately enter idle state. - -# EVENTS - -*timeout* <timeout> <timeout command> [resume <resume command>] - Execute _timeout command_ if there is no activity for <timeout> seconds. - - If you specify "resume <resume command>", _resume command_ will be run when - there is activity again. - -*before-sleep* <command> - If built with systemd support, executes _command_ before systemd puts the - computer to sleep. - -All commands are executed in a shell. - -# EXAMPLE - -``` -swayidle \ - timeout 300 'swaylock -c 000000' \ - timeout 600 'swaymsg "output * dpms off"' \ - resume 'swaymsg "output * dpms on"' \ - before-sleep 'swaylock -c 000000' -``` - -This will lock your screen after 300 seconds of inactivity, then turn off your -displays after another 300 seconds, and turn your screens back on when resumed. -It will also lock your screen before your computer goes to sleep. - -# AUTHORS - -Maintained by Drew DeVault <sir@cmpwn.com>, who is assisted by other open -source contributors. For more information about sway development, see -https://github.com/swaywm/sway. - -# SEE ALSO - -*sway*(5) *swaymsg*(1) *sway-input*(5) *sway-output*(5) *sway-bar*(5) diff --git a/swaylock/main.c b/swaylock/main.c index 9a4f3b58..0b167da1 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -396,28 +396,34 @@ static void set_default_colors(struct swaylock_colors *colors) { colors->background = 0xFFFFFFFF; colors->bs_highlight = 0xDB3300FF; colors->key_highlight = 0x33DB00FF; + colors->caps_lock_bs_highlight = 0xDB3300FF; + colors->caps_lock_key_highlight = 0x33DB00FF; colors->separator = 0x000000FF; colors->inside = (struct swaylock_colorset){ .input = 0x000000C0, .cleared = 0xE5A445C0, + .caps_lock = 0x000000C0, .verifying = 0x0072FFC0, .wrong = 0xFA0000C0, }; colors->line = (struct swaylock_colorset){ .input = 0x000000FF, .cleared = 0x000000FF, + .caps_lock = 0x000000FF, .verifying = 0x000000FF, .wrong = 0x000000FF, }; colors->ring = (struct swaylock_colorset){ .input = 0x337D00FF, .cleared = 0xE5A445FF, + .caps_lock = 0xE5A445FF, .verifying = 0x3300FFFF, .wrong = 0x7D3300FF, }; colors->text = (struct swaylock_colorset){ .input = 0xE5A445FF, .cleared = 0x000000FF, + .caps_lock = 0xE5A445FF, .verifying = 0x000000FF, .wrong = 0x000000FF, }; @@ -433,25 +439,31 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, enum line_mode *line_mode, char **config_path) { enum long_option_codes { LO_BS_HL_COLOR = 256, + LO_CAPS_LOCK_BS_HL_COLOR, + LO_CAPS_LOCK_KEY_HL_COLOR, LO_FONT, LO_IND_RADIUS, LO_IND_THICKNESS, LO_INSIDE_COLOR, LO_INSIDE_CLEAR_COLOR, + LO_INSIDE_CAPS_LOCK_COLOR, LO_INSIDE_VER_COLOR, LO_INSIDE_WRONG_COLOR, LO_KEY_HL_COLOR, LO_LINE_COLOR, LO_LINE_CLEAR_COLOR, + LO_LINE_CAPS_LOCK_COLOR, LO_LINE_VER_COLOR, LO_LINE_WRONG_COLOR, LO_RING_COLOR, LO_RING_CLEAR_COLOR, + LO_RING_CAPS_LOCK_COLOR, LO_RING_VER_COLOR, LO_RING_WRONG_COLOR, LO_SEP_COLOR, LO_TEXT_COLOR, LO_TEXT_CLEAR_COLOR, + LO_TEXT_CAPS_LOCK_COLOR, LO_TEXT_VER_COLOR, LO_TEXT_WRONG_COLOR, }; @@ -463,6 +475,8 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, {"daemonize", no_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, {"image", required_argument, NULL, 'i'}, + {"disable-caps-lock-text", no_argument, NULL, 'L'}, + {"indicator-caps-lock", no_argument, NULL, 'l'}, {"line-uses-inside", no_argument, NULL, 'n'}, {"socket", required_argument, NULL, 'p'}, {"line-uses-ring", no_argument, NULL, 'r'}, @@ -471,25 +485,31 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, {"no-unlock-indicator", no_argument, NULL, 'u'}, {"version", no_argument, NULL, 'v'}, {"bs-hl-color", required_argument, NULL, LO_BS_HL_COLOR}, + {"caps-lock-bs-hl-color", required_argument, NULL, LO_CAPS_LOCK_BS_HL_COLOR}, + {"caps-lock-key-hl-color", required_argument, NULL, LO_CAPS_LOCK_KEY_HL_COLOR}, {"font", required_argument, NULL, LO_FONT}, {"indicator-radius", required_argument, NULL, LO_IND_RADIUS}, {"indicator-thickness", required_argument, NULL, LO_IND_THICKNESS}, {"inside-color", required_argument, NULL, LO_INSIDE_COLOR}, {"inside-clear-color", required_argument, NULL, LO_INSIDE_CLEAR_COLOR}, + {"inside-caps-lock-color", required_argument, NULL, LO_INSIDE_CAPS_LOCK_COLOR}, {"inside-ver-color", required_argument, NULL, LO_INSIDE_VER_COLOR}, {"inside-wrong-color", required_argument, NULL, LO_INSIDE_WRONG_COLOR}, {"key-hl-color", required_argument, NULL, LO_KEY_HL_COLOR}, {"line-color", required_argument, NULL, LO_LINE_COLOR}, {"line-clear-color", required_argument, NULL, LO_LINE_CLEAR_COLOR}, + {"line-caps-lock-color", required_argument, NULL, LO_LINE_CAPS_LOCK_COLOR}, {"line-ver-color", required_argument, NULL, LO_LINE_VER_COLOR}, {"line-wrong-color", required_argument, NULL, LO_LINE_WRONG_COLOR}, {"ring-color", required_argument, NULL, LO_RING_COLOR}, {"ring-clear-color", required_argument, NULL, LO_RING_CLEAR_COLOR}, + {"ring-caps-lock-color", required_argument, NULL, LO_RING_CAPS_LOCK_COLOR}, {"ring-ver-color", required_argument, NULL, LO_RING_VER_COLOR}, {"ring-wrong-color", required_argument, NULL, LO_RING_WRONG_COLOR}, {"separator-color", required_argument, NULL, LO_SEP_COLOR}, {"text-color", required_argument, NULL, LO_TEXT_COLOR}, {"text-clear-color", required_argument, NULL, LO_TEXT_CLEAR_COLOR}, + {"text-caps-lock-color", required_argument, NULL, LO_TEXT_CAPS_LOCK_COLOR}, {"text-ver-color", required_argument, NULL, LO_TEXT_VER_COLOR}, {"text-wrong-color", required_argument, NULL, LO_TEXT_WRONG_COLOR}, {0, 0, 0, 0} @@ -498,76 +518,97 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, const char usage[] = "Usage: swaylock [options...]\n" "\n" - " -C, --config <config_file> " + " -C, --config <config_file> " "Path to the config file.\n" - " -c, --color <color> " + " -c, --color <color> " "Turn the screen into the given color instead of white.\n" - " -e, --ignore-empty-password " + " -e, --ignore-empty-password " "When an empty password is provided, do not validate it.\n" - " -f, --daemonize " + " -f, --daemonize " "Detach from the controlling terminal after locking.\n" - " -h, --help " + " -h, --help " "Show help message and quit.\n" - " -i, --image [<output>:]<path> " + " -i, --image [<output>:]<path> " "Display the given image.\n" - " -s, --scaling <mode> " + " -L, --disable-caps-lock-text " + "Disable the Caps Lock text.\n" + " -l, --indicator-caps-lock " + "Show the current Caps Lock state also on the indicator.\n" + " -s, --scaling <mode> " "Scaling mode: stretch, fill, fit, center, tile.\n" - " -t, --tiling " + " -t, --tiling " "Same as --scaling=tile.\n" - " -u, --no-unlock-indicator " + " -u, --no-unlock-indicator " "Disable the unlock indicator.\n" - " -v, --version " + " -v, --version " "Show the version number and quit.\n" - " --bs-hl-color <color> " + " --bs-hl-color <color> " "Sets the color of backspace highlight segments.\n" - " --font <font> " + " --caps-lock-bs-hl-color <color> " + "Sets the color of backspace highlight segments when Caps Lock " + "is active.\n" + " --caps-lock-key-hl-color <color> " + "Sets the color of the key press highlight segments when " + "Caps Lock is active.\n" + " --font <font> " "Sets the font of the text.\n" - " --indicator-radius <radius> " + " --indicator-radius <radius> " "Sets the indicator radius.\n" - " --indicator-thickness <thick> " + " --indicator-thickness <thick> " "Sets the indicator thickness.\n" - " --inside-color <color> " + " --inside-color <color> " "Sets the color of the inside of the indicator.\n" - " --inside-clear-color <color> " + " --inside-clear-color <color> " "Sets the color of the inside of the indicator when cleared.\n" - " --inside-ver-color <color> " + " --inside-caps-lock-color <color> " + "Sets the color of the inside of the indicator when Caps Lock " + "is active.\n" + " --inside-ver-color <color> " "Sets the color of the inside of the indicator when verifying.\n" - " --inside-wrong-color <color> " + " --inside-wrong-color <color> " "Sets the color of the inside of the indicator when invalid.\n" - " --key-hl-color <color> " + " --key-hl-color <color> " "Sets the color of the key press highlight segments.\n" - " --line-color <color> " + " --line-color <color> " "Sets the color of the line between the inside and ring.\n" - " --line-clear-color <color> " + " --line-clear-color <color> " "Sets the color of the line between the inside and ring when " "cleared.\n" - " --line-ver-color <color> " + " --line-caps-lock-color <color> " + "Sets the color of the line between the inside and ring when " + "Caps Lock is active.\n" + " --line-ver-color <color> " "Sets the color of the line between the inside and ring when " "verifying.\n" - " --line-wrong-color <color> " + " --line-wrong-color <color> " "Sets the color of the line between the inside and ring when " "invalid.\n" - " -n, --line-uses-inside " + " -n, --line-uses-inside " "Use the inside color for the line between the inside and ring.\n" - " -r, --line-uses-ring " + " -r, --line-uses-ring " "Use the ring color for the line between the inside and ring.\n" - " --ring-color <color> " + " --ring-color <color> " "Sets the color of the ring of the indicator.\n" - " --ring-clear-color <color> " + " --ring-clear-color <color> " "Sets the color of the ring of the indicator when cleared.\n" - " --ring-ver-color <color> " + " --ring-caps-lock-color <color> " + "Sets the color of the ring of the indicator when Caps Lock " + "is active.\n" + " --ring-ver-color <color> " "Sets the color of the ring of the indicator when verifying.\n" - " --ring-wrong-color <color> " + " --ring-wrong-color <color> " "Sets the color of the ring of the indicator when invalid.\n" - " --separator-color <color> " + " --separator-color <color> " "Sets the color of the lines that separate highlight segments.\n" - " --text-color <color> " + " --text-color <color> " "Sets the color of the text.\n" - " --text-clear-color <color> " + " --text-clear-color <color> " "Sets the color of the text when cleared.\n" - " --text-ver-color <color> " + " --text-caps-lock-color <color> " + "Sets the color of the text when Caps Lock is active.\n" + " --text-ver-color <color> " "Sets the color of the text when verifying.\n" - " --text-wrong-color <color> " + " --text-wrong-color <color> " "Sets the color of the text when invalid.\n" "\n" "All <color> options are of the form <rrggbb[aa]>.\n"; @@ -576,7 +617,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, optind = 1; while (1) { int opt_idx = 0; - c = getopt_long(argc, argv, "c:efhi:nrs:tuvC:", long_options, &opt_idx); + c = getopt_long(argc, argv, "c:efhi:Llnrs:tuvC:", long_options, &opt_idx); if (c == -1) { break; } @@ -607,6 +648,16 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, load_image(optarg, state); } break; + case 'L': + if (state) { + state->args.show_caps_lock_text = false; + } + break; + case 'l': + if (state) { + state->args.show_caps_lock_indicator = true; + } + break; case 'n': if (line_mode) { *line_mode = LM_INSIDE; @@ -644,6 +695,16 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, state->args.colors.bs_highlight = parse_color(optarg); } break; + case LO_CAPS_LOCK_BS_HL_COLOR: + if (state) { + state->args.colors.caps_lock_bs_highlight = parse_color(optarg); + } + break; + case LO_CAPS_LOCK_KEY_HL_COLOR: + if (state) { + state->args.colors.caps_lock_key_highlight = parse_color(optarg); + } + break; case LO_FONT: if (state) { free(state->args.font); @@ -670,6 +731,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, state->args.colors.inside.cleared = parse_color(optarg); } break; + case LO_INSIDE_CAPS_LOCK_COLOR: + if (state) { + state->args.colors.inside.caps_lock = parse_color(optarg); + } + break; case LO_INSIDE_VER_COLOR: if (state) { state->args.colors.inside.verifying = parse_color(optarg); @@ -695,6 +761,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, state->args.colors.line.cleared = parse_color(optarg); } break; + case LO_LINE_CAPS_LOCK_COLOR: + if (state) { + state->args.colors.line.caps_lock = parse_color(optarg); + } + break; case LO_LINE_VER_COLOR: if (state) { state->args.colors.line.verifying = parse_color(optarg); @@ -715,6 +786,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, state->args.colors.ring.cleared = parse_color(optarg); } break; + case LO_RING_CAPS_LOCK_COLOR: + if (state) { + state->args.colors.ring.caps_lock = parse_color(optarg); + } + break; case LO_RING_VER_COLOR: if (state) { state->args.colors.ring.verifying = parse_color(optarg); @@ -740,6 +816,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, state->args.colors.text.cleared = parse_color(optarg); } break; + case LO_TEXT_CAPS_LOCK_COLOR: + if (state) { + state->args.colors.text.caps_lock = parse_color(optarg); + } + break; case LO_TEXT_VER_COLOR: if (state) { state->args.colors.text.verifying = parse_color(optarg); @@ -857,6 +938,8 @@ int main(int argc, char **argv) { .thickness = 10, .ignore_empty = false, .show_indicator = true, + .show_caps_lock_indicator = false, + .show_caps_lock_text = true }; wl_list_init(&state.images); set_default_colors(&state.args.colors); diff --git a/swaylock/render.c b/swaylock/render.c index cbd5d01d..5aedaad5 100644 --- a/swaylock/render.c +++ b/swaylock/render.c @@ -18,7 +18,17 @@ static void set_color_for_state(cairo_t *cairo, struct swaylock_state *state, } else if (state->auth_state == AUTH_STATE_CLEAR) { cairo_set_source_u32(cairo, colorset->cleared); } else { - cairo_set_source_u32(cairo, colorset->input); + if (state->xkb.caps_lock && state->args.show_caps_lock_indicator) { + cairo_set_source_u32(cairo, colorset->caps_lock); + } else if (state->xkb.caps_lock && !state->args.show_caps_lock_indicator && + state->args.show_caps_lock_text) { + uint32_t inputtextcolor = state->args.colors.text.input; + state->args.colors.text.input = state->args.colors.text.caps_lock; + cairo_set_source_u32(cairo, colorset->input); + state->args.colors.text.input = inputtextcolor; + } else { + cairo_set_source_u32(cairo, colorset->input); + } } } @@ -92,7 +102,8 @@ void render_frame(struct swaylock_surface *surface) { break; case AUTH_STATE_INPUT: case AUTH_STATE_INPUT_NOP: - if (state->xkb.caps_lock) { + case AUTH_STATE_BACKSPACE: + if (state->xkb.caps_lock && state->args.show_caps_lock_text) { text = "Caps Lock"; } break; @@ -125,9 +136,17 @@ void render_frame(struct swaylock_surface *surface) { arc_radius, highlight_start, highlight_start + TYPE_INDICATOR_RANGE); if (state->auth_state == AUTH_STATE_INPUT) { - cairo_set_source_u32(cairo, state->args.colors.key_highlight); + if (state->xkb.caps_lock && state->args.show_caps_lock_indicator) { + cairo_set_source_u32(cairo, state->args.colors.caps_lock_key_highlight); + } else { + cairo_set_source_u32(cairo, state->args.colors.key_highlight); + } } else { - cairo_set_source_u32(cairo, state->args.colors.bs_highlight); + if (state->xkb.caps_lock && state->args.show_caps_lock_indicator) { + cairo_set_source_u32(cairo, state->args.colors.caps_lock_bs_highlight); + } else { + cairo_set_source_u32(cairo, state->args.colors.bs_highlight); + } } cairo_stroke(cairo); diff --git a/swaylock/swaylock.1.scd b/swaylock/swaylock.1.scd index 9f39a913..2c7979be 100644 --- a/swaylock/swaylock.1.scd +++ b/swaylock/swaylock.1.scd @@ -44,6 +44,12 @@ Locks your Wayland session. Display the given image, optionally only on the given output. Use -c to set a background color. +*-L, --disable-caps-lock-text* + Disable the Caps Lock Text. + +*-l, --indicator-caps-lock* + Show the current Caps Lock state also on the indicator. + *-s, --scaling* Scaling mode for images: _stretch_, _fill_, _fit_, _center_, or _tile_. @@ -58,6 +64,12 @@ Locks your Wayland session. *--bs-hl-color* <rrggbb[aa]> Sets the color of backspace highlight segments. +*--caps-lock-bs-hl-color* <rrggbb[aa]> + Sets the color of backspace highlight segments when Caps Lock is active. + +*--caps-lock-bs-hl-color* <rrggbb[aa]> + Sets the color of the key press highlight segments when Caps Lock is active. + *--font* <font> Sets the font of the text inside the indicator. @@ -75,6 +87,9 @@ Locks your Wayland session. *--inside-clear-color* <rrggbb[aa]> Sets the color of the inside of the indicator when cleared. +*--inside-caps-lock-color* <rrggbb[aa]> + Sets the color of the inside of the indicator when Caps Lock is active. + *--inside-ver-color* <rrggbb[aa]> Sets the color of the inside of the indicator when verifying. @@ -92,6 +107,10 @@ Locks your Wayland session. Sets the color of the lines that separate the inside and outside of the indicator when cleared. +*--line-caps-lock-color* <rrggbb[aa]> + Sets the color of the line between the inside and ring when Caps Lock + is active. + *--line-ver-color* <rrggbb[aa]> Sets the color of the lines that separate the inside and outside of the indicator when verifying. @@ -114,6 +133,9 @@ Locks your Wayland session. *--ring-clear-color* <rrggbb[aa]> Sets the color of the outside of the indicator when cleared. +*--ring-caps-lock-color* <rrggbb[aa]> + Sets the color of the ring of the indicator when Caps Lock is active. + *--ring-ver-color* <rrggbb[aa]> Sets the color of the outside of the indicator when verifying. @@ -129,6 +151,9 @@ Locks your Wayland session. *--text-clear-color* <rrggbb[aa]> Sets the color of the text inside the indicator when cleared. +*--text-caps-lock-color* <rrggbb[aa]> + Sets the color of the text when Caps Lock is active. + *--text-ver-color* <rrggbb[aa]> Sets the color of the text inside the indicator when verifying. diff --git a/swaymsg/main.c b/swaymsg/main.c index f1bb5e3e..e5eee631 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -113,7 +113,7 @@ static const char *pretty_type_name(const char *name) { } static void pretty_print_input(json_object *i) { - json_object *id, *name, *type, *product, *vendor, *kbdlayout; + json_object *id, *name, *type, *product, *vendor, *kbdlayout, *events; json_object_object_get_ex(i, "identifier", &id); json_object_object_get_ex(i, "name", &name); json_object_object_get_ex(i, "type", &type); @@ -139,6 +139,10 @@ static void pretty_print_input(json_object *i) { json_object_get_string(kbdlayout)); } + if (json_object_object_get_ex(i, "libinput_send_events", &events)) { + printf(" Libinput Send Events: %s\n", json_object_get_string(events)); + } + printf("\n"); } |