Skip to content

Commit c1468f9

Browse files
committed
Add RoundedCorners border decoration
Wayland only as x11 will render black artefacts.
1 parent db0e5ae commit c1468f9

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
2024-07-07: [FEATURE] Add `RoundedCorners` border decoration (Wayland only)
12
2024-07-07: [FEATURE] Add `ConditionalBorderWidth` to set border width depending on window conditions
23
2024-06-13: [FEATURE] Add new `CustomBorder` to draw window borders with user-defined functions
34
2024-06-06: [FEATURE] Add new `ConditionalBorder` to set window border depending on window conditions (name, class etc.)
34.8 KB
Loading

qtile_extras/layout/decorations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
CustomBorder,
2626
GradientBorder,
2727
GradientFrame,
28+
RoundedCorners,
2829
ScreenGradientBorder,
2930
SolidEdge,
3031
)

qtile_extras/layout/decorations/borders.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020
import inspect
21+
import math
2122

2223
import cairocffi
2324
import xcffib.xproto
@@ -573,6 +574,50 @@ def draw(self, surface, bw, x, y, width, height):
573574
self.func(ctx, bw, width, height)
574575

575576

577+
class RoundedCorners(_BorderStyle):
578+
"""
579+
A simple decoration to draw rounded corners.
580+
581+
.. note::
582+
583+
This border will not render well on x11 backends as it does not implement transparency.
584+
As a result, the border will display with black artefacts in the corners.
585+
586+
"""
587+
588+
needs_surface = True
589+
590+
defaults = [
591+
("colour", "00f", "Border colour"),
592+
]
593+
594+
_screenshots = [
595+
("border_rounded_corners.png", "Rounded corners"),
596+
]
597+
598+
def __init__(self, **config):
599+
_BorderStyle.__init__(self, **config)
600+
self.add_defaults(RoundedCorners.defaults)
601+
602+
def draw(self, surface, bw, x, y, width, height):
603+
with cairocffi.Context(surface) as ctx:
604+
ctx.translate(x, y)
605+
606+
radius = bw / 2
607+
degrees = math.pi / 180.0
608+
609+
ctx.new_sub_path()
610+
ctx.arc(width - bw, bw, radius, -90 * degrees, 0 * degrees)
611+
ctx.arc(width - bw, height - bw, radius, 0 * degrees, 90 * degrees)
612+
ctx.arc(bw, height - bw, radius, 90 * degrees, 180 * degrees)
613+
ctx.arc(bw, bw, radius, 180 * degrees, 270 * degrees)
614+
ctx.close_path()
615+
616+
ctx.set_line_width(bw)
617+
ctx.set_source_rgba(*rgb(self.colour))
618+
ctx.stroke()
619+
620+
576621
class ConditionalBorderWidth(Configurable):
577622
"""
578623
A class that allows finer control as to which border width is applied to which window.

test/layout/decorations/test_border_decorations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
CustomBorder,
2929
GradientBorder,
3030
GradientFrame,
31+
RoundedCorners,
3132
ScreenGradientBorder,
3233
SolidEdge,
3334
)
@@ -74,6 +75,8 @@ class BorderDecorationConfig(Config):
7475
ConditionalBorder(matches=[(Match(title="three"), "f00")], fallback="00f"),
7576
ConditionalBorder(matches=[(Match(title="three"), "f00")], fallback=GradientBorder()),
7677
CustomBorder(func=lambda ctx, bw, x, y: None),
78+
RoundedCorners(),
79+
RoundedCorners(colour="f00"),
7780
],
7881
indirect=True,
7982
)

0 commit comments

Comments
 (0)