tearing-control: minor cleanups/style improvements

This commit also tweaks the riverctl interface to make the global
allow-tearing option apply only to tearing-control-v1 hints from
clients. The global option no longer affects tearing/no-tearing rules
explicitly created by the user.
This commit is contained in:
Isaac Freund 2024-08-15 11:42:38 +02:00
parent 066baa5753
commit f82b2f5816
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
6 changed files with 37 additions and 40 deletions

View File

@ -307,11 +307,10 @@ matches everything while _\*\*_ and the empty string are invalid.
- *fullscreen*: Make the view fullscreen. Applies only to new views.
- *no-fullscreen*: Don't make the view fullscreen. Applies only to
new views.
- *tearing*: Enable tearing for view when fullscreen regardless of the
supplied tearing hint. Note that tearing additionally requires setting the
*allow-tearing* server option. Applies to new and existing views.
- *no-tearing*: Disable tearing for view regardless of the supplied
tearing hint. Applies to new and existing views.
- *tearing*: Allow the view to tear when fullscreen regardless of the
view's preference. Applies to new and existing views.
- *no-tearing*: Disable tearing for the view regardless of the view's
preference. Applies to new and existing views.
Both *float* and *no-float* rules are added to the same list,
which means that adding a *no-float* rule with the same arguments
@ -371,7 +370,8 @@ matches everything while _\*\*_ and the empty string are invalid.
default-attach-mode if any.
*allow-tearing* *enabled*|*disabled*
Allow windows to tear if requested by either the program or the user.
Allow fullscreen views to tear if requested by the view. See also the
*tearing* rule to force enable tearing for specific views.
*background-color* _0xRRGGBB_|_0xRRGGBBAA_
Set the background color.

View File

@ -31,11 +31,6 @@ const Mode = @import("Mode.zig");
const RuleList = @import("rule_list.zig").RuleList;
const View = @import("View.zig");
pub const AllowTearing = enum {
disabled,
enabled,
};
pub const AttachMode = union(enum) {
top,
bottom,
@ -73,8 +68,8 @@ pub const Dimensions = struct {
height: u31,
};
/// Whether to allow tearing page flips if a view requests it.
allow_tearing: AllowTearing = .disabled,
/// Whether to allow tearing page flips when fullscreen if a view requests it.
allow_tearing: bool = false,
/// Color of background in RGBA with premultiplied alpha (alpha should only affect nested sessions)
background_color: [4]f32 = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }, // Solarized base03

View File

@ -557,18 +557,21 @@ fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void {
}
}
if (output.allowTearing() and server.config.allow_tearing == .enabled) {
state.tearing_page_flip = true;
if (!output.wlr_output.testState(&state)) {
log.debug("tearing page flip test failed for {s}, retrying without tearing", .{output.wlr_output.name});
state.tearing_page_flip = false;
if (output.current.fullscreen) |fullscreen| {
if (fullscreen.allowTearing()) {
state.tearing_page_flip = true;
if (!output.wlr_output.testState(&state)) {
log.debug("tearing page flip test failed for {s}, retrying without tearing", .{
output.wlr_output.name,
});
state.tearing_page_flip = false;
}
}
}
if (!output.wlr_output.commitState(&state)) return error.CommitFailed;
if (output.gamma_dirty) output.gamma_dirty = false;
output.gamma_dirty = false;
if (server.lock_manager.state == .locked or
(server.lock_manager.state == .waiting_for_lock_surfaces and output.locked_content.node.enabled) or
@ -642,14 +645,6 @@ fn setTitle(output: Output) void {
}
}
fn allowTearing(output: *Output) bool {
if (output.current.fullscreen) |fullscreen_view| {
return fullscreen_view.allowTearing();
}
return false;
}
pub fn handleLayoutNamespaceChange(output: *Output) void {
// The user changed the layout namespace of this output. Try to find a
// matching layout.

View File

@ -61,8 +61,8 @@ const AttachRelativeMode = enum {
};
const TearingMode = enum {
override_false,
override_true,
no_tearing,
tearing,
window_hint,
};
@ -184,7 +184,6 @@ foreign_toplevel_handle: ForeignToplevelHandle = .{},
/// Connector name of the output this view occupied before an evacuation.
output_before_evac: ?[]const u8 = null,
// Current tearing mode of the view. Defaults to using the window tearing hint.
tearing_mode: TearingMode = .window_hint,
pub fn create(impl: Impl) error{OutOfMemory}!*View {
@ -582,14 +581,19 @@ pub fn getAppId(view: View) ?[*:0]const u8 {
};
}
/// Return true if the view can currently tear.
/// Return true if tearing should be allowed for the view.
pub fn allowTearing(view: *View) bool {
switch (view.tearing_mode) {
TearingMode.override_false => return false,
TearingMode.override_true => return true,
TearingMode.window_hint => if (view.rootSurface()) |root_surface| {
return server.tearing_control_manager.hintFromSurface(root_surface) == .@"async";
} else return false,
.no_tearing => return false,
.tearing => return true,
.window_hint => {
if (server.config.allow_tearing) {
if (view.rootSurface()) |root_surface| {
return server.tearing_control_manager.hintFromSurface(root_surface) == .@"async";
}
}
return false;
},
}
}
@ -662,7 +666,7 @@ pub fn map(view: *View) !void {
}
if (server.config.rules.tearing.match(view)) |tearing| {
view.tearing_mode = if (tearing) .override_true else .override_false;
view.tearing_mode = if (tearing) .tearing else .no_tearing;
}
if (server.config.rules.dimensions.match(view)) |dimensions| {

View File

@ -31,8 +31,11 @@ pub fn allowTearing(
) Error!void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
server.config.allow_tearing = std.meta.stringToEnum(Config.AllowTearing, args[1]) orelse
const arg = std.meta.stringToEnum(enum { enabled, disabled }, args[1]) orelse
return Error.UnknownOption;
server.config.allow_tearing = arg == .enabled;
}
pub fn borderWidth(

View File

@ -211,7 +211,7 @@ fn apply_tearing_rules() void {
if (view.destroying) continue;
if (server.config.rules.tearing.match(view)) |tearing| {
view.tearing_mode = if (tearing) .override_true else .override_false;
view.tearing_mode = if (tearing) .tearing else .no_tearing;
}
}
}