mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-14 07:14:00 -04:00
* fix(bar): keep widget content on whole pixels Bar widgets centre their content inside a box of widgetThickness - horizontalPadding * 2, and Qt rounds the offset of a centred anchor to whole pixels. When the content and that box have different parity the exact offset falls on a half pixel, Qt rounds it away from zero and the content renders half a pixel above the centre. Widgets drawn from rectangles, such as the workspace switcher, compute their own snapped height and stay exactly centred, which is why they look right next to everything else in #3074. With the stock configuration this is the normal case: the bar is 40 px, the box is 14 px and barIconSize returns round((40 / 48) * 18) = 15. Two sizes now round to whole pairs of pixels. The icon size, so that it matches the parity of the box, and widgetThickness, because the box inherits its parity from there (the padding is doubled, so it never changes it). Going through every innerPadding from 0 to 16, nine of the seventeen configurations currently put the icon on a half pixel and none of them do afterwards. The 48 px default bar is untouched, the sizes that change do so by one pixel. Measured in a nested Hyprland at scale 1, ink centroid of the widget content relative to the centre of its pill, before and after: launcher -0.50 +0.00 weather -0.81 -0.52 clipboard -1.49 -0.93 notifications +0.03 +0.46 battery -0.63 -0.49 bluetooth -0.53 -0.03 Every icon moves down by half a pixel. What remains matches the ink asymmetry of the individual glyphs, measured separately at an exact position, and is not a placement error. Two things this does not cover. On a fractional or HiDPI scale horizontalPadding can land on a half pixel, which puts the box back between the grid lines, and a text only widget such as the clock has a line box of 15 px at the default font size, which cannot sit exactly on the centre of a 28 px pill no matter how it is rounded. Closes #3074 * fix(bar): give bar text a line box that can be centred A widget without an icon is centred as one line box, and the same parity rule applies to it as to the icon in the commit before this one. At fontSizeSmall the line box of the bar font is 15 px tall, so on a 28 px pill it cannot sit on the centre no matter which way the offset is rounded, and the clock reads about half a pixel high next to everything else. One step up the box is 16 px and it lands on the grid. Only the branch the standard bar uses changes. The 0.9 branch below a scale of 0.75 already comes out at 14 px, and the fontSizeMedium branch above 1.25 is left alone because there the next even box is two steps away, which would be a bigger change than this is worth. Same session and same measurement as the previous commit, ink centroid of the widget content relative to the centre of its pill: clock and date -0.58 +0.05 battery -0.63 -0.05 weather -0.82 -0.28 The bar font goes from 12 px to 13 px, which is the visible part of this and the reason it is a separate commit. It can be dropped without touching the icon fix. * bar: snap widget thickness to even device pixels and pick text sizes by line box parity * bar: snap bar thickness to even so the pill centres on whole pixels * bar: share the bar thickness formula so dock, osd and popouts stay in step * dock: read the bar clearance at the compositor screen scale --------- Co-authored-by: bbedward <[email protected]>
92 lines
3.1 KiB
QML
92 lines
3.1 KiB
QML
import QtQuick
|
|
import qs.Common
|
|
import qs.Modals.Common
|
|
import qs.Services
|
|
import qs.Modules.PowerMenu
|
|
|
|
DankModal {
|
|
id: root
|
|
|
|
layerNamespace: "dms:power-menu"
|
|
keepPopoutsOpen: true
|
|
useOverlayLayer: true
|
|
|
|
property rect parentBounds: Qt.rect(0, 0, 0, 0)
|
|
property var parentScreen: null
|
|
|
|
signal powerActionRequested(string action, string title, string message)
|
|
signal lockRequested
|
|
signal switchUserRequested
|
|
|
|
function openCentered() {
|
|
parentBounds = Qt.rect(0, 0, 0, 0);
|
|
parentScreen = null;
|
|
open();
|
|
}
|
|
|
|
function openFromControlCenter(bounds, targetScreen) {
|
|
parentBounds = bounds;
|
|
parentScreen = targetScreen;
|
|
open();
|
|
}
|
|
|
|
shouldBeVisible: false
|
|
modalWidth: contentLoader.item?.desiredWidth ?? 400
|
|
modalHeight: contentLoader.item ? contentLoader.item.implicitHeight : 300
|
|
enableShadow: true
|
|
targetScreen: parentScreen
|
|
positioning: parentBounds.width > 0 ? "custom" : "center"
|
|
customPosition: {
|
|
if (parentBounds.width > 0) {
|
|
const bar = SettingsData.getPrimaryBarConfig();
|
|
const effectiveBarThickness = Theme.barThickness(bar?.innerPadding ?? 4, CompositorService.getScreenScale(parentScreen));
|
|
const barExclusionZone = effectiveBarThickness + (bar?.spacing ?? 4) + (bar?.bottomGap ?? 0);
|
|
const barPosition = bar?.position ?? SettingsData.Position.Top;
|
|
const screenW = parentScreen?.width ?? 1920;
|
|
const screenH = parentScreen?.height ?? 1080;
|
|
const margin = Theme.spacingL;
|
|
|
|
let targetX = parentBounds.x + (parentBounds.width - modalWidth) / 2;
|
|
let targetY = parentBounds.y + (parentBounds.height - modalHeight) / 2;
|
|
|
|
const topChrome = Math.max(bar && barPosition === SettingsData.Position.Top ? barExclusionZone : 0, SettingsData.dankIslandEdgeOffset(parentScreen, "top"));
|
|
const bottomChrome = Math.max(bar && barPosition === SettingsData.Position.Bottom ? barExclusionZone : 0, SettingsData.dankIslandEdgeOffset(parentScreen, "bottom"));
|
|
const minY = topChrome + margin;
|
|
const maxY = screenH - modalHeight - bottomChrome - margin;
|
|
|
|
targetY = Math.max(minY, Math.min(maxY, targetY));
|
|
|
|
return Qt.point(targetX, targetY);
|
|
}
|
|
return Qt.point(0, 0);
|
|
}
|
|
onBackgroundClicked: () => {
|
|
contentLoader.item?.cancelHold();
|
|
close();
|
|
}
|
|
onShouldBeVisibleChanged: {
|
|
if (!shouldBeVisible)
|
|
return;
|
|
contentLoader.item?.resetState();
|
|
}
|
|
onShouldHaveFocusChanged: {
|
|
if (!shouldHaveFocus)
|
|
return;
|
|
Qt.callLater(() => contentLoader.item?.forceActiveFocus());
|
|
}
|
|
onDialogClosed: () => {
|
|
contentLoader.item?.cancelHold();
|
|
}
|
|
|
|
content: Component {
|
|
PowerMenuContent {
|
|
anchors.fill: parent
|
|
focus: true
|
|
onPowerActionRequested: action => root.powerActionRequested(action, "", "")
|
|
onLockRequested: root.lockRequested()
|
|
onSwitchUserRequested: root.switchUserRequested()
|
|
onCloseRequested: root.close()
|
|
}
|
|
}
|
|
}
|