Allow switching VTs

This commit is contained in:
Isaac Freund 2020-04-06 22:23:30 +02:00
parent aef2245272
commit 5c320c0b8c
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
4 changed files with 42 additions and 9 deletions

View file

@ -1,5 +1,6 @@
#define WLR_USE_UNSTABLE
#include <wlr/backend.h>
#include <wlr/backend/multi.h>
#include <wlr/render/wlr_renderer.h>
struct wlr_backend *river_wlr_backend_autocreate(struct wl_display *display) {
@ -13,3 +14,11 @@ struct wlr_renderer *river_wlr_backend_get_renderer(struct wlr_backend *backend)
bool river_wlr_backend_start(struct wlr_backend *backend) {
return wlr_backend_start(backend);
}
bool river_wlr_backend_is_multi(struct wlr_backend *backend) {
return wlr_backend_is_multi(backend);
}
struct wlr_session *river_wlr_backend_get_session(struct wlr_backend *backend) {
return wlr_backend_get_session(backend);
}

View file

@ -25,6 +25,7 @@ struct wlr_backend {
struct wlr_backend *river_wlr_backend_autocreate(struct wl_display *display);
struct wlr_renderer *river_wlr_backend_get_renderer(struct wlr_backend *backend);
bool river_wlr_backend_start(struct wlr_backend *backend);
bool river_wlr_backend_is_multi(struct wlr_backend *backend);
struct wlr_session *river_wlr_backend_get_session(struct wlr_backend *backend);
#endif

View file

@ -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;
}
};

View file

@ -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 => {