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
|
|
|
|
// 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");
|
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 Seat = @import("Seat.zig");
|
|
|
|
const Output = @import("Output.zig");
|
|
|
|
const View = @import("View.zig");
|
|
|
|
|
|
|
|
seat: *Seat,
|
2020-11-03 15:23:21 -08:00
|
|
|
seat_status: *zriver.SeatStatusV1,
|
2020-06-04 07:56:58 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
pub fn init(self: *Self, seat: *Seat, seat_status: *zriver.SeatStatusV1) void {
|
|
|
|
self.* = .{ .seat = seat, .seat_status = seat_status };
|
2020-06-04 07:56:58 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
seat_status.setHandler(*Self, handleRequest, handleDestroy, self);
|
2020-06-04 07:56:58 -07:00
|
|
|
|
|
|
|
// Send focused output/view once on bind
|
|
|
|
self.sendOutput(.focused);
|
|
|
|
self.sendFocusedView();
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn handleRequest(seat_status: *zriver.SeatStatusV1, request: zriver.SeatStatusV1.Request, self: *Self) void {
|
|
|
|
switch (request) {
|
|
|
|
.destroy => seat_status.destroy(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handleDestroy(seat_status: *zriver.SeatStatusV1, self: *Self) void {
|
2020-06-04 07:56:58 -07:00
|
|
|
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
|
|
|
|
self.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
|
|
|
}
|
|
|
|
|
2020-08-21 11:29:05 -07:00
|
|
|
pub fn sendOutput(self: Self, state: enum { focused, unfocused }) void {
|
2020-11-03 15:23:21 -08:00
|
|
|
const client = self.seat_status.getClient();
|
|
|
|
var it = self.seat.focused_output.wlr_output.resources.iterator(.forward);
|
|
|
|
while (it.next()) |wl_output| {
|
|
|
|
if (wl_output.getClient() == client) switch (state) {
|
|
|
|
.focused => self.seat_status.sendFocusedOutput(wl_output),
|
|
|
|
.unfocused => self.seat_status.sendUnfocusedOutput(wl_output),
|
2020-06-04 07:56:58 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sendFocusedView(self: Self) void {
|
2020-07-15 05:15:17 -07:00
|
|
|
const title: [*:0]const u8 = if (self.seat.focused == .view) self.seat.focused.view.getTitle() else "";
|
2020-11-03 15:23:21 -08:00
|
|
|
self.seat_status.sendFocusedView(title);
|
2020-06-04 07:56:58 -07:00
|
|
|
}
|