forked from trav/lintunes
v0.91.1: now-playing panel debossed again; window rim 1 px heavier and kept when maximized; square corners when tiled
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.91.0"
|
||||
__version__ = "0.91.1"
|
||||
|
||||
@@ -48,7 +48,8 @@ CORNER = 14 # how far along an edge a corner reaches
|
||||
BUTTON = 24 # the round button's diameter
|
||||
SPACING = 8 # between buttons, and from the bar's ends
|
||||
RADIUS = 10 # the window's corners
|
||||
RIM = 3 # how far in from the edge the frame paints
|
||||
RIM_WIDTH = 2.5 # the soft emboss's light/dark rims, inside the outline
|
||||
RIM = 4 # how far in from the edge the frame paints
|
||||
|
||||
_BUTTONS = ("close", "minimize", "maximize")
|
||||
_FALLBACK_LAYOUT = ":minimize,close"
|
||||
@@ -135,10 +136,27 @@ def _framed(window: QWidget) -> bool:
|
||||
| Qt.WindowState.WindowFullScreen))
|
||||
|
||||
|
||||
TILED_SLACK = 64 # a window this close to the screen's height is tiled
|
||||
|
||||
|
||||
def tiled(window: QWidget) -> bool:
|
||||
"""Snapped to half the screen (or any edge-to-edge height). Wayland
|
||||
tells Qt the tiled state but Qt keeps it to itself, and its available
|
||||
geometry still includes the top bar, so: as tall as the screen, give
|
||||
or take the bar."""
|
||||
screen = window.screen()
|
||||
return (screen is not None and window.height()
|
||||
>= screen.geometry().height() - TILED_SLACK)
|
||||
|
||||
|
||||
def _radius(window: QWidget) -> int:
|
||||
"""Round corners only on a free-floating, see-through window: maximized,
|
||||
fullscreen or tiled windows meet the screen's edges or a neighbour."""
|
||||
see_through = window.testAttribute(
|
||||
Qt.WidgetAttribute.WA_TranslucentBackground)
|
||||
return RADIUS if see_through and _framed(window) else 0
|
||||
if not see_through or not _framed(window) or tiled(window):
|
||||
return 0
|
||||
return RADIUS
|
||||
|
||||
|
||||
def _outline(rect: QRect, radius: int) -> QPainterPath:
|
||||
@@ -178,7 +196,8 @@ class _Frame(QWidget):
|
||||
for x, y in ((0, 0), (w - k, 0), (0, h - k), (w - k, h - k)):
|
||||
ring = ring.united(QRegion(x, y, k, k))
|
||||
self.setMask(ring)
|
||||
self.setVisible(_framed(window))
|
||||
self.show()
|
||||
self.update()
|
||||
self.raise_()
|
||||
|
||||
def paintEvent(self, _event):
|
||||
@@ -199,10 +218,13 @@ class _Frame(QWidget):
|
||||
rims.setColorAt(0.94, QColor(0, 0, 0, 0))
|
||||
rims.setColorAt(1, bg.darker(112))
|
||||
inner = QPainterPath()
|
||||
inner.addRoundedRect(QRectF(self.rect()).adjusted(1.5, 1.5, -1.5, -1.5),
|
||||
max(0, r - 1), max(0, r - 1))
|
||||
# The rims start just inside the outline and run RIM_WIDTH in.
|
||||
inset = 1 + RIM_WIDTH / 2
|
||||
inner.addRoundedRect(
|
||||
QRectF(self.rect()).adjusted(inset, inset, -inset, -inset),
|
||||
max(0.0, r - inset + 0.5), max(0.0, r - inset + 0.5))
|
||||
painter.setBrush(Qt.BrushStyle.NoBrush)
|
||||
painter.setPen(QPen(QBrush(rims), 1.5))
|
||||
painter.setPen(QPen(QBrush(rims), RIM_WIDTH))
|
||||
painter.drawPath(inner)
|
||||
painter.setPen(QPen(bg.darker(128), 1))
|
||||
painter.drawPath(path)
|
||||
@@ -485,6 +507,17 @@ class TitleBarInstaller(QObject):
|
||||
if (isinstance(obj, QWidget) and obj.isWindow()
|
||||
and obj.property(_DONE)):
|
||||
paint_window_background(obj)
|
||||
elif kind == QEvent.Type.ParentChange:
|
||||
# Polished while parentless (a style sheet set before it went
|
||||
# into a layout), it looked like a window: undo it, or a
|
||||
# see-through child paints no background of its own.
|
||||
if (isinstance(obj, QWidget) and not obj.isWindow()
|
||||
and obj.property(_DONE) == "frameless"):
|
||||
obj.setProperty(_DONE, None)
|
||||
obj.setAttribute(
|
||||
Qt.WidgetAttribute.WA_TranslucentBackground, False)
|
||||
obj.setAttribute(
|
||||
Qt.WidgetAttribute.WA_NoSystemBackground, False)
|
||||
elif kind == QEvent.Type.Polish:
|
||||
if wants_bar(obj) and not obj.property(_DONE) and not (
|
||||
obj.windowFlags() & Qt.WindowType.FramelessWindowHint):
|
||||
|
||||
Reference in New Issue
Block a user