Add keybind to move current focus to top of stack

This commit is contained in:
Isaac Freund 2020-03-28 14:37:30 +01:00
parent d7d5cf06ee
commit ca2e169535
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
2 changed files with 28 additions and 18 deletions

View file

@ -94,7 +94,7 @@ pub const Keyboard = struct {
// process it as a compositor keybinding. // process it as a compositor keybinding.
var i: usize = 0; var i: usize = 0;
while (i < nsyms) { while (i < nsyms) {
handled = keyboard.seat.server.handleKeybinding(syms.?[i]); handled = keyboard.seat.server.handleKeybinding(syms.?[i], modifiers);
if (handled) { if (handled) {
break; break;
} }

View file

@ -105,24 +105,34 @@ pub const Server = struct {
c.wl_display_run(self.wl_display); c.wl_display_run(self.wl_display);
} }
pub fn handleKeybinding(self: *Self, sym: c.xkb_keysym_t) bool { pub fn handleKeybinding(self: *Self, sym: c.xkb_keysym_t, modifiers: u32) bool {
// Here we handle compositor keybindings. This is when the compositor is
// processing keys, rather than passing them on to the client for its own
// processing.
//
// This function assumes the proper modifier is held down. // This function assumes the proper modifier is held down.
switch (sym) { if (modifiers & @intCast(u32, c.WLR_MODIFIER_SHIFT) != 0) {
c.XKB_KEY_Escape => c.wl_display_terminate(self.wl_display), switch (sym) {
c.XKB_KEY_j => self.root.focusNextView(), c.XKB_KEY_Return => {
c.XKB_KEY_k => self.root.focusPrevView(), if (self.root.focused_view) |current_focus| {
c.XKB_KEY_Return => { const node = @fieldParentPtr(std.TailQueue(View).Node, "data", current_focus);
// Spawn an instance of alacritty self.root.views.remove(node);
// const argv = [_][]const u8{ "/bin/sh", "-c", "WAYLAND_DEBUG=1 alacritty" }; self.root.views.prepend(node);
const argv = [_][]const u8{ "/bin/sh", "-c", "alacritty" }; self.root.arrange();
const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch unreachable; }
std.ChildProcess.spawn(child) catch unreachable; },
}, else => return false,
else => return false, }
} else {
switch (sym) {
c.XKB_KEY_e => c.wl_display_terminate(self.wl_display),
c.XKB_KEY_j => self.root.focusNextView(),
c.XKB_KEY_k => self.root.focusPrevView(),
c.XKB_KEY_Return => {
// Spawn an instance of alacritty
// const argv = [_][]const u8{ "/bin/sh", "-c", "WAYLAND_DEBUG=1 alacritty" };
const argv = [_][]const u8{ "/bin/sh", "-c", "alacritty" };
const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch unreachable;
std.ChildProcess.spawn(child) catch unreachable;
},
else => return false,
}
} }
return true; return true;
} }