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
focus_follows_cursor: FocusFollowsCursorMode = .disabled,
/// The opacity of the focused view
view_opacity_focused: f32 = 1.0,
/// The opacity of unfocused views
view_opacity_unfocused: f32 = 1.0,
/// The starting opacity of new views
view_opacity_initial: f32 = 1.0,
/// View opacity transition step
view_opacity_delta: f32 = 1.0,
/// Time between view opacity transition steps in msec
view_opacity_delta_t: u31 = 20,
opacity: struct {
/// The opacity of focused views
focused: f32 = 1.0,
/// The opacity of unfocused views
unfocused: f32 = 1.0,
/// The initial opacity of new views
initial: f32 = 1.0,
/// View opacity transition step
delta: f32 = 1.0,
/// Time between view opacity transition steps in milliseconds
delta_t: u31 = 20,
} = .{},
/// Keyboard repeat rate in characters per second
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)
self.focused.view.impl.xwayland_view.xwayland_surface.activate(false);
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)
target_view.impl.xwayland_view.xwayland_surface.activate(true);
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),

View file

@ -140,14 +140,14 @@ pub fn init(self: *Self, output: *Output, tags: u32, surface: anytype) void {
.output = output,
.current = .{
.tags = tags,
.target_opacity = output.root.server.config.view_opacity_initial,
.target_opacity = output.root.server.config.opacity.initial,
},
.pending = .{
.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),
.opacity = output.root.server.config.view_opacity_initial,
.opacity = output.root.server.config.opacity.initial,
};
if (@TypeOf(surface) == *wlr.XdgSurface) {
@ -224,9 +224,9 @@ pub fn applyPending(self: *Self) void {
// Restore configured opacity
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
self.output.root.server.config.view_opacity_unfocused;
self.output.root.server.config.opacity.unfocused;
}
if (arrange_output) self.output.arrangeViews();
@ -440,7 +440,7 @@ pub fn shouldTrackConfigure(self: Self) bool {
pub fn map(self: *Self) void {
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()});
@ -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.
fn incrementOpacity(self: *Self) bool {
// TODO damage view when implementing damage based rendering
const config = &self.output.root.server.config;
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;
} else {
self.opacity -= config.view_opacity_delta;
self.opacity -= config.opacity.delta;
if (self.opacity > self.current.target_opacity) return false;
}
self.opacity = self.current.target_opacity;
@ -552,7 +552,7 @@ fn killOpacityTimer(self: *Self) void {
/// Set the timeout on a views opacity timer
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| {
log.err(.view, "failed to update opacity timer: {}", .{err});
self.killOpacityTimer();

View file

@ -39,28 +39,28 @@ pub fn opacity(
const server = seat.input_manager.server;
// Focused opacity
server.config.view_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)
server.config.opacity.focused = try std.fmt.parseFloat(f32, args[1]);
if (server.config.opacity.focused < 0.0 or server.config.opacity.focused > 1.0)
return Error.InvalidValue;
// Unfocused opacity
server.config.view_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)
server.config.opacity.unfocused = try std.fmt.parseFloat(f32, args[2]);
if (server.config.opacity.unfocused < 0.0 or server.config.opacity.unfocused > 1.0)
return Error.InvalidValue;
// Starting opacity for new views
server.config.view_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)
server.config.opacity.initial = try std.fmt.parseFloat(f32, args[3]);
if (server.config.opacity.initial < 0.0 or server.config.opacity.initial > 1.0)
return Error.InvalidValue;
// Opacity transition step
server.config.view_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)
server.config.opacity.delta = try std.fmt.parseFloat(f32, args[4]);
if (server.config.opacity.delta < 0.0 or server.config.opacity.delta > 1.0)
return Error.InvalidValue;
// Time between step
server.config.view_opacity_delta_t = try std.fmt.parseInt(u31, args[5], 10);
if (server.config.view_opacity_delta_t < 1) return Error.InvalidValue;
server.config.opacity.delta_t = try std.fmt.parseInt(u31, args[5], 10);
if (server.config.opacity.delta_t < 1) return Error.InvalidValue;
// Update opacity of all views
// 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);
while (vit.next()) |vnode| {
if (vnode.current.focus > 0) {
vnode.pending.target_opacity = server.config.view_opacity_focused;
vnode.pending.target_opacity = server.config.opacity.focused;
} else {
vnode.pending.target_opacity = server.config.view_opacity_unfocused;
vnode.pending.target_opacity = server.config.opacity.unfocused;
}
}
}