1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-28 07:22:50 -05:00

smarter distance calculation

This commit is contained in:
bbedward
2025-07-24 15:09:28 -04:00
parent 8bcac36be3
commit c6df2bc11d
10 changed files with 423 additions and 486 deletions

View File

@@ -5,64 +5,13 @@ import qs.Services
Rectangle {
id: root
// Dynamic screen detection for laptop vs desktop monitor
readonly property bool isSmallScreen: {
// Walk up the parent chain to find the TopBar PanelWindow
let current = root.parent
while (current && !current.screen) {
current = current.parent
}
if (!current || !current.screen) {
return true // Default to small if we can't detect
}
const s = current.screen
// Multi-method detection for laptop/small screens:
// Method 1: Check screen name for laptop indicators
const screenName = (s.name || "").toLowerCase()
if (screenName.includes("edp") || screenName.includes("lvds")) {
return true
}
// Method 2: Check pixel density if available
try {
if (s.pixelDensity && s.pixelDensity > 1.5) {
return true
}
} catch (e) { /* ignore */ }
// Method 3: Check device pixel ratio if available
try {
if (s.devicePixelRatio && s.devicePixelRatio > 1.25) {
return true
}
} catch (e) { /* ignore */ }
// Method 4: Resolution-based fallback for smaller displays
if (s.width <= 1920 && s.height <= 1200) {
return true
}
// Method 5: Check for high-res laptop displays
if ((s.width === 2400 && s.height === 1600) ||
(s.width === 2560 && s.height === 1600) ||
(s.width === 2880 && s.height === 1800)) {
return true
}
return false // Default to large screen
}
// Dynamic sizing based on screen type
readonly property int maxWidth: isSmallScreen ? 288 : 456
readonly property int appNameMaxWidth: isSmallScreen ? 130 : 180
readonly property int separatorWidth: 15
readonly property int titleMaxWidth: maxWidth - appNameMaxWidth - separatorWidth - (Theme.spacingS * 2)
property bool compactMode: false
property int availableWidth: 400
readonly property int baseWidth: contentRow.implicitWidth + Theme.spacingS * 2
readonly property int maxNormalWidth: 456
readonly property int maxCompactWidth: 200
width: Math.min(contentRow.implicitWidth + Theme.spacingS * 2, maxWidth)
width: compactMode ? Math.min(baseWidth, maxCompactWidth) : Math.min(baseWidth, maxNormalWidth)
height: 30
radius: Theme.cornerRadius
color: mouseArea.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08)
@@ -83,10 +32,9 @@ Rectangle {
font.weight: Font.Medium
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
// App name gets reasonable space - only truncate if absolutely necessary
elide: Text.ElideRight
maximumLineCount: 1
width: Math.min(implicitWidth, root.appNameMaxWidth)
width: Math.min(implicitWidth, compactMode ? 80 : 180)
}
Text {
@@ -105,17 +53,15 @@ Rectangle {
font.weight: Font.Medium
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
// Window title gets remaining space and shows ellipsis when truncated
elide: Text.ElideRight
maximumLineCount: 1
width: Math.min(implicitWidth, root.titleMaxWidth)
width: Math.min(implicitWidth, compactMode ? 60 : 250)
visible: !compactMode || text.length < 15
}
}
MouseArea {
// Non-interactive widget - just provides hover state for visual feedback
id: mouseArea
anchors.fill: parent
@@ -130,7 +76,6 @@ Rectangle {
}
// Smooth width animation when the text changes
Behavior on width {
NumberAnimation {
duration: Theme.shortDuration