From cb70e8f5e51cf79206cb41696b6f3c189c5f22b9 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Tue, 27 Jun 2017 16:48:33 +0800 Subject: [PATCH 1/4] merged new win32 option to hide overlay --- src/Carnac.Logic/Win32Methods.cs | 5 +++-- src/Carnac/UI/KeyShowView.xaml.cs | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Carnac.Logic/Win32Methods.cs b/src/Carnac.Logic/Win32Methods.cs index 455b5563..ea777fdc 100644 --- a/src/Carnac.Logic/Win32Methods.cs +++ b/src/Carnac.Logic/Win32Methods.cs @@ -16,6 +16,7 @@ public static class Win32Methods public const int WM_SYSKEYUP = 261; public const int WM_SYSKEYDOWN = 260; public const int WS_EX_TRANSPARENT = 0x00000020; + public const int WS_EX_TOOLWINDOW = 0x00000080; public const int GWL_EXSTYLE = (-20); // @@ -40,10 +41,10 @@ public static class Win32Methods [DllImport("user32.dll")] static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle); - public static void SetWindowExTransparent(IntPtr hwnd) + public static void SetWindowExTransparentAndNotInWindowList(IntPtr hwnd) { var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); - SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT); + SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW); } } } \ No newline at end of file diff --git a/src/Carnac/UI/KeyShowView.xaml.cs b/src/Carnac/UI/KeyShowView.xaml.cs index 149362be..72abbdf7 100644 --- a/src/Carnac/UI/KeyShowView.xaml.cs +++ b/src/Carnac/UI/KeyShowView.xaml.cs @@ -20,8 +20,7 @@ protected override void OnSourceInitialized(EventArgs e) base.OnSourceInitialized(e); var hwnd = new WindowInteropHelper(this).Handle; - Win32Methods.SetWindowExTransparent(hwnd); - + Win32Methods.SetWindowExTransparentAndNotInWindowList(hwnd); var timer = new Timer(100); timer.Elapsed += (s, x) => @@ -83,7 +82,7 @@ public static readonly int private void WindowLoaded(object sender, RoutedEventArgs e) { - + } void SettingsLeftChanged(object sender, EventArgs e) From 4d391d00284488f99e15d12dafbb7e3148ce8d83 Mon Sep 17 00:00:00 2001 From: Boris Fritscher Date: Sat, 10 Jun 2017 01:50:07 +0200 Subject: [PATCH 2/4] Added option to only show keys which have a modifier. Fix shortcutOnly to work only with keymaps file. Maybe shortcutOnly should be renamed or better explained? --- src/Carnac.Logic/MessageProvider.cs | 17 ++++++++++++++++- src/Carnac.Logic/Models/Message.cs | 11 ++++++++--- src/Carnac.Logic/Models/PopupSettings.cs | 1 + src/Carnac.Logic/ShortcutAccumulator.cs | 2 +- src/Carnac/UI/PreferencesView.xaml | 7 +++++-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Carnac.Logic/MessageProvider.cs b/src/Carnac.Logic/MessageProvider.cs index e69a13d9..8a3ca989 100644 --- a/src/Carnac.Logic/MessageProvider.cs +++ b/src/Carnac.Logic/MessageProvider.cs @@ -37,7 +37,22 @@ public IObservable GetMessageStream() .Where(c => c.HasCompletedValue) .SelectMany(c => c.GetMessages()) .Scan(new Message(), (acc, key) => Message.MergeIfNeeded(acc, key)) - .Where(m => !settings.DetectShortcutsOnly || m.IsShortcut); + .Where(m => + { + if (settings.DetectShortcutsOnly && settings.ShowOnlyModifiers) + { + return m.IsShortcut && m.IsModifier; + } + if (settings.DetectShortcutsOnly) + { + return m.IsShortcut; + } + if (settings.ShowOnlyModifiers) + { + return m.IsModifier; + } + return true; + }); } } } \ No newline at end of file diff --git a/src/Carnac.Logic/Models/Message.cs b/src/Carnac.Logic/Models/Message.cs index 415492b0..43c46cd0 100644 --- a/src/Carnac.Logic/Models/Message.cs +++ b/src/Carnac.Logic/Models/Message.cs @@ -15,6 +15,7 @@ public sealed class Message readonly string shortcutName; readonly bool canBeMerged; readonly bool isShortcut; + readonly bool isModifier; readonly bool isDeleting; readonly DateTime lastMessage; readonly Message previous; @@ -30,12 +31,13 @@ public Message(KeyPress key) processName = key.Process.ProcessName; processIcon = key.Process.ProcessIcon; canBeMerged = !key.HasModifierPressed; + isModifier = key.HasModifierPressed; keys = new ReadOnlyCollection(new[] { key }); textCollection = new ReadOnlyCollection(CreateTextSequence(key).ToArray()); } - public Message(IEnumerable keys, KeyShortcut shortcut) + public Message(IEnumerable keys, KeyShortcut shortcut, Boolean isShortcut = false) : this() { var allKeys = keys.ToArray(); @@ -48,7 +50,8 @@ public Message(IEnumerable keys, KeyShortcut shortcut) processName = distinctProcessName.Single(); processIcon = allKeys.First().Process.ProcessIcon; shortcutName = shortcut.Name; - isShortcut = true; + this.isShortcut = isShortcut; + this.isModifier = allKeys.Any(k => k.HasModifierPressed); canBeMerged = false; this.keys = new ReadOnlyCollection(allKeys); @@ -91,7 +94,9 @@ private Message(Message initial, bool isDeleting) public DateTime LastMessage { get { return lastMessage; } } public bool IsDeleting { get { return isDeleting; } } - + + public bool IsModifier { get { return isModifier; } } + public Message Merge(Message other) { return new Message(this, other); diff --git a/src/Carnac.Logic/Models/PopupSettings.cs b/src/Carnac.Logic/Models/PopupSettings.cs index 8331f73f..809f603a 100644 --- a/src/Carnac.Logic/Models/PopupSettings.cs +++ b/src/Carnac.Logic/Models/PopupSettings.cs @@ -85,5 +85,6 @@ public string SortDescription public bool DetectShortcutsOnly { get; set; } public bool ShowApplicationIcon { get; set; } public bool SettingsConfigured { get; set; } + public bool ShowOnlyModifiers { get; set; } } } diff --git a/src/Carnac.Logic/ShortcutAccumulator.cs b/src/Carnac.Logic/ShortcutAccumulator.cs index f709903f..00168e61 100644 --- a/src/Carnac.Logic/ShortcutAccumulator.cs +++ b/src/Carnac.Logic/ShortcutAccumulator.cs @@ -88,7 +88,7 @@ void ShortcutCompleted(KeyShortcut shortcut) if (HasCompletedValue) throw new InvalidOperationException(); - messages = new[] { new Message(Keys, shortcut) }; + messages = new[] { new Message(Keys, shortcut, true) }; HasCompletedValue = true; } diff --git a/src/Carnac/UI/PreferencesView.xaml b/src/Carnac/UI/PreferencesView.xaml index bcbcecac..4942d15c 100644 --- a/src/Carnac/UI/PreferencesView.xaml +++ b/src/Carnac/UI/PreferencesView.xaml @@ -138,9 +138,12 @@ - + - + + + + From 2c9d69be7952e1fb71e4cb74948a4743f6a9ab52 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Tue, 27 Jun 2017 18:32:26 +0800 Subject: [PATCH 3/4] add an option AutoUpdate to control auto updating (default is false) --- src/Carnac.Logic/Models/PopupSettings.cs | 3 +++ src/Carnac/App.xaml.cs | 29 +++++++++++++----------- src/Carnac/UI/PreferencesView.xaml | 10 +++++--- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/Carnac.Logic/Models/PopupSettings.cs b/src/Carnac.Logic/Models/PopupSettings.cs index 8331f73f..e89a1f00 100644 --- a/src/Carnac.Logic/Models/PopupSettings.cs +++ b/src/Carnac.Logic/Models/PopupSettings.cs @@ -30,6 +30,9 @@ public class PopupSettings : NotifyPropertyChanged [NotifyProperty(AlsoNotifyFor = new[] { "ScaleTransform", "Alignment" })] public NotificationPlacement Placement { get; set; } + [DefaultValue(false)] + public bool AutoUpdate { get; set; } + //Used to determine which from it's leftmost co-ord double left; public double Left diff --git a/src/Carnac/App.xaml.cs b/src/Carnac/App.xaml.cs index 98be0c52..f73efa71 100644 --- a/src/Carnac/App.xaml.cs +++ b/src/Carnac/App.xaml.cs @@ -53,22 +53,25 @@ protected override void OnStartup(StartupEventArgs e) carnac.Start(); #if !DEBUG - Observable - .Timer(TimeSpan.FromMinutes(5)) - .Subscribe(async x => - { - try + if (settings.AutoUpdate) + { + Observable + .Timer(TimeSpan.FromMinutes(5)) + .Subscribe(async x => { - using (var mgr = UpdateManager.GitHubUpdateManager(carnacUpdateUrl)) + try { - await mgr.Result.UpdateApp(); + using (var mgr = UpdateManager.GitHubUpdateManager(carnacUpdateUrl)) + { + await mgr.Result.UpdateApp(); + } } - } - catch - { - // Do something useful with the exception - } - }); + catch + { + // Do something useful with the exception + } + }); + } #endif base.OnStartup(e); diff --git a/src/Carnac/UI/PreferencesView.xaml b/src/Carnac/UI/PreferencesView.xaml index bcbcecac..6ae72de5 100644 --- a/src/Carnac/UI/PreferencesView.xaml +++ b/src/Carnac/UI/PreferencesView.xaml @@ -7,7 +7,7 @@ xmlns:utilities="clr-namespace:Carnac.Utilities" xmlns:carnac="clr-namespace:Carnac" x:Class="Carnac.UI.PreferencesView" - Width="610" Height="420" Icon="../icon.ico" + Width="610" Height="420" Icon="../icon.ico" Foreground="{DynamicResource BlackBrush}" d:DataContext="{d:DesignInstance ui:PreferencesViewModel}" mc:Ignorable="d" ShowTitleBar="False" ShowMinButton="False" ShowMaxRestoreButton="False" @@ -25,7 +25,7 @@ - + @@ -56,7 +56,7 @@ - @@ -84,6 +84,10 @@ + + + +