Start adding tags
Right now, essentially nothing has changed, there is still no multi- output support and not even a way to change/set/toggle/view/etc. tags. However, tags *are* implemented at a core level. Next step is to add keybinds for the various tag actions. After that, I will work on multi-output support.
This commit is contained in:
parent
87ec2d4f60
commit
b8d31de3ef
6 changed files with 160 additions and 106 deletions
|
|
@ -10,7 +10,7 @@ const MIN_RIVER_SEAT_V1_VERSION: u2 = 3;
|
|||
|
||||
context: *Context,
|
||||
|
||||
window_manager_v1: *river.WindowManagerV1,
|
||||
river_window_manager_v1: *river.WindowManagerV1,
|
||||
|
||||
seats: wl.list.Head(Seat, .link),
|
||||
outputs: wl.list.Head(Output, .link),
|
||||
|
|
@ -24,7 +24,7 @@ pub fn create(context: *Context, window_manager_v1: *river.WindowManagerV1) !*Wi
|
|||
|
||||
wm.* = .{
|
||||
.context = context,
|
||||
.window_manager_v1 = window_manager_v1,
|
||||
.river_window_manager_v1 = window_manager_v1,
|
||||
.seats = undefined, // we will initialize these shortly
|
||||
.outputs = undefined,
|
||||
.windows = undefined,
|
||||
|
|
@ -34,28 +34,32 @@ pub fn create(context: *Context, window_manager_v1: *river.WindowManagerV1) !*Wi
|
|||
wm.outputs.init();
|
||||
wm.windows.init();
|
||||
|
||||
wm.window_manager_v1.setListener(*WindowManager, windowManagerV1Listener, wm);
|
||||
wm.river_window_manager_v1.setListener(*WindowManager, windowManagerV1Listener, wm);
|
||||
|
||||
return wm;
|
||||
}
|
||||
|
||||
pub fn destroy(wm: *WindowManager) void {
|
||||
var window_it = wm.windows.iterator(.forward);
|
||||
while (window_it.next()) |window| {
|
||||
window.link.remove();
|
||||
window.destroy();
|
||||
{
|
||||
var it = wm.windows.safeIterator(.forward);
|
||||
while (it.next()) |window| {
|
||||
window.link.remove();
|
||||
window.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
var output_it = wm.outputs.iterator(.forward);
|
||||
while (output_it.next()) |output| {
|
||||
output.link.remove();
|
||||
output.destroy();
|
||||
{
|
||||
var it = wm.outputs.safeIterator(.forward);
|
||||
while (it.next()) |output| {
|
||||
output.link.remove();
|
||||
output.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
var seat_it = wm.seats.iterator(.forward);
|
||||
while (seat_it.next()) |seat| {
|
||||
seat.link.remove();
|
||||
seat.destroy();
|
||||
{
|
||||
var it = wm.seats.safeIterator(.forward);
|
||||
while (it.next()) |seat| {
|
||||
seat.link.remove();
|
||||
seat.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
utils.allocator.destroy(wm);
|
||||
|
|
@ -89,20 +93,34 @@ pub fn getPrevWindow(wm: *WindowManager, current: *Window) ?*Window {
|
|||
/// - Single window: maximized
|
||||
/// - Multiple windows: stack (45% left, vertically tiled), primary (55% right)
|
||||
fn calculatePrimaryStackLayout(wm: *WindowManager) void {
|
||||
const count = wm.window_count;
|
||||
if (count == 0) return;
|
||||
|
||||
// TODO: Support multiple outputs
|
||||
const output = wm.outputs.first() orelse return;
|
||||
|
||||
// Get a list of active windows
|
||||
var active_list: DoublyLinkedList = .{};
|
||||
var active_count: u31 = 0;
|
||||
var it = wm.windows.iterator(.forward);
|
||||
while (it.next()) |window| {
|
||||
if (output.tags & window.tags != 0x0000) {
|
||||
active_list.append(&window.active_list_node);
|
||||
active_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (active_count == 0) return;
|
||||
|
||||
// Output dimensions come as i32 from the protocol, convert to u31 for window dimensions
|
||||
// since they can't be negative.
|
||||
const output_width: u31 = @intCast(output.width);
|
||||
const output_height: u31 = @intCast(output.height);
|
||||
const output_x = output.x;
|
||||
const output_y = output.y;
|
||||
|
||||
var index: u8 = 0;
|
||||
var it = wm.windows.iterator(.forward);
|
||||
while (it.next()) |window| {
|
||||
if (count == 1) {
|
||||
// Iterate through the active windows and apply the tags
|
||||
var i: u31 = 0;
|
||||
while (active_list.popFirst()) |node| : (i += 1) {
|
||||
const window: *Window = @fieldParentPtr("active_list_node", node);
|
||||
if (active_count == 1) {
|
||||
// Single window: maximize
|
||||
window.pending_render.x = output_x;
|
||||
window.pending_render.y = output_y;
|
||||
|
|
@ -114,11 +132,11 @@ fn calculatePrimaryStackLayout(wm: *WindowManager) void {
|
|||
// TODO: Support multiple windows in primary stack
|
||||
const primary_width: u31 = @intFromFloat(@as(f32, @floatFromInt(output_width)) * PRIMARY_RATIO);
|
||||
const stack_width: u31 = output_width - primary_width;
|
||||
const stack_count = count - 1;
|
||||
const stack_count = active_count - 1;
|
||||
const stack_height: u31 = @divFloor(output_height, stack_count);
|
||||
window.pending_manage.maximized = false;
|
||||
|
||||
if (index == 0) {
|
||||
if (i == 0) {
|
||||
// Primary window (first window) - right side
|
||||
window.pending_render.x = output_x + @as(i32, stack_width);
|
||||
window.pending_render.y = output_y;
|
||||
|
|
@ -126,12 +144,12 @@ fn calculatePrimaryStackLayout(wm: *WindowManager) void {
|
|||
window.pending_manage.height = output_height;
|
||||
} else {
|
||||
// Stack window(s) - left side
|
||||
const stack_index = index - 1;
|
||||
const stack_index = i - 1;
|
||||
window.pending_render.x = output_x;
|
||||
window.pending_render.y = output_y + @as(i32, stack_index) * @as(i32, stack_height);
|
||||
window.pending_manage.width = stack_width;
|
||||
// Last stack window gets remaining height to avoid gaps from integer division
|
||||
if (index == count - 1) {
|
||||
if (i == active_count - 1) {
|
||||
window.pending_manage.height = output_height - stack_index * stack_height;
|
||||
} else {
|
||||
window.pending_manage.height = stack_height;
|
||||
|
|
@ -142,83 +160,92 @@ fn calculatePrimaryStackLayout(wm: *WindowManager) void {
|
|||
// Borders are automatically disabled when a window is fullscreened so we don't
|
||||
// have to worry about that.
|
||||
const border_width = wm.context.config.border_width;
|
||||
// We use .? because we know we set the windows height, width, x, and y above
|
||||
window.pending_manage.height.? -= 2 * border_width;
|
||||
window.pending_manage.width.? -= 2 * border_width;
|
||||
window.pending_render.x.? += border_width;
|
||||
window.pending_render.y.? += border_width;
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
||||
// Make sure we went through the whole list
|
||||
assert(active_list.first == null);
|
||||
}
|
||||
|
||||
fn manage_start(wm: *WindowManager) void {
|
||||
const river_window_manager_v1 = wm.river_window_manager_v1;
|
||||
const context = wm.context;
|
||||
if (!context.initialized) {
|
||||
// This code (should) only be run once while initializing the WM, so let's
|
||||
// mark it as cold.
|
||||
@branchHint(.cold);
|
||||
context.initialized = true;
|
||||
|
||||
const seat = wm.seats.first() orelse @panic("Failed to get seat");
|
||||
const river_seat_v1 = seat.river_seat_v1;
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.t, .{ .mod4 = true }, .{ .spawn = &.{"foot"} });
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.j, .{ .mod4 = true }, .focus_next);
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.k, .{ .mod4 = true }, .focus_prev);
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.f, .{ .mod4 = true }, .fullscreen);
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.q, .{ .mod4 = true, .shift = true }, .close_window);
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.e, .{ .mod4 = true, .shift = true }, .exit);
|
||||
}
|
||||
|
||||
{
|
||||
var it = wm.outputs.iterator(.forward);
|
||||
while (it.next()) |output| {
|
||||
output.manage();
|
||||
}
|
||||
}
|
||||
{
|
||||
// Calculate layout before managing windows
|
||||
wm.calculatePrimaryStackLayout();
|
||||
var it = wm.windows.iterator(.forward);
|
||||
while (it.next()) |window| {
|
||||
window.manage();
|
||||
}
|
||||
}
|
||||
{
|
||||
var it = wm.seats.iterator(.forward);
|
||||
while (it.next()) |seat| {
|
||||
seat.manage();
|
||||
}
|
||||
}
|
||||
river_window_manager_v1.manageFinish();
|
||||
}
|
||||
|
||||
fn render_start(wm: *WindowManager) void {
|
||||
const river_window_manager_v1 = wm.river_window_manager_v1;
|
||||
{
|
||||
var it = wm.seats.iterator(.forward);
|
||||
while (it.next()) |seat| {
|
||||
seat.render();
|
||||
}
|
||||
}
|
||||
{
|
||||
var it = wm.outputs.iterator(.forward);
|
||||
while (it.next()) |output| {
|
||||
output.render();
|
||||
}
|
||||
}
|
||||
{
|
||||
var it = wm.windows.iterator(.forward);
|
||||
while (it.next()) |window| {
|
||||
window.render();
|
||||
}
|
||||
}
|
||||
river_window_manager_v1.renderFinish();
|
||||
}
|
||||
|
||||
fn windowManagerV1Listener(window_manager_v1: *river.WindowManagerV1, event: river.WindowManagerV1.Event, wm: *WindowManager) void {
|
||||
assert(wm.window_manager_v1 == window_manager_v1);
|
||||
assert(wm.river_window_manager_v1 == window_manager_v1);
|
||||
const context = wm.context;
|
||||
switch (event) {
|
||||
.unavailable => {
|
||||
log.err("Window manager unavailable (some other wm instance is running). Exiting", .{});
|
||||
std.posix.exit(1);
|
||||
},
|
||||
.manage_start => {
|
||||
if (!context.initialized) {
|
||||
// This code (should) only be run once while initializing the WM, so let's
|
||||
// mark it as cold.
|
||||
@branchHint(.cold);
|
||||
context.initialized = true;
|
||||
|
||||
const seat = wm.seats.first() orelse @panic("Failed to get seat");
|
||||
const river_seat_v1 = seat.river_seat_v1;
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.t, .{ .mod4 = true }, .{ .spawn = &.{"foot"} });
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.j, .{ .mod4 = true }, .focus_next);
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.k, .{ .mod4 = true }, .focus_prev);
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.f, .{ .mod4 = true }, .fullscreen);
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.q, .{ .mod4 = true, .shift = true }, .close_window);
|
||||
context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.e, .{ .mod4 = true, .shift = true }, .exit);
|
||||
}
|
||||
|
||||
{
|
||||
var it = wm.outputs.iterator(.forward);
|
||||
while (it.next()) |output| {
|
||||
output.manage();
|
||||
}
|
||||
}
|
||||
// Calculate layout before managing windows
|
||||
wm.calculatePrimaryStackLayout();
|
||||
{
|
||||
var it = wm.windows.iterator(.forward);
|
||||
while (it.next()) |window| {
|
||||
window.manage();
|
||||
}
|
||||
}
|
||||
{
|
||||
var it = wm.seats.iterator(.forward);
|
||||
while (it.next()) |seat| {
|
||||
seat.manage();
|
||||
}
|
||||
}
|
||||
window_manager_v1.manageFinish();
|
||||
},
|
||||
.render_start => {
|
||||
{
|
||||
var it = wm.seats.iterator(.forward);
|
||||
while (it.next()) |seat| {
|
||||
seat.render();
|
||||
}
|
||||
}
|
||||
{
|
||||
var it = wm.outputs.iterator(.forward);
|
||||
while (it.next()) |output| {
|
||||
output.render();
|
||||
}
|
||||
}
|
||||
{
|
||||
var it = wm.windows.iterator(.forward);
|
||||
while (it.next()) |window| {
|
||||
window.render();
|
||||
}
|
||||
}
|
||||
window_manager_v1.renderFinish();
|
||||
},
|
||||
.manage_start => wm.manage_start(),
|
||||
.render_start => wm.render_start(),
|
||||
.output => |ev| {
|
||||
log.debug("initializing new wl_output: {d}", .{ev.id.getId()});
|
||||
// TODO: Support multi-output
|
||||
|
|
@ -238,6 +265,7 @@ fn windowManagerV1Listener(window_manager_v1: *river.WindowManagerV1, event: riv
|
|||
wm.seats.append(seat);
|
||||
},
|
||||
.window => |ev| {
|
||||
// TODO: Support multiple seats
|
||||
const seat = wm.seats.first() orelse @panic("Failed to get seat");
|
||||
// TODO: Support multiple outputs
|
||||
const output = wm.outputs.first() orelse @panic("Failed to get output");
|
||||
|
|
@ -258,6 +286,7 @@ fn windowManagerV1Listener(window_manager_v1: *river.WindowManagerV1, event: riv
|
|||
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const DoublyLinkedList = std.DoublyLinkedList;
|
||||
|
||||
const wayland = @import("wayland");
|
||||
const wl = wayland.client.wl;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue