river-options: remove protocol

This protocol involves far too much accidental complexity. The original
motivating use-case was to provide a convenient way to send arbitrary
data to layout clients at runtime in order to avoid layout clients
needing to implement their own IPC and do this over a side-channel.
Instead of implementing a quite complex but still rigid options protocol
and storing this state in the compositor, instead we will simply add
events to the layout protocol to support this use case.

Consider the status quo event sequence:

1. send get_option_handle request (riverctl)
2. roundtrip waiting for first event (riverctl)
3. send set_foo_value request (riverctl)
4. receive set_foo_value request (river)
5. send foo_value event to all current handles (river)
6. receive foo_value event (rivertile)
7. send parameters_changed request (rivertile)
8. receive parameters_changed request (river)
9. send layout_demand (river)

And compare with the event sequence after the proposed change:

1. send set_foo_value request (riverctl)
2. receive set_foo_value request (river)
3. send set_foo_value event (river)
4. send layout_demand (river)

This requires *much* less back and forth between the server and clients
and is clearly much simpler.
This commit is contained in:
Isaac Freund
2021-04-26 21:03:04 +02:00
parent a6f908d7eb
commit 871fc7c8de
17 changed files with 65 additions and 1449 deletions

View File

@ -22,26 +22,13 @@ const assert = std.debug.assert;
const wayland = @import("wayland");
const wl = wayland.client.wl;
const river = wayland.client.river;
const zriver = wayland.client.zriver;
const zxdg = wayland.client.zxdg;
const gpa = std.heap.c_allocator;
const options = @import("options.zig");
pub const Output = struct {
wl_output: *wl.Output,
name: []const u8,
};
pub const Globals = struct {
control: ?*zriver.ControlV1 = null,
options_manager: ?*river.OptionsManagerV2 = null,
status_manager: ?*zriver.StatusManagerV1 = null,
seat: ?*wl.Seat = null,
output_manager: ?*zxdg.OutputManagerV1 = null,
outputs: std.ArrayList(Output) = std.ArrayList(Output).init(gpa),
};
pub fn main() !void {
@ -54,20 +41,9 @@ pub fn main() !void {
\\The Wayland server does not support river-control-unstable-v1.
\\Do your versions of river and riverctl match?
, .{}),
error.RiverStatusManagerNotAdvertised => printErrorExit(
\\The Wayland server does not support river-status-unstable-v1.
\\Do your versions of river and riverctl match?
, .{}),
error.RiverOptionsManagerNotAdvertised => printErrorExit(
\\The Wayland server does not support river-options-unstable-v1.
\\Do your versions of river and riverctl match?
, .{}),
error.SeatNotAdverstised => printErrorExit(
\\The Wayland server did not advertise any seat.
, .{}),
error.XdgOutputNotAdvertised => printErrorExit(
\\The Wayland server does not support xdg-output-unstable-v1.
, .{}),
else => return err,
}
};
@ -82,32 +58,20 @@ fn _main() !void {
registry.setListener(*Globals, registryListener, &globals) catch unreachable;
_ = try display.roundtrip();
if (os.argv.len > 2 and mem.eql(u8, "declare-option", mem.span(os.argv[1]))) {
try options.declareOption(display, &globals);
} else if (os.argv.len > 2 and mem.eql(u8, "get-option", mem.span(os.argv[1]))) {
try options.getOption(display, &globals);
} else if (os.argv.len > 2 and mem.eql(u8, "set-option", mem.span(os.argv[1]))) {
try options.setOption(display, &globals);
} else if (os.argv.len > 2 and mem.eql(u8, "unset-option", mem.span(os.argv[1]))) {
try options.unsetOption(display, &globals);
} else if (os.argv.len > 2 and mem.eql(u8, "mod-option", mem.span(os.argv[1]))) {
try options.modOption(display, &globals);
} else {
const control = globals.control orelse return error.RiverControlNotAdvertised;
const seat = globals.seat orelse return error.SeatNotAdverstised;
const control = globals.control orelse return error.RiverControlNotAdvertised;
const seat = globals.seat orelse return error.SeatNotAdverstised;
// Skip our name, send all other args
// This next line is needed cause of https://github.com/ziglang/zig/issues/2622
const args = os.argv;
for (args[1..]) |arg| control.addArgument(arg);
// Skip our name, send all other args
// This next line is needed cause of https://github.com/ziglang/zig/issues/2622
const args = os.argv;
for (args[1..]) |arg| control.addArgument(arg);
const callback = try control.runCommand(seat);
const callback = try control.runCommand(seat);
callback.setListener(?*c_void, callbackListener, null) catch unreachable;
callback.setListener(?*c_void, callbackListener, null) catch unreachable;
// Loop until our callback is called and we exit.
while (true) _ = try display.dispatch();
}
// Loop until our callback is called and we exit.
while (true) _ = try display.dispatch();
}
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, globals: *Globals) void {
@ -118,15 +82,6 @@ fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, globals: *
globals.seat = registry.bind(global.name, wl.Seat, 1) catch @panic("out of memory");
} else if (std.cstr.cmp(global.interface, zriver.ControlV1.getInterface().name) == 0) {
globals.control = registry.bind(global.name, zriver.ControlV1, 1) catch @panic("out of memory");
} else if (std.cstr.cmp(global.interface, river.OptionsManagerV2.getInterface().name) == 0) {
globals.options_manager = registry.bind(global.name, river.OptionsManagerV2, 1) catch @panic("out of memory");
} else if (std.cstr.cmp(global.interface, zriver.StatusManagerV1.getInterface().name) == 0) {
globals.status_manager = registry.bind(global.name, zriver.StatusManagerV1, 1) catch @panic("out of memory");
} else if (std.cstr.cmp(global.interface, zxdg.OutputManagerV1.getInterface().name) == 0 and global.version >= 2) {
globals.output_manager = registry.bind(global.name, zxdg.OutputManagerV1, 2) catch @panic("out of memory");
} else if (std.cstr.cmp(global.interface, wl.Output.getInterface().name) == 0) {
const output = registry.bind(global.name, wl.Output, 1) catch @panic("out of memory");
globals.outputs.append(.{ .wl_output = output, .name = undefined }) catch @panic("out of memory");
}
},
.global_remove => {},
@ -142,10 +97,7 @@ fn callbackListener(callback: *zriver.CommandCallbackV1, event: zriver.CommandCa
}
os.exit(0);
},
.failure => |failure| {
std.debug.print("Error: {}\n", .{failure.failure_message});
os.exit(1);
},
.failure => |failure| printErrorExit("Error: {}\n", .{failure.failure_message}),
}
}