Skip to content

Commit

Permalink
Fix bad rulers display
Browse files Browse the repository at this point in the history
  • Loading branch information
mgth committed Mar 7, 2016
1 parent 4981ee1 commit 62b811b
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 22 deletions.
Binary file modified LittleBigMouse_Control/MainIcon.ico
Binary file not shown.
5 changes: 4 additions & 1 deletion LittleBigMouse_Control/MultiScreensViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private void BringSelectedToFront()
[DependsOn(nameof(Config))]
private void UpdateConfig()
{
if (Config == null) return;
AllScreens_CollectionChanged(Config.AllScreens, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add,Config.AllScreens));
Config.AllScreens.CollectionChanged += AllScreens_CollectionChanged;
}
Expand Down Expand Up @@ -94,8 +95,10 @@ private void AllScreens_CollectionChanged(object sender, NotifyCollectionChanged


[DependsOn("Size", "Config.MovingPhysicalOutsideBounds")]
private void UpdateRatio(string s)
private void UpdateRatio()
{
if (Config == null) return;

Rect all = Config.MovingPhysicalOutsideBounds;

double ratio = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ public ScreenConfig Config
StartCommand = new StartCommand(Config);
StopCommand = new StopCommand(Config);
LittleBigMouseClient.Client.StateChanged += Client_StateChanged;

View.Unloaded += View_Unloaded;
}
}
}

private void View_Unloaded(object sender, System.Windows.RoutedEventArgs e)
{
ShowRulers = false;
}

