~novakane/rivercarro

c3fdedeba780dc8391446ca305cec0a1b265961a — Hugo Machet 4 months ago a1623d0
Add a command to limit the usable screen width

`-width-ratio`:
  - Can be used at runtime.
  - Use a percentage (i.e. 0.7 == 70% of the screen).
  - Use +/- to modify the value.
  - Clamp between 0.1 and 1.0.
3 files changed, 55 insertions(+), 3 deletions(-)

M README.md
M doc/rivercarro.1.scd
M src/main.zig
M README.md => README.md +6 -1
@@ 8,6 8,7 @@ Compared to _rivertile_, _rivercarro_ adds:
-   monocle layout
-   smart gaps
-   "true" inner gaps instead of padding around views
-   Limit the width of the usable area of the screen.

I don't want to add too much complexity, the only thing I intend
to add now is `smart borders`, after that I'll consider _rivercarro_


@@ 37,7 38,7 @@ set `PKG_CONFIG_PATH` in your shell rc, e.g.
## Usage

Works exactly as _rivertile_, you can just replace _rivertile_ name by
_rivercarro_ in your config, and read `rivertile(1)` man page
_rivercarro_ in your config, and read `rivercarro(1)` man page

`e.g.` In your **river** init (usually `$XDG_CONFIG_HOME/river/init`)



@@ 84,6 85,8 @@ Usage: rivercarro [options]
                  layout. (Default 1)
  -main-ratio     Set the initial ratio of main area to total layout
                  area. (Default: 0.6)
  -width-ratio    Set the ratio of the usable area width of the screen.
                  (Default: 1.0)
  -no-smart-gaps  Disable smart gaps
```



@@ 93,6 96,8 @@ For patches, questions or discussion send a [plain text] mail to my
[public inbox] [~novakane/public-inbox@lists.sr.ht] with project
prefix set to `rivercarro`:

You can configure your repo like so:

```bash
git config sendemail.to "~novakane/public-inbox@lists.sr.ht"
git config format.subjectPrefix "PATCH rivercarro"

M doc/rivercarro.1.scd => doc/rivercarro.1.scd +18 -0
@@ 21,6 21,7 @@ In addition to *rivertile*(1), *rivercarro* provides:
- Monocle layout, views will takes all the usable area on the screen.
- Smart gaps, if there is only one view, gaps will be disable.
- Inner gaps instead of padding around views.
- Limit the width of the usable area of the screen.

# OPTIONS



@@ 57,6 58,12 @@ In addition to *rivertile*(1), *rivercarro* provides:

	Default: 0.6

*-width-ratio* <ratio>
	Set the initial ratio of the width of the usable area of the
	screen. The _ratio_ must be between 0.1 and 1.0, inclusive.

	Default: 1.0

*-no-smart-gaps*
	Disable smart gaps.



@@ 80,6 87,13 @@ These commands may be sent to rivercarro at runtime with the help of
	_value_. Note that the ratio will always be clamped to the range
	0.1 to 0.9.

*width-ratio* <value>
	Set or modify the ratio of the the width of the usable area of
	the screen. If _value_ is prefixed by a +/- sign, _value_ is
	added/subtracted from the current ratio. If there is no sign, the
	width ratio is set to _value_. Note that the ratio will always be
	clamped to the range 0.1 to 1.0.

# EXAMPLES

Start *rivercarro* with 4 pixels outer padding and the *top* main location:


@@ 94,6 108,10 @@ Set the main count to 3 at runtime:

	riverctl send-layout-cmd rivercarro "main-count 3"

Set the width ratio at 70% at runtime:

	riverctl send-layout-cmd rivercarro "width-ratio 0.7"

# SEE ALSO

*river*(1), *riverctl*(1), *rivertile*(1)

