Skip to content

Commit

Permalink
Add blur support
Browse files Browse the repository at this point in the history
  • Loading branch information
luisbocanegra committed Mar 20, 2024
1 parent 6c8f815 commit 9da768f
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 4 deletions.
18 changes: 18 additions & 0 deletions package/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,23 @@
<label>Pause video when battery is below PauseBatteryLevel</label>
<default>true</default>
</entry>
<entry name="BatteryDisablesBlur" type="Bool">
<label>Disable blur when battery is below PauseBatteryLevel</label>
<default>false</default>
</entry>
<!-- Show blur
0: when existing a maximized or full-screen windows
1: when a visible window is active
2: when a window is visible
3: video is paused
4: always
5: never
-->
<entry name="BlurMode" type="Int">
<default>0</default>
</entry>
<entry name="BlurRadius" type="Int">
<default>32</default>
</entry>
</group>
</kcfg>
28 changes: 28 additions & 0 deletions package/contents/ui/WindowModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Item {
property var screenGeometry
property int pauseMode: wallpaper.configuration.PauseMode
property bool playVideoWallpaper: false
property bool videoIsPlaying: false
property int blurMode: wallpaper.configuration.BlurMode
property bool showBlur: false
property bool maximizedExists: false
property bool visibleExists: false
property bool activeExists: false
Expand Down Expand Up @@ -62,6 +65,30 @@ Item {
playVideoWallpaper = shouldPlay
}

function updateBlur() {
let shouldBlur = true
switch(blurMode) {
case 0:
shouldBlur = maximizedExists
break
case 1:
shouldBlur = activeExists
break
case 2:
shouldBlur = visibleExists
break
case 3:
shouldBlur = !videoIsPlaying
break
case 4:
shouldBlur = true
break
case 5:
shouldBlur = false
}
showBlur = shouldBlur
}

TaskManager.VirtualDesktopInfo {
id: virtualDesktopInfo
}
Expand Down Expand Up @@ -113,6 +140,7 @@ Item {
maximizedExists = maximizedCount > 0
activeExists = activeCount > 0
updatePlay()
updateBlur()
}
}

75 changes: 75 additions & 0 deletions package/contents/ui/config.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Kirigami.FormLayout {
property alias cfg_BackgroundColor: colorButton.color
property int cfg_PauseBatteryLevel: pauseBatteryLevel.value
property bool cfg_BatteryPausesVideo: batteryPausesVideo.checked
property int cfg_BlurMode: wallpaper.configuration.BlurMode
property bool cfg_BatteryDisablesBlur: wallpaper.configuration.BatteryDisablesBlur
property int cfg_BlurRadius: wallpaper.configuration.BlurRadius

RowLayout {
Layout.fillWidth:true
Expand Down Expand Up @@ -158,6 +161,70 @@ Kirigami.FormLayout {
}
}


RadioButton {
id: maximizedBlurRadioButtton
Kirigami.FormData.label: i18nd("@buttonGroup:blur_mode", "Blur video:")
text: i18n("When there are maximized or full-screen windows")
ButtonGroup.group: blurModeGroup
property int index: 0
checked: wallpaper.configuration.BlurMode === index
}
RadioButton {
id: busyBlurRadioButton
text: i18n("When an active window is shown")
ButtonGroup.group: blurModeGroup
property int index: 1
checked: wallpaper.configuration.BlurMode === index
}
RadioButton {
id: visibleBlurRadioButton
text: i18n("When a window is shown")
ButtonGroup.group: blurModeGroup
property int index: 2
checked: wallpaper.configuration.BlurMode === index
}
RadioButton {
id: pausedBlurRadioButton
text: i18n("When video is paused")
ButtonGroup.group: blurModeGroup
property int index: 3
checked: wallpaper.configuration.BlurMode === index
}
RadioButton {
id: alwaysBlurRadioButton
text: i18n("Always")
ButtonGroup.group: blurModeGroup
property int index: 4
checked: wallpaper.configuration.BlurMode === index
}
RadioButton {
id: neverBlurRadioButton
text: i18n("Never")
ButtonGroup.group: blurModeGroup
property int index: 5
checked: wallpaper.configuration.BlurMode === index
}
ButtonGroup {
id: blurModeGroup
onCheckedButtonChanged: {
if (checkedButton) {
cfg_BlurMode = checkedButton.index
}
}
}

SpinBox {
Kirigami.FormData.label: i18nd("@checkGroup:battery_mode", "Blur radius")
id: blurRadiusSpinBox
from: 0
to: 145
value: cfg_BlurRadius
onValueChanged: {
cfg_BlurRadius = value
}
}

RowLayout {
Kirigami.FormData.label: i18nd("@checkGroup:battery_mode", "On Battery below:")
SpinBox {
Expand All @@ -182,6 +249,14 @@ Kirigami.FormLayout {
}
}

CheckBox {
text: i18n("Disable blur")
checked: cfg_BatteryDisablesBlur
onCheckedChanged: {
cfg_BatteryDisablesBlur = checked
}
}

FileDialog {
id: fileDialog
fileMode : FileDialog.OpenFile
Expand Down
23 changes: 19 additions & 4 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ import org.kde.plasma.core as Plasmacore
import QtMultimedia
import org.kde.plasma.plasma5support as P5Support
import org.kde.plasma.plasmoid
import Qt5Compat.GraphicalEffects

WallpaperItem {
anchors.fill: parent
id: main
property string videoWallpaperBackgroundVideo: wallpaper.configuration.VideoWallpaperBackgroundVideo
property bool playing: windowModel.playVideoWallpaper && !pauseBattery
property bool isLoading: true
property string videoWallpaperBackgroundVideo: wallpaper.configuration.VideoWallpaperBackgroundVideo
property int pauseBatteryLevel: wallpaper.configuration.PauseBatteryLevel
property bool playing: windowModel.playVideoWallpaper && !batteryPausesVideo
property bool batteryPausesVideo: pauseBattery && wallpaper.configuration.BatteryPausesVideo

property bool showBlur: windowModel.showBlur && !batteryDisablesBlur
property bool batteryDisablesBlur: pauseBattery && wallpaper.configuration.BatteryDisablesBlur

onPlayingChanged: {
playing && !isLoading ? main.play() : main.pause()
Expand All @@ -47,11 +52,9 @@ WallpaperItem {
onSourceAdded: source => {
disconnectSource(source);
connectSource(source);
dumpProps(pmSource.connectedSources)
}
onSourceRemoved: source => {
disconnectSource(source);
dumpProps(pmSource.connectedSources)
}
}

Expand All @@ -66,6 +69,7 @@ WallpaperItem {
WindowModel {
id: windowModel
screenGeometry: main.parent.screenGeometry
videoIsPlaying: main.playing
}

Rectangle {
Expand All @@ -83,6 +87,17 @@ WallpaperItem {
}
}

FastBlur {
source: player
radius: showBlur ? wallpaper.configuration.BlurRadius : 0
anchors.fill: parent
Behavior on radius {
NumberAnimation {
duration: 300
}
}
}

function play(){
pauseTimer.stop();
player.play();
Expand Down

0 comments on commit 9da768f

Please sign in to comment.