config: implement map-pointer command
This command takes a mode, modifiers, button/event name, and pointer action as arguments. It stores these in the config data structure. The currently available pointer actions are move-view and resize-view, which replace the previously hard-coded functionality. Closing the hovered view with middle click has temorarily been removed until it is decided if we wish to make this another special pointer action or perhaps allow running any arbitrary command (which would of course include close).
This commit is contained in:
@ -397,23 +397,11 @@ fn handleButton(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||
// perhaps enter move/resize mode.
|
||||
if (View.fromWlrSurface(wlr_surface)) |view| {
|
||||
if (event.state == .WLR_BUTTON_PRESSED and self.pressed_count == 1) {
|
||||
// If the button is pressed and the pointer modifier is
|
||||
// active, enter cursor mode or close view and return.
|
||||
const fullscreen = view.current.fullscreen or view.pending.fullscreen;
|
||||
if (self.seat.pointer_modifier) {
|
||||
switch (event.button) {
|
||||
c.BTN_LEFT => if (!fullscreen) Mode.enter(self, .move, event, view),
|
||||
c.BTN_MIDDLE => view.close(),
|
||||
c.BTN_RIGHT => if (!fullscreen) Mode.enter(self, .resize, event, view),
|
||||
|
||||
// TODO Some mice have additional buttons. These
|
||||
// could also be bound to some useful action.
|
||||
else => {},
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
Mode.enter(self, .down, event, view);
|
||||
}
|
||||
// If there is an active mapping for this button which is
|
||||
// handled we are done here
|
||||
if (self.handlePointerMapping(event, view)) return;
|
||||
// Otherwise enter cursor down mode
|
||||
Mode.enter(self, .down, event, view);
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,6 +414,26 @@ fn handleButton(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle the mapping for the passed button if any. Returns true if there
|
||||
/// was a mapping and the button was handled.
|
||||
fn handlePointerMapping(self: *Self, event: *c.wlr_event_pointer_button, view: *View) bool {
|
||||
const wlr_keyboard = c.wlr_seat_get_keyboard(self.seat.wlr_seat);
|
||||
const modifiers = c.wlr_keyboard_get_modifiers(wlr_keyboard);
|
||||
|
||||
const fullscreen = view.current.fullscreen or view.pending.fullscreen;
|
||||
|
||||
const config = self.seat.input_manager.server.config;
|
||||
return for (config.modes.items[self.seat.mode_id].pointer_mappings.items) |mapping| {
|
||||
if (event.button == mapping.event_code and modifiers == mapping.modifiers) {
|
||||
switch (mapping.action) {
|
||||
.move => if (!fullscreen) Mode.enter(self, .move, event, view),
|
||||
.resize => if (!fullscreen) Mode.enter(self, .resize, event, view),
|
||||
}
|
||||
break true;
|
||||
}
|
||||
} else false;
|
||||
}
|
||||
|
||||
fn handleFrame(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||
// This event is forwarded by the cursor when a pointer emits an frame
|
||||
// event. Frame events are sent after regular pointer events to group
|
||||
|
Reference in New Issue
Block a user