M src/main.zig => src/main.zig +31 -2
@@ 48,6 48,8 @@ const usage =
    \\                  layout. (Default 1)
    \\  -main-ratio     Set the initial ratio of main area to total layout
    \\                  area. (Default: 0.6)
    \\  -width-ratio    Set the ratio of the usable area width of the screen.
    \\                  (Default: 1.0)
    \\  -no-smart-gaps  Disable smart gaps
    \\
;


@@ 56,6 58,7 @@ const Command = enum {
    @"main-location",
    @"main-count",
    @"main-ratio",
    @"width-ratio",
};

const Location = enum {


@@ 72,6 75,7 @@ var default_outer_padding: u32 = 6;
var default_main_location: Location = .left;
var default_main_count: u32 = 1;
var default_main_ratio: f64 = 0.6;
var default_width_ratio: f64 = 1.0;
var smart_gaps: bool = true;

var only_one_view: bool = false;


@@ 101,6 105,7 @@ const Output = struct {
    main_location: Location,
    main_count: u32,
    main_ratio: f64,
    width_ratio: f64,

    outer_padding: u32,
    view_padding: u32,


@@ 114,6 119,7 @@ const Output = struct {
            .main_location = default_main_location,
            .main_count = default_main_count,
            .main_ratio = default_main_ratio,
            .width_ratio = default_width_ratio,
            .outer_padding = default_outer_padding,
            .view_padding = default_view_padding,
        };


@@ 190,6 196,18 @@ const Output = struct {
                            else => output.main_ratio = math.clamp(arg, 0.1, 0.9),
                        }
                    },
                    .@"width-ratio" => {
                        const arg = std.fmt.parseFloat(f64, raw_arg) catch |err| {
                            log.err("failed to parse argument: {}", .{err});
                            return;
                        };
                        switch (raw_arg[0]) {
                            '+', '-' => {
                                output.width_ratio = math.clamp(output.width_ratio + arg, 0.1, 1.0);
                            },
                            else => output.width_ratio = math.clamp(arg, 0.1, 1.0),
                        }
                    },
                }
            },



@@ 215,12 233,18 @@ const Output = struct {
                }

                const usable_width = switch (output.main_location) {
                    .left, .right, .monocle => ev.usable_width - 2 * default_outer_padding,
                    .left, .right, .monocle => @floatToInt(
                        u32,
                        (@intToFloat(f64, ev.usable_width)) * output.width_ratio,
                    ) - 2 * default_outer_padding,
                    .top, .bottom => ev.usable_height - 2 * default_outer_padding,
                };
                const usable_height = switch (output.main_location) {
                    .left, .right, .monocle => ev.usable_height - 2 * default_outer_padding,
                    .top, .bottom => ev.usable_width - 2 * default_outer_padding,
                    .top, .bottom => @floatToInt(
                        u32,
                        (@intToFloat(f64, ev.usable_width)) * output.width_ratio,
                    ) - 2 * default_outer_padding,
                };

                // to make things pixel-perfect, we make the first main and first secondary


@@ 356,6 380,7 @@ pub fn main() !void {
        .{ .name = "-main-location", .kind = .arg },
        .{ .name = "-main-count", .kind = .arg },
        .{ .name = "-main-ratio", .kind = .arg },
        .{ .name = "-width-ratio", .kind = .arg },
        .{ .name = "-no-smart-gaps", .kind = .boolean },
    }) catch {
        try std.io.getStdErr().writeAll(usage);


@@ 391,6 416,10 @@ pub fn main() !void {
        default_main_ratio = std.fmt.parseFloat(f64, raw) catch
            fatalPrintUsage("invalid value '{s}' provided to -main-ratio", .{raw});
    }
    if (result.argFlag("-width-ratio")) |raw| {
        default_width_ratio = std.fmt.parseFloat(f64, raw) catch
            fatalPrintUsage("invalid value '{s}' provided to -width-ratio", .{raw});
    }
    if (result.boolFlag("-no-smart-gaps")) {
        smart_gaps = false;
    }