mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Implement mouse warping
This commit is contained in:
		
							parent
							
								
									eb5a8e03ff
								
							
						
					
					
						commit
						ae6d459000
					
				
					 5 changed files with 39 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -101,6 +101,7 @@ static struct cmd_handler handlers[] = {
 | 
			
		|||
	{ "include", cmd_include },
 | 
			
		||||
	{ "input", cmd_input },
 | 
			
		||||
	{ "mode", cmd_mode },
 | 
			
		||||
	{ "mouse_warping", cmd_mouse_warping },
 | 
			
		||||
	{ "output", cmd_output },
 | 
			
		||||
	{ "seat", cmd_seat },
 | 
			
		||||
	{ "workspace", cmd_workspace },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										19
									
								
								sway/commands/mouse_warping.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								sway/commands/mouse_warping.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
#include <string.h>
 | 
			
		||||
#include <strings.h>
 | 
			
		||||
#include "sway/commands.h"
 | 
			
		||||
 | 
			
		||||
struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
 | 
			
		||||
	struct cmd_results *error = NULL;
 | 
			
		||||
	if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) {
 | 
			
		||||
		return error;
 | 
			
		||||
	} else if (strcasecmp(argv[0], "output") == 0) {
 | 
			
		||||
		config->mouse_warping = true;
 | 
			
		||||
	} else if (strcasecmp(argv[0], "none") == 0) {
 | 
			
		||||
		config->mouse_warping = false;
 | 
			
		||||
	} else {
 | 
			
		||||
		return cmd_results_new(CMD_FAILURE, "mouse_warping",
 | 
			
		||||
				"Expected 'mouse_warping output|none'");
 | 
			
		||||
	}
 | 
			
		||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -156,8 +156,8 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) {
 | 
			
		|||
	cursor_send_pointer_motion(cursor, event->time_msec);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void handle_cursor_motion_absolute(struct wl_listener *listener,
 | 
			
		||||
		void *data) {
 | 
			
		||||
static void handle_cursor_motion_absolute(
 | 
			
		||||
		struct wl_listener *listener, void *data) {
 | 
			
		||||
	struct sway_cursor *cursor =
 | 
			
		||||
		wl_container_of(listener, cursor, motion_absolute);
 | 
			
		||||
	struct wlr_event_pointer_motion_absolute *event = data;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -333,15 +333,29 @@ void sway_seat_set_focus(struct sway_seat *seat,
 | 
			
		|||
	if (last_focus) {
 | 
			
		||||
		struct sway_container *last_ws = last_focus;
 | 
			
		||||
		if (last_ws && last_ws->type != C_WORKSPACE) {
 | 
			
		||||
			last_ws = container_parent(last_focus, C_WORKSPACE);
 | 
			
		||||
			last_ws = container_parent(last_ws, C_WORKSPACE);
 | 
			
		||||
		}
 | 
			
		||||
		if (last_ws) {
 | 
			
		||||
			wlr_log(L_DEBUG, "sending workspace event");
 | 
			
		||||
			ipc_event_workspace(last_ws, container, "focus");
 | 
			
		||||
			if (last_ws->children->length == 0) {
 | 
			
		||||
				container_workspace_destroy(last_ws);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		struct sway_container *last_output = last_focus;
 | 
			
		||||
		if (last_output && last_output->type != C_OUTPUT) {
 | 
			
		||||
			last_output = container_parent(last_output, C_OUTPUT);
 | 
			
		||||
		}
 | 
			
		||||
		struct sway_container *new_output = container;
 | 
			
		||||
		if (new_output && new_output->type != C_OUTPUT) {
 | 
			
		||||
			new_output = container_parent(new_output, C_OUTPUT);
 | 
			
		||||
		}
 | 
			
		||||
		if (new_output != last_output && config->mouse_warping) {
 | 
			
		||||
			struct wlr_output *output = new_output->sway_output->wlr_output;
 | 
			
		||||
			// TODO: Change container coords to layout coords
 | 
			
		||||
			double x = container->x + output->lx + container->width / 2.0;
 | 
			
		||||
			double y = container->y + output->ly + container->height / 2.0;
 | 
			
		||||
			wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (last_focus && last_focus->type == C_VIEW &&
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -63,6 +63,7 @@ sway_sources = files(
 | 
			
		|||
	'commands/input/xkb_options.c',
 | 
			
		||||
	'commands/input/xkb_rules.c',
 | 
			
		||||
	'commands/input/xkb_variant.c',
 | 
			
		||||
	'commands/mouse_warping.c',
 | 
			
		||||
	'commands/output.c',
 | 
			
		||||
	'commands/reload.c',
 | 
			
		||||
	'commands/workspace.c',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue