river/river/OutputStatus.zig

80 lines
2.6 KiB
Zig
Raw Normal View History

2020-06-04 07:56:58 -07:00
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 The River Developers
2020-06-04 07:56:58 -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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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/>.
const Self = @This();
const std = @import("std");
const wayland = @import("wayland");
const wl = wayland.server.wl;
const zriver = wayland.server.zriver;
2020-06-04 07:56:58 -07:00
2020-06-16 11:54:05 -07:00
const util = @import("util.zig");
2020-06-04 07:56:58 -07:00
const Output = @import("Output.zig");
const View = @import("View.zig");
const ViewStack = @import("view_stack.zig").ViewStack;
2021-02-05 00:46:18 -08:00
const log = std.log.scoped(.river_status);
2020-06-04 07:56:58 -07:00
output: *Output,
output_status: *zriver.OutputStatusV1,
2020-06-04 07:56:58 -07:00
pub fn init(self: *Self, output: *Output, output_status: *zriver.OutputStatusV1) void {
self.* = .{ .output = output, .output_status = output_status };
2020-06-04 07:56:58 -07:00
output_status.setHandler(*Self, handleRequest, handleDestroy, self);
2020-06-04 07:56:58 -07:00
// Send view/focused tags once on bind.
self.sendViewTags();
self.sendFocusedTags();
}
fn handleRequest(output_status: *zriver.OutputStatusV1, request: zriver.OutputStatusV1.Request, self: *Self) void {
switch (request) {
.destroy => output_status.destroy(),
}
2020-06-04 07:56:58 -07:00
}
fn handleDestroy(output_status: *zriver.OutputStatusV1, self: *Self) void {
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
self.output.status_trackers.remove(node);
2020-06-04 07:56:58 -07:00
}
/// Send the current tags of each view on the output to the client.
pub fn sendViewTags(self: Self) void {
var view_tags = std.ArrayList(u32).init(util.gpa);
defer view_tags.deinit();
var it = self.output.views.first;
while (it) |node| : (it = node.next) {
if (node.view.destroying) continue;
view_tags.append(node.view.current.tags) catch {
self.output_status.postNoMemory();
2021-02-05 00:46:18 -08:00
log.crit("out of memory", .{});
return;
};
}
var wl_array = wl.Array.fromArrayList(u32, view_tags);
self.output_status.sendViewTags(&wl_array);
2020-06-04 07:56:58 -07:00
}
/// Send the currently focused tags of the output to the client.
pub fn sendFocusedTags(self: Self) void {
self.output_status.sendFocusedTags(self.output.current.tags);
2020-06-04 07:56:58 -07:00
}