command: allow map/map-pointer overwrite existing
The ergonomics of remapping keys are currently quite bad as unmap must first be called for every mapping before defining a new one. Any benefit that might be gained by the current strictness of map/ map-pointer is outweighed by this fact. In a similar spirit, silently ignore unmapping a non-existent mapping.
This commit is contained in:
parent
fb7d50a019
commit
5c0be25142
@ -49,16 +49,15 @@ pub fn map(
|
|||||||
|
|
||||||
const mode_mappings = &seat.input_manager.server.config.modes.items[mode_id].mappings;
|
const mode_mappings = &seat.input_manager.server.config.modes.items[mode_id].mappings;
|
||||||
|
|
||||||
if (mappingExists(mode_mappings, modifiers, keysym, optionals.release)) |_| {
|
const new = try Mapping.init(keysym, modifiers, optionals.release, args[4 + offset ..]);
|
||||||
out.* = try std.fmt.allocPrint(
|
errdefer new.deinit();
|
||||||
allocator,
|
|
||||||
"a mapping for modifiers '{}' and keysym '{}' already exists",
|
|
||||||
.{ args[2 + offset], args[3 + offset] },
|
|
||||||
);
|
|
||||||
return Error.Other;
|
|
||||||
}
|
|
||||||
|
|
||||||
try mode_mappings.append(try Mapping.init(keysym, modifiers, optionals.release, args[4 + offset ..]));
|
if (mappingExists(mode_mappings, modifiers, keysym, optionals.release)) |current| {
|
||||||
|
mode_mappings.items[current].deinit();
|
||||||
|
mode_mappings.items[current] = new;
|
||||||
|
} else {
|
||||||
|
try mode_mappings.append(new);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new pointer mapping for a given mode
|
/// Create a new pointer mapping for a given mode
|
||||||
@ -78,16 +77,6 @@ pub fn mapPointer(
|
|||||||
const modifiers = try parseModifiers(allocator, args[2], out);
|
const modifiers = try parseModifiers(allocator, args[2], out);
|
||||||
const event_code = try parseEventCode(allocator, args[3], out);
|
const event_code = try parseEventCode(allocator, args[3], out);
|
||||||
|
|
||||||
const mode_pointer_mappings = &seat.input_manager.server.config.modes.items[mode_id].pointer_mappings;
|
|
||||||
if (pointerMappingExists(mode_pointer_mappings, modifiers, event_code)) |_| {
|
|
||||||
out.* = try std.fmt.allocPrint(
|
|
||||||
allocator,
|
|
||||||
"a pointer mapping for modifiers '{}' and button '{}' already exists",
|
|
||||||
.{ args[2], args[3] },
|
|
||||||
);
|
|
||||||
return Error.Other;
|
|
||||||
}
|
|
||||||
|
|
||||||
const action = if (std.mem.eql(u8, args[4], "move-view"))
|
const action = if (std.mem.eql(u8, args[4], "move-view"))
|
||||||
PointerMapping.Action.move
|
PointerMapping.Action.move
|
||||||
else if (std.mem.eql(u8, args[4], "resize-view"))
|
else if (std.mem.eql(u8, args[4], "resize-view"))
|
||||||
@ -101,11 +90,18 @@ pub fn mapPointer(
|
|||||||
return Error.Other;
|
return Error.Other;
|
||||||
};
|
};
|
||||||
|
|
||||||
try mode_pointer_mappings.append(.{
|
const new = PointerMapping{
|
||||||
.event_code = event_code,
|
.event_code = event_code,
|
||||||
.modifiers = modifiers,
|
.modifiers = modifiers,
|
||||||
.action = action,
|
.action = action,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const mode_pointer_mappings = &seat.input_manager.server.config.modes.items[mode_id].pointer_mappings;
|
||||||
|
if (pointerMappingExists(mode_pointer_mappings, modifiers, event_code)) |current| {
|
||||||
|
mode_pointer_mappings.items[current] = new;
|
||||||
|
} else {
|
||||||
|
try mode_pointer_mappings.append(new);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modeNameToId(allocator: *std.mem.Allocator, seat: *Seat, mode_name: []const u8, out: *?[]const u8) !usize {
|
fn modeNameToId(allocator: *std.mem.Allocator, seat: *Seat, mode_name: []const u8, out: *?[]const u8) !usize {
|
||||||
@ -260,14 +256,7 @@ pub fn unmap(
|
|||||||
const keysym = try parseKeysym(allocator, args[3 + offset], out);
|
const keysym = try parseKeysym(allocator, args[3 + offset], out);
|
||||||
|
|
||||||
const mode_mappings = &seat.input_manager.server.config.modes.items[mode_id].mappings;
|
const mode_mappings = &seat.input_manager.server.config.modes.items[mode_id].mappings;
|
||||||
const mapping_idx = mappingExists(mode_mappings, modifiers, keysym, optionals.release) orelse {
|
const mapping_idx = mappingExists(mode_mappings, modifiers, keysym, optionals.release) orelse return;
|
||||||
out.* = try std.fmt.allocPrint(
|
|
||||||
allocator,
|
|
||||||
"there is no mapping for modifiers '{}' and keysym '{}'",
|
|
||||||
.{ args[2 + offset], args[3 + offset] },
|
|
||||||
);
|
|
||||||
return Error.Other;
|
|
||||||
};
|
|
||||||
|
|
||||||
var mapping = mode_mappings.swapRemove(mapping_idx);
|
var mapping = mode_mappings.swapRemove(mapping_idx);
|
||||||
mapping.deinit();
|
mapping.deinit();
|
||||||
@ -291,14 +280,7 @@ pub fn unmapPointer(
|
|||||||
const event_code = try parseEventCode(allocator, args[3], out);
|
const event_code = try parseEventCode(allocator, args[3], out);
|
||||||
|
|
||||||
const mode_pointer_mappings = &seat.input_manager.server.config.modes.items[mode_id].pointer_mappings;
|
const mode_pointer_mappings = &seat.input_manager.server.config.modes.items[mode_id].pointer_mappings;
|
||||||
const mapping_idx = pointerMappingExists(mode_pointer_mappings, modifiers, event_code) orelse {
|
const mapping_idx = pointerMappingExists(mode_pointer_mappings, modifiers, event_code) orelse return;
|
||||||
out.* = try std.fmt.allocPrint(
|
|
||||||
allocator,
|
|
||||||
"there is no mapping for modifiers '{}' and button '{}'",
|
|
||||||
.{ args[2], args[3] },
|
|
||||||
);
|
|
||||||
return Error.Other;
|
|
||||||
};
|
|
||||||
|
|
||||||
_ = mode_pointer_mappings.swapRemove(mapping_idx);
|
_ = mode_pointer_mappings.swapRemove(mapping_idx);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user