git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit0bbbfec8989efe7209e2b5ace8d8c25d085e2116
parenta3d9e4a40a
authorIsaac Freund <[email protected]>
date2020-06-19 18:44
command: add background_color option

This is trivial to support and allows basic customization without
running a layer-shell program such as swaybg. This is especially useful
in low memory situations.

 doc/riverctl.1.scd           | 1 +
 river/Config.zig             | 4 ++++
 river/command/set_option.zig | 2 ++
 river/render.zig             | 4 ++--
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/doc/riverctl.1.scd b/doc/riverctl.1.scd
index 0d52de4..3788919 100644
--- a/doc/riverctl.1.scd
+++ b/doc/riverctl.1.scd
@@ -114,6 +114,7 @@ that tag 1 through 9 are visible.
 *set-option* _option_ _value_
 	Set _option_ to a specified _value_. List of valid options:
 
+	- *background_color* _RGB/RGBA_hex_code_
 	- *border_width* _non-negative_integer_
 	- *border_color_focused* _RGB/RGBA_hex_code_
 	- *border_color_unfocused* _RGB/RGBA_hex_code_
diff --git a/river/Config.zig b/river/Config.zig
index 760f5b5..015d02d 100644
--- a/river/Config.zig
+++ b/river/Config.zig
@@ -25,6 +25,9 @@ const util = @import("util.zig");
 const Server = @import("Server.zig");
 const Mapping = @import("Mapping.zig");
 
+/// Color of background in RGBA (alpha should only affect nested sessions)
+background_color: [4]f32,
+
 /// Width of borders in pixels
 border_width: u32,
 
@@ -50,6 +53,7 @@ modes: std.ArrayList(std.ArrayList(Mapping)),
 float_filter: std.ArrayList([*:0]const u8),
 
 pub fn init(self: *Self) !void {
+    self.background_color = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }; // Solarized base03
     self.border_width = 2;
     self.border_color_focused = [_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 }; // Solarized base1
     self.border_color_unfocused = [_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }; // Solarized base0
diff --git a/river/command/set_option.zig b/river/command/set_option.zig
index 6d7456e..5e87f90 100644
--- a/river/command/set_option.zig
+++ b/river/command/set_option.zig
@@ -22,6 +22,7 @@ const Error = @import("../command.zig").Error;
 const Seat = @import("../Seat.zig");
 
 const Option = enum {
+    background_color,
     border_width,
     border_color_focused,
     border_color_unfocused,
@@ -45,6 +46,7 @@ pub fn setOption(
 
     // Assign value to option.
     switch (option) {
+        .background_color => config.background_color = try parseRgba(args[2]),
         .border_width => config.border_width = try std.fmt.parseInt(u32, args[2], 10),
         .border_color_focused => config.border_color_focused = try parseRgba(args[2]),
         .border_color_unfocused => config.border_color_unfocused = try parseRgba(args[2]),
diff --git a/river/render.zig b/river/render.zig
index 8fe41db..4a2256e 100644
--- a/river/render.zig
+++ b/river/render.zig
@@ -39,6 +39,7 @@ const SurfaceRenderData = struct {
 };
 
 pub fn renderOutput(output: *Output) void {
+    const config = &output.root.server.config;
     const wlr_renderer = output.getRenderer();
 
     var now: c.timespec = undefined;
@@ -55,8 +56,7 @@ pub fn renderOutput(output: *Output) void {
     // Begin the renderer (calls glViewport and some other GL sanity checks)
     c.wlr_renderer_begin(wlr_renderer, width, height);
 
-    const color = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 };
-    c.wlr_renderer_clear(wlr_renderer, &color);
+    c.wlr_renderer_clear(wlr_renderer, &config.background_color);
 
     renderLayer(output.*, output.layers[c.ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &now);
     renderLayer(output.*, output.layers[c.ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &now);