mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	input_cmd_scroll_button: utilize mouse btn helpers
This modifies `input_cmd_scroll_button` to utilize the mouse button helper `get_mouse_button` when parsing the button. x11 axis buttons are not supported with this command and `CMD_INVALID` will be returned, but all other x11 buttons, button event names, and button event codes should be working
This commit is contained in:
		
							parent
							
								
									212baf2f75
								
							
						
					
					
						commit
						4e6bd53abf
					
				
					 3 changed files with 24 additions and 21 deletions
				
			
		| 
						 | 
					@ -1,9 +1,7 @@
 | 
				
			||||||
#include <string.h>
 | 
					#include <libevdev/libevdev.h>
 | 
				
			||||||
#include <strings.h>
 | 
					 | 
				
			||||||
#include <errno.h>
 | 
					 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
#include "sway/commands.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 *input_cmd_scroll_button(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -16,22 +14,26 @@ struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {
 | 
				
			||||||
			"No input device defined.");
 | 
								"No input device defined.");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	errno = 0;
 | 
						if (strcmp(*argv, "disable") == 0) {
 | 
				
			||||||
	char *endptr;
 | 
							ic->scroll_button = 0;
 | 
				
			||||||
	int scroll_button = strtol(*argv, &endptr, 10);
 | 
							return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
	if (endptr == *argv && scroll_button == 0) {
 | 
					 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "scroll_button",
 | 
					 | 
				
			||||||
				"Scroll button identifier must be an integer.");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	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",
 | 
							return cmd_results_new(CMD_INVALID, "scroll_button",
 | 
				
			||||||
				"Scroll button identifier out of range.");
 | 
									"X11 axis buttons are not supported for scroll_button");
 | 
				
			||||||
	}
 | 
						} else if (!button) {
 | 
				
			||||||
	if (scroll_button < 0) {
 | 
					 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "scroll_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);
 | 
						return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1593,7 +1593,7 @@ uint32_t get_mouse_bindcode(const char *name, char **error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint32_t get_mouse_button(const char *name, char **error) {
 | 
					uint32_t get_mouse_button(const char *name, char **error) {
 | 
				
			||||||
	uint32_t button = get_mouse_bindsym(name, error);
 | 
						uint32_t button = get_mouse_bindsym(name, error);
 | 
				
			||||||
	if (!button && !error) {
 | 
						if (!button && !*error) {
 | 
				
			||||||
		button = get_mouse_bindcode(name, error);
 | 
							button = get_mouse_bindcode(name, error);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return button;
 | 
						return button;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -105,10 +105,11 @@ The following commands may only be used in the configuration file.
 | 
				
			||||||
*input* <identifier> repeat\_rate <characters per second>
 | 
					*input* <identifier> repeat\_rate <characters per second>
 | 
				
			||||||
	Sets the frequency of key repeats once the repeat\_delay has passed.
 | 
						Sets the frequency of key repeats once the repeat\_delay has passed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
*input* <identifier> scroll\_button <button\_identifier>
 | 
					*input* <identifier> scroll\_button disable|button[1-3,8,9]|<event-code-or-name>
 | 
				
			||||||
	Sets button used for scroll\_method on\_button\_down. The button identifier
 | 
						Sets the button used for scroll\_method on\_button\_down. The button can
 | 
				
			||||||
	can be obtained from `libinput debug-events`.
 | 
						be given as an event name or code, which can be obtained from `libinput
 | 
				
			||||||
	If set to 0, it disables the scroll\_button on\_button\_down.
 | 
						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>
 | 
					*input* <identifier> scroll\_factor <floating point value>
 | 
				
			||||||
	Changes the scroll factor for the specified input device. Scroll speed will
 | 
						Changes the scroll factor for the specified input device. Scroll speed will
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue