Skip to content

Commit

Permalink
Add RoundedCorners border decoration
Browse files Browse the repository at this point in the history
Wayland only as x11 will render black artefacts.
  • Loading branch information
elParaguayo committed Jul 7, 2024
1 parent db0e5ae commit c1468f9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2024-07-07: [FEATURE] Add `RoundedCorners` border decoration (Wayland only)
2024-07-07: [FEATURE] Add `ConditionalBorderWidth` to set border width depending on window conditions
2024-06-13: [FEATURE] Add new `CustomBorder` to draw window borders with user-defined functions
2024-06-06: [FEATURE] Add new `ConditionalBorder` to set window border depending on window conditions (name, class etc.)
Expand Down
Binary file added docs/_static/images/border_rounded_corners.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions qtile_extras/layout/decorations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
CustomBorder,
GradientBorder,
GradientFrame,
RoundedCorners,
ScreenGradientBorder,
SolidEdge,
)
Expand Down
45 changes: 45 additions & 0 deletions qtile_extras/layout/decorations/borders.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import inspect
import math

import cairocffi
import xcffib.xproto
Expand Down Expand Up @@ -573,6 +574,50 @@ def draw(self, surface, bw, x, y, width, height):
self.func(ctx, bw, width, height)


class RoundedCorners(_BorderStyle):
"""
A simple decoration to draw rounded corners.
.. note::
This border will not render well on x11 backends as it does not implement transparency.
As a result, the border will display with black artefacts in the corners.
"""

needs_surface = True

defaults = [
("colour", "00f", "Border colour"),
]

_screenshots = [
("border_rounded_corners.png", "Rounded corners"),
]

def __init__(self, **config):
_BorderStyle.__init__(self, **config)
self.add_defaults(RoundedCorners.defaults)

def draw(self, surface, bw, x, y, width, height):
with cairocffi.Context(surface) as ctx:
ctx.translate(x, y)

radius = bw / 2
degrees = math.pi / 180.0

ctx.new_sub_path()
ctx.arc(width - bw, bw, radius, -90 * degrees, 0 * degrees)
ctx.arc(width - bw, height - bw, radius, 0 * degrees, 90 * degrees)
ctx.arc(bw, height - bw, radius, 90 * degrees, 180 * degrees)
ctx.arc(bw, bw, radius, 180 * degrees, 270 * degrees)
ctx.close_path()

ctx.set_line_width(bw)
ctx.set_source_rgba(*rgb(self.colour))
ctx.stroke()


class ConditionalBorderWidth(Configurable):
"""
A class that allows finer control as to which border width is applied to which window.
Expand Down
3 changes: 3 additions & 0 deletions test/layout/decorations/test_border_decorations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
CustomBorder,
GradientBorder,
GradientFrame,
RoundedCorners,
ScreenGradientBorder,
SolidEdge,
)
Expand Down Expand Up @@ -74,6 +75,8 @@ class BorderDecorationConfig(Config):
ConditionalBorder(matches=[(Match(title="three"), "f00")], fallback="00f"),
ConditionalBorder(matches=[(Match(title="three"), "f00")], fallback=GradientBorder()),
CustomBorder(func=lambda ctx, bw, x, y: None),
RoundedCorners(),
RoundedCorners(colour="f00"),
],
indirect=True,
)
Expand Down

0 comments on commit c1468f9

Please sign in to comment.