mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	Scroll-Bindings: Add support for mouse wheel bindings
This commit is contained in:
		
							parent
							
								
									e45e2c7e60
								
							
						
					
					
						commit
						063a26ae9d
					
				
					 3 changed files with 56 additions and 6 deletions
				
			
		| 
						 | 
					@ -13,6 +13,7 @@ enum mouse_event {
 | 
				
			||||||
	MOUSE_ACTION_PRESS,
 | 
						MOUSE_ACTION_PRESS,
 | 
				
			||||||
	MOUSE_ACTION_RELEASE,
 | 
						MOUSE_ACTION_RELEASE,
 | 
				
			||||||
	MOUSE_ACTION_DRAG,
 | 
						MOUSE_ACTION_DRAG,
 | 
				
			||||||
 | 
						MOUSE_ACTION_SCROLL,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct mousebind {
 | 
					struct mousebind {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +34,10 @@ mousebind_button_from_str(const char *str, uint32_t *modifiers)
 | 
				
			||||||
		return BTN_RIGHT;
 | 
							return BTN_RIGHT;
 | 
				
			||||||
	} else if (!strcasecmp(str, "Middle")) {
 | 
						} else if (!strcasecmp(str, "Middle")) {
 | 
				
			||||||
		return BTN_MIDDLE;
 | 
							return BTN_MIDDLE;
 | 
				
			||||||
 | 
						} else if (!strcasecmp(str, "Up")) {
 | 
				
			||||||
 | 
							return BTN_GEAR_UP;
 | 
				
			||||||
 | 
						} else if (!strcasecmp(str, "Down")) {
 | 
				
			||||||
 | 
							return BTN_GEAR_DOWN;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
invalid:
 | 
					invalid:
 | 
				
			||||||
	wlr_log(WLR_ERROR, "unknown button (%s)", str);
 | 
						wlr_log(WLR_ERROR, "unknown button (%s)", str);
 | 
				
			||||||
| 
						 | 
					@ -54,6 +58,8 @@ mousebind_event_from_str(const char *str)
 | 
				
			||||||
		return MOUSE_ACTION_RELEASE;
 | 
							return MOUSE_ACTION_RELEASE;
 | 
				
			||||||
	} else if (!strcasecmp(str, "drag")) {
 | 
						} else if (!strcasecmp(str, "drag")) {
 | 
				
			||||||
		return MOUSE_ACTION_DRAG;
 | 
							return MOUSE_ACTION_DRAG;
 | 
				
			||||||
 | 
						} else if (!strcasecmp(str, "scroll")) {
 | 
				
			||||||
 | 
							return MOUSE_ACTION_SCROLL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	wlr_log(WLR_ERROR, "unknown mouse action (%s)", str);
 | 
						wlr_log(WLR_ERROR, "unknown mouse action (%s)", str);
 | 
				
			||||||
	return MOUSE_ACTION_NONE;
 | 
						return MOUSE_ACTION_NONE;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										55
									
								
								src/cursor.c
									
										
									
									
									
								
							
							
						
						
									
										55
									
								
								src/cursor.c
									
										
									
									
									
								
							| 
						 | 
					@ -882,6 +882,42 @@ cursor_button(struct wl_listener *listener, void *data)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					handle_cursor_axis(struct server *server, struct cursor_context *ctx,
 | 
				
			||||||
 | 
							struct wlr_pointer_axis_event *event)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct mousebind *mousebind;
 | 
				
			||||||
 | 
						bool activated_any = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint32_t modifiers = wlr_keyboard_get_modifiers(
 | 
				
			||||||
 | 
								&server->seat.keyboard_group->keyboard);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint32_t button = 0;
 | 
				
			||||||
 | 
						if (event->delta_discrete < 0) {
 | 
				
			||||||
 | 
							button = BTN_GEAR_UP;
 | 
				
			||||||
 | 
						} else if (event->delta_discrete > 0) {
 | 
				
			||||||
 | 
							button = BTN_GEAR_DOWN;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!button || event->source != WLR_AXIS_SOURCE_WHEEL
 | 
				
			||||||
 | 
								|| event->orientation != WLR_AXIS_ORIENTATION_VERTICAL) {
 | 
				
			||||||
 | 
							wlr_log(WLR_DEBUG, "Failed to handle cursor axis event");
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wl_list_for_each(mousebind, &rc.mousebinds, link) {
 | 
				
			||||||
 | 
							if (ssd_part_contains(mousebind->context, ctx->type)
 | 
				
			||||||
 | 
									&& mousebind->button == button
 | 
				
			||||||
 | 
									&& modifiers == mousebind->modifiers
 | 
				
			||||||
 | 
									&& mousebind->mouse_event == MOUSE_ACTION_SCROLL) {
 | 
				
			||||||
 | 
								activated_any = true;
 | 
				
			||||||
 | 
								actions_run(ctx->view, server, &mousebind->actions, /*resize_edges*/ 0);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return activated_any;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
cursor_axis(struct wl_listener *listener, void *data)
 | 
					cursor_axis(struct wl_listener *listener, void *data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -891,15 +927,22 @@ cursor_axis(struct wl_listener *listener, void *data)
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	struct seat *seat = wl_container_of(listener, seat, cursor_axis);
 | 
						struct seat *seat = wl_container_of(listener, seat, cursor_axis);
 | 
				
			||||||
	struct wlr_pointer_axis_event *event = data;
 | 
						struct wlr_pointer_axis_event *event = data;
 | 
				
			||||||
 | 
						struct server *server = seat->server;
 | 
				
			||||||
 | 
						struct cursor_context ctx = get_cursor_context(server);
 | 
				
			||||||
	wlr_idle_notify_activity(seat->wlr_idle, seat->seat);
 | 
						wlr_idle_notify_activity(seat->wlr_idle, seat->seat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Make sure we are sending the events to the surface under the cursor */
 | 
						/* Bindings swallow mouse events if activated */
 | 
				
			||||||
	cursor_update_focus(seat->server);
 | 
						bool triggered_axis_binding = handle_cursor_axis(server, &ctx, event);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Notify the client with pointer focus of the axis event. */
 | 
						if (ctx.surface && !triggered_axis_binding) {
 | 
				
			||||||
	wlr_seat_pointer_notify_axis(seat->seat, event->time_msec,
 | 
							/* Make sure we are sending the events to the surface under the cursor */
 | 
				
			||||||
		event->orientation, event->delta, event->delta_discrete,
 | 
							cursor_update_common(server, &ctx, event->time_msec, false);
 | 
				
			||||||
		event->source);
 | 
					
 | 
				
			||||||
 | 
							/* Notify the client with pointer focus of the axis event. */
 | 
				
			||||||
 | 
							wlr_seat_pointer_notify_axis(seat->seat, event->time_msec,
 | 
				
			||||||
 | 
								event->orientation, event->delta, event->delta_discrete,
 | 
				
			||||||
 | 
								event->source);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue