Skip to content

Commit

Permalink
add wallpaper support fix #19
Browse files Browse the repository at this point in the history
  • Loading branch information
mgth committed Jan 22, 2018
1 parent 51fcd11 commit effdafd
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 2 deletions.
2 changes: 1 addition & 1 deletion HLab/Windows.API/WinAPI_SetupAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SP_DEVINFO_DATA(bool init)

public static Guid GUID_CLASS_MONITOR = new Guid(0x4d36e96e, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18);
const int MAX_DEVICE_ID_LEN = 200;
const int MAX_PATH = 260;
public const int MAX_PATH = 260;

public const int DIGCF_PRESENT = 0x2;
public const int DIGCF_PROFILE = 0x8;
Expand Down
6 changes: 6 additions & 0 deletions HLab/Windows.API/WinAPI_User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,5 +1582,11 @@ public struct AccentPolicy
public int GradientColor;
public int AnimationId;
}

public const uint SPI_GETDESKWALLPAPER = 0x73;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(UInt32 uAction, int uParam, string lpvParam, int fuWinIni);

}
}
4 changes: 4 additions & 0 deletions HLab/Windows.Monitors/DispalyChangesView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam
{
var message = (WindowMessage)msg;
var subCode = (WindowMessageParameter)wParam.ToInt64();
if (message == WindowMessage.WM_WININICHANGE)
{
//MonitorsService.D.UpdateDevices();
}

if (message == WindowMessage.WM_DISPLAYCHANGE /*|| message == WindowMessage.WM_WININICHANGE*/)
{
Expand Down
4 changes: 4 additions & 0 deletions LittleBigMouse/Control.Core/ScreenFrameView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@
</ContentControl.Effect>
</ContentControl>
</Grid>

<Grid Grid.Column="1" Grid.Row="1" Background="{Binding BackgroundColor}"/>

<ContentControl Grid.Column="1" Grid.Row="1" Content="{Binding WallPaper}"/>

<mvvm:ViewLocator
Grid.Column="1" Grid.Row="1"
Expand Down
48 changes: 48 additions & 0 deletions LittleBigMouse/Control.Core/ScreenFrameViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ You should have received a copy of the GNU General Public License
mailto:mathieu@mgth.fr
http://www.mgth.fr
*/

using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using HLab.Mvvm;
using HLab.Notify;
using LittleBigMouse.ScreenConfigs;
Expand Down Expand Up @@ -155,6 +158,51 @@ public Viewbox Logo
get => this.Get<Viewbox>(); private set => this.Set(value);
}

[TriggedOn("Model.Config.WallpaperStyle")]
public Stretch WallPaperStretch => this.Get(() =>
{
switch (Model.Config.WallpaperStyle)
{
case 0:
return Stretch.None;
case 2:
return Stretch.Fill;
case 6:
return Stretch.Uniform;
case 10:
return Stretch.UniformToFill;
case 22: // stretched across all screens
default:
return Stretch.None;
}
});

[TriggedOn(nameof(WallPaperStretch))]
[TriggedOn("Model.Config.WallPaperPath")]
public Image WallPaper => this.Get(() =>
{
try
{
return new Image
{
Source = new BitmapImage(new Uri(Model.Config.WallPaperPath)),
Stretch = WallPaperStretch,
HorizontalAlignment = HorizontalAlignment.Center
};
}
catch (Exception)
{
return null;
}
});

public Brush BackgroundColor => this.Get(() => new SolidColorBrush(
Color.FromRgb(
(byte)Model.Config.BackGroundColor[0],
(byte)Model.Config.BackGroundColor[1],
(byte)Model.Config.BackGroundColor[2]
)));

[TriggedOn(nameof(Model),"Monitor","Edid","ManufacturerCode")]
public void UpdateLogo()
{
Expand Down
4 changes: 3 additions & 1 deletion LittleBigMouse/ScreenConfig/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,8 @@ public void PlaceAuto(IEnumerable<Screen> screens)
else InMm.Y -= bottom;
}
}
}


}
}

52 changes: 52 additions & 0 deletions LittleBigMouse/ScreenConfig/ScreenConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ You should have received a copy of the GNU General Public License
using System.Management;
using System.Windows;
using HLab.Notify;
using HLab.Windows.API;
using HLab.Windows.Monitors;
using Microsoft.Win32;
using Newtonsoft.Json;
Expand Down Expand Up @@ -93,12 +94,63 @@ public ScreenConfig(IMonitorsService monitorsService) : base(false)
{
this.SubscribeNotifier();

SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;

MonitorsOnCollectionChanged(monitorsService.AttachedMonitors,
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, MonitorsService.D.AttachedMonitors));

monitorsService.AttachedMonitors.CollectionChanged += MonitorsOnCollectionChanged;
}

private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
Notifier.Update(GetType().GetProperty("WallPaperPath"));
}

public string WallPaperPath => this.Get(GetCurrentDesktopWallpaper);

public string GetCurrentDesktopWallpaper()
{
string currentWallpaper = new string('\0', NativeMethods.MAX_PATH);
NativeMethods.SystemParametersInfo(NativeMethods.SPI_GETDESKWALLPAPER, currentWallpaper.Length, currentWallpaper, 0);
return currentWallpaper.Substring(0, currentWallpaper.IndexOf('\0'));
}

public bool TiledWallPaper => this.Get(() =>
{
using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", false))
{
if (key == null) return false;
return key.GetValue("WallpaperStyle","0").ToString() == "1";
}
});

public int WallpaperStyle => this.Get(() =>
{
using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", false))
{
if (key == null) return 0;
if(int.TryParse(key.GetValue("WallpaperStyle","0").ToString(),out var value))
{
return value;
}
return 0;
}
});

public int[] BackGroundColor => this.Get<int[]>(() =>
{
using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Colors", false))
{
if (key == null) return new []{0,0,0};
var s = key.GetValue("Background", "0 0 0").ToString();
var ss = s.Split(' ');
var i = ss.Select(int.Parse).ToArray();
return i;
}
});

private void MonitorsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
{
if (args.NewItems != null)
Expand Down

0 comments on commit effdafd

Please sign in to comment.