idle-inhibit: fix naming, eliminate "self" naming convention

Also add missing copyright headers
This commit is contained in:
Isaac Freund 2024-03-14 12:51:34 +01:00
parent b0d4610999
commit b65e4f6b17
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
4 changed files with 76 additions and 37 deletions

View File

@ -1,4 +1,20 @@
const Self = @This(); // This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2022 The River Developers
//
// 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, version 3.
//
// 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 IdleInhibitManager = @This();
const std = @import("std"); const std = @import("std");
const wlr = @import("wlroots"); const wlr = @import("wlroots");
@ -11,31 +27,31 @@ const IdleInhibitor = @import("IdleInhibitor.zig");
const SceneNodeData = @import("SceneNodeData.zig"); const SceneNodeData = @import("SceneNodeData.zig");
const View = @import("View.zig"); const View = @import("View.zig");
idle_inhibit_manager: *wlr.IdleInhibitManagerV1, wlr_manager: *wlr.IdleInhibitManagerV1,
new_idle_inhibitor: wl.Listener(*wlr.IdleInhibitorV1) = new_idle_inhibitor: wl.Listener(*wlr.IdleInhibitorV1) =
wl.Listener(*wlr.IdleInhibitorV1).init(handleNewIdleInhibitor), wl.Listener(*wlr.IdleInhibitorV1).init(handleNewIdleInhibitor),
inhibitors: std.TailQueue(IdleInhibitor) = .{}, inhibitors: std.TailQueue(IdleInhibitor) = .{},
pub fn init(self: *Self) !void { pub fn init(inhibit_manager: *IdleInhibitManager) !void {
self.* = .{ inhibit_manager.* = .{
.idle_inhibit_manager = try wlr.IdleInhibitManagerV1.create(server.wl_server), .wlr_manager = try wlr.IdleInhibitManagerV1.create(server.wl_server),
}; };
self.idle_inhibit_manager.events.new_inhibitor.add(&self.new_idle_inhibitor); inhibit_manager.wlr_manager.events.new_inhibitor.add(&inhibit_manager.new_idle_inhibitor);
} }
pub fn deinit(self: *Self) void { pub fn deinit(inhibit_manager: *IdleInhibitManager) void {
while (self.inhibitors.pop()) |inhibitor| { while (inhibit_manager.inhibitors.pop()) |inhibitor| {
inhibitor.data.destroy.link.remove(); inhibitor.data.destroy.link.remove();
util.gpa.destroy(inhibitor); util.gpa.destroy(inhibitor);
} }
self.new_idle_inhibitor.link.remove(); inhibit_manager.new_idle_inhibitor.link.remove();
} }
pub fn idleInhibitCheckActive(self: *Self) void { pub fn checkActive(inhibit_manager: *IdleInhibitManager) void {
var inhibited = false; var inhibited = false;
var it = self.inhibitors.first; var it = inhibit_manager.inhibitors.first;
while (it) |node| : (it = node.next) { while (it) |node| : (it = node.next) {
const node_data = SceneNodeData.fromSurface(node.data.inhibitor.surface) orelse continue; const node_data = SceneNodeData.fromSurface(node.data.wlr_inhibitor.surface) orelse continue;
switch (node_data.data) { switch (node_data.data) {
.view => |view| { .view => |view| {
if (view.current.output != null and if (view.current.output != null and
@ -62,14 +78,14 @@ pub fn idleInhibitCheckActive(self: *Self) void {
} }
fn handleNewIdleInhibitor(listener: *wl.Listener(*wlr.IdleInhibitorV1), inhibitor: *wlr.IdleInhibitorV1) void { fn handleNewIdleInhibitor(listener: *wl.Listener(*wlr.IdleInhibitorV1), inhibitor: *wlr.IdleInhibitorV1) void {
const self = @fieldParentPtr(Self, "new_idle_inhibitor", listener); const inhibit_manager = @fieldParentPtr(IdleInhibitManager, "new_idle_inhibitor", listener);
const inhibitor_node = util.gpa.create(std.TailQueue(IdleInhibitor).Node) catch return; const inhibitor_node = util.gpa.create(std.TailQueue(IdleInhibitor).Node) catch return;
inhibitor_node.data.init(inhibitor, self) catch { inhibitor_node.data.init(inhibitor, inhibit_manager) catch {
util.gpa.destroy(inhibitor_node); util.gpa.destroy(inhibitor_node);
return; return;
}; };
self.inhibitors.append(inhibitor_node); inhibit_manager.inhibitors.append(inhibitor_node);
self.idleInhibitCheckActive(); inhibit_manager.checkActive();
} }

View File

@ -1,4 +1,20 @@
const Self = @This(); // This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2022 The River Developers
//
// 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, version 3.
//
// 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 IdleInhibitor = @This();
const std = @import("std"); const std = @import("std");
const wlr = @import("wlroots"); const wlr = @import("wlroots");
@ -7,29 +23,36 @@ const wl = @import("wayland").server.wl;
const server = &@import("main.zig").server; const server = &@import("main.zig").server;
const util = @import("util.zig"); const util = @import("util.zig");
const IdleInhibitorManager = @import("IdleInhibitorManager.zig"); const IdleInhibitManager = @import("IdleInhibitManager.zig");
inhibit_manager: *IdleInhibitManager,
wlr_inhibitor: *wlr.IdleInhibitorV1,
inhibitor_manager: *IdleInhibitorManager,
inhibitor: *wlr.IdleInhibitorV1,
destroy: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleDestroy), destroy: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleDestroy),
pub fn init(self: *Self, inhibitor: *wlr.IdleInhibitorV1, inhibitor_manager: *IdleInhibitorManager) !void { pub fn init(
self.inhibitor_manager = inhibitor_manager; inhibitor: *IdleInhibitor,
self.inhibitor = inhibitor; wlr_inhibitor: *wlr.IdleInhibitorV1,
self.destroy.setNotify(handleDestroy); inhibit_manager: *IdleInhibitManager,
inhibitor.events.destroy.add(&self.destroy); ) !void {
inhibitor.* = .{
.inhibit_manager = inhibit_manager,
.wlr_inhibitor = wlr_inhibitor,
};
wlr_inhibitor.events.destroy.add(&inhibitor.destroy);
inhibitor_manager.idleInhibitCheckActive(); inhibit_manager.checkActive();
} }
fn handleDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { fn handleDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
const self = @fieldParentPtr(Self, "destroy", listener); const inhibitor = @fieldParentPtr(IdleInhibitor, "destroy", listener);
self.destroy.link.remove();
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self); inhibitor.destroy.link.remove();
server.idle_inhibitor_manager.inhibitors.remove(node);
self.inhibitor_manager.idleInhibitCheckActive(); const node = @fieldParentPtr(std.TailQueue(IdleInhibitor).Node, "data", inhibitor);
server.idle_inhibit_manager.inhibitors.remove(node);
inhibitor.inhibit_manager.checkActive();
util.gpa.destroy(node); util.gpa.destroy(node);
} }

View File

@ -725,7 +725,7 @@ fn commitTransaction(root: *Root) void {
} }
} }
server.idle_inhibitor_manager.idleInhibitCheckActive(); server.idle_inhibit_manager.checkActive();
if (root.pending_state_dirty) { if (root.pending_state_dirty) {
root.applyPending(); root.applyPending();

View File

@ -26,7 +26,7 @@ const util = @import("util.zig");
const Config = @import("Config.zig"); const Config = @import("Config.zig");
const Control = @import("Control.zig"); const Control = @import("Control.zig");
const IdleInhibitorManager = @import("IdleInhibitorManager.zig"); const IdleInhibitManager = @import("IdleInhibitManager.zig");
const InputManager = @import("InputManager.zig"); const InputManager = @import("InputManager.zig");
const LayerSurface = @import("LayerSurface.zig"); const LayerSurface = @import("LayerSurface.zig");
const LayoutManager = @import("LayoutManager.zig"); const LayoutManager = @import("LayoutManager.zig");
@ -88,7 +88,7 @@ config: Config,
control: Control, control: Control,
status_manager: StatusManager, status_manager: StatusManager,
layout_manager: LayoutManager, layout_manager: LayoutManager,
idle_inhibitor_manager: IdleInhibitorManager, idle_inhibit_manager: IdleInhibitManager,
lock_manager: LockManager, lock_manager: LockManager,
pub fn init(server: *Server, runtime_xwayland: bool) !void { pub fn init(server: *Server, runtime_xwayland: bool) !void {
@ -130,7 +130,7 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
.control = undefined, .control = undefined,
.status_manager = undefined, .status_manager = undefined,
.layout_manager = undefined, .layout_manager = undefined,
.idle_inhibitor_manager = undefined, .idle_inhibit_manager = undefined,
.lock_manager = undefined, .lock_manager = undefined,
}; };
@ -165,7 +165,7 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
try server.control.init(); try server.control.init();
try server.status_manager.init(); try server.status_manager.init();
try server.layout_manager.init(); try server.layout_manager.init();
try server.idle_inhibitor_manager.init(); try server.idle_inhibit_manager.init();
try server.lock_manager.init(); try server.lock_manager.init();
server.xdg_shell.events.new_surface.add(&server.new_xdg_surface); server.xdg_shell.events.new_surface.add(&server.new_xdg_surface);
@ -207,7 +207,7 @@ pub fn deinit(server: *Server) void {
server.root.deinit(); server.root.deinit();
server.input_manager.deinit(); server.input_manager.deinit();
server.idle_inhibitor_manager.deinit(); server.idle_inhibit_manager.deinit();
server.lock_manager.deinit(); server.lock_manager.deinit();
server.wl_server.destroy(); server.wl_server.destroy();