2020-06-16 05:48:30 -07:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
2021-04-14 15:28:39 -07:00
|
|
|
// Copyright 2020-2021 The River Developers
|
2020-06-16 05:48:30 -07:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2022-01-31 10:33:22 -08:00
|
|
|
// the Free Software Foundation, version 3.
|
2020-06-16 05:48:30 -07:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-10-02 06:53:08 -07:00
|
|
|
|
|
|
|
// This is an implementation of the default "tiled" layout of dwm and the
|
2021-04-14 15:28:39 -07:00
|
|
|
// 3 other orientations thereof. This code is written for the main stack
|
|
|
|
// to the left and then the input/output values are adjusted to apply
|
|
|
|
// the necessary transformations to derive the other orientations.
|
2020-10-02 06:53:08 -07:00
|
|
|
//
|
2021-04-14 15:28:39 -07:00
|
|
|
// With 4 views and one main on the left, the layout looks something like this:
|
2020-10-02 06:53:08 -07:00
|
|
|
//
|
|
|
|
// +-----------------------+------------+
|
|
|
|
// | | |
|
|
|
|
// | | |
|
|
|
|
// | | |
|
|
|
|
// | +------------+
|
|
|
|
// | | |
|
|
|
|
// | | |
|
|
|
|
// | | |
|
|
|
|
// | +------------+
|
|
|
|
// | | |
|
|
|
|
// | | |
|
|
|
|
// | | |
|
|
|
|
// +-----------------------+------------+
|
2020-06-16 05:48:30 -07:00
|
|
|
|
|
|
|
const std = @import("std");
|
2022-02-07 13:07:27 -08:00
|
|
|
const fmt = std.fmt;
|
2021-04-14 15:28:39 -07:00
|
|
|
const mem = std.mem;
|
2021-04-26 12:03:28 -07:00
|
|
|
const math = std.math;
|
2021-07-24 09:29:48 -07:00
|
|
|
const os = std.os;
|
2021-04-14 15:28:39 -07:00
|
|
|
const assert = std.debug.assert;
|
|
|
|
|
2020-10-02 06:53:08 -07:00
|
|
|
const wayland = @import("wayland");
|
|
|
|
const wl = wayland.client.wl;
|
|
|
|
const river = wayland.client.river;
|
|
|
|
|
2021-07-24 09:29:48 -07:00
|
|
|
const flags = @import("flags");
|
2021-04-26 14:41:30 -07:00
|
|
|
|
2021-05-01 03:49:49 -07:00
|
|
|
const usage =
|
2021-07-24 09:29:48 -07:00
|
|
|
\\usage: rivertile [options]
|
2021-05-01 03:49:49 -07:00
|
|
|
\\
|
2021-10-31 16:34:15 -07:00
|
|
|
\\ -h Print this help message and exit.
|
2021-07-24 02:31:17 -07:00
|
|
|
\\ -version Print the version number and exit.
|
2021-05-01 03:49:49 -07:00
|
|
|
\\ -view-padding Set the padding around views in pixels. (Default 6)
|
|
|
|
\\ -outer-padding Set the padding around the edge of the layout area in
|
|
|
|
\\ pixels. (Default 6)
|
|
|
|
\\ -main-location Set the initial location of the main area in the
|
|
|
|
\\ layout. (Default left)
|
|
|
|
\\ -main-count Set the initial number of views in the main area of the
|
|
|
|
\\ layout. (Default 1)
|
2021-07-15 04:22:37 -07:00
|
|
|
\\ -main-ratio Set the initial ratio of main area to total layout
|
2021-05-01 03:49:49 -07:00
|
|
|
\\ area. (Default: 0.6)
|
|
|
|
\\
|
|
|
|
;
|
|
|
|
|
2021-07-15 04:22:37 -07:00
|
|
|
const Command = enum {
|
2021-07-15 13:57:50 -07:00
|
|
|
@"main-location",
|
|
|
|
@"main-count",
|
|
|
|
@"main-ratio",
|
2021-07-15 04:22:37 -07:00
|
|
|
};
|
|
|
|
|
2021-04-14 15:28:39 -07:00
|
|
|
const Location = enum {
|
|
|
|
top,
|
|
|
|
right,
|
|
|
|
bottom,
|
|
|
|
left,
|
|
|
|
};
|
|
|
|
|
2021-04-26 14:41:30 -07:00
|
|
|
// Configured through command line options
|
|
|
|
var view_padding: u32 = 6;
|
|
|
|
var outer_padding: u32 = 6;
|
|
|
|
var default_main_location: Location = .left;
|
|
|
|
var default_main_count: u32 = 1;
|
2021-07-15 04:22:37 -07:00
|
|
|
var default_main_ratio: f64 = 0.6;
|
2021-04-14 15:28:39 -07:00
|
|
|
|
|
|
|
/// We don't free resources on exit, only when output globals are removed.
|
2020-10-02 06:53:08 -07:00
|
|
|
const gpa = std.heap.c_allocator;
|
|
|
|
|
|
|
|
const Context = struct {
|
2021-04-14 15:28:39 -07:00
|
|
|
initialized: bool = false,
|
2021-07-15 04:22:37 -07:00
|
|
|
layout_manager: ?*river.LayoutManagerV3 = null,
|
2020-10-02 06:53:08 -07:00
|
|
|
outputs: std.TailQueue(Output) = .{},
|
|
|
|
|
2021-04-14 15:28:39 -07:00
|
|
|
fn addOutput(context: *Context, registry: *wl.Registry, name: u32) !void {
|
|
|
|
const wl_output = try registry.bind(name, wl.Output, 3);
|
|
|
|
errdefer wl_output.release();
|
2020-10-02 06:53:08 -07:00
|
|
|
const node = try gpa.create(std.TailQueue(Output).Node);
|
2021-04-14 15:28:39 -07:00
|
|
|
errdefer gpa.destroy(node);
|
|
|
|
try node.data.init(context, wl_output, name);
|
|
|
|
context.outputs.append(node);
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
2021-04-14 15:28:39 -07:00
|
|
|
};
|
2020-06-16 05:48:30 -07:00
|
|
|
|
2020-10-02 06:53:08 -07:00
|
|
|
const Output = struct {
|
2021-04-14 15:28:39 -07:00
|
|
|
wl_output: *wl.Output,
|
|
|
|
name: u32,
|
2020-10-02 06:53:08 -07:00
|
|
|
|
2021-04-26 14:41:30 -07:00
|
|
|
main_location: Location,
|
|
|
|
main_count: u32,
|
2021-07-15 04:22:37 -07:00
|
|
|
main_ratio: f64,
|
2021-04-26 12:03:28 -07:00
|
|
|
|
2021-07-15 04:22:37 -07:00
|
|
|
layout: *river.LayoutV3 = undefined,
|
2020-10-02 06:53:08 -07:00
|
|
|
|
2021-04-14 15:28:39 -07:00
|
|
|
fn init(output: *Output, context: *Context, wl_output: *wl.Output, name: u32) !void {
|
2021-04-26 14:41:30 -07:00
|
|
|
output.* = .{
|
|
|
|
.wl_output = wl_output,
|
|
|
|
.name = name,
|
|
|
|
.main_location = default_main_location,
|
|
|
|
.main_count = default_main_count,
|
2021-07-15 04:22:37 -07:00
|
|
|
.main_ratio = default_main_ratio,
|
2021-04-26 14:41:30 -07:00
|
|
|
};
|
2021-04-26 12:03:04 -07:00
|
|
|
if (context.initialized) try output.getLayout(context);
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
|
|
|
|
2021-04-26 12:03:04 -07:00
|
|
|
fn getLayout(output: *Output, context: *Context) !void {
|
2021-04-14 15:28:39 -07:00
|
|
|
assert(context.initialized);
|
|
|
|
output.layout = try context.layout_manager.?.getLayout(output.wl_output, "rivertile");
|
2021-04-27 03:24:30 -07:00
|
|
|
output.layout.setListener(*Output, layoutListener, output);
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
|
|
|
|
2021-04-14 15:28:39 -07:00
|
|
|
fn deinit(output: *Output) void {
|
|
|
|
output.wl_output.release();
|
|
|
|
output.layout.destroy();
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
|
|
|
|
2021-07-15 04:22:37 -07:00
|
|
|
fn layoutListener(layout: *river.LayoutV3, event: river.LayoutV3.Event, output: *Output) void {
|
2020-10-02 06:53:08 -07:00
|
|
|
switch (event) {
|
2021-04-14 15:28:39 -07:00
|
|
|
.namespace_in_use => fatal("namespace 'rivertile' already in use.", .{}),
|
2020-10-02 06:53:08 -07:00
|
|
|
|
2021-07-15 04:22:37 -07:00
|
|
|
.user_command => |ev| {
|
2021-10-11 03:44:46 -07:00
|
|
|
var it = mem.tokenize(u8, mem.span(ev.command), " ");
|
2021-07-15 04:22:37 -07:00
|
|
|
const raw_cmd = it.next() orelse {
|
|
|
|
std.log.err("not enough arguments", .{});
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
const raw_arg = it.next() orelse {
|
|
|
|
std.log.err("not enough arguments", .{});
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
if (it.next() != null) {
|
|
|
|
std.log.err("too many arguments", .{});
|
|
|
|
return;
|
2021-04-26 12:03:28 -07:00
|
|
|
}
|
2021-07-15 04:22:37 -07:00
|
|
|
const cmd = std.meta.stringToEnum(Command, raw_cmd) orelse {
|
|
|
|
std.log.err("unknown command: {s}", .{raw_cmd});
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
switch (cmd) {
|
2021-07-15 13:57:50 -07:00
|
|
|
.@"main-location" => {
|
2021-07-15 04:22:37 -07:00
|
|
|
output.main_location = std.meta.stringToEnum(Location, raw_arg) orelse {
|
|
|
|
std.log.err("unknown location: {s}", .{raw_arg});
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
},
|
2021-07-15 13:57:50 -07:00
|
|
|
.@"main-count" => {
|
2022-02-07 13:07:27 -08:00
|
|
|
const arg = fmt.parseInt(i32, raw_arg, 10) catch |err| {
|
2021-07-15 04:22:37 -07:00
|
|
|
std.log.err("failed to parse argument: {}", .{err});
|
|
|
|
return;
|
|
|
|
};
|
2021-07-15 13:57:50 -07:00
|
|
|
switch (raw_arg[0]) {
|
2022-01-13 04:08:42 -08:00
|
|
|
'+' => output.main_count +|= @intCast(u32, arg),
|
2021-07-15 13:57:50 -07:00
|
|
|
'-' => {
|
|
|
|
const result = @as(i33, output.main_count) + arg;
|
|
|
|
if (result >= 0) output.main_count = @intCast(u32, result);
|
|
|
|
},
|
|
|
|
else => output.main_count = @intCast(u32, arg),
|
|
|
|
}
|
2021-07-15 04:22:37 -07:00
|
|
|
},
|
2021-07-15 13:57:50 -07:00
|
|
|
.@"main-ratio" => {
|
2022-02-07 13:07:27 -08:00
|
|
|
const arg = fmt.parseFloat(f64, raw_arg) catch |err| {
|
2021-07-15 04:22:37 -07:00
|
|
|
std.log.err("failed to parse argument: {}", .{err});
|
|
|
|
return;
|
|
|
|
};
|
2021-07-15 13:57:50 -07:00
|
|
|
switch (raw_arg[0]) {
|
|
|
|
'+', '-' => {
|
|
|
|
output.main_ratio = math.clamp(output.main_ratio + arg, 0.1, 0.9);
|
|
|
|
},
|
|
|
|
else => output.main_ratio = math.clamp(arg, 0.1, 0.9),
|
|
|
|
}
|
2021-07-15 04:22:37 -07:00
|
|
|
},
|
2021-04-26 12:03:28 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-04-14 15:28:39 -07:00
|
|
|
.layout_demand => |ev| {
|
2021-05-15 08:24:23 -07:00
|
|
|
const main_count = math.clamp(output.main_count, 1, ev.view_count);
|
|
|
|
const secondary_count = if (ev.view_count > main_count)
|
|
|
|
ev.view_count - main_count
|
2020-10-02 06:53:08 -07:00
|
|
|
else
|
|
|
|
0;
|
|
|
|
|
2021-04-26 12:03:28 -07:00
|
|
|
const usable_width = switch (output.main_location) {
|
2021-04-26 14:41:30 -07:00
|
|
|
.left, .right => ev.usable_width - 2 * outer_padding,
|
|
|
|
.top, .bottom => ev.usable_height - 2 * outer_padding,
|
2021-04-14 15:28:39 -07:00
|
|
|
};
|
2021-04-26 12:03:28 -07:00
|
|
|
const usable_height = switch (output.main_location) {
|
2021-04-26 14:41:30 -07:00
|
|
|
.left, .right => ev.usable_height - 2 * outer_padding,
|
|
|
|
.top, .bottom => ev.usable_width - 2 * outer_padding,
|
2021-04-14 15:28:39 -07:00
|
|
|
};
|
2020-10-02 06:53:08 -07:00
|
|
|
|
|
|
|
// to make things pixel-perfect, we make the first main and first secondary
|
|
|
|
// view slightly larger if the height is not evenly divisible
|
|
|
|
var main_width: u32 = undefined;
|
|
|
|
var main_height: u32 = undefined;
|
|
|
|
var main_height_rem: u32 = undefined;
|
|
|
|
|
|
|
|
var secondary_width: u32 = undefined;
|
|
|
|
var secondary_height: u32 = undefined;
|
|
|
|
var secondary_height_rem: u32 = undefined;
|
|
|
|
|
2021-05-15 08:24:23 -07:00
|
|
|
if (main_count > 0 and secondary_count > 0) {
|
2021-07-15 04:22:37 -07:00
|
|
|
main_width = @floatToInt(u32, output.main_ratio * @intToFloat(f64, usable_width));
|
2021-05-15 08:24:23 -07:00
|
|
|
main_height = usable_height / main_count;
|
|
|
|
main_height_rem = usable_height % main_count;
|
2020-10-02 06:53:08 -07:00
|
|
|
|
|
|
|
secondary_width = usable_width - main_width;
|
|
|
|
secondary_height = usable_height / secondary_count;
|
|
|
|
secondary_height_rem = usable_height % secondary_count;
|
2021-05-15 08:24:23 -07:00
|
|
|
} else if (main_count > 0) {
|
2020-10-02 06:53:08 -07:00
|
|
|
main_width = usable_width;
|
2021-05-15 08:24:23 -07:00
|
|
|
main_height = usable_height / main_count;
|
|
|
|
main_height_rem = usable_height % main_count;
|
2020-10-02 06:53:08 -07:00
|
|
|
} else if (secondary_width > 0) {
|
|
|
|
main_width = 0;
|
|
|
|
secondary_width = usable_width;
|
|
|
|
secondary_height = usable_height / secondary_count;
|
|
|
|
secondary_height_rem = usable_height % secondary_count;
|
|
|
|
}
|
2020-06-16 05:48:30 -07:00
|
|
|
|
2020-10-02 06:53:08 -07:00
|
|
|
var i: u32 = 0;
|
2021-04-14 15:28:39 -07:00
|
|
|
while (i < ev.view_count) : (i += 1) {
|
2020-10-02 06:53:08 -07:00
|
|
|
var x: i32 = undefined;
|
|
|
|
var y: i32 = undefined;
|
|
|
|
var width: u32 = undefined;
|
|
|
|
var height: u32 = undefined;
|
|
|
|
|
2021-05-15 08:24:23 -07:00
|
|
|
if (i < main_count) {
|
2020-10-02 06:53:08 -07:00
|
|
|
x = 0;
|
|
|
|
y = @intCast(i32, (i * main_height) + if (i > 0) main_height_rem else 0);
|
|
|
|
width = main_width;
|
|
|
|
height = main_height + if (i == 0) main_height_rem else 0;
|
|
|
|
} else {
|
|
|
|
x = @intCast(i32, main_width);
|
2021-05-15 08:24:23 -07:00
|
|
|
y = @intCast(i32, (i - main_count) * secondary_height +
|
|
|
|
if (i > main_count) secondary_height_rem else 0);
|
2020-10-02 06:53:08 -07:00
|
|
|
width = secondary_width;
|
2021-05-15 08:24:23 -07:00
|
|
|
height = secondary_height + if (i == main_count) secondary_height_rem else 0;
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
|
|
|
|
2021-04-26 14:41:30 -07:00
|
|
|
x += @intCast(i32, view_padding);
|
|
|
|
y += @intCast(i32, view_padding);
|
|
|
|
width -= 2 * view_padding;
|
|
|
|
height -= 2 * view_padding;
|
2020-10-02 06:53:08 -07:00
|
|
|
|
2021-04-26 12:03:28 -07:00
|
|
|
switch (output.main_location) {
|
2020-10-02 06:53:08 -07:00
|
|
|
.left => layout.pushViewDimensions(
|
2021-04-26 14:41:30 -07:00
|
|
|
x + @intCast(i32, outer_padding),
|
|
|
|
y + @intCast(i32, outer_padding),
|
2020-10-02 06:53:08 -07:00
|
|
|
width,
|
|
|
|
height,
|
2021-07-15 04:22:37 -07:00
|
|
|
ev.serial,
|
2020-10-02 06:53:08 -07:00
|
|
|
),
|
|
|
|
.right => layout.pushViewDimensions(
|
2021-04-26 14:41:30 -07:00
|
|
|
@intCast(i32, usable_width - width) - x + @intCast(i32, outer_padding),
|
|
|
|
y + @intCast(i32, outer_padding),
|
2020-10-02 06:53:08 -07:00
|
|
|
width,
|
|
|
|
height,
|
2021-07-15 04:22:37 -07:00
|
|
|
ev.serial,
|
2020-10-02 06:53:08 -07:00
|
|
|
),
|
|
|
|
.top => layout.pushViewDimensions(
|
2021-04-26 14:41:30 -07:00
|
|
|
y + @intCast(i32, outer_padding),
|
|
|
|
x + @intCast(i32, outer_padding),
|
2020-10-02 06:53:08 -07:00
|
|
|
height,
|
|
|
|
width,
|
2021-07-15 04:22:37 -07:00
|
|
|
ev.serial,
|
2020-10-02 06:53:08 -07:00
|
|
|
),
|
|
|
|
.bottom => layout.pushViewDimensions(
|
2021-04-26 14:41:30 -07:00
|
|
|
y + @intCast(i32, outer_padding),
|
|
|
|
@intCast(i32, usable_width - width) - x + @intCast(i32, outer_padding),
|
2020-10-02 06:53:08 -07:00
|
|
|
height,
|
|
|
|
width,
|
2021-07-15 04:22:37 -07:00
|
|
|
ev.serial,
|
2020-10-02 06:53:08 -07:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 04:22:37 -07:00
|
|
|
switch (output.main_location) {
|
|
|
|
.left => layout.commit("rivertile - left", ev.serial),
|
|
|
|
.right => layout.commit("rivertile - right", ev.serial),
|
|
|
|
.top => layout.commit("rivertile - top", ev.serial),
|
|
|
|
.bottom => layout.commit("rivertile - bottom", ev.serial),
|
|
|
|
}
|
2020-10-02 06:53:08 -07:00
|
|
|
},
|
2020-06-16 05:48:30 -07:00
|
|
|
}
|
|
|
|
}
|
2020-10-02 06:53:08 -07:00
|
|
|
};
|
2020-06-16 05:48:30 -07:00
|
|
|
|
2020-10-02 06:53:08 -07:00
|
|
|
pub fn main() !void {
|
2021-04-26 14:41:30 -07:00
|
|
|
// https://github.com/ziglang/zig/issues/7807
|
2021-07-24 09:29:48 -07:00
|
|
|
const argv: [][*:0]const u8 = os.argv;
|
|
|
|
const result = flags.parse(argv[1..], &[_]flags.Flag{
|
2021-10-31 16:34:15 -07:00
|
|
|
.{ .name = "-h", .kind = .boolean },
|
2021-07-24 02:31:17 -07:00
|
|
|
.{ .name = "-version", .kind = .boolean },
|
2021-04-26 14:41:30 -07:00
|
|
|
.{ .name = "-view-padding", .kind = .arg },
|
|
|
|
.{ .name = "-outer-padding", .kind = .arg },
|
|
|
|
.{ .name = "-main-location", .kind = .arg },
|
|
|
|
.{ .name = "-main-count", .kind = .arg },
|
2021-07-15 04:22:37 -07:00
|
|
|
.{ .name = "-main-ratio", .kind = .arg },
|
2021-07-24 09:29:48 -07:00
|
|
|
}) catch {
|
|
|
|
try std.io.getStdErr().writeAll(usage);
|
|
|
|
os.exit(1);
|
|
|
|
};
|
2021-10-31 16:34:15 -07:00
|
|
|
if (result.boolFlag("-h")) {
|
2021-05-01 03:54:57 -07:00
|
|
|
try std.io.getStdOut().writeAll(usage);
|
2021-07-24 09:29:48 -07:00
|
|
|
os.exit(0);
|
2021-05-01 03:49:49 -07:00
|
|
|
}
|
2021-07-24 10:31:04 -07:00
|
|
|
if (result.args.len != 0) fatalPrintUsage("unknown option '{s}'", .{result.args[0]});
|
|
|
|
|
2021-07-24 09:29:48 -07:00
|
|
|
if (result.boolFlag("-version")) {
|
2021-11-02 15:54:44 -07:00
|
|
|
try std.io.getStdOut().writeAll(@import("build_options").version ++ "\n");
|
2021-07-24 09:29:48 -07:00
|
|
|
os.exit(0);
|
2021-07-24 02:31:17 -07:00
|
|
|
}
|
2021-07-24 09:29:48 -07:00
|
|
|
if (result.argFlag("-view-padding")) |raw| {
|
2022-02-07 13:07:27 -08:00
|
|
|
view_padding = fmt.parseUnsigned(u32, raw, 10) catch
|
2021-07-24 09:29:48 -07:00
|
|
|
fatalPrintUsage("invalid value '{s}' provided to -view-padding", .{raw});
|
2021-04-26 14:41:30 -07:00
|
|
|
}
|
2021-07-24 09:29:48 -07:00
|
|
|
if (result.argFlag("-outer-padding")) |raw| {
|
2022-02-07 13:07:27 -08:00
|
|
|
outer_padding = fmt.parseUnsigned(u32, raw, 10) catch
|
2021-07-24 09:29:48 -07:00
|
|
|
fatalPrintUsage("invalid value '{s}' provided to -outer-padding", .{raw});
|
2021-04-26 14:41:30 -07:00
|
|
|
}
|
2021-07-24 09:29:48 -07:00
|
|
|
if (result.argFlag("-main-location")) |raw| {
|
2021-12-15 08:09:45 -08:00
|
|
|
default_main_location = std.meta.stringToEnum(Location, raw) orelse
|
2021-07-24 09:29:48 -07:00
|
|
|
fatalPrintUsage("invalid value '{s}' provided to -main-location", .{raw});
|
2021-04-26 14:41:30 -07:00
|
|
|
}
|
2021-07-24 09:29:48 -07:00
|
|
|
if (result.argFlag("-main-count")) |raw| {
|
2022-02-07 13:07:27 -08:00
|
|
|
default_main_count = fmt.parseUnsigned(u32, raw, 10) catch
|
2021-07-24 09:29:48 -07:00
|
|
|
fatalPrintUsage("invalid value '{s}' provided to -main-count", .{raw});
|
2021-04-26 14:41:30 -07:00
|
|
|
}
|
2021-07-24 09:29:48 -07:00
|
|
|
if (result.argFlag("-main-ratio")) |raw| {
|
2022-02-07 13:07:27 -08:00
|
|
|
default_main_ratio = fmt.parseFloat(f64, raw) catch
|
2021-07-24 09:29:48 -07:00
|
|
|
fatalPrintUsage("invalid value '{s}' provided to -main-ratio", .{raw});
|
2021-04-26 14:41:30 -07:00
|
|
|
}
|
|
|
|
|
2020-10-02 06:53:08 -07:00
|
|
|
const display = wl.Display.connect(null) catch {
|
2021-10-11 03:44:46 -07:00
|
|
|
std.debug.print("Unable to connect to Wayland server.\n", .{});
|
2021-07-24 09:29:48 -07:00
|
|
|
os.exit(1);
|
2020-10-02 06:53:08 -07:00
|
|
|
};
|
|
|
|
defer display.disconnect();
|
|
|
|
|
|
|
|
var context: Context = .{};
|
2020-06-16 08:06:24 -07:00
|
|
|
|
2020-10-02 06:53:08 -07:00
|
|
|
const registry = try display.getRegistry();
|
2021-04-27 03:24:30 -07:00
|
|
|
registry.setListener(*Context, registryListener, &context);
|
2020-10-02 06:53:08 -07:00
|
|
|
_ = try display.roundtrip();
|
2020-06-16 08:06:24 -07:00
|
|
|
|
2020-10-02 06:53:08 -07:00
|
|
|
if (context.layout_manager == null) {
|
2021-07-15 13:57:50 -07:00
|
|
|
fatal("wayland compositor does not support river-layout-v3.\n", .{});
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
2021-04-14 15:28:39 -07:00
|
|
|
|
|
|
|
context.initialized = true;
|
2020-10-02 06:53:08 -07:00
|
|
|
|
2021-04-14 15:28:39 -07:00
|
|
|
var it = context.outputs.first;
|
|
|
|
while (it) |node| : (it = node.next) {
|
|
|
|
const output = &node.data;
|
2021-04-26 12:03:04 -07:00
|
|
|
try output.getLayout(&context);
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
2021-04-14 15:28:39 -07:00
|
|
|
|
|
|
|
while (true) _ = try display.dispatch();
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: *Context) void {
|
|
|
|
switch (event) {
|
|
|
|
.global => |global| {
|
2021-07-15 04:22:37 -07:00
|
|
|
if (std.cstr.cmp(global.interface, river.LayoutManagerV3.getInterface().name) == 0) {
|
|
|
|
context.layout_manager = registry.bind(global.name, river.LayoutManagerV3, 1) catch return;
|
2020-10-02 06:53:08 -07:00
|
|
|
} else if (std.cstr.cmp(global.interface, wl.Output.getInterface().name) == 0) {
|
2021-04-14 15:28:39 -07:00
|
|
|
context.addOutput(registry, global.name) catch |err| fatal("failed to bind output: {}", .{err});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.global_remove => |ev| {
|
|
|
|
var it = context.outputs.first;
|
|
|
|
while (it) |node| : (it = node.next) {
|
|
|
|
const output = &node.data;
|
|
|
|
if (output.name == ev.name) {
|
|
|
|
context.outputs.remove(node);
|
|
|
|
output.deinit();
|
|
|
|
gpa.destroy(node);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2020-06-16 08:06:24 -07:00
|
|
|
}
|
2021-04-14 15:28:39 -07:00
|
|
|
|
2021-07-24 09:29:48 -07:00
|
|
|
fn fatal(comptime format: []const u8, args: anytype) noreturn {
|
|
|
|
std.log.err(format, args);
|
|
|
|
os.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fatalPrintUsage(comptime format: []const u8, args: anytype) noreturn {
|
|
|
|
std.log.err(format, args);
|
|
|
|
std.io.getStdErr().writeAll(usage) catch {};
|
|
|
|
os.exit(1);
|
2021-04-14 15:28:39 -07:00
|
|
|
}
|