private void Client_StateChanged()
{
Running = LittleBigMouseClient.Client.Running();
Expand Down
15 changes: 15 additions & 0 deletions LittleBigMouse_Control/ScreenFrameView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@
<RowDefinition Height="{Binding Path=BottomBorder,FallbackValue=20}"/>
</Grid.RowDefinitions>

<Grid Grid.Column="1" Grid.Row="1" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<!--<RowDefinition Height="2*"/>-->
<RowDefinition/>
</Grid.RowDefinitions>
<ContentControl Grid.Column="1" Grid.Row="1" Content="{StaticResource LogoLbm}" Opacity="0.02" VerticalAlignment="Bottom">
<ContentControl.Effect>
<BlurEffect Radius="5"></BlurEffect>
</ContentControl.Effect>
</ContentControl>
</Grid>
<ContentControl Grid.Column="1" Grid.Row="1" Content="{Binding ControlViewModel.View}"/>
</Grid>
</Canvas>
Expand Down
10 changes: 9 additions & 1 deletion LittleBigMouse_Control/ScreenFrameViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public double UnrotatedHeight
[DependsOn("Screen", "Monitor.DisplayOrientation", "Width", "Height")]
private void UpdateUnrotatedWidthHeight()
{
if(Screen?.Monitor == null) return;

if (Screen.Monitor.DisplayOrientation % 2 == 0)
{
UnrotatedHeight = Height;
Expand Down Expand Up @@ -179,6 +181,8 @@ public GridLength UnrotatedLeftBorder
[DependsOn(nameof(LeftBorder), nameof(TopBorder), nameof(RightBorder), nameof(BottomBorder))]
private void UpdateUnrotated()
{
if (Screen == null) return;

GridLength[] unrotated = { TopBorder, RightBorder, BottomBorder, LeftBorder };

int o = Screen.Monitor.DisplayOrientation;
Expand Down Expand Up @@ -211,6 +215,8 @@ public Transform ScreenOrientation
[DependsOn("Monitor.DisplayOrientation", nameof(Width), nameof(Height))]
public void UpddateScreenOrientation()
{
if (Screen?.Monitor == null) return;

var t = new TransformGroup();
if (Screen.Monitor.DisplayOrientation > 0) t.Children.Add(new RotateTransform(90 * Screen.Monitor.DisplayOrientation));

Expand Down Expand Up @@ -238,9 +244,11 @@ public Viewbox Logo
private set { SetProperty(ref _logo, value); }
}

[DependsOn("Monitor.ManufacturerCode")]
[DependsOn("Screen", "Monitor.ManufacturerCode")]
public void UpdateLogo()
{
if (Screen?.Monitor == null) return;

switch (Screen.Monitor.ManufacturerCode.ToLower())
{
case "sam":
Expand Down
7 changes: 5 additions & 2 deletions LittleBigMouse_Control/ScreenViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public Screen Screen
[DependsOn("Screen")]
private void WatchConfig()
{
Watch(Screen.Config,"Config");
Watch(Screen.Monitor,"Monitor");
if (Screen?.Config != null)
Watch(Screen.Config,"Config");

if (Screen?.Monitor != null)
Watch(Screen.Monitor,"Monitor");
}


Expand Down
2 changes: 1 addition & 1 deletion LittleBigMouse_Control/setup/LittleBigMouse.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; -- LittleBigMouse.iss --
;#define AppVer GetFileVersion('..\bin\x64\Release\LittleBigMouse_Control.exe')
#define AppVer '3.0-alpha4'
#define AppVer '3.0-alpha7'

[Setup]
AppName=Little Big Mouse
Expand Down
35 changes: 35 additions & 0 deletions NotifyChange/PropertyChangeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace NotifyChange
{
public class Notifier : DependencyObject, INotifyPropertyChanged
{
public Notifier()
{
Init();
}

public event PropertyChangedEventHandler PropertyChanged;

protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
Expand Down Expand Up @@ -97,6 +102,36 @@ public bool SetAndWatch<T>(ref T storage, T value, [CallerMemberName] string pro
// return true;
//}

private void Init()
{
Type t = GetType();
while (t != null)
{
MethodInfo[] m = t.GetMethods(
BindingFlags.DeclaredOnly |
BindingFlags.Instance | BindingFlags.Public
| BindingFlags.NonPublic
);
foreach (MethodInfo mi in m)
{
if(mi.GetCustomAttributes(false).OfType<DependsOn>().Any())
{
if (mi.GetParameters().Length == 0)
{
mi.Invoke(this, null);

}
else
{
mi.Invoke(this, new object[] { "" });
}
}
}

t = t.BaseType;
}
}

private void GetDependOn(string propertyName, ref List<string> list, ref List<MethodInfo> listMethods)
{
list.Add(propertyName);
Expand Down
4 changes: 2 additions & 2 deletions ScreenConfig/AbsolutePoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public virtual WpfPoint Wpf
);
case NativeMethods.Process_DPI_Awareness.Process_System_DPI_Aware:
return new WpfPoint(Config, Screen,
Pixel.X*Screen.PixelToWpfRatioX,
Pixel.Y*Screen.PixelToWpfRatioY
Pixel.X * Screen.PixelToWpfRatioX,
Pixel.Y * Screen.PixelToWpfRatioY
);
default:
return new WpfPoint(Config, Screen,
Expand Down
9 changes: 5 additions & 4 deletions ScreenConfig/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public bool SetPhysicalY(double value)
[DependsOn("Monitor.DeviceCapsHorzSize")]
public double RealPhysicalWidth
{
get { return double.IsNaN(_realPhysicalWidth) ? Monitor.DeviceCapsHorzSize : _realPhysicalWidth; }
get { return double.IsNaN(_realPhysicalWidth) ? (Monitor?.DeviceCapsHorzSize??0) : _realPhysicalWidth; }
set
{
double ratio = value / RealPhysicalWidth;
Expand Down Expand Up @@ -257,6 +257,7 @@ private bool SetUnrotatedRealPhysicalHeight(double value)
[DependsOn("Monitor.DeviceCapsHorzSize", "Monitor.DeviceCapsVertSize")]
public void InitPhysicalSize()
{
if (Monitor == null) return;
if (double.IsNaN(_realPhysicalWidth)) SetRealPhysicalWidth(Monitor.DeviceCapsHorzSize);
if (double.IsNaN(_realPhysicalHeight)) SetRealPhysicalHeight(Monitor.DeviceCapsVertSize);
}
Expand All @@ -272,7 +273,7 @@ private bool SetRealPhysicalWidth(double value)
[DependsOn("Monitor.DeviceCapsVertSize")]
public double RealPhysicalHeight
{
get { return double.IsNaN(_realPhysicalHeight) ? Monitor.DeviceCapsVertSize : _realPhysicalHeight; }
get { return double.IsNaN(_realPhysicalHeight) ? (Monitor?.DeviceCapsVertSize??0) : _realPhysicalHeight; }
set
{
double ratio = value / RealPhysicalHeight;
Expand Down Expand Up @@ -905,7 +906,7 @@ public double WpfToPixelRatioX
case NativeMethods.Process_DPI_Awareness.Process_System_DPI_Aware:
return Config.PrimaryScreen.EffectiveDpiX / 96;
case NativeMethods.Process_DPI_Awareness.Process_Per_Monitor_DPI_Aware:
return Config.PrimaryScreen.EffectiveDpiX / 96;//EffectiveDpiX/96;
return Config.MaxEffectiveDpiX / 96;
default:
throw new ArgumentOutOfRangeException();
}
Expand All @@ -924,7 +925,7 @@ public double WpfToPixelRatioY
case NativeMethods.Process_DPI_Awareness.Process_System_DPI_Aware:
return Config.PrimaryScreen.EffectiveDpiY / 96;
case NativeMethods.Process_DPI_Awareness.Process_Per_Monitor_DPI_Aware:
return Config.PrimaryScreen.EffectiveDpiY / 96;
return Config.MaxEffectiveDpiY / 96;
default:
throw new ArgumentOutOfRangeException();
}
Expand Down
33 changes: 26 additions & 7 deletions ScreenConfig/ScreenConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ public static IEnumerable<string> ConfigsList
}

private static ObservableCollection<DisplayMonitor> Monitors => DisplayDevice.AttachedMonitors;

public ScreenConfig()
{
MonitorsOnCollectionChanged(Monitors,new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add,Monitors));
MonitorsOnCollectionChanged(Monitors,
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, Monitors));
Monitors.CollectionChanged += MonitorsOnCollectionChanged;

Watch(AllScreens, "Screen");
Expand Down Expand Up @@ -115,7 +117,7 @@ public Screen Selected
[DependsOn("Screen.Selected")]
public void UpdateSelected()
{
Selected = AllScreens.FirstOrDefault ( screen => screen.Selected );
Selected = AllScreens.FirstOrDefault(screen => screen.Selected);
}

private static readonly string RootKey = @"SOFTWARE\Mgth\LittleBigMouse";
Expand Down Expand Up @@ -201,7 +203,8 @@ public static bool IsDoableConfig(String id)
}
return true;
}
public static void AttachToDesktop(string configId, string monitorId, bool apply=true)

public static void AttachToDesktop(string configId, string monitorId, bool apply = true)
{
//using (RegistryKey monkey = Screen.OpenMonitorRegKey(monitorId))
//{
Expand All @@ -220,11 +223,11 @@ public static void AttachToDesktop(string configId, string monitorId, bool apply
area.Height = double.Parse(monkey.GetValue("PixelHeight").ToString());

primary = double.Parse(monkey.GetValue("Primary").ToString()) == 1;
orientation = (int)double.Parse(monkey.GetValue("Orientation").ToString());
orientation = (int) double.Parse(monkey.GetValue("Orientation").ToString());
}

DisplayMonitor monitor = DisplayDevice.AllMonitors.FirstOrDefault(
d => monitorId == d.ManufacturerCode + d.ProductCode + "_" + d.Serial);
d => monitorId == d.ManufacturerCode + d.ProductCode + "_" + d.Serial);

monitor?.AttachToDesktop(primary, area, orientation, apply);
}
Expand Down Expand Up @@ -324,7 +327,7 @@ public Rect PhysicalOutsideBounds
private set { if (SetProperty(ref _physicalOutsideBounds, value)) Saved = false; }
}

[DependsOn(nameof(Moving),"Screen.PhysicalOutsideBounds")]
[DependsOn(nameof(Moving), "Screen.PhysicalOutsideBounds")]
public void UpdatePhysicalOutsideBounds()
{
Rect outside = new Rect();
Expand Down Expand Up @@ -619,7 +622,7 @@ public void Compact()
_compacting = true;
}

List<Screen> done = new List<Screen> { PrimaryScreen };
List<Screen> done = new List<Screen> {PrimaryScreen};

List<Screen> todo = AllBut(PrimaryScreen).OrderBy(s => s.Distance(PrimaryScreen)).ToList();

Expand Down Expand Up @@ -670,5 +673,21 @@ public bool Saved
get { return _saved; }
set { SetProperty(ref _saved, value); }
}

[DependsOn("Screen.EffectiveDpiX")]
public double MaxEffectiveDpiX {
get
{
return AllScreens.Select(screen => screen.EffectiveDpiX).Concat(new double[] {0}).Max();
}
}
[DependsOn("Screen.EffectiveDpiY")]
public double MaxEffectiveDpiY
{
get
{
return AllScreens.Select(screen => screen.EffectiveDpiY).Concat(new double[] { 0 }).Max();
}
}
}
}
14 changes: 10 additions & 4 deletions WindowsMonitors/DisplayMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void UpdateEdid()
private void UpdateManufacturerCode()
{
String code;
if (Edid.Length < 10) code = "XXX";
if (Edid==null || Edid.Length < 10) code = "XXX";
else
{
code = "" + (char)(64 + ((Edid[8] >> 2) & 0x1F));
Expand All @@ -285,7 +285,7 @@ public String ProductCode
[DependsOn(nameof(Edid))]
private void UpdateProductCode()
{
if (Edid.Length < 12) ProductCode = "0000";
if (Edid == null || Edid.Length < 12) ProductCode = "0000";
else ProductCode = (Edid[10] + (Edid[11] << 8)).ToString("X4");

}
Expand All @@ -299,7 +299,11 @@ public string Serial
[DependsOn(nameof(Edid))]
private void UpdateSerial()
{
if (Edid.Length < 16) Serial = "00000000";
if (Edid == null || Edid.Length < 16)
{
Serial = "00000000";
return;
}
string serial = "";
for (int i = 12; i <= 15; i++) serial = (Edid[i]).ToString("X2") + serial;
Serial = serial;
Expand Down Expand Up @@ -327,7 +331,7 @@ public string SerialNo
[DependsOn(nameof(Edid))]
private void UpdatePhysicalSize()
{
if (Edid.Length > 68)
if (Edid != null && Edid.Length > 68)
{
int w = ((Edid[68] & 0xF0) << 4) + Edid[66];
int h = ((Edid[68] & 0x0F) << 8) + Edid[67];
Expand All @@ -350,6 +354,8 @@ private void UpdatePhysicalSize()

public string Block(char code)
{
if (Edid == null) return "";

for (int i = 54; i <= 108; i += 18)
{
if (i < Edid.Length && Edid[i] == 0 && Edid[i + 1] == 0 && Edid[i + 2] == 0 && Edid[i + 3] == code)
Expand Down

0 comments on commit 62b811b

Please sign in to comment.