Config: move opacity settings to sub struct

This commit is contained in:
Isaac Freund 2020-12-31 15:52:03 +01:00
parent cc08be2dee
commit 4984944c60
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
4 changed files with 36 additions and 38 deletions

View file

@ -66,20 +66,18 @@ csd_filter: std.ArrayList([]const u8),
/// The selected focus_follows_cursor mode /// The selected focus_follows_cursor mode
focus_follows_cursor: FocusFollowsCursorMode = .disabled, focus_follows_cursor: FocusFollowsCursorMode = .disabled,
/// The opacity of the focused view opacity: struct {
view_opacity_focused: f32 = 1.0, /// The opacity of focused views
focused: f32 = 1.0,
/// The opacity of unfocused views /// The opacity of unfocused views
view_opacity_unfocused: f32 = 1.0, unfocused: f32 = 1.0,
/// The initial opacity of new views
/// The starting opacity of new views initial: f32 = 1.0,
view_opacity_initial: f32 = 1.0, /// View opacity transition step
delta: f32 = 1.0,
/// View opacity transition step /// Time between view opacity transition steps in milliseconds
view_opacity_delta: f32 = 1.0, delta_t: u31 = 20,
} = .{},
/// Time between view opacity transition steps in msec
view_opacity_delta_t: u31 = 20,
/// Keyboard repeat rate in characters per second /// Keyboard repeat rate in characters per second
repeat_rate: u31 = 25, repeat_rate: u31 = 25,

View file

@ -200,7 +200,7 @@ pub fn setFocusRaw(self: *Self, new_focus: FocusTarget) void {
if (build_options.xwayland and self.focused.view.impl == .xwayland_view) if (build_options.xwayland and self.focused.view.impl == .xwayland_view)
self.focused.view.impl.xwayland_view.xwayland_surface.activate(false); self.focused.view.impl.xwayland_view.xwayland_surface.activate(false);
if (self.focused.view.pending.focus == 0 and !self.focused.view.pending.fullscreen) { if (self.focused.view.pending.focus == 0 and !self.focused.view.pending.fullscreen) {
self.focused.view.pending.target_opacity = self.input_manager.server.config.view_opacity_unfocused; self.focused.view.pending.target_opacity = self.input_manager.server.config.opacity.unfocused;
} }
} }
@ -214,7 +214,7 @@ pub fn setFocusRaw(self: *Self, new_focus: FocusTarget) void {
if (build_options.xwayland and target_view.impl == .xwayland_view) if (build_options.xwayland and target_view.impl == .xwayland_view)
target_view.impl.xwayland_view.xwayland_surface.activate(true); target_view.impl.xwayland_view.xwayland_surface.activate(true);
if (!target_view.pending.fullscreen) { if (!target_view.pending.fullscreen) {
target_view.pending.target_opacity = self.input_manager.server.config.view_opacity_focused; target_view.pending.target_opacity = self.input_manager.server.config.opacity.focused;
} }
}, },
.layer => |target_layer| std.debug.assert(self.focused_output == target_layer.output), .layer => |target_layer| std.debug.assert(self.focused_output == target_layer.output),

View file

