mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
keyboard groups work in drm mode
This commit is contained in:
parent
976900ffa6
commit
d9ebb6197d
6 changed files with 71 additions and 22 deletions
27
output.txt
Normal file
27
output.txt
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
info: Starting mezzaluna
|
||||||
|
info: Creating root of mezzaluna
|
||||||
|
|
||||||
|
debug: Loaded lua
|
||||||
|
info: Starting backend
|
||||||
|
error: New input request for input that is not a keyboard or pointer: Lid Switch
|
||||||
|
info: Handling a new output - eDP-1
|
||||||
|
debug: adding output: eDP-1
|
||||||
|
info: Starting server
|
||||||
|
warn: wayland.c:1777: compositor does not implement the primary selection interface
|
||||||
|
warn: wayland.c:1780: compositor does not implement XDG activation, bell.urgent will fall back to coloring the window margins red
|
||||||
|
warn: wayland.c:1786: compositor does not implement fractional scaling
|
||||||
|
warn: wayland.c:1789: compositor does not implement server-side cursors, falling back to client-side cursors
|
||||||
|
warn: wayland.c:1794: compositor does not implement the XDG toplevel icon protocol
|
||||||
|
warn: wayland.c:1799: text input interface not implemented by compositor; IME will be disabled
|
||||||
|
debug: Request for new toplevel
|
||||||
|
debug: Mapping view 'foot'
|
||||||
|
Segmentation fault at address 0xc8f8920
|
||||||
|
???:?:?: 0xc8f8920 in ??? (???)
|
||||||
|
Unwind information for `???:0xc8f8920` was not available, trace may be incomplete
|
||||||
|
|
||||||
|
err: wayland.c:1675: failed to read events from the Wayland socket: Broken pipe
|
||||||
|
err: wayland.c:2318: failed to roundtrip Wayland display: Broken pipe
|
||||||
|
err: wayland.c:2318: failed to roundtrip Wayland display: Broken pipe
|
||||||
|
err: wayland.c:2318: failed to roundtrip Wayland display: Broken pipe
|
||||||
|
warn: terminal.c:2029: slave exited with signal 1 (Hangup)
|
||||||
|
err: wayland.c:2283: failed to flush wayland socket: Broken pipe
|
||||||
|
|
@ -138,7 +138,7 @@ fn handleButton(
|
||||||
|
|
||||||
switch (event.state) {
|
switch (event.state) {
|
||||||
.pressed => {
|
.pressed => {
|
||||||
if(server.keyboard.wlr_keyboard.getModifiers().alt) {
|
if(server.seat.keyboard_group.keyboard.getModifiers().alt) {
|
||||||
// Can be BTN_RIGHT, BTN_LEFT, or BTN_MIDDLE
|
// Can be BTN_RIGHT, BTN_LEFT, or BTN_MIDDLE
|
||||||
if(server.seat.focused_view) |view| {
|
if(server.seat.focused_view) |view| {
|
||||||
// Keep track of where the drag started
|
// Keep track of where the drag started
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ const std = @import("std");
|
||||||
const gpa = std.heap.c_allocator;
|
const gpa = std.heap.c_allocator;
|
||||||
const server = &@import("main.zig").server;
|
const server = &@import("main.zig").server;
|
||||||
const Keymap = @import("keymap.zig");
|
const Keymap = @import("keymap.zig");
|
||||||
|
const Utils = @import("utils.zig");
|
||||||
|
|
||||||
const wl = @import("wayland").server.wl;
|
const wl = @import("wayland").server.wl;
|
||||||
const wlr = @import("wlroots");
|
const wlr = @import("wlroots");
|
||||||
|
|
@ -16,8 +17,6 @@ wlr_keyboard: *wlr.Keyboard,
|
||||||
context: *xkb.Context,
|
context: *xkb.Context,
|
||||||
device: *wlr.InputDevice,
|
device: *wlr.InputDevice,
|
||||||
|
|
||||||
keyboards: wl.list.Head(Keyboard, .link) = undefined,
|
|
||||||
|
|
||||||
link: wl.list.Link = undefined,
|
link: wl.list.Link = undefined,
|
||||||
|
|
||||||
// Keyboard listeners
|
// Keyboard listeners
|
||||||
|
|
@ -28,8 +27,9 @@ modifiers: wl.Listener(*wlr.Keyboard) = .init(handleModifiers),
|
||||||
// Device listeners
|
// Device listeners
|
||||||
destroy: wl.Listener(*wlr.InputDevice) = .init(handleDestroy),
|
destroy: wl.Listener(*wlr.InputDevice) = .init(handleDestroy),
|
||||||
|
|
||||||
|
pub fn init(device: *wlr.InputDevice) *Keyboard {
|
||||||
|
const self = gpa.create(Keyboard) catch Utils.oomPanic();
|
||||||
|
|
||||||
pub fn init(self: *Keyboard, device: *wlr.InputDevice) void {
|
|
||||||
errdefer {
|
errdefer {
|
||||||
std.log.err("Unable to initialize new keyboard, exiting", .{});
|
std.log.err("Unable to initialize new keyboard, exiting", .{});
|
||||||
std.process.exit(6);
|
std.process.exit(6);
|
||||||
|
|
@ -40,14 +40,10 @@ pub fn init(self: *Keyboard, device: *wlr.InputDevice) void {
|
||||||
.wlr_keyboard = device.toKeyboard(),
|
.wlr_keyboard = device.toKeyboard(),
|
||||||
.device = device,
|
.device = device,
|
||||||
};
|
};
|
||||||
defer self.context.unref();
|
|
||||||
|
|
||||||
const keymap = xkb.Keymap.newFromNames(self.context, null, .no_flags) orelse return error.KeymapFailed;
|
|
||||||
defer keymap.unref();
|
|
||||||
|
|
||||||
// TODO: configure this via lua later
|
// TODO: configure this via lua later
|
||||||
// Should handle this error here
|
// Should handle this error here
|
||||||
if (!self.wlr_keyboard.setKeymap(keymap)) return error.SetKeymapFailed;
|
if (!self.wlr_keyboard.setKeymap(server.seat.keymap)) return error.SetKeymapFailed;
|
||||||
self.wlr_keyboard.setRepeatInfo(25, 600);
|
self.wlr_keyboard.setRepeatInfo(25, 600);
|
||||||
|
|
||||||
self.wlr_keyboard.events.modifiers.add(&self.modifiers);
|
self.wlr_keyboard.events.modifiers.add(&self.modifiers);
|
||||||
|
|
@ -56,12 +52,14 @@ pub fn init(self: *Keyboard, device: *wlr.InputDevice) void {
|
||||||
|
|
||||||
device.events.destroy.add(&self.destroy);
|
device.events.destroy.add(&self.destroy);
|
||||||
|
|
||||||
std.log.debug("adding keyboard: {s}", .{self.wlr_keyboard.base.name orelse "(null)"});
|
self.wlr_keyboard.data = self;
|
||||||
|
|
||||||
server.seat.wlr_seat.setKeyboard(self.wlr_keyboard);
|
std.log.err("Adding new keyboard {s}", .{device.name orelse "(unnamed)"});
|
||||||
|
if(!server.seat.keyboard_group.addKeyboard(self.wlr_keyboard)) {
|
||||||
|
std.log.err("Adding new keyboard {s} failed", .{device.name orelse "(unnamed)"});
|
||||||
|
}
|
||||||
|
|
||||||
self.keyboards.init();
|
return self;
|
||||||
self.keyboards.append(self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit (self: *Keyboard) void {
|
pub fn deinit (self: *Keyboard) void {
|
||||||
|
|
@ -80,8 +78,8 @@ fn handleKey(_: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboard.even
|
||||||
const keycode = event.keycode + 8;
|
const keycode = event.keycode + 8;
|
||||||
|
|
||||||
var handled = false;
|
var handled = false;
|
||||||
const modifiers = server.keyboard.wlr_keyboard.getModifiers();
|
const modifiers = server.seat.keyboard_group.keyboard.getModifiers();
|
||||||
for (server.keyboard.wlr_keyboard.xkb_state.?.keyGetSyms(keycode)) |sym| {
|
for (server.seat.keyboard_group.keyboard.xkb_state.?.keyGetSyms(keycode)) |sym| {
|
||||||
if (server.keymaps.get(Keymap.hash(modifiers, sym))) |map| {
|
if (server.keymaps.get(Keymap.hash(modifiers, sym))) |map| {
|
||||||
if (event.state == .pressed and map.lua_press_ref_idx > 0) {
|
if (event.state == .pressed and map.lua_press_ref_idx > 0) {
|
||||||
map.callback(false);
|
map.callback(false);
|
||||||
|
|
@ -94,7 +92,7 @@ fn handleKey(_: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboard.even
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
server.seat.wlr_seat.setKeyboard(server.keyboard.wlr_keyboard);
|
server.seat.wlr_seat.setKeyboard(&server.seat.keyboard_group.keyboard);
|
||||||
server.seat.wlr_seat.keyboardNotifyKey(event.time_msec, event.keycode, event.state);
|
server.seat.wlr_seat.keyboardNotifyKey(event.time_msec, event.keycode, event.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
26
src/seat.zig
26
src/seat.zig
|
|
@ -3,6 +3,7 @@ const Seat = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const wlr = @import("wlroots");
|
const wlr = @import("wlroots");
|
||||||
const wl = @import("wayland").server.wl;
|
const wl = @import("wayland").server.wl;
|
||||||
|
const xkb = @import("xkbcommon");
|
||||||
|
|
||||||
const Utils = @import("utils.zig");
|
const Utils = @import("utils.zig");
|
||||||
const View = @import("view.zig");
|
const View = @import("view.zig");
|
||||||
|
|
@ -14,6 +15,9 @@ wlr_seat: *wlr.Seat,
|
||||||
focused_view: ?*View,
|
focused_view: ?*View,
|
||||||
focused_output: ?*Output,
|
focused_output: ?*Output,
|
||||||
|
|
||||||
|
keyboard_group: *wlr.KeyboardGroup,
|
||||||
|
keymap: *xkb.Keymap,
|
||||||
|
|
||||||
request_set_cursor: wl.Listener(*wlr.Seat.event.RequestSetCursor) = .init(handleRequestSetCursor),
|
request_set_cursor: wl.Listener(*wlr.Seat.event.RequestSetCursor) = .init(handleRequestSetCursor),
|
||||||
request_set_selection: wl.Listener(*wlr.Seat.event.RequestSetSelection) = .init(handleRequestSetSelection),
|
request_set_selection: wl.Listener(*wlr.Seat.event.RequestSetSelection) = .init(handleRequestSetSelection),
|
||||||
// request_set_primary_selection
|
// request_set_primary_selection
|
||||||
|
|
@ -22,11 +26,32 @@ request_set_selection: wl.Listener(*wlr.Seat.event.RequestSetSelection) = .init(
|
||||||
pub fn init(self: *Seat) void {
|
pub fn init(self: *Seat) void {
|
||||||
errdefer Utils.oomPanic();
|
errdefer Utils.oomPanic();
|
||||||
|
|
||||||
|
const xkb_context = xkb.Context.new(.no_flags) orelse {
|
||||||
|
std.log.err("Unable to create a xkb context, exiting", .{});
|
||||||
|
std.process.exit(7);
|
||||||
|
};
|
||||||
|
defer xkb_context.unref();
|
||||||
|
|
||||||
|
const keymap = xkb.Keymap.newFromNames(xkb_context, null, .no_flags) orelse {
|
||||||
|
std.log.err("Unable to create a xkb keymap, exiting", .{});
|
||||||
|
std.process.exit(8);
|
||||||
|
};
|
||||||
|
defer keymap.unref();
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.wlr_seat = try wlr.Seat.create(server.wl_server, "default"),
|
.wlr_seat = try wlr.Seat.create(server.wl_server, "default"),
|
||||||
.focused_view = null,
|
.focused_view = null,
|
||||||
.focused_output = null,
|
.focused_output = null,
|
||||||
|
.keyboard_group = try wlr.KeyboardGroup.create(),
|
||||||
|
.keymap = keymap.ref(),
|
||||||
};
|
};
|
||||||
|
errdefer {
|
||||||
|
self.keyboard_group.destroy();
|
||||||
|
self.wlr_seat.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = self.keyboard_group.keyboard.setKeymap(self.keymap);
|
||||||
|
self.wlr_seat.setKeyboard(&self.keyboard_group.keyboard);
|
||||||
|
|
||||||
self.wlr_seat.events.request_set_cursor.add(&self.request_set_cursor);
|
self.wlr_seat.events.request_set_cursor.add(&self.request_set_cursor);
|
||||||
self.wlr_seat.events.request_set_selection.add(&self.request_set_selection);
|
self.wlr_seat.events.request_set_selection.add(&self.request_set_selection);
|
||||||
|
|
@ -36,6 +61,7 @@ pub fn deinit(self: *Seat) void {
|
||||||
self.request_set_cursor.link.remove();
|
self.request_set_cursor.link.remove();
|
||||||
self.request_set_selection.link.remove();
|
self.request_set_selection.link.remove();
|
||||||
|
|
||||||
|
self.keyboard_group.destroy();
|
||||||
self.wlr_seat.destroy();
|
self.wlr_seat.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ allocator: *wlr.Allocator,
|
||||||
root: Root,
|
root: Root,
|
||||||
seat: Seat,
|
seat: Seat,
|
||||||
cursor: Cursor,
|
cursor: Cursor,
|
||||||
keyboard: Keyboard,
|
|
||||||
keymaps: std.AutoHashMap(u64, Keymap),
|
keymaps: std.AutoHashMap(u64, Keymap),
|
||||||
|
|
||||||
// Backend listeners
|
// Backend listeners
|
||||||
|
|
@ -90,7 +89,6 @@ pub fn init(self: *Server) void {
|
||||||
.root = undefined,
|
.root = undefined,
|
||||||
.seat = undefined,
|
.seat = undefined,
|
||||||
.cursor = undefined,
|
.cursor = undefined,
|
||||||
.keyboard = undefined,
|
|
||||||
.keymaps = .init(gpa),
|
.keymaps = .init(gpa),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -145,7 +143,7 @@ fn handleNewInput(
|
||||||
device: *wlr.InputDevice
|
device: *wlr.InputDevice
|
||||||
) void {
|
) void {
|
||||||
switch (device.type) {
|
switch (device.type) {
|
||||||
.keyboard => server.keyboard.init(device),
|
.keyboard => _ = Keyboard.init(device),
|
||||||
.pointer => server.cursor.wlr_cursor.attachInputDevice(device),
|
.pointer => server.cursor.wlr_cursor.attachInputDevice(device),
|
||||||
else => {
|
else => {
|
||||||
std.log.err(
|
std.log.err(
|
||||||
|
|
@ -157,7 +155,7 @@ fn handleNewInput(
|
||||||
|
|
||||||
server.seat.wlr_seat.setCapabilities(.{
|
server.seat.wlr_seat.setCapabilities(.{
|
||||||
.pointer = true,
|
.pointer = true,
|
||||||
.keyboard = server.keyboard.keyboards.length() > 0,
|
.keyboard = true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,8 +110,8 @@ fn handleMap(listener: *wl.Listener(void)) void {
|
||||||
const xdg_surface = view.xdg_toplevel.base;
|
const xdg_surface = view.xdg_toplevel.base;
|
||||||
server.seat.wlr_seat.keyboardNotifyEnter(
|
server.seat.wlr_seat.keyboardNotifyEnter(
|
||||||
xdg_surface.surface,
|
xdg_surface.surface,
|
||||||
server.keyboard.wlr_keyboard.keycodes[0..server.keyboard.wlr_keyboard.num_keycodes],
|
server.seat.keyboard_group.keyboard.keycodes[0..server.seat.keyboard_group.keyboard.num_keycodes],
|
||||||
&server.keyboard.wlr_keyboard.modifiers
|
&server.seat.keyboard_group.keyboard.modifiers
|
||||||
);
|
);
|
||||||
|
|
||||||
if(view.xdg_toplevel_decoration) |decoration| {
|
if(view.xdg_toplevel_decoration) |decoration| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue