2020-06-04 07:56:58 -07:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
2020-11-11 11:30:21 -08:00
|
|
|
// 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
|
2022-01-31 10:33:22 -08:00
|
|
|
// the Free Software Foundation, version 3.
|
2020-06-04 07:56:58 -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/>.
|
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
const OutputStatus = @This();
|
2020-06-04 07:56:58 -07:00
|
|
|
|
|
|
|
const std = @import("std");
|
2023-02-28 08:45:08 -08:00
|
|
|
const assert = std.debug.assert;
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
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");
|
|
|
|
|
2021-02-05 00:46:18 -08:00
|
|
|
const log = std.log.scoped(.river_status);
|
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
resources: wl.list.Head(zriver.OutputStatusV1, null),
|
|
|
|
view_tags: std.ArrayListUnmanaged(u32) = .{},
|
|
|
|
focused_tags: u32 = 0,
|
|
|
|
urgent_tags: u32 = 0,
|
2021-08-12 07:16:23 -07:00
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
pub fn init(status: *OutputStatus) void {
|
|
|
|
status.* = .{
|
|
|
|
.resources = undefined,
|
|
|
|
};
|
|
|
|
status.resources.init();
|
|
|
|
}
|
2022-08-14 08:16:38 -07:00
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
pub fn add(status: *OutputStatus, resource: *zriver.OutputStatusV1, output: *Output) void {
|
|
|
|
resource.setHandler(?*anyopaque, handleRequest, handleDestroy, null);
|
|
|
|
|
|
|
|
var wl_array: wl.Array = .{
|
|
|
|
.size = status.view_tags.items.len * @sizeOf(u32),
|
|
|
|
.alloc = status.view_tags.items.len * @sizeOf(u32),
|
|
|
|
.data = status.view_tags.items.ptr,
|
|
|
|
};
|
|
|
|
resource.sendViewTags(&wl_array);
|
|
|
|
resource.sendFocusedTags(status.focused_tags);
|
|
|
|
if (resource.getVersion() >= 2) resource.sendUrgentTags(status.urgent_tags);
|
|
|
|
if (resource.getVersion() >= 4) {
|
|
|
|
if (output.layout_name) |name| resource.sendLayoutName(name);
|
2022-08-14 08:16:38 -07:00
|
|
|
}
|
2023-02-28 08:45:08 -08:00
|
|
|
|
|
|
|
status.resources.append(resource);
|
2020-06-04 07:56:58 -07:00
|
|
|
}
|
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
pub fn deinit(status: *OutputStatus) void {
|
|
|
|
{
|
|
|
|
var it = status.resources.safeIterator(.forward);
|
|
|
|
while (it.next()) |resource| {
|
|
|
|
resource.setHandler(?*anyopaque, handleRequest, null, null);
|
|
|
|
resource.getLink().remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
status.view_tags.deinit(util.gpa);
|
2021-08-12 13:38:08 -07:00
|
|
|
}
|
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
fn handleRequest(resource: *zriver.OutputStatusV1, request: zriver.OutputStatusV1.Request, _: ?*anyopaque) void {
|
2020-11-03 15:23:21 -08:00
|
|
|
switch (request) {
|
2023-02-28 08:45:08 -08:00
|
|
|
.destroy => resource.destroy(),
|
2020-11-03 15:23:21 -08:00
|
|
|
}
|
2020-06-04 07:56:58 -07:00
|
|
|
}
|
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
fn handleDestroy(resource: *zriver.OutputStatusV1, _: ?*anyopaque) void {
|
|
|
|
resource.getLink().remove();
|
2020-06-04 07:56:58 -07:00
|
|
|
}
|
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
pub fn handleTransactionCommit(status: *OutputStatus, output: *Output) void {
|
|
|
|
status.sendViewTags(output);
|
|
|
|
status.sendFocusedTags(output);
|
|
|
|
status.sendUrgentTags(output);
|
|
|
|
}
|
2020-06-16 13:46:29 -07:00
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
fn sendViewTags(status: *OutputStatus, output: *Output) void {
|
|
|
|
var dirty: bool = false;
|
2023-02-24 10:28:37 -08:00
|
|
|
{
|
2023-02-28 08:45:08 -08:00
|
|
|
var it = output.inflight.wm_stack.iterator(.forward);
|
|
|
|
var i: usize = 0;
|
|
|
|
while (it.next()) |view| : (i += 1) {
|
|
|
|
assert(view.inflight.tags == view.current.tags);
|
|
|
|
if (status.view_tags.items.len <= i) {
|
|
|
|
dirty = true;
|
|
|
|
_ = status.view_tags.addOne(util.gpa) catch {
|
|
|
|
log.err("out of memory", .{});
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
} else if (view.inflight.tags != status.view_tags.items[i]) {
|
|
|
|
dirty = true;
|
|
|
|
}
|
|
|
|
status.view_tags.items[i] = view.inflight.tags;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != status.view_tags.items.len) {
|
|
|
|
assert(i < status.view_tags.items.len);
|
|
|
|
status.view_tags.items.len = i;
|
|
|
|
dirty = true;
|
2023-02-24 10:28:37 -08:00
|
|
|
}
|
2020-08-21 06:08:28 -07:00
|
|
|
}
|
2020-06-16 13:46:29 -07:00
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
if (dirty) {
|
|
|
|
var wl_array: wl.Array = .{
|
|
|
|
.size = status.view_tags.items.len * @sizeOf(u32),
|
|
|
|
.alloc = status.view_tags.items.len * @sizeOf(u32),
|
|
|
|
.data = status.view_tags.items.ptr,
|
|
|
|
};
|
|
|
|
var it = status.resources.iterator(.forward);
|
|
|
|
while (it.next()) |resource| resource.sendViewTags(&wl_array);
|
|
|
|
}
|
2020-06-04 07:56:58 -07:00
|
|
|
}
|
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
fn sendFocusedTags(status: *OutputStatus, output: *Output) void {
|
|
|
|
assert(output.inflight.tags == output.current.tags);
|
|
|
|
if (status.focused_tags != output.inflight.tags) {
|
|
|
|
status.focused_tags = output.inflight.tags;
|
|
|
|
|
|
|
|
var it = status.resources.iterator(.forward);
|
|
|
|
while (it.next()) |resource| resource.sendFocusedTags(status.focused_tags);
|
|
|
|
}
|
2020-06-04 07:56:58 -07:00
|
|
|
}
|
2021-08-12 07:16:23 -07:00
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
fn sendUrgentTags(status: *OutputStatus, output: *Output) void {
|
|
|
|
var urgent_tags: u32 = 0;
|
|
|
|
{
|
|
|
|
var it = output.inflight.wm_stack.iterator(.forward);
|
|
|
|
while (it.next()) |view| {
|
|
|
|
if (view.current.urgent) urgent_tags |= view.current.tags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.urgent_tags != urgent_tags) {
|
|
|
|
status.urgent_tags = urgent_tags;
|
|
|
|
|
|
|
|
var it = status.resources.iterator(.forward);
|
|
|
|
while (it.next()) |resource| {
|
|
|
|
if (resource.getVersion() >= 2) resource.sendUrgentTags(urgent_tags);
|
|
|
|
}
|
2021-08-12 07:16:23 -07:00
|
|
|
}
|
|
|
|
}
|
2022-08-14 08:16:38 -07:00
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
pub fn sendLayoutName(status: *OutputStatus, output: *Output) void {
|
|
|
|
assert(output.layout_name != null);
|
|
|
|
|
|
|
|
var it = status.resources.iterator(.forward);
|
|
|
|
while (it.next()) |resource| {
|
|
|
|
if (resource.getVersion() >= 4) resource.sendLayoutName(output.layout_name.?);
|
2022-08-14 08:16:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 08:45:08 -08:00
|
|
|
pub fn sendLayoutNameClear(status: *OutputStatus, output: *Output) void {
|
|
|
|
assert(output.layout_name == null);
|
|
|
|
|
|
|
|
var it = status.resources.iterator(.forward);
|
|
|
|
while (it.next()) |resource| {
|
|
|
|
if (resource.getVersion() >= 4) resource.sendLayoutNameClear();
|
2022-08-14 08:16:38 -07:00
|
|
|
}
|
|
|
|
}
|