Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure all corner radii separately #2294

Closed
zappolowski opened this issue Dec 13, 2020 · 2 comments
Closed

Allow to configure all corner radii separately #2294

zappolowski opened this issue Dec 13, 2020 · 2 comments
Labels

Comments

@zappolowski
Copy link
Contributor

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);
@patrick96
Copy link
Member

The patch looks good. Can you open up a PR for it, I will review it properly then. Thanks :)

@zappolowski
Copy link
Contributor Author

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants