Skip to content

Commit

Permalink
Fix Config switch
Browse files Browse the repository at this point in the history
  • Loading branch information
mgth committed Mar 7, 2016
1 parent 666e3d8 commit 4981ee1
Show file tree
Hide file tree
Showing 16 changed files with 275 additions and 152 deletions.
15 changes: 12 additions & 3 deletions LittleBigMouse_Control/MultiScreensView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</LinearGradientBrush>
</Grid.Background>

<Grid>
<Label FontSize="50">
<Label.Foreground>

Expand All @@ -40,10 +41,18 @@
<Label.Effect>
<BlurEffect Radius="10"></BlurEffect>
</Label.Effect>

Little Big Mon
Little Big Mouse

</Label>

<ContentControl Content="{StaticResource LogoLbm}" Opacity="0.02">
<!--<ContentControl.Effect>
<BlurEffect Radius="50"></BlurEffect>
</ContentControl.Effect>-->
</ContentControl>



</Grid>
<ContentControl Content="{Binding ScreensCanvas}"/>
</Grid>
</UserControl>
4 changes: 2 additions & 2 deletions LittleBigMouse_Control/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Mgth")]
[assembly: AssemblyProduct("LittleBigMouse_Control")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: DisableDpiAwareness]
Expand Down Expand Up @@ -51,5 +51,5 @@
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.*")]
[assembly: AssemblyVersion("3.0.*")]
//[assembly: AssemblyFileVersion("2.0.0.0")]
2 changes: 1 addition & 1 deletion LittleBigMouse_Control/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<!--<dpiAware>True/PM</dpiAware>-->
<dpiAware>True/PM</dpiAware>
<!--<dpiAware>True</dpiAware>-->
<!--<dpiAware>False</dpiAware>-->
</asmv3:windowsSettings>
Expand Down
37 changes: 28 additions & 9 deletions LittleBigMouse_Daemon/LittleBigMouseDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,47 @@ private void OnStartup(object sender, EventArgs exitEventArgs)
_notify = new Notify();
_engine = new MouseEngine();

_engine.ConfigLoaded += _engine_ConfigLoaded;

_engine.StartServer(this);



if (_notify != null)
_notify.Click += OnNotifyClick;

UpdateConfig();

//_notify.AddMenu("Brightness", Brightness);

_notify.AddMenu(-1,"Open", Open);
_notify.AddMenu(-1,"Start", Start);
_notify.AddMenu(-1,"Stop", Stop);
_notify.AddMenu(-1,"Exit", Quit);

Start();
}

private void _engine_ConfigLoaded(object sender, EventArgs e)
{
UpdateConfig();
}

public void UpdateConfig()
{
_notify.RemoveMenu("config");

foreach (string configName in ScreenConfig.ConfigsList)
{
_notify.AddMenu(configName, MatchConfig);
bool chk = configName==_engine.Config?.Id;

if (ScreenConfig.IsDoableConfig(configName))
_notify.AddMenu(0,configName, MatchConfig, "config", chk);
}

//_notify.AddMenu("Brightness", Brightness);
}

_notify.AddMenu("Open", Open);
_notify.AddMenu("Start", Start);
_notify.AddMenu("Stop", Stop);
_notify.AddMenu("Exit", Quit);

Start();
}
private void OnNotifyClick(object sender, EventArgs e) { Open(); }

private void OnDeactivated(object sender, EventArgs eventArgs)
Expand All @@ -78,7 +97,7 @@ private void OnExit(object sender, ExitEventArgs exitEventArgs)
{
Stop();
_engine.StopServer();
_notify.Dispose();
_notify.Hide();
}

