diff --git a/App.config b/App.config index 8f8a57e..a42ba7c 100644 --- a/App.config +++ b/App.config @@ -24,7 +24,7 @@ - + diff --git a/App.xaml.cs b/App.xaml.cs index f67817b..b145026 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -24,11 +24,15 @@ namespace GeekDesk private void App_Startup(object sender, StartupEventArgs e) { - bool ret; - mutex = new System.Threading.Mutex(true, Constants.MY_NAME, out ret); + mutex = new System.Threading.Mutex(true, Constants.MY_NAME, out bool ret); if (!ret) { - Environment.Exit(0); + System.Threading.Thread.Sleep(2000); + mutex = new System.Threading.Mutex(true, Constants.MY_NAME, out ret); + if (!ret) + { + Environment.Exit(0); + } } } } diff --git a/Constant/CommonEnum.cs b/Constant/CommonEnum.cs index 7bf6b75..33310c9 100644 --- a/Constant/CommonEnum.cs +++ b/Constant/CommonEnum.cs @@ -14,5 +14,6 @@ namespace GeekDesk.Constant IMAGE_HEIGHT_AM = 52, //动画变换高度 IMAGE_PANEL_WIDTH = 110, //图标容器宽度 IMAGE_PANEL_HEIGHT = 90, //图标容器高度 + WINDOW_ANIMATION_TIME = 200, //主窗口动画时间 } } diff --git a/Constant/Constants.cs b/Constant/Constants.cs index eefd0e0..8a2826f 100644 --- a/Constant/Constants.cs +++ b/Constant/Constants.cs @@ -15,7 +15,7 @@ namespace GeekDesk.Constant /// /// app数据文件路径 /// - public static string DATA_FILE_PATH = APP_DIR + "//Data"; //app数据文件路径 + public static string DATA_FILE_PATH = APP_DIR + "Data"; //app数据文件路径 //默认文件夹图标 public static string DEFAULT_DIR_IMAGE_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAASISURBVHhe7dvPi9R1HMfx/Qu6RYfqEp1CZ8Yko0MQRNEPgnQ36FJEFyPoF/0DHbx06dSlnVkF6SgEgocOYUEG0cFWpQ476yhbQfTDslJxk+k79S1IP/NSF3f2O+7jBY/TKgvz/j5nXMUZMzMzMzMzMzMzMzMzMzMzu959023dsbSw9YGlbuchyk7v3XbP0t5tt9Yvmd3MW3r//luWu623TvbahytDrtvBQa/9xvJ85776JbWbZf359s7quCcKR2cNqjeaQ/35zgv1y2vTvOqgOy4/MDdG9abzwWC+06lfapu2jf4cXTosN9SZ5W7n9folt2nZ6Ifw6niDy47JelloH6hfepuGLffa7xQPyfpZaL9Xv/zW5K307r27eEDWXfXG9GJ9BmvqqneyV0rHYzL63a3b61NYEzfodT4rHY4J8UetZq/6mF8pHo6J8SnS4JUOxqS19tTnsKatfDAm7Hh9DmvaCsdiAwx6rcfqk1iTVjoWkzfotd+uT2JNWulYTN5yr/VFfRJr0krHYoN0t7Tqs1hTVjwUG6L6OeS1+izWlJUOxYb5xb+JNGyFI7Gxfqp+YN83+h+drK/+wtbH+3u33FmnUF7hQLCpLPfaSycX2u/WSfx/pd8Am1H1yf3d6FOlTuOflX4hbGrd1vN1HgKBou6W2wQC4+0XCASnuu1dAoGxWnsEAmMMeq1DAoExRn/tKxAIBALBmgMZ7Nsx/Pbgc9B4J3udK57fa7WmQEbf1GyatnLg6eKzfDVrCuTcypH625pNx37rHyo+y1ezpkAufL9Yf1uz6dgfpz8uPstXIxDbFBOIWZhAzMIEYhYmELMwgZiFCcQsTCBmYQIxCxOIWZhAzMIEYhYmELMwgZiFrTmQ0/u3D89+8tjw/OdPXbPVr18eXlp6E6bG6le7i8/yOL8efnR4at+24czvR54Y/nl8DrjM6INjpvQFYG548ehOgcA4AoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCC4e3XVJIDBG9QmyKhAY4+Li7HmBwBirx2bPCgTGOTH3g0BgHIFAIBAI6kDOXPEFoDLbn7l0bG53+YuwyS3OPTsz2oVjs3etLs49OM65T5/c9fNHj7z044cPvwrTbvQsj57p0rP+r3NfPnP733GYmZmZmZmZmZmZmZmZmZnZf5uZ+QsdP8v10G4AYgAAAABJRU5ErkJggg=="; diff --git a/Control/UserControls/Config/AboutControl.xaml b/Control/UserControls/Config/AboutControl.xaml index 825e9dc..1887376 100644 --- a/Control/UserControls/Config/AboutControl.xaml +++ b/Control/UserControls/Config/AboutControl.xaml @@ -17,7 +17,7 @@ - + diff --git a/Control/UserControls/Config/MotionControl.xaml b/Control/UserControls/Config/MotionControl.xaml index ea9bbad..c574c76 100644 --- a/Control/UserControls/Config/MotionControl.xaml +++ b/Control/UserControls/Config/MotionControl.xaml @@ -13,11 +13,11 @@ - - + + - + @@ -27,7 +27,7 @@ - + @@ -36,10 +36,31 @@ - - + + + + + + + + + - + + + + + + + + + + + + + + + @@ -51,11 +72,11 @@ IsChecked="{Binding AppHideType, Mode=TwoWay, Converter={StaticResource HideTypeConvert}, ConverterParameter=3}"/> - - + + - - + + + /> - + /> + - + diff --git a/Control/UserControls/Config/MotionControl.xaml.cs b/Control/UserControls/Config/MotionControl.xaml.cs index ffbf02c..79785c8 100644 --- a/Control/UserControls/Config/MotionControl.xaml.cs +++ b/Control/UserControls/Config/MotionControl.xaml.cs @@ -1,4 +1,5 @@ -using GeekDesk.Control.Windows; +using GeekDesk.Constant; +using GeekDesk.Control.Windows; using GeekDesk.Util; using GeekDesk.ViewModel; using HandyControl.Data; @@ -19,6 +20,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using static GeekDesk.Util.GlobalHotKey; namespace GeekDesk.Control.UserControls.Config { @@ -212,14 +214,16 @@ namespace GeekDesk.Control.UserControls.Config { if (MainWindow.hotKeyId != -1) { - Hotkey.UnRegist(new WindowInteropHelper(MainWindow.mainWindow).Handle, Hotkey.keymap[MainWindow.hotKeyId]); + //Hotkey.UnRegist(new WindowInteropHelper(MainWindow.mainWindow).Handle, Hotkey.keymap[MainWindow.hotKeyId]); + GlobalHotKey.Dispose(MainWindow.hotKeyId); } MainWindow.RegisterHotKey(false); } else { if (MainWindow.toDoHotKeyId != -1) { - Hotkey.UnRegist(new WindowInteropHelper(MainWindow.toDoInfoWindow).Handle, Hotkey.keymap[MainWindow.toDoHotKeyId]); + //Hotkey.UnRegist(new WindowInteropHelper(MainWindow.toDoInfoWindow).Handle, Hotkey.keymap[MainWindow.toDoHotKeyId]); + GlobalHotKey.Dispose(MainWindow.toDoHotKeyId); } MainWindow.RegisterCreateToDoHotKey(false); } @@ -242,66 +246,30 @@ namespace GeekDesk.Control.UserControls.Config } } - //private void ShowApp(MainWindow mainWindow) - //{ - // if (appConfig.FollowMouse) - // { - // ShowAppAndFollowMouse(mainWindow); - // } - // else - // { - // this.Visibility = Visibility.Visible; - // } - // Keyboard.Focus(this); - //} + private void MarginHide_Changed(object sender, RoutedEventArgs e) + { + if (appConfig.MarginHide) + { + MainWindow.hide.TimerSet(); + } else + { + if (MainWindow.hide.timer != null) + { + MainWindow.hide.TimerStop(); + } + } + } - ///// - ///// 随鼠标位置显示面板 (鼠标始终在中间) - ///// - //private void ShowAppAndFollowMouse(MainWindow mainWindow) - //{ - // //获取鼠标位置 - // System.Windows.Point p = MouseUtil.GetMousePosition(); - // double left = SystemParameters.VirtualScreenLeft; - // double top = SystemParameters.VirtualScreenTop; - // double width = SystemParameters.VirtualScreenWidth; - // double height = SystemParameters.VirtualScreenHeight; - // double right = width - Math.Abs(left); - // double bottom = height - Math.Abs(top); + private void Animation_Checked(object sender, RoutedEventArgs e) + { + if (MainWindow.mainWindow.Visibility == Visibility.Collapsed) + { + MainWindow.mainWindow.Visibility = Visibility.Visible; + // 执行一下动画 防止太过突兀 + MainWindow.FadeStoryBoard(0, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Collapsed); + } + } - // if (p.X - mainWindow.Width / 2 < left) - // { - // //判断是否在最左边缘 - // mainWindow.Left = left; - // } - // else if (p.X + mainWindow.Width / 2 > right) - // { - // //判断是否在最右边缘 - // mainWindow.Left = right - mainWindow.Width; - // } - // else - // { - // mainWindow.Left = p.X - mainWindow.Width / 2; - // } - - - // if (p.Y - mainWindow.Height / 2 < top) - // { - // //判断是否在最上边缘 - // mainWindow.Top = top; - // } - // else if (p.Y + mainWindow.Height / 2 > bottom) - // { - // //判断是否在最下边缘 - // mainWindow.Top = bottom - mainWindow.Height; - // } - // else - // { - // mainWindow.Top = p.Y - mainWindow.Height / 2; - // } - - // mainWindow.Visibility = Visibility.Visible; - //} } } diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml b/Control/UserControls/PannelCard/RightCardControl.xaml index a037d97..ee78712 100644 --- a/Control/UserControls/PannelCard/RightCardControl.xaml +++ b/Control/UserControls/PannelCard/RightCardControl.xaml @@ -100,7 +100,7 @@ MouseEnter="StackPanel_MouseEnter" MouseLeave="StackPanel_MouseLeave" > - + + - + diff --git a/MainWindow.xaml b/MainWindow.xaml index 8ae4828..2c5f8d6 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -14,10 +14,12 @@ d:DesignHeight="500" d:DesignWidth="700" WindowStyle="None" AllowsTransparency="True" - Background="Transparent" + Background="#00FFFFFF" OpacityMask ="White" - Deactivated="window_Deactivated" - SizeChanged="window_SizeChanged" + ShowInTaskbar="False" + Opacity="0" + Deactivated="Window_Deactivated" + SizeChanged="Window_SizeChanged" > @@ -114,7 +116,9 @@ + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 56af67e..26ee807 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -18,6 +18,7 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; +using System.Windows.Media.Animation; using static GeekDesk.Util.ShowWindowFollowMouse; namespace GeekDesk @@ -35,6 +36,7 @@ namespace GeekDesk public static int hotKeyId = -1; public static int toDoHotKeyId = -1; public static MainWindow mainWindow; + public static MarginHide hide; public MainWindow() { LoadData(); @@ -44,6 +46,13 @@ namespace GeekDesk this.Loaded += Window_Loaded; this.SizeChanged += MainWindow_Resize; ToDoTask.BackLogCheck(); + + ////实例化隐藏 Hide类,进行时间timer设置 + hide = new MarginHide(this); + if (appData.AppConfig.MarginHide) + { + hide.TimerSet(); + } } private void LoadData() @@ -63,13 +72,19 @@ namespace GeekDesk { if (!appData.AppConfig.StartedShowPanel) { - this.Visibility = Visibility.Collapsed; + if (appData.AppConfig.AppAnimation) + { + this.Opacity = 0; + } else + { + this.Visibility = Visibility.Collapsed; + } } else { ShowApp(); } RegisterHotKey(true); - //RegisterCreateToDoHotKey(true); + RegisterCreateToDoHotKey(true); if (!appData.AppConfig.SelfStartUped) { @@ -88,18 +103,18 @@ namespace GeekDesk { if (appData.AppConfig.HotkeyModifiers != 0) { - //加载完毕注册热键 - hotKeyId = Hotkey.Regist(new WindowInteropHelper(MainWindow.mainWindow).Handle, appData.AppConfig.HotkeyModifiers, appData.AppConfig.Hotkey, () => + + hotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.HotkeyModifiers, appData.AppConfig.Hotkey, () => { if (MotionControl.hotkeyFinished) { - if (mainWindow.Visibility == Visibility.Collapsed) + if (mainWindow.Visibility == Visibility.Collapsed || mainWindow.Opacity == 0) { ShowApp(); } else { - mainWindow.Visibility = Visibility.Collapsed; + HideApp(); } } }); @@ -123,6 +138,39 @@ namespace GeekDesk } } + public static void FadeStoryBoard(int opacity, int milliseconds, Visibility visibility) + { + if (appData.AppConfig.AppAnimation) + { + DoubleAnimation opacityAnimation = new DoubleAnimation + { + From = mainWindow.Opacity, + To = opacity, + Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds)) + }; + opacityAnimation.Completed += (s, e) => + { + mainWindow.BeginAnimation(OpacityProperty, null); + if (visibility == Visibility.Visible) + { + mainWindow.Opacity = 1; + } else + { + mainWindow.Opacity = 0; + } + }; + Timeline.SetDesiredFrameRate(opacityAnimation, 30); + mainWindow.BeginAnimation(OpacityProperty, opacityAnimation); + } else + { + //防止关闭动画后 窗体仍是0透明度 + mainWindow.Opacity = 1; + mainWindow.Visibility = visibility; + } + + + } + /// /// 注册新建待办的热键 /// @@ -130,14 +178,15 @@ namespace GeekDesk { try { + if (appData.AppConfig.ToDoHotkeyModifiers!=0) { //加载完毕注册热键 - toDoHotKeyId = Hotkey.Regist(new WindowInteropHelper(MainWindow.mainWindow).Handle, appData.AppConfig.ToDoHotkeyModifiers, appData.AppConfig.ToDoHotkey, () => + toDoHotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.ToDoHotkeyModifiers, appData.AppConfig.ToDoHotkey, () => { if (MotionControl.hotkeyFinished) { - ToDoInfoWindow.ShowNone(); + ToDoInfoWindow.ShowOrHide(); } }); } @@ -159,22 +208,6 @@ namespace GeekDesk } } - //private void DisplayWindowHotKeyPress(object sender, KeyPressedEventArgs e) - //{ - // if (e.HotKey.Key == Key.Y) - // { - // if (this.Visibility == Visibility.Collapsed) - // { - // ShowApp(); - // } - // else - // { - // this.Visibility = Visibility.Collapsed; - // } - // } - - //} - void MainWindow_Resize(object sender, System.EventArgs e) { @@ -231,7 +264,13 @@ namespace GeekDesk /// private void CloseButtonClick(object sender, RoutedEventArgs e) { - this.Visibility = Visibility.Collapsed; + if (appData.AppConfig.AppAnimation) + { + FadeStoryBoard(0, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Collapsed); + } else + { + this.Visibility = Visibility.Collapsed; + } } @@ -261,15 +300,18 @@ namespace GeekDesk { if (appData.AppConfig.FollowMouse) { - ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0); - } else - { - mainWindow.Visibility = Visibility.Visible; + ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0, false); } + FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible); Keyboard.Focus(mainWindow); } - + public static void HideApp() + { + FadeStoryBoard(0, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Collapsed); + } + + /// @@ -279,13 +321,13 @@ namespace GeekDesk /// private void NotifyIcon_Click(object sender, RoutedEventArgs e) { - if (this.Visibility == Visibility.Collapsed) + if (this.Visibility == Visibility.Collapsed || this.Opacity == 0) { ShowApp(); } else { - this.Visibility = Visibility.Collapsed; + HideApp(); } } @@ -299,6 +341,20 @@ namespace GeekDesk ConfigWindow.Show(appData.AppConfig, this); } + + /// + /// 右键任务栏图标打开程序目录 + /// + /// + /// + private void OpenThisDir(object sender, RoutedEventArgs e) + { + Process p = new Process(); + p.StartInfo.FileName = "Explorer.exe"; + p.StartInfo.Arguments = "/e,/select," + Constants.APP_DIR + Constants.MY_NAME + ".exe"; + p.Start(); + } + /// /// 右键任务栏图标退出 /// @@ -311,17 +367,6 @@ namespace GeekDesk - //public static void ShowContextMenu(IntPtr hAppWnd, Window taskBar, System.Windows.Point pt) - //{ - // WindowInteropHelper helper = new WindowInteropHelper(taskBar); - // IntPtr callingTaskBarWindow = helper.Handle; - // IntPtr wMenu = GetSystemMenu(hAppWnd, false); - // // Display the menu - // uint command = TrackPopupMenuEx(wMenu, TPM.LEFTBUTTON | TPM.RETURNCMD, (int) pt.X, (int) pt.Y, callingTaskBarWindow, IntPtr.Zero); - // if (command == 0) return; - // PostMessage(hAppWnd, WM.SYSCOMMAND, new IntPtr(command), IntPtr.Zero); - //} - /// /// 设置图标 /// @@ -364,11 +409,15 @@ namespace GeekDesk { if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS) { - this.Visibility = Visibility.Collapsed; + //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 + if (appData.AppConfig.MarginHide && !hide.IsMargin()) + { + this.Visibility = Visibility.Collapsed; + } } } - private void window_Deactivated(object sender, EventArgs e) + private void Window_Deactivated(object sender, EventArgs e) { if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS) { @@ -376,7 +425,7 @@ namespace GeekDesk } } - private void window_SizeChanged(object sender, SizeChangedEventArgs e) + private void Window_SizeChanged(object sender, SizeChangedEventArgs e) { if (this.DataContext != null) { @@ -385,6 +434,20 @@ namespace GeekDesk appData.AppConfig.WindowHeight = this.Height; } } + + /// + /// 重启 + /// + /// + /// + private void ReStartApp(object sender, RoutedEventArgs e) + { + Process p = new Process(); + p.StartInfo.FileName = Constants.APP_DIR + Constants.MY_NAME + ".exe"; + p.StartInfo.WorkingDirectory = Constants.APP_DIR; + p.Start(); + Application.Current.Shutdown(); + } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 359c9bb..d20c83d 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -49,5 +49,5 @@ using System.Windows; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.1")] -[assembly: AssemblyFileVersion("2.1")] +[assembly: AssemblyVersion("2.2")] +[assembly: AssemblyFileVersion("2.2")] diff --git a/Update.json b/Update.json index ab345e6..62d6955 100644 --- a/Update.json +++ b/Update.json @@ -1,9 +1,9 @@ { "title" : "汾", - "subTitle" : "V2.1 ʽ", + "subTitle" : "V2.2 ʽ", "msgTitle" : "θ", - "msg" : "['ֳ޸', 'ͼ깦ܳ޸','Զɫ','URLĿ']", - "githubUrl" : "https://github.com/Demo-Liu/GeekDesk/releases/tag/2.1", - "giteeUrl" : "https://gitee.com/demo_liu/GeekDesk/releases/2.1", - "version": "2.1" + "msg" : "['Ե','ڵ뵭','ݼ(ĬCtrl+Shift+Q)','Ҽͼ򿪳Ŀ¼˵']", + "githubUrl" : "https://github.com/Demo-Liu/GeekDesk/releases/tag", + "giteeUrl" : "https://gitee.com/demo_liu/GeekDesk/releases", + "version": "2.2" } \ No newline at end of file diff --git a/Util/GlobalHotKey.cs b/Util/GlobalHotKey.cs new file mode 100644 index 0000000..b626522 --- /dev/null +++ b/Util/GlobalHotKey.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Input; +using System.Windows.Interop; + +namespace GeekDesk.Util +{ + public class GlobalHotKey + { + public enum HotkeyModifiers + { + MOD_ALT = 0x1, + MOD_CONTROL = 0x2, + MOD_SHIFT = 0x4, + MOD_WIN = 0x8 + } + + private static int currentID; + const int WM_HOTKEY = 0x312; + private static Dictionary handleTemp = new Dictionary(); + public static Dictionary callbackTemp = new Dictionary(); + + public delegate void HotKeyCallBackHanlder(); + /// + /// Registers a global hotkey + /// + /// e.g. Alt + Shift + Control + Win + S + /// Action to be called when hotkey is pressed + /// true, if registration succeeded, otherwise false + public static int RegisterHotKey(string aKeyGestureString, HotKeyCallBackHanlder callback) + { + var c = new KeyGestureConverter(); + KeyGesture aKeyGesture = (KeyGesture)c.ConvertFrom(aKeyGestureString); + return RegisterHotKey((HotkeyModifiers)aKeyGesture.Modifiers, aKeyGesture.Key, callback); + } + + public static int RegisterHotKey(HotkeyModifiers aModifier, Key key, HotKeyCallBackHanlder callback) + { + Window window = new Window + { + WindowStyle = WindowStyle.None, + Height = 0, + Width = 0, + Visibility = Visibility.Collapsed, + ShowInTaskbar = false + }; + window.Show(); + IntPtr handle = new WindowInteropHelper(window).Handle; + HwndSource hs = HwndSource.FromHwnd(handle); + hs.AddHook(WndProc); + currentID += 1; + if (!RegisterHotKey(handle, currentID, aModifier, (uint)KeyInterop.VirtualKeyFromKey(key))) + { + window.Close(); + throw new Exception("RegisterHotKey Failed"); + } + handleTemp.Add(currentID, window); + callbackTemp.Add(currentID, callback); + return currentID; + } + /// + /// 快捷键消息处理 + /// + static IntPtr WndProc(IntPtr windowHandle, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + if (msg == WM_HOTKEY) + { + int id = wParam.ToInt32(); + if (callbackTemp.TryGetValue(id, out var callback)) + { + callback(); + } + } + return IntPtr.Zero; + } + + public static void Dispose(int id) + { + bool test = UnregisterHotKey(new WindowInteropHelper(handleTemp[id]).Handle, id); + GlobalHotKey.handleTemp[id].Close(); + GlobalHotKey.handleTemp.Remove(id); + GlobalHotKey.callbackTemp.Remove(id); + Console.WriteLine(test); + } + + // Registers a hot key with Windows. + [DllImport("user32.dll")] + private static extern bool RegisterHotKey(IntPtr hWnd, int id, HotkeyModifiers fsModifiers, uint vk); + // Unregisters the hot key with Windows. + [DllImport("user32.dll")] + private static extern bool UnregisterHotKey(IntPtr hWnd, int id); + } +} diff --git a/Util/HotKey.cs b/Util/HotKey.cs deleted file mode 100644 index 81ef6f4..0000000 --- a/Util/HotKey.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Windows; -using System.Windows.Input; -using System.Windows.Interop; - - -/// -/// 热键注册 -/// -namespace GeekDesk.Util -{ - - class Hotkey - { - #region 系统api - [DllImport("user32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool RegisterHotKey(IntPtr hWnd, int id, HotkeyModifiers fsModifiers, uint vk); - - [DllImport("user32.dll")] - static extern bool UnregisterHotKey(IntPtr hWnd, int id); - #endregion - - /// - /// 注册快捷键 - /// - /// 持有快捷键窗口 - /// 组合键 - /// 快捷键 - /// 回调函数 - public static int Regist(IntPtr windowHandle, HotkeyModifiers fsModifiers, Key key, HotKeyCallBackHanlder callBack) - { - HwndSource hs = HwndSource.FromHwnd(windowHandle); - hs.AddHook(WndProc); - - int id = keyid++; - int vk = KeyInterop.VirtualKeyFromKey(key); - keymap.Add(id, callBack); - if (!RegisterHotKey(windowHandle, id, fsModifiers, (uint)vk)) throw new Exception("RegisterHotKey Failed"); - return id; - } - - /// - /// 快捷键消息处理 - /// - static IntPtr WndProc(IntPtr windowHandle, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) - { - if (msg == WM_HOTKEY) - { - int id = wParam.ToInt32(); - if (keymap.TryGetValue(id, out var callback)) - { - callback(); - } - } - return IntPtr.Zero; - } - - /// - /// 注销快捷键 - /// - /// 持有快捷键窗口的句柄 - /// 回调函数 - public static void UnRegist(IntPtr windowHandle, HotKeyCallBackHanlder callBack) - { - List list = new List(keymap.Keys); - for (int i=0; i < list.Count; i++) - { - if (keymap[list[i]] == callBack) - { - HwndSource hs = HwndSource.FromHwnd(windowHandle); - hs.RemoveHook(WndProc); - UnregisterHotKey(windowHandle, list[i]); - keymap.Remove(list[i]); - } - } - } - - const int WM_HOTKEY = 0x312; - static int keyid = 10; - public static Dictionary keymap = new Dictionary(); - - public delegate void HotKeyCallBackHanlder(); - } - - public enum HotkeyModifiers - { - MOD_ALT = 0x1, - MOD_CONTROL = 0x2, - MOD_SHIFT = 0x4, - MOD_WIN = 0x8 - } - -} diff --git a/Util/MarginHide.cs b/Util/MarginHide.cs new file mode 100644 index 0000000..dccf12f --- /dev/null +++ b/Util/MarginHide.cs @@ -0,0 +1,199 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using System.Drawing; //添加引用 +using System.Windows.Forms;//添加引用 +using MouseEventArgs = System.Windows.Input.MouseEventArgs; +using System.Windows; +using System.Windows.Media.Animation; +using System.Windows.Media; + +namespace GeekDesk.Util +{ + + enum HidePosition + { + TOP = 1, + LEFT = 2, + RIGHT = 3 + } + + public class MarginHide + { + readonly Window window;//定义使用该方法的窗体 + + private readonly int hideTime = 150; + + private readonly int taskTime = 200; + + private bool isHide; + + public Timer timer; + //构造函数,传入将要匹配的窗体 + public MarginHide(Window window) + { + this.window = window; + } + + + /// + /// 窗体是否贴边 + /// + /// + public bool IsMargin() + { + double screenLeft = SystemParameters.VirtualScreenLeft; + double screenTop = SystemParameters.VirtualScreenTop; + double screenWidth = SystemParameters.VirtualScreenWidth; + + double windowWidth = window.Width; + + double windowTop = window.Top; + double windowLeft = window.Left; + + //窗体是否贴边 + return (windowLeft <= screenLeft + || windowTop <= screenTop + || windowLeft + windowWidth + Math.Abs(screenLeft) >= screenWidth); + } + + + + #region 窗体贴边隐藏功能 + private void TimerDealy(object o, EventArgs e) + { + if (window.Visibility != Visibility.Visible) return; + + double screenLeft = SystemParameters.VirtualScreenLeft; + double screenTop = SystemParameters.VirtualScreenTop; + double screenWidth = SystemParameters.VirtualScreenWidth; + + double windowHeight = window.Height; + double windowWidth = window.Width; + + double windowTop = window.Top; + double windowLeft = window.Left; + + //获取鼠标位置 + System.Windows.Point p = MouseUtil.GetMousePosition(); + double mouseX = p.X; + double mouseY = p.Y; + + //鼠标不在窗口上 + if (mouseX < windowLeft || mouseX > windowLeft + windowWidth + || mouseY < windowTop || mouseY > windowTop + windowHeight) + { + //上方隐藏条件 + if (windowTop <= screenTop) + { + HideAnimation(windowTop, screenTop - windowHeight + 1, Window.TopProperty); + isHide = true; + return; + } + //左侧隐藏条件 + if (windowLeft <= screenLeft) + { + HideAnimation(windowLeft, screenLeft - windowWidth + 1, Window.LeftProperty); + return; + } + //右侧隐藏条件 + if (windowLeft + windowWidth + Math.Abs(screenLeft) >= screenWidth) + { + HideAnimation(windowLeft, screenWidth - Math.Abs(screenLeft) - 1, Window.LeftProperty); + return; + } + } else if (mouseX >= windowLeft && mouseX <= windowLeft + windowWidth + && mouseY >= windowTop && mouseY <= windowTop + windowHeight) + { + //上方显示 + if (windowTop <= screenTop - 1) + { + HideAnimation(windowTop, screenTop, Window.TopProperty); + return; + } + //左侧显示 + if (windowLeft <= screenLeft -1) + { + HideAnimation(windowLeft, screenLeft, Window.LeftProperty); + return; + } + //右侧显示 + if (windowLeft + Math.Abs(screenLeft) == screenWidth -1) + { + HideAnimation(windowLeft, screenWidth - Math.Abs(screenLeft) - windowWidth, Window.LeftProperty); + return; + } + } + + } + #endregion + + + public void TimerSet() + { + timer = new Timer();//添加timer计时器,隐藏功能 + #region 计时器设置,隐藏功能 + timer.Interval = taskTime; + timer.Tick += TimerDealy; + timer.Start(); + #endregion + } + + public void TimerStop() + { + timer.Stop(); + //功能关闭 如果界面是隐藏状态 那么要显示界面 ↓ + + double screenLeft = SystemParameters.VirtualScreenLeft; + double screenTop = SystemParameters.VirtualScreenTop; + double screenWidth = SystemParameters.VirtualScreenWidth; + + double windowWidth = window.Width; + + double windowTop = window.Top; + double windowLeft = window.Left; + + //左侧显示 + if (windowLeft <= screenLeft - 1) + { + HideAnimation(windowLeft, screenLeft, Window.LeftProperty); + return; + } + + //上方显示 + if (windowTop <= screenTop - 1) + { + HideAnimation(windowTop, screenTop, Window.TopProperty); + return; + } + + //右侧显示 + if (windowLeft + Math.Abs(screenLeft) == screenWidth - 1) + { + HideAnimation(windowLeft, screenWidth - Math.Abs(screenLeft) - windowWidth, Window.LeftProperty); + return; + } + } + + + private void HideAnimation(double from, double to, DependencyProperty property) + { + DoubleAnimation da = new DoubleAnimation + { + From = from, + To = to, + Duration = new Duration(TimeSpan.FromMilliseconds(hideTime)) + }; + da.Completed += (s, e) => + { + window.BeginAnimation(property, null); + }; + Timeline.SetDesiredFrameRate(da, 30); + window.BeginAnimation(property, da); + } + } +} + diff --git a/Util/ShowWindowFollowMouse.cs b/Util/ShowWindowFollowMouse.cs index 5432dfe..b5db6ec 100644 --- a/Util/ShowWindowFollowMouse.cs +++ b/Util/ShowWindowFollowMouse.cs @@ -18,9 +18,9 @@ namespace GeekDesk.Util } /// - /// 随鼠标位置显示面板 (鼠标始终在中间) + /// 随鼠标位置显示面板 /// - public static void Show(Window window, MousePosition position, double widthOffset, double heightOffset) + public static void Show(Window window, MousePosition position, double widthOffset = 0, double heightOffset = 0, bool visibility = true) { //获取鼠标位置 System.Windows.Point p = MouseUtil.GetMousePosition(); @@ -100,7 +100,11 @@ namespace GeekDesk.Util { window.Top = p.Y - afterHeight; } - window.Visibility = Visibility.Visible; + if (visibility) + { + window.Opacity = 0; + window.Visibility = Visibility.Visible; + } } } diff --git a/ViewModel/AppConfig.cs b/ViewModel/AppConfig.cs index 97a2829..3656295 100644 --- a/ViewModel/AppConfig.cs +++ b/ViewModel/AppConfig.cs @@ -7,6 +7,7 @@ using System.ComponentModel; using System.Windows; using System.Windows.Input; using System.Windows.Media.Imaging; +using static GeekDesk.Util.GlobalHotKey; /// /// 程序设置 @@ -42,9 +43,9 @@ namespace GeekDesk.ViewModel private HotkeyModifiers hotkeyModifiers = HotkeyModifiers.MOD_CONTROL; //默认启动面板快捷键 private Key hotkey = Key.Q; //默认启动面板快捷键 - private string toDoHotkeyStr; //待办任务快捷键 + private string toDoHotkeyStr = "Ctrl + Shift + Q"; //待办任务快捷键 private HotkeyModifiers toDoHotkeyModifiers; //待办任务快捷键 - private Key toDoHotkey; //待办任务快捷键 + private Key toDoHotkey = Key.E; //待办任务快捷键 private string customIconUrl; //自定义图标url private string customIconJsonUrl; //自定义图标json信息url @@ -61,9 +62,39 @@ namespace GeekDesk.ViewModel private double imgPanelWidth = (double)CommonEnum.IMAGE_PANEL_WIDTH; private double imgPanelHeight = (double)CommonEnum.IMAGE_PANEL_HEIGHT; + private bool marginHide = false; //贴边隐藏 + + private bool appAnimation = false; //主窗口动画效果 + #region GetSet + public bool AppAnimation + { + get + { + return appAnimation; + } + set + { + appAnimation = value; + OnPropertyChanged("AppAnimation"); + } + } + + public bool MarginHide + { + get + { + return marginHide; + } + set + { + marginHide = value; + OnPropertyChanged("MarginHide"); + } + } + public double ImgPanelWidth { get @@ -150,6 +181,11 @@ namespace GeekDesk.ViewModel { get { + //兼容老版本 + if (toDoHotkey == Key.None) + { + toDoHotkey = Key.Q; + } return toDoHotkey; } set @@ -164,6 +200,10 @@ namespace GeekDesk.ViewModel { get { + if (toDoHotkeyModifiers == 0) + { + toDoHotkeyModifiers = HotkeyModifiers.MOD_CONTROL | HotkeyModifiers.MOD_SHIFT; + } return toDoHotkeyModifiers; } set @@ -177,6 +217,11 @@ namespace GeekDesk.ViewModel { get { + //兼容老版本 + if (toDoHotkeyStr == null) + { + toDoHotkeyStr = "Ctrl + Shift + Q"; + } return toDoHotkeyStr; } set @@ -283,6 +328,10 @@ namespace GeekDesk.ViewModel { get { + if (hotkeyModifiers == 0) + { + hotkeyModifiers = HotkeyModifiers.MOD_CONTROL; + } return hotkeyModifiers; } set