diff --git a/CLAUDE.md b/CLAUDE.md index 147abc7..734f765 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1311,14 +1311,18 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal on its own window — that is called during the window's teardown and aborts. **The window is the house tile** (Round 126, design.html#window, after routine-widget): translucent with 10 px round corners (square when - maximized), its gray filled by the installer on the window's `Paint`, and + maximized, fullscreen or `titlebar.tiled` — within 64 px of the screen's + height, since Qt hides Wayland's tiled state), its gray filled by the installer on the window's `Paint`, and `titlebar._Frame` — a mouse-transparent overlay masked to the edge ring, on top of everything — clears outside the curve and paints the soft emboss and outline. No line under the title bar, nor under the menu bar (`ClickToJumpScrollStyle.drawControl` paints over Fusion's). The main window sets `BLANK_TITLE` (the song is in the panel right under it); `VisualizerWindow` sets `SQUARE` — Kaleidostrobe's GL clears to alpha 0, - which would show the desktop through a translucent window. + which would show the desktop through a translucent window. A widget + polished while parentless looks like a window to the installer, so a + `ParentChange` takes the translucency back off — kept on, the now-playing + panel (style sheet set before it had a parent) painted no background. - **Music files are only touched deliberately:** tag edits via `tagging.py`, and — since Round 18 — artist/album_artist/album edits relocate the file inside `LibraryManager.organize_root()` (`/Music`) to keep the diff --git a/lintunes/__init__.py b/lintunes/__init__.py index 2113580..b3c1565 100644 --- a/lintunes/__init__.py +++ b/lintunes/__init__.py @@ -1,3 +1,3 @@ """LinTunes — iTunes-style music library manager and player for Linux.""" -__version__ = "0.91.0" +__version__ = "0.91.1" diff --git a/lintunes/gui/titlebar.py b/lintunes/gui/titlebar.py index 2d46ec3..0f1d800 100644 --- a/lintunes/gui/titlebar.py +++ b/lintunes/gui/titlebar.py @@ -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): diff --git a/tests/test_round126.py b/tests/test_round126.py index 9f59de0..60d31ec 100644 --- a/tests/test_round126.py +++ b/tests/test_round126.py @@ -52,11 +52,31 @@ def test_no_line_under_the_title_bar(installed): dialog.close() -def test_maximized_corners_are_square(installed): +def test_maximized_and_tiled_corners_are_square(installed, monkeypatch): dialog = _dialog() dialog.setWindowState(Qt.WindowState.WindowMaximized) QApplication.processEvents() - assert not title_bar(dialog)._frame.isVisible() + assert titlebar._radius(dialog) == 0 + # The emboss stays, as in routine-widget. + assert title_bar(dialog)._frame.isVisible() + dialog.setWindowState(Qt.WindowState.WindowNoState) + QApplication.processEvents() + assert titlebar._radius(dialog) == titlebar.RADIUS + monkeypatch.setattr(titlebar, "tiled", lambda window: True) + assert titlebar._radius(dialog) == 0 + dialog.close() + + +def test_a_child_styled_before_it_had_a_parent_still_paints(installed): + from PyQt6.QtWidgets import QFrame + frame = QFrame() # parentless: polishing it sees a window + frame.setStyleSheet("QFrame { background: #ff0000; }") + frame.ensurePolished() + dialog = _dialog() + dialog.layout().addWidget(frame) + assert not frame.testAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + frame.resize(40, 20) + assert frame.grab().toImage().pixelColor(20, 10).name() == "#ff0000" dialog.close()