about summary refs log tree commit diff stats
path: root/pkgs/by-name/i3/i3bar-river-patched/0002-feat-crate-bar-Put-the-leftmost-block-in-the-middle-.patch
blob: 6f4bd528964d59a7b561b16f76f4aad8a434c642 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From b8568a2b626bd4d5f50ee24c304d19177bda5d4b Mon Sep 17 00:00:00 2001
From: Benedikt Peetz <benedikt.peetz@b-peetz.de>
Date: Tue, 20 May 2025 19:58:57 +0200
Subject: [PATCH] feat(crate::bar): Put the leftmost block in the middle of the
 bar

This is a workaround for the limitation in the i3 blocks protocol, as
this does not allow for centred blocks.
---
 src/bar.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 53 insertions(+), 11 deletions(-)

diff --git a/src/bar.rs b/src/bar.rs
index fb88150..e66c2cf 100644
--- a/src/bar.rs
+++ b/src/bar.rs
@@ -344,16 +344,56 @@ impl Bar {
         }
 
         // Display the blocks
-        render_blocks(
-            &cairo_ctx,
-            ss,
-            &self.output,
-            ss.blocks_cache.get_computed(),
-            &mut self.blocks_btns,
-            offset_left,
-            width_f,
-            height_f,
-        );
+        {
+            if !ss.blocks_cache.get_computed().is_empty() {
+                let first_block = &ss.blocks_cache.get_computed()[0];
+
+                let blocks = &ss.blocks_cache.get_computed()[1..];
+
+                let other_start = render_blocks(
+                    &cairo_ctx,
+                    ss,
+                    &self.output,
+                    blocks,
+                    &mut self.blocks_btns,
+                    offset_left,
+                    width_f,
+                    height_f,
+                );
+
+                // Draw the first block _after_ the other ones, so that we can nudge it more to the
+                // left, if the others are spanning over the middle.
+                let mut start = (width_f / 2.0) - (first_block.full.width / 2.0);
+                if start + first_block.full.width > other_start {
+                    start = other_start - first_block.full.width - first_block.block.separator_block_width as f64;
+                }
+
+                first_block.full.render(
+                    &cairo_ctx,
+                    RenderOptions {
+                        x_offset: start,
+                        bar_height: height_f,
+                        fg_color: first_block
+                            .block
+                            .color
+                            .unwrap_or(sfo!(ss, &self.output, color)),
+                        bg_color: first_block.block.background,
+                        r_left: ss.config.blocks_r,
+                        r_right: ss.config.blocks_r,
+                        overlap: ss.config.blocks_overlap,
+                    },
+                );
+
+                self.blocks_btns.push(
+                    start,
+                    first_block.full.width,
+                    (
+                        first_block.block.name.clone(),
+                        first_block.block.instance.clone(),
+                    ),
+                );
+            }
+        }
 
         self.viewport
             .set_destination(conn, self.width as i32, self.height as i32);
@@ -428,7 +468,7 @@ fn render_blocks(
     offset_left: f64,
     full_width: f64,
     full_height: f64,
-) {
+) -> f64 {
     context.rectangle(offset_left, 0.0, full_width - offset_left, full_height);
     context.clip();
 
@@ -513,6 +553,7 @@ fn render_blocks(
     }
 
     // Render blocks
+    let leftmost_start = full_width - blocks_width;
     buttons.clear();
     for series in blocks_computed {
         let s_len = series.blocks.len();
@@ -560,6 +601,7 @@ fn render_blocks(
     }
 
     context.reset_clip();
+    leftmost_start
 }
 
 fn layer_surface_cb(ctx: EventCtx<State, ZwlrLayerSurfaceV1>) {
-- 
2.49.0