@ -140,14 +140,14 @@ pub fn init(self: *Self, output: *Output, tags: u32, surface: anytype) void {
.output = output, .output = output,
.current = .{ .current = .{
.tags = tags, .tags = tags,
.target_opacity = output.root.server.config.view_opacity_initial, .target_opacity = output.root.server.config.opacity.initial,
}, },
.pending = .{ .pending = .{
.tags = tags, .tags = tags,
.target_opacity = output.root.server.config.view_opacity_initial, .target_opacity = output.root.server.config.opacity.initial,
}, },
.saved_buffers = std.ArrayList(SavedBuffer).init(util.gpa), .saved_buffers = std.ArrayList(SavedBuffer).init(util.gpa),
.opacity = output.root.server.config.view_opacity_initial, .opacity = output.root.server.config.opacity.initial,
}; };
if (@TypeOf(surface) == *wlr.XdgSurface) { if (@TypeOf(surface) == *wlr.XdgSurface) {
@ -224,9 +224,9 @@ pub fn applyPending(self: *Self) void {
// Restore configured opacity // Restore configured opacity
self.pending.target_opacity = if (self.pending.focus > 0) self.pending.target_opacity = if (self.pending.focus > 0)
self.output.root.server.config.view_opacity_focused self.output.root.server.config.opacity.focused
else else
self.output.root.server.config.view_opacity_unfocused; self.output.root.server.config.opacity.unfocused;
} }
if (arrange_output) self.output.arrangeViews(); if (arrange_output) self.output.arrangeViews();
@ -440,7 +440,7 @@ pub fn shouldTrackConfigure(self: Self) bool {
pub fn map(self: *Self) void { pub fn map(self: *Self) void {
const root = self.output.root; const root = self.output.root;
self.pending.target_opacity = self.output.root.server.config.view_opacity_unfocused; self.pending.target_opacity = self.output.root.server.config.opacity.unfocused;
log.debug(.server, "view '{}' mapped", .{self.getTitle()}); log.debug(.server, "view '{}' mapped", .{self.getTitle()});
@ -528,16 +528,16 @@ pub fn notifyAppId(self: Self) void {
} }
} }
/// Change the opacity of a view by config.view_opacity_delta. /// Change the opacity of a view by config.opacity.delta.
/// If the target opacity was reached, return true. /// If the target opacity was reached, return true.
fn incrementOpacity(self: *Self) bool { fn incrementOpacity(self: *Self) bool {
// TODO damage view when implementing damage based rendering // TODO damage view when implementing damage based rendering
const config = &self.output.root.server.config; const config = &self.output.root.server.config;
if (self.opacity < self.current.target_opacity) { if (self.opacity < self.current.target_opacity) {
self.opacity += config.view_opacity_delta; self.opacity += config.opacity.delta;
if (self.opacity < self.current.target_opacity) return false; if (self.opacity < self.current.target_opacity) return false;
} else { } else {
self.opacity -= config.view_opacity_delta; self.opacity -= config.opacity.delta;
if (self.opacity > self.current.target_opacity) return false; if (self.opacity > self.current.target_opacity) return false;
} }
self.opacity = self.current.target_opacity; self.opacity = self.current.target_opacity;
@ -552,7 +552,7 @@ fn killOpacityTimer(self: *Self) void {
/// Set the timeout on a views opacity timer /// Set the timeout on a views opacity timer
fn armOpacityTimer(self: *Self) void { fn armOpacityTimer(self: *Self) void {
const delta_t = self.output.root.server.config.view_opacity_delta_t; const delta_t = self.output.root.server.config.opacity.delta_t;
self.opacity_timer.?.timerUpdate(delta_t) catch |err| { self.opacity_timer.?.timerUpdate(delta_t) catch |err| {
log.err(.view, "failed to update opacity timer: {}", .{err}); log.err(.view, "failed to update opacity timer: {}", .{err});
self.killOpacityTimer(); self.killOpacityTimer();

View file

@ -39,28 +39,28 @@ pub fn opacity(
const server = seat.input_manager.server; const server = seat.input_manager.server;
// Focused opacity // Focused opacity
server.config.view_opacity_focused = try std.fmt.parseFloat(f32, args[1]); server.config.opacity.focused = try std.fmt.parseFloat(f32, args[1]);
if (server.config.view_opacity_focused < 0.0 or server.config.view_opacity_focused > 1.0) if (server.config.opacity.focused < 0.0 or server.config.opacity.focused > 1.0)
return Error.InvalidValue; return Error.InvalidValue;
// Unfocused opacity // Unfocused opacity
server.config.view_opacity_unfocused = try std.fmt.parseFloat(f32, args[2]); server.config.opacity.unfocused = try std.fmt.parseFloat(f32, args[2]);
if (server.config.view_opacity_unfocused < 0.0 or server.config.view_opacity_unfocused > 1.0) if (server.config.opacity.unfocused < 0.0 or server.config.opacity.unfocused > 1.0)
return Error.InvalidValue; return Error.InvalidValue;
// Starting opacity for new views // Starting opacity for new views
server.config.view_opacity_initial = try std.fmt.parseFloat(f32, args[3]); server.config.opacity.initial = try std.fmt.parseFloat(f32, args[3]);
if (server.config.view_opacity_initial < 0.0 or server.config.view_opacity_initial > 1.0) if (server.config.opacity.initial < 0.0 or server.config.opacity.initial > 1.0)
return Error.InvalidValue; return Error.InvalidValue;
// Opacity transition step // Opacity transition step
server.config.view_opacity_delta = try std.fmt.parseFloat(f32, args[4]); server.config.opacity.delta = try std.fmt.parseFloat(f32, args[4]);
if (server.config.view_opacity_delta < 0.0 or server.config.view_opacity_delta > 1.0) if (server.config.opacity.delta < 0.0 or server.config.opacity.delta > 1.0)
return Error.InvalidValue; return Error.InvalidValue;
// Time between step // Time between step
server.config.view_opacity_delta_t = try std.fmt.parseInt(u31, args[5], 10); server.config.opacity.delta_t = try std.fmt.parseInt(u31, args[5], 10);
if (server.config.view_opacity_delta_t < 1) return Error.InvalidValue; if (server.config.opacity.delta_t < 1) return Error.InvalidValue;
// Update opacity of all views // Update opacity of all views
// Unmapped views will be skipped, however their opacity gets updated on map anyway // Unmapped views will be skipped, however their opacity gets updated on map anyway
@ -69,9 +69,9 @@ pub fn opacity(
var vit = ViewStack(View).iter(onode.data.views.first, .forward, {}, opacityUpdateFilter); var vit = ViewStack(View).iter(onode.data.views.first, .forward, {}, opacityUpdateFilter);
while (vit.next()) |vnode| { while (vit.next()) |vnode| {
if (vnode.current.focus > 0) { if (vnode.current.focus > 0) {
vnode.pending.target_opacity = server.config.view_opacity_focused; vnode.pending.target_opacity = server.config.opacity.focused;
} else { } else {
vnode.pending.target_opacity = server.config.view_opacity_unfocused; vnode.pending.target_opacity = server.config.opacity.unfocused;
} }
} }
} }