Add borders to windows; add navigation keybinds
Right now, colors are hardcoded in the Config in main.zig. This commit also adds a couple of new keybinds for navigating between windows. All keybinds are hardcoded as well right now.
This commit is contained in:
parent
42494ae5d1
commit
578e2f449e
7 changed files with 235 additions and 23 deletions
|
|
@ -4,13 +4,25 @@
|
|||
|
||||
const XkbBindings = @This();
|
||||
|
||||
pub const Command = union(enum) {
|
||||
spawn: []const []const u8,
|
||||
focus_next,
|
||||
focus_prev,
|
||||
close_window,
|
||||
exit,
|
||||
};
|
||||
|
||||
const XkbBinding = struct {
|
||||
xkb_binding_v1: *river.XkbBindingV1,
|
||||
command: Command,
|
||||
context: *Context,
|
||||
link: wl.list.Link,
|
||||
|
||||
fn init(xkb_binding: *XkbBinding, xkb_binding_v1: *river.XkbBindingV1) void {
|
||||
fn init(xkb_binding: *XkbBinding, xkb_binding_v1: *river.XkbBindingV1, command: Command, context: *Context) void {
|
||||
xkb_binding.* = .{
|
||||
.xkb_binding_v1 = xkb_binding_v1,
|
||||
.command = command,
|
||||
.context = context,
|
||||
.link = undefined, // Handled by the wl.list
|
||||
};
|
||||
|
||||
|
|
@ -21,10 +33,7 @@ const XkbBinding = struct {
|
|||
assert(xkb_binding.xkb_binding_v1 == xkb_binding_v1);
|
||||
switch (event) {
|
||||
.pressed => {
|
||||
var child = std.process.Child.init(&.{"foot"}, std.heap.c_allocator);
|
||||
_ = child.spawn() catch |err| {
|
||||
log.err("Failed to spawn foot: {}", .{err});
|
||||
};
|
||||
xkb_binding.executeCommand();
|
||||
},
|
||||
.released => {},
|
||||
else => |ev| {
|
||||
|
|
@ -32,6 +41,48 @@ const XkbBinding = struct {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn executeCommand(xkb_binding: *XkbBinding) void {
|
||||
const context = xkb_binding.context;
|
||||
switch (xkb_binding.command) {
|
||||
.spawn => |cmd| {
|
||||
var child = std.process.Child.init(cmd, std.heap.c_allocator);
|
||||
_ = child.spawn() catch |err| {
|
||||
log.err("Failed to spawn foot: {}", .{err});
|
||||
};
|
||||
},
|
||||
.focus_next => {
|
||||
const seat = context.wm.seats.first() orelse return;
|
||||
if (seat.focused) |current| {
|
||||
seat.focused = context.wm.getNextWindow(current);
|
||||
} else {
|
||||
// No window focused, focus the first one
|
||||
seat.focused = context.wm.windows.first();
|
||||
}
|
||||
context.wm.window_manager_v1.manageDirty();
|
||||
},
|
||||
.focus_prev => {
|
||||
const seat = context.wm.seats.first() orelse return;
|
||||
if (seat.focused) |current| {
|
||||
seat.focused = context.wm.getPrevWindow(current);
|
||||
} else {
|
||||
// No window focused, focus the last one
|
||||
seat.focused = context.wm.windows.last();
|
||||
}
|
||||
context.wm.window_manager_v1.manageDirty();
|
||||
},
|
||||
.close_window => {
|
||||
const seat = context.wm.seats.first() orelse return;
|
||||
if (seat.focused) |window| {
|
||||
window.window_v1.close();
|
||||
}
|
||||
},
|
||||
.exit => {
|
||||
// TODO: Disabled while I'm working with river within river :P
|
||||
// _ = std.process.Child.init(&.{"killall river"}, std.heap.c_allocator);
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
context: *Context,
|
||||
|
|
@ -58,7 +109,7 @@ pub fn getSeat(xkb_bindings: *XkbBindings) *river.SeatV1 {
|
|||
return seat.seat_v1;
|
||||
}
|
||||
|
||||
pub fn addBinding(xkb_bindings: *XkbBindings, keysym: u32, modifiers: river.SeatV1.Modifiers) void {
|
||||
pub fn addBinding(xkb_bindings: *XkbBindings, keysym: u32, modifiers: river.SeatV1.Modifiers, command: Command) void {
|
||||
const seat_v1 = xkb_bindings.getSeat();
|
||||
const xkb_binding_v1 = xkb_bindings.xkb_bindings_v1.getXkbBinding(seat_v1, keysym, modifiers) catch |err| {
|
||||
log.err("Failed to get xkb binding: {}", .{err});
|
||||
|
|
@ -66,7 +117,7 @@ pub fn addBinding(xkb_bindings: *XkbBindings, keysym: u32, modifiers: river.Seat
|
|||
};
|
||||
|
||||
const xkb_binding = xkb_bindings.context.allocator.create(XkbBinding) catch @panic("out-of-memory");
|
||||
xkb_binding.init(xkb_binding_v1);
|
||||
xkb_binding.init(xkb_binding_v1, command, xkb_bindings.context);
|
||||
xkb_bindings.bindings.append(xkb_binding);
|
||||
|
||||
xkb_binding_v1.enable();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue