river-layout: update to v2
This implements the changes to the river-layout protocol proposed in the previous commit removing river-options.
This commit is contained in:
@ -16,6 +16,8 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
const wl = @import("wayland").server.wl;
|
||||
const util = @import("../util.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
@ -52,3 +54,98 @@ pub fn defaultLayout(
|
||||
if (output.layout_namespace == null) output.handleLayoutNamespaceChange();
|
||||
}
|
||||
}
|
||||
|
||||
const SetType = enum {
|
||||
int,
|
||||
fixed,
|
||||
string,
|
||||
};
|
||||
|
||||
/// riverctl set-layout-value rivertile int main_count 42
|
||||
/// riverctl set-layout-value rivertile fixed main_factor 42.0
|
||||
/// riverctl set-layout-value rivertile string main_location top
|
||||
pub fn setLayoutValue(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 5) return Error.NotEnoughArguments;
|
||||
if (args.len > 5) return Error.TooManyArguments;
|
||||
|
||||
const target_namespace = args[1];
|
||||
const kind = std.meta.stringToEnum(SetType, args[2]) orelse return Error.InvalidType;
|
||||
|
||||
const output = seat.focused_output;
|
||||
|
||||
var it = output.layouts.first;
|
||||
const layout = while (it) |node| : (it = node.next) {
|
||||
const layout = &node.data;
|
||||
if (mem.eql(u8, layout.namespace, target_namespace)) break layout;
|
||||
} else return;
|
||||
|
||||
const null_terminated_name = try util.gpa.dupeZ(u8, args[3]);
|
||||
defer util.gpa.free(null_terminated_name);
|
||||
|
||||
switch (kind) {
|
||||
.int => {
|
||||
const value = try std.fmt.parseInt(i32, args[4], 10);
|
||||
layout.layout.sendSetIntValue(null_terminated_name, value);
|
||||
},
|
||||
.fixed => {
|
||||
const value = try std.fmt.parseFloat(f64, args[4]);
|
||||
layout.layout.sendSetFixedValue(null_terminated_name, wl.Fixed.fromDouble(value));
|
||||
},
|
||||
.string => {
|
||||
const null_terminated_value = try util.gpa.dupeZ(u8, args[4]);
|
||||
defer util.gpa.free(null_terminated_value);
|
||||
layout.layout.sendSetStringValue(null_terminated_name, null_terminated_value);
|
||||
},
|
||||
}
|
||||
|
||||
output.arrangeViews();
|
||||
}
|
||||
|
||||
const ModType = enum {
|
||||
int,
|
||||
fixed,
|
||||
};
|
||||
|
||||
/// riverctl mode-layout-value rivertile int main_count 42
|
||||
/// riverctl set-layout-value rivertile fixed main_factor 42.0
|
||||
pub fn modLayoutValue(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 5) return Error.NotEnoughArguments;
|
||||
if (args.len > 5) return Error.TooManyArguments;
|
||||
|
||||
const target_namespace = args[1];
|
||||
const kind = std.meta.stringToEnum(ModType, args[2]) orelse return Error.InvalidType;
|
||||
|
||||
const output = seat.focused_output;
|
||||
|
||||
var it = output.layouts.first;
|
||||
const layout = while (it) |node| : (it = node.next) {
|
||||
const layout = &node.data;
|
||||
if (mem.eql(u8, layout.namespace, target_namespace)) break layout;
|
||||
} else return;
|
||||
|
||||
const null_terminated_name = try util.gpa.dupeZ(u8, args[3]);
|
||||
defer util.gpa.free(null_terminated_name);
|
||||
|
||||
switch (kind) {
|
||||
.int => {
|
||||
const value = try std.fmt.parseInt(i32, args[4], 10);
|
||||
layout.layout.sendModIntValue(null_terminated_name, value);
|
||||
},
|
||||
.fixed => {
|
||||
const value = try std.fmt.parseFloat(f64, args[4]);
|
||||
layout.layout.sendModFixedValue(null_terminated_name, wl.Fixed.fromDouble(value));
|
||||
},
|
||||
}
|
||||
|
||||
output.arrangeViews();
|
||||
}
|
||||
|
Reference in New Issue
Block a user