Add Media OSD functions

This commit is contained in:
Mridul Agarwal
2026-01-13 22:50:27 +05:30
parent bec32a30e9
commit 962b3b2128
+127 -10
View File
@@ -19,7 +19,8 @@ Variants {
Volume,
InputVolume,
Brightness,
LockKey
LockKey,
Media
}
model: Quickshell.screens.filter(screen => (Settings.data.osd.monitors.includes(screen.name) || Settings.data.osd.monitors.length === 0) && Settings.data.osd.enabled)
@@ -39,6 +40,11 @@ Variants {
// Lock Key States
property string lastLockKeyChanged: "" // "caps", "num", "scroll", or ""
// Media States
property string mediaAction: "" // "play", "pause", or ""
property string mediaTrackTitle: ""
property string mediaTrackArtist: ""
// Current values (computed properties)
readonly property real currentVolume: AudioService.volume
readonly property bool isMuted: AudioService.muted
@@ -78,6 +84,12 @@ Variants {
return currentBrightness <= 0.5 ? "brightness-low" : "brightness-high";
case OSD.Type.LockKey:
return "keyboard";
case OSD.Type.Media:
if (root.mediaAction === "pause")
return "player-pause";
if (root.mediaAction === "play")
return "player-play";
return "music";
default:
return "";
}
@@ -93,6 +105,8 @@ Variants {
return currentBrightness;
case OSD.Type.LockKey:
return 1.0; // Always show 100% when showing lock key status
case OSD.Type.Media:
return 1.0; // Always show full for media
default:
return 0;
}
@@ -111,6 +125,21 @@ Variants {
return lastLockKeyChanged;
}
if (currentOSDType === OSD.Type.Media) {
// For media, show the action or track info
if (root.mediaTrackTitle) {
return root.mediaTrackTitle;
}
switch (root.mediaAction) {
case "play":
return "Playing";
case "pause":
return "Paused";
default:
return "Media";
}
}
const value = getCurrentValue();
const max = getMaxValue();
if ((currentOSDType === OSD.Type.Volume || currentOSDType === OSD.Type.InputVolume) && Settings.data.audio.volumeOverdrive) {
@@ -144,6 +173,10 @@ Variants {
return LockKeysService.scrollLockOn ? Color.mPrimary : Color.mOnSurfaceVariant;
}
}
// For media, use primary color
if (currentOSDType === OSD.Type.Media) {
return Color.mPrimary;
}
return Color.mPrimary;
}
@@ -163,6 +196,10 @@ Variants {
}
}
if (currentOSDType === OSD.Type.Media) {
return Color.mPrimary;
}
return Color.mOnSurface;
}
@@ -185,6 +222,14 @@ Variants {
showOSD(OSD.Type.Brightness);
}
// Media Control handling
function triggerMediaAction(action) {
root.mediaAction = action;
root.mediaTrackTitle = MediaService.trackTitle;
root.mediaTrackArtist = MediaService.trackArtist;
showOSD(OSD.Type.Media);
}
// Check if a specific OSD type is enabled
function isTypeEnabled(type) {
const enabledTypes = Settings.data.osd.enabledTypes || [];
@@ -283,6 +328,48 @@ Variants {
}
}
// Media playback monitoring
Connections {
target: MediaService
function onIsPlayingChanged() {
if (MediaService.isPlaying) {
root.mediaAction = "play";
root.mediaTrackTitle = MediaService.trackTitle;
root.mediaTrackArtist = MediaService.trackArtist;
showOSD(OSD.Type.Media);
} else {
// Show OSD when track is paused
root.mediaAction = "pause";
root.mediaTrackTitle = MediaService.trackTitle;
root.mediaTrackArtist = MediaService.trackArtist;
showOSD(OSD.Type.Media);
}
}
function onCurrentPlayerChanged() {
// Show OSD when a new player takes over
if (MediaService.currentPlayer) {
root.mediaTrackTitle = MediaService.trackTitle;
root.mediaTrackArtist = MediaService.trackArtist;
if (MediaService.isPlaying) {
root.mediaAction = "play";
showOSD(OSD.Type.Media);
}
}
}
function onTrackTitleChanged() {
// Show OSD when track changes
root.mediaTrackTitle = MediaService.trackTitle;
root.mediaTrackArtist = MediaService.trackArtist;
root.mediaAction = "play";
if (MediaService.isPlaying) {
showOSD(OSD.Type.Media);
}
}
}
// LockKeys monitoring with a cleaner approach
// Only connect when LockKey OSD is enabled to avoid starting the service unnecessarily
Connections {
@@ -557,9 +644,23 @@ Variants {
Layout.alignment: Qt.AlignVCenter
}
// Media Information Text (replaces progress bar)
NText {
visible: root.currentOSDType === OSD.Type.Media
text: root.getDisplayPercentage()
color: Color.mOnSurface
pointSize: Style.fontSizeS
family: Settings.data.ui.fontFixed
font.weight: Style.fontWeightRegular
elide: Text.ElideRight
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignVCenter
}
// Progress Bar for Volume/Brightness
Rectangle {
visible: root.currentOSDType !== OSD.Type.LockKey
visible: root.currentOSDType !== OSD.Type.LockKey && root.currentOSDType !== OSD.Type.Media
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
height: panel.barThickness
@@ -591,7 +692,7 @@ Variants {
// Percentage Text for Volume/Brightness
NText {
visible: root.currentOSDType !== OSD.Type.LockKey
visible: root.currentOSDType !== OSD.Type.LockKey && root.currentOSDType !== OSD.Type.Media
text: root.getDisplayPercentage()
color: Color.mOnSurface
pointSize: Style.fontSizeS
@@ -613,8 +714,8 @@ Variants {
anchors.fill: parent
anchors.topMargin: Style.marginL
anchors.bottomMargin: Style.marginL
spacing: root.currentOSDType === OSD.Type.LockKey ? Style.marginM : Style.marginS
clip: root.currentOSDType !== OSD.Type.LockKey
spacing: root.currentOSDType === OSD.Type.LockKey || root.currentOSDType === OSD.Type.Media ? Style.marginM : Style.marginS
clip: root.currentOSDType !== OSD.Type.LockKey && root.currentOSDType !== OSD.Type.Media
ColumnLayout {
id: textVerticalLayout
@@ -673,7 +774,7 @@ Variants {
}
NText {
visible: root.currentOSDType !== OSD.Type.LockKey
visible: root.currentOSDType !== OSD.Type.LockKey && root.currentOSDType !== OSD.Type.Media
text: root.getDisplayPercentage()
color: Color.mOnSurface
pointSize: Style.fontSizeS
@@ -686,10 +787,26 @@ Variants {
Layout.preferredHeight: Math.round(20 * Style.uiScaleRatio)
}
Item {
visible: root.currentOSDType !== OSD.Type.LockKey
NText {
visible: root.currentOSDType === OSD.Type.Media
text: root.getDisplayPercentage()
color: Color.mOnSurface
pointSize: Style.fontSizeXS
family: Settings.data.ui.fontFixed
font.weight: Style.fontWeightRegular
Layout.fillWidth: true
Layout.fillHeight: root.currentOSDType !== OSD.Type.LockKey
Layout.alignment: Qt.AlignHCenter
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
Layout.preferredHeight: Math.round(20 * Style.uiScaleRatio)
elide: Text.ElideRight
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
Item {
visible: root.currentOSDType !== OSD.Type.LockKey && root.currentOSDType !== OSD.Type.Media
Layout.fillWidth: true
Layout.fillHeight: root.currentOSDType !== OSD.Type.LockKey && root.currentOSDType !== OSD.Type.Media
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
@@ -778,4 +895,4 @@ Variants {
}
}
}
}
}