Skip to content

Allow to configure all corner radii separately #2294

@zappolowski

Description

@zappolowski

I'm running a setup with a 49" 32:9 screen, which is partitioned into three virtual monitors of which each is running its own instance of polybar (different modules enabled per monitor). To get the illusion of having a single bar I configured the bar of the center monitor to use 100% of the available width. As I'm also using rounded corners (for a single screen setup), which I'd like to keep for the outer bars. This is currently not feasible as configuration just covers either all corners or top and bottom corners, but there's no way to just set corner radii for each corner separately (I would need to set {bottom,top}-left for the leftmost as well as {bottom,top}-left for the rightmost bar).

Configuration could look like

[bar/single_screen]
radius = 8

[bar/left]
radius-top-left = 8
radius-bottom-left = 8

[bar/center]
radius = 0

[bar/right]
radius-top-right = 8
radius-bottom-right = 8

A possible implementation (which should be compatible with existing configurations):

diff --git a/include/cairo/context.hpp b/include/cairo/context.hpp
index be881c5..42e692f 100644
--- a/include/cairo/context.hpp
+++ b/include/cairo/context.hpp
@@ -118,10 +118,10 @@ namespace cairo {
     context& operator<<(const rounded_corners& c) {
       double d = M_PI / 180.0;
       cairo_new_sub_path(m_c);
-      cairo_arc(m_c, c.x + c.w - c.radius.top, c.y + c.radius.top, c.radius.top, -90 * d, 0 * d);
-      cairo_arc(m_c, c.x + c.w - c.radius.bottom, c.y + c.h - c.radius.bottom, c.radius.bottom, 0 * d, 90 * d);
-      cairo_arc(m_c, c.x + c.radius.bottom, c.y + c.h - c.radius.bottom, c.radius.bottom, 90 * d, 180 * d);
-      cairo_arc(m_c, c.x + c.radius.top, c.y + c.radius.top, c.radius.top, 180 * d, 270 * d);
+      cairo_arc(m_c, c.x + c.w - c.radius.top_right, c.y + c.radius.top_right, c.radius.top_right, -90 * d, 0 * d);
+      cairo_arc(m_c, c.x + c.w - c.radius.bottom_right, c.y + c.h - c.radius.bottom_right, c.radius.bottom_right, 0 * d, 90 * d);
+      cairo_arc(m_c, c.x + c.radius.bottom_left, c.y + c.h - c.radius.bottom_left, c.radius.bottom_left, 90 * d, 180 * d);
+      cairo_arc(m_c, c.x + c.radius.top_left, c.y + c.radius.top_left, c.radius.top_left, 180 * d, 270 * d);
       cairo_close_path(m_c);
       return *this;
     }
diff --git a/include/components/types.hpp b/include/components/types.hpp
index c1baefa..acc7b5b 100644
--- a/include/components/types.hpp
+++ b/include/components/types.hpp
@@ -98,11 +98,13 @@ struct edge_values {
 };
 
 struct radius {
-  double top{0.0};
-  double bottom{0.0};
+  double top_left{0.0};
+  double top_right{0.0};
+  double bottom_left{0.0};
+  double bottom_right{0.0};
 
   operator bool() const {
-    return top != 0.0 || bottom != 0.0;
+    return top_left != 0.0 || top_right != 0.0 || bottom_left != 0.0 || bottom_right != 0.0;
   }
 };
 
diff --git a/src/components/bar.cpp b/src/components/bar.cpp
index 4fdfbce..4ce27a4 100644
--- a/src/components/bar.cpp
+++ b/src/components/bar.cpp
@@ -161,8 +161,12 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
   m_opts.locale = m_conf.get(bs, "locale", ""s);
 
   auto radius = m_conf.get<double>(bs, "radius", 0.0);
-  m_opts.radius.top = m_conf.get(bs, "radius-top", radius);
-  m_opts.radius.bottom = m_conf.get(bs, "radius-bottom", radius);
+  auto top = m_conf.get(bs, "radius-top", radius);
+  m_opts.radius.top_left = m_conf.get(bs, "radius-top-left", top);
+  m_opts.radius.top_right = m_conf.get(bs, "radius-top-right", top);
+  auto bottom = m_conf.get(bs, "radius-bottom", radius);
+  m_opts.radius.bottom_left = m_conf.get(bs, "radius-bottom-left", bottom);
+  m_opts.radius.bottom_right = m_conf.get(bs, "radius-bottom-right", bottom);
 
   auto padding = m_conf.get<unsigned int>(bs, "padding", 0U);
   m_opts.padding.left = m_conf.get(bs, "padding-left", padding);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions