aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2020-04-06 22:23:30 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2020-04-06 22:23:30 +0200
commit5c320c0b8c5620f7927d392f7c36eecaecdaac51 (patch)
tree8eb72851318f978a18e0831bdc258057a274ab32 /src
parentaef2245272a312669b0aba6e8349982dd1d09800 (diff)
downloadriver-5c320c0b8c5620f7927d392f7c36eecaecdaac51.tar.gz
river-5c320c0b8c5620f7927d392f7c36eecaecdaac51.tar.xz
Allow switching VTs
Diffstat (limited to 'src')
-rw-r--r--src/keyboard.zig35
-rw-r--r--src/server.zig4
2 files changed, 31 insertions, 8 deletions
diff --git a/src/keyboard.zig b/src/keyboard.zig
index 57f1d37..8be9975 100644
--- a/src/keyboard.zig
+++ b/src/keyboard.zig
@@ -1,6 +1,7 @@
const std = @import("std");
const c = @import("c.zig");
+const Log = @import("log.zig").Log;
const Seat = @import("seat.zig").Seat;
pub const Keyboard = struct {
@@ -105,14 +106,13 @@ pub const Keyboard = struct {
var handled = false;
// TODO: These modifiers aren't properly handled, see sway's code
const modifiers = c.wlr_keyboard_get_modifiers(wlr_keyboard);
- if (modifiers & @intCast(u32, c.WLR_MODIFIER_LOGO) != 0 and
- event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED)
- {
- // If mod is held down and this button was _pressed_, we attempt to
- // process it as a compositor keybinding.
+ if (event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED) {
var i: usize = 0;
while (i < translated_keysyms_len) : (i += 1) {
- if (keyboard.seat.server.handleKeybinding(translated_keysyms.?[i], modifiers)) {
+ if (keyboard.handleBuiltinKeybind(translated_keysyms.?[i])) {
+ handled = true;
+ break;
+ } else if (keyboard.seat.server.handleKeybinding(translated_keysyms.?[i], modifiers)) {
handled = true;
break;
}
@@ -120,7 +120,10 @@ pub const Keyboard = struct {
if (!handled) {
i = 0;
while (i < raw_keysyms_len) : (i += 1) {
- if (keyboard.seat.server.handleKeybinding(raw_keysyms.?[i], modifiers)) {
+ if (keyboard.handleBuiltinKeybind(raw_keysyms.?[i])) {
+ handled = true;
+ break;
+ } else if (keyboard.seat.server.handleKeybinding(raw_keysyms.?[i], modifiers)) {
handled = true;
break;
}
@@ -140,4 +143,22 @@ pub const Keyboard = struct {
);
}
}
+
+ /// Handle any builtin, harcoded compsitor bindings such as VT switching.
+ /// Returns true if the keysym was handled.
+ fn handleBuiltinKeybind(self: Self, keysym: c.xkb_keysym_t) bool {
+ if (keysym >= c.XKB_KEY_XF86Switch_VT_1 and keysym <= c.XKB_KEY_XF86Switch_VT_12) {
+ Log.Debug.log("Switch VT keysym received", .{});
+ const wlr_backend = self.seat.server.wlr_backend;
+ if (c.river_wlr_backend_is_multi(wlr_backend)) {
+ if (c.river_wlr_backend_get_session(wlr_backend)) |session| {
+ const vt = keysym - c.XKB_KEY_XF86Switch_VT_1 + 1;
+ Log.Debug.log("Switching to VT {}", .{vt});
+ _ = c.wlr_session_change_vt(session, vt);
+ }
+ }
+ return true;
+ }
+ return false;
+ }
};
diff --git a/src/server.zig b/src/server.zig
index 469a10a..8a391f7 100644
--- a/src/server.zig
+++ b/src/server.zig
@@ -115,7 +115,9 @@ pub const Server = struct {
/// Handle all compositor keybindings
/// Note: this is a hacky initial implementation for testing and will be rewritten eventually
pub fn handleKeybinding(self: *Self, sym: c.xkb_keysym_t, modifiers: u32) bool {
- // This function assumes the proper modifier is held down.
+ if (modifiers & @intCast(u32, c.WLR_MODIFIER_LOGO) == 0) {
+ return false;
+ }
if (modifiers & @intCast(u32, c.WLR_MODIFIER_SHIFT) != 0) {
switch (sym) {
c.XKB_KEY_H => {