From ca2e1695350d696cbce00ef71823c1ab958c11c0 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 28 Mar 2020 14:37:30 +0100 Subject: [PATCH] Add keybind to move current focus to top of stack --- src/keyboard.zig | 2 +- src/server.zig | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/keyboard.zig b/src/keyboard.zig index 4229e0d..b85c671 100644 --- a/src/keyboard.zig +++ b/src/keyboard.zig @@ -94,7 +94,7 @@ pub const Keyboard = struct { // process it as a compositor keybinding. var i: usize = 0; while (i < nsyms) { - handled = keyboard.seat.server.handleKeybinding(syms.?[i]); + handled = keyboard.seat.server.handleKeybinding(syms.?[i], modifiers); if (handled) { break; } diff --git a/src/server.zig b/src/server.zig index fde69e4..30b06d5 100644 --- a/src/server.zig +++ b/src/server.zig @@ -105,24 +105,34 @@ pub const Server = struct { c.wl_display_run(self.wl_display); } - pub fn handleKeybinding(self: *Self, sym: c.xkb_keysym_t) 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. - // + pub fn handleKeybinding(self: *Self, sym: c.xkb_keysym_t, modifiers: u32) bool { // This function assumes the proper modifier is held down. - switch (sym) { - c.XKB_KEY_Escape => 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, + if (modifiers & @intCast(u32, c.WLR_MODIFIER_SHIFT) != 0) { + switch (sym) { + c.XKB_KEY_Return => { + if (self.root.focused_view) |current_focus| { + const node = @fieldParentPtr(std.TailQueue(View).Node, "data", current_focus); + self.root.views.remove(node); + self.root.views.prepend(node); + self.root.arrange(); + } + }, + 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; }