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,14 +105,23 @@ 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.
if (modifiers & @intCast(u32, c.WLR_MODIFIER_SHIFT) != 0) {
switch (sym) { switch (sym) {
c.XKB_KEY_Escape => c.wl_display_terminate(self.wl_display), 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_j => self.root.focusNextView(),
c.XKB_KEY_k => self.root.focusPrevView(), c.XKB_KEY_k => self.root.focusPrevView(),
c.XKB_KEY_Return => { c.XKB_KEY_Return => {
@ -124,6 +133,7 @@ pub const Server = struct {
}, },
else => return false, else => return false,
} }
}
return true; return true;
} }