Skip to content

Commit 1f0845c

Browse files
committed
focus and selected display fix
- focus fix for wallpaper playback. - fixed a bug where if selected display deviceid is missing and bounds are incorrect - wallpaper loads with incorrect data. - hw accel flag for mpv player. - updated attribution doc.
1 parent d13276d commit 1f0845c

File tree

8 files changed

+188
-176
lines changed

8 files changed

+188
-176
lines changed

src/livelywpf/livelywpf/App.xaml.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Data;
3-
using System.Globalization;
43
using System.IO;
54
using System.Linq;
65
using System.Threading.Tasks;

src/livelywpf/livelywpf/Core/Display/LivelyScreen.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class LivelyScreen
2424
public LivelyScreen(string DeviceId, string DeviceName, int BitsPerPixel, Rectangle Bounds, Rectangle WorkingArea)
2525
{
2626
//Backward compatibility: lively < v1.1.9 does not have DeviceId.
27-
this.DeviceId = DeviceId ?? (ScreenHelper.GetScreen().FirstOrDefault(x => x.Bounds == Bounds)?.DeviceId);
27+
this.DeviceId = DeviceId ?? (ScreenHelper.GetScreen().FirstOrDefault(x => x.Bounds == Bounds)?.DeviceId);
2828
this.DeviceName = DeviceName;
2929
this.DeviceNumber = ScreenHelper.GetScreenNumber(DeviceName);
3030
this.BitsPerPixel = BitsPerPixel;

src/livelywpf/livelywpf/Core/Playback/Playback.cs

+19-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static PlaybackState WallpaperPlaybackState
4646
private readonly DispatcherTimer dispatcherTimer = new DispatcherTimer();
4747
private bool _isLockScreen, _isRemoteSession;
4848
private bool disposedValue;
49+
private int livelyPid = 0;
4950

5051
public Playback()
5152
{
@@ -69,6 +70,18 @@ private void Initialize()
6970
InitializeTimer();
7071
WallpaperPlaybackState = PlaybackState.play;
7172

73+
try
74+
{
75+
using (Process process = Process.GetCurrentProcess())
76+
{
77+
livelyPid = process.Id;
78+
}
79+
}
80+
catch (Exception e)
81+
{
82+
Logger.Error("Failed to retrieve Lively Pid:" + e.Message);
83+
}
84+
7285
// Check if already in remote/lockscreen session.
7386
_isRemoteSession = System.Windows.Forms.SystemInformation.TerminalServerSession;
7487
if (_isRemoteSession)
@@ -187,10 +200,7 @@ private void ForegroundAppMonitor()
187200
return;
188201
}
189202

190-
if (fProcess.ProcessName.Equals("livelywpf", StringComparison.OrdinalIgnoreCase) ||
191-
fProcess.ProcessName.Equals("livelycefsharp", StringComparison.OrdinalIgnoreCase) ||
192-
fProcess.ProcessName.Equals("libvlcplayer", StringComparison.OrdinalIgnoreCase) ||
193-
fProcess.ProcessName.Equals("libmpvplayer", StringComparison.OrdinalIgnoreCase))
203+
if (fProcess.Id == livelyPid || IsLivelyPlugin(fProcess.Id))
194204
{
195205
PlayWallpapers();
196206
SetWallpaperVolume(Program.SettingsVM.Settings.AudioVolumeGlobal);
@@ -401,6 +411,11 @@ private static void SetWallpaperVolume(int volume, LivelyScreen display)
401411
});
402412
}
403413

414+
private static bool IsLivelyPlugin(int pid)
415+
{
416+
return SetupDesktop.Wallpapers.Exists(x => x.GetProcess() != null && x.GetProcess().Id == pid);
417+
}
418+
404419
/// <summary>
405420
/// Checks if hWnd window size is >95% for its running screen.
406421
/// </summary>

src/livelywpf/livelywpf/Core/Wallpapers/VideoMpvPlayer.cs

+8-10
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ public class VideoMpvPlayer : IWallpaper
2424
Process Proc { get; set; }
2525
LibraryModel Model { get; set; }
2626
LivelyScreen Display { get; set; }
27-
public UInt32 SuspendCnt { get; set; }
2827
private readonly CancellationTokenSource ctsProcessWait = new CancellationTokenSource();
2928
private Task processWaitTask;
3029
private readonly int timeOut;
3130
private readonly string ipcServerName;
3231
JObject livelyPropertiesData;
3332
string LivelyPropertyCopy { get; set; }
3433

35-
//todo: yt-dl support.
3634
public VideoMpvPlayer(string path, LibraryModel model, LivelyScreen display,
3735
WallpaperScaler scaler = WallpaperScaler.fill, StreamQualitySuggestion streamQuality = StreamQualitySuggestion.Highest)
3836
{
@@ -84,24 +82,25 @@ public VideoMpvPlayer(string path, LibraryModel model, LivelyScreen display,
8482

8583
ipcServerName = "mpvsocket" + Path.GetRandomFileName();
8684
string cmdArgs =
87-
//always create gui window
88-
"--force-window=yes " +
85+
"--volume=0 " +
8986
//alternative: --loop-file=inf
9087
"--loop-file " +
9188
//do not close after media end
9289
"--keep-open " +
93-
//gpu decode preferred
94-
"--hwdec=auto " +
90+
//always create gui window
91+
"--force-window=yes " +
92+
//open window at (-9999,0)
93+
"--geometry=-9999:0 " +
9594
//allow screensaver
9695
"--stop-screensaver=no " +
97-
//open window at (-9999,0)
98-
"--geometry=-9999:0 " +
9996
//alternative: --input-ipc-server=\\.\pipe\
10097
"--input-ipc-server=" + ipcServerName + " " +
10198
//stretch algorithm
10299
scalerArg + " " +
103100
//integer scaler for sharpness
104-
(model.LivelyInfo.Type == WallpaperType.gif ? "--scale=nearest " : " ") +
101+
(model.LivelyInfo.Type == WallpaperType.gif ? "--scale=nearest " : " ") +
102+
//gpu decode preference
103+
(Program.SettingsVM.Settings.VideoPlayerHwAccel ? "--hwdec=auto " : "--hwdec=no ") +
105104
//file, stream path
106105
(model.LivelyInfo.Type == WallpaperType.videostream ? Helpers.StreamHelper.YoutubeDLMpvArgGenerate(streamQuality, path) : "\"" + path + "\"");
107106

@@ -122,7 +121,6 @@ public VideoMpvPlayer(string path, LibraryModel model, LivelyScreen display,
122121
this.Model = model;
123122
this.Display = display;
124123
this.timeOut = 20000;
125-
SuspendCnt = 0;
126124
}
127125

128126
public async void Close()

0 commit comments

Comments
 (0)