public void CommandLine(IList<string> args)
Expand Down
36 changes: 19 additions & 17 deletions LittleBigMouse_Daemon/MouseEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace LittleBigMouse_Daemon
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class MouseEngine
{
private ScreenConfig _config;
public ScreenConfig Config { get; private set; }
private double _initMouseSpeed;
public readonly MouseHookListener Hook = new MouseHookListener(new GlobalHooker());
private PixelPoint _oldPoint = null;
Expand Down Expand Up @@ -53,10 +53,10 @@ public void Start()
{
if (Hook.Enabled) return;

if (_config == null)
if (Config == null)
LoadConfig();

if (_config == null || !_config.Enabled) return;
if (Config == null || !Config.Enabled) return;

SystemEvents.DisplaySettingsChanged += OnDisplaySettingsChanged;

Expand Down Expand Up @@ -96,9 +96,9 @@ public void Stop()
Hook.Enabled = false;
// LittleBigMouseDaemon.Callback?.OnStateChange();

if (_config == null) return;
if (Config == null) return;

if (_config.AdjustSpeed)
if (Config.AdjustSpeed)
{
LbmMouse.MouseSpeed = _initMouseSpeed;
using (var key = ScreenConfig.OpenRootRegKey(true))
Expand All @@ -107,7 +107,7 @@ public void Stop()
}
}

if (_config.AdjustPointer)
if (Config.AdjustPointer)
{
using (var key = ScreenConfig.OpenRootRegKey())
{
Expand All @@ -126,15 +126,17 @@ public void Stop()

public void LoadConfig(ScreenConfig config)
{
_config = config;
Config = config;
ConfigLoaded?.Invoke(config,null);
}

public event EventHandler ConfigLoaded;
public void LoadConfig()
{
LoadConfig(new ScreenConfig());
}
private void OnDisplaySettingsChanged(object sender, EventArgs e)
{
Debug.Print("LoadConfig");
LoadConfig();
}

Expand All @@ -143,7 +145,7 @@ private void OnMouseMoveExt(object sender, MouseEventExtArgs e)
// If first time called just save that point
if (_oldPoint == null)
{
_oldPoint = new PixelPoint(_config, null, e.X, e.Y);
_oldPoint = new PixelPoint(Config, null, e.X, e.Y);
return;
}

Expand Down Expand Up @@ -187,9 +189,9 @@ private void OnMouseMoveExt(object sender, MouseEventExtArgs e)
Side side = seg.IntersectSide(_oldPoint.Screen.PhysicalBounds);


foreach (Screen screen in _config.AllScreens.Where(s => s != oldScreen))
foreach (Screen screen in Config.AllScreens.Where(s => s != oldScreen))
{
if (_config.AllowCornerCrossing)
if (Config.AllowCornerCrossing)
{
foreach ( Point p in seg.Line.Intersect(screen.PhysicalBounds) )
{
Expand All @@ -198,7 +200,7 @@ private void OnMouseMoveExt(object sender, MouseEventExtArgs e)
if (travel.Size > dist) continue;

dist = travel.Size;
pOut = (new PhysicalPoint(_config, screen, p.X, p.Y)).Pixel.Inside;
pOut = (new PhysicalPoint(Config, screen, p.X, p.Y)).Pixel.Inside;
screenOut = screen;
}
}
Expand Down Expand Up @@ -235,7 +237,7 @@ private void OnMouseMoveExt(object sender, MouseEventExtArgs e)
if (offset.Length > 0 && offset.Length < dist)
{
Point shiftedPoint = pIn.Physical.Point + offset;
PhysicalPoint shifted = new PhysicalPoint(_config, screen, shiftedPoint.X , shiftedPoint.Y);
PhysicalPoint shifted = new PhysicalPoint(Config, screen, shiftedPoint.X , shiftedPoint.Y);
if (shifted.TargetScreen == screen)
{
dist = offset.Length;
Expand All @@ -262,7 +264,7 @@ private void OnMouseMoveExt(object sender, MouseEventExtArgs e)
Debug.Print(">" + LbmMouse.CursorPos.X + "," + LbmMouse.CursorPos.Y);

// Adjust pointer size to dpi ratio : should not be usefull if windows screen ratio is used
if (_config.AdjustPointer)
if (Config.AdjustPointer)
{
if (screenOut.RealDpiAvg > 110)
{
Expand All @@ -273,12 +275,12 @@ private void OnMouseMoveExt(object sender, MouseEventExtArgs e)


// Adjust pointer speed to dpi ratio : should not be usefull if windows screen ratio is used
if (_config.AdjustSpeed)
if (Config.AdjustSpeed)
{
LbmMouse.MouseSpeed = Math.Round((5.0/96.0)*screenOut.RealDpiAvg, 0);
}

if (_config.HomeCinema)
if (Config.HomeCinema)
{
oldScreen.Monitor.Vcp().Power = false;
}
Expand All @@ -290,7 +292,7 @@ private void OnMouseMoveExt(object sender, MouseEventExtArgs e)

public void MatchConfig(string configId)
{
_config.MatchConfig(configId);
Config.MatchConfig(configId);
}
}
}
Expand Down
63 changes: 49 additions & 14 deletions LittleBigMouse_Daemon/Notify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ You should have received a copy of the GNU General Public License

namespace LittleBigMouse_Daemon
{
public class Notify : IDisposable
public class Notify //: IDisposable
{
private System.Windows.Forms.NotifyIcon _notify;
private readonly System.Windows.Forms.NotifyIcon _notify;

public Notify()
{
Expand All @@ -52,6 +52,14 @@ public void SetOff()
{
_notify.Icon = Properties.Resources.lbm_off;
}
public void Show()
{
_notify.Visible = true;
}
public void Hide()
{
_notify.Visible = false;
}

private void _notify_MouseClick(object sender, MouseEventArgs e)
{
Expand All @@ -64,25 +72,52 @@ private void _notify_MouseClick(object sender, MouseEventArgs e)


public event EventHandler Click;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
//public void Dispose()
//{
// Dispose(true);
// GC.SuppressFinalize(this);
//}
public delegate void Func();

public void AddMenu(string txt, EventHandler evt)
public void AddMenu(int pos, string txt, EventHandler evt, string tag=null, bool chk = false)
{
_notify.ContextMenuStrip.Items.Add(txt, null, evt);
ToolStripMenuItem item = new ToolStripMenuItem(txt, null, evt);

item.Checked = chk;

item.Tag = tag;

if(pos<0 || pos>= _notify.ContextMenuStrip.Items.Count) _notify.ContextMenuStrip.Items.Add(item);

else _notify.ContextMenuStrip.Items.Insert(pos,item);

}

protected virtual void Dispose(bool disposing)
public void RemoveMenu(string tag)
{
if (!disposing) return;

_notify.Visible = false;
_notify.Dispose();
bool done = false;
while (!done)
{
ToolStripItem[] items = new ToolStripItem[_notify.ContextMenuStrip.Items.Count];
_notify.ContextMenuStrip.Items.CopyTo(items,0);
done = true;
foreach (ToolStripItem i in items)
{
if (i.Tag == tag)
{
_notify.ContextMenuStrip.Items.Remove(i);
done = false;
}
}
}
}

//protected virtual void Dispose(bool disposing)
//{
// if (!disposing) return;

// _notify.Visible = false;
// _notify.Dispose();
//}
}
}
10 changes: 5 additions & 5 deletions LittleBigMouse_Daemon/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("LittleBigMouse_Daemon")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Little Big Mouse Service")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LittleBigMouse_Daemon")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyCompany("Mgth")]
[assembly: AssemblyProduct("LittleBigMouse")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -31,6 +31,6 @@
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.*")]
[assembly: AssemblyVersion("3.0.*")]
//[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
9 changes: 4 additions & 5 deletions MonitorVcp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("MonitorVcp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Monitor VCP control")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MonitorVcp")]
[assembly: AssemblyCompany("Mgth")]
[assembly: AssemblyProduct("LittleBigMouse")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand All @@ -32,5 +32,4 @@
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("3.0.*")]
Loading

0 comments on commit 4981ee1

Please sign in to comment.