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/>.
|
|
|
|
|
2024-03-14 04:55:54 -07:00
|
|
|
const SeatStatus = @This();
|
2020-06-04 07:56:58 -07:00
|
|
|
|
|
|
|
const std = @import("std");
|
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
|
|
|
|
2022-05-31 09:09:03 -07:00
|
|
|
const server = &@import("main.zig").server;
|
2020-06-16 11:54:05 -07:00
|
|
|
const util = @import("util.zig");
|
2020-06-04 07:56:58 -07:00
|
|
|
|
|
|
|
const Seat = @import("Seat.zig");
|
|
|
|
const Output = @import("Output.zig");
|
|
|
|
const View = @import("View.zig");
|
|
|
|
|
|
|
|
seat: *Seat,
|
2024-03-14 04:55:54 -07:00
|
|
|
seat_status_v1: *zriver.SeatStatusV1,
|
2020-06-04 07:56:58 -07:00
|
|
|
|
2024-03-14 04:55:54 -07:00
|
|
|
pub fn init(seat_status: *SeatStatus, seat: *Seat, seat_status_v1: *zriver.SeatStatusV1) void {
|
|
|
|
seat_status.* = .{ .seat = seat, .seat_status_v1 = seat_status_v1 };
|
2020-06-04 07:56:58 -07:00
|
|
|
|
2024-03-14 04:55:54 -07:00
|
|
|
seat_status_v1.setHandler(*SeatStatus, handleRequest, handleDestroy, seat_status);
|
2020-06-04 07:56:58 -07:00
|
|
|
|
2022-05-31 09:09:03 -07:00
|
|
|
// Send all info once on bind
|
2024-03-14 04:55:54 -07:00
|
|
|
seat_status.sendMode(server.config.modes.items[seat.mode_id].name);
|
|
|
|
if (seat.focused_output) |output| seat_status.sendOutput(output, .focused);
|
|
|
|
seat_status.sendFocusedView();
|
2020-06-04 07:56:58 -07:00
|
|
|
}
|
|
|
|
|
2024-03-14 04:55:54 -07:00
|
|
|
fn handleRequest(seat_status_v1: *zriver.SeatStatusV1, request: zriver.SeatStatusV1.Request, _: *SeatStatus) void {
|
2020-11-03 15:23:21 -08:00
|
|
|
switch (request) {
|
2024-03-14 04:55:54 -07:00
|
|
|
.destroy => seat_status_v1.destroy(),
|
2020-11-03 15:23:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-14 04:55:54 -07:00
|
|
|
fn handleDestroy(_: *zriver.SeatStatusV1, seat_status: *SeatStatus) void {
|
2024-03-07 07:19:22 -08:00
|
|
|
const node: *std.SinglyLinkedList(SeatStatus).Node = @fieldParentPtr("data", seat_status);
|
2024-03-14 04:55:54 -07:00
|
|
|
seat_status.seat.status_trackers.remove(node);
|
2020-06-19 05:48:28 -07:00
|
|
|
util.gpa.destroy(node);
|
2020-06-04 07:56:58 -07:00
|
|
|
}
|
|
|
|
|
2024-03-14 04:55:54 -07:00
|
|
|
pub fn sendOutput(seat_status: SeatStatus, output: *Output, state: enum { focused, unfocused }) void {
|
|
|
|
const client = seat_status.seat_status_v1.getClient();
|
2023-02-24 10:28:37 -08:00
|
|
|
var it = output.wlr_output.resources.iterator(.forward);
|
2020-11-03 15:23:21 -08:00
|
|
|
while (it.next()) |wl_output| {
|
|
|
|
if (wl_output.getClient() == client) switch (state) {
|
2024-03-14 04:55:54 -07:00
|
|
|
.focused => seat_status.seat_status_v1.sendFocusedOutput(wl_output),
|
|
|
|
.unfocused => seat_status.seat_status_v1.sendUnfocusedOutput(wl_output),
|
2020-06-04 07:56:58 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-14 04:55:54 -07:00
|
|
|
pub fn sendFocusedView(seat_status: SeatStatus) void {
|
|
|
|
const title: [*:0]const u8 = if (seat_status.seat.focused == .view)
|
|
|
|
seat_status.seat.focused.view.getTitle() orelse ""
|
2020-12-23 16:59:30 -08:00
|
|
|
else
|
|
|
|
"";
|
2024-03-14 04:55:54 -07:00
|
|
|
seat_status.seat_status_v1.sendFocusedView(title);
|
2020-06-04 07:56:58 -07:00
|
|
|
}
|
2022-06-02 03:21:57 -07:00
|
|
|
|
2024-03-14 04:55:54 -07:00
|
|
|
pub fn sendMode(seat_status: SeatStatus, mode: [*:0]const u8) void {
|
|
|
|
if (seat_status.seat_status_v1.getVersion() >= 3) {
|
|
|
|
seat_status.seat_status_v1.sendMode(mode);
|
2022-06-02 03:21:57 -07:00
|
|
|
}
|
|
|
|
}
|