mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-06 03:07:54 +08:00
Merge pull request #340 from lances101/master
Option to ignore hotkeys on fullscreen windows
This commit is contained in:
commit
326ee9a9c2
@ -86,6 +86,9 @@ namespace Wox.Core.UserSettings
|
|||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public bool RememberLastLaunchLocation { get; set; }
|
public bool RememberLastLaunchLocation { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty]
|
||||||
|
public bool IgnoreHotkeysOnFullscreen { get; set; }
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public string ProxyServer { get; set; }
|
public string ProxyServer { get; set; }
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Drawing;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Windows.Interop;
|
||||||
|
|
||||||
namespace Wox.Helper
|
namespace Wox.Helper
|
||||||
{
|
{
|
||||||
@ -11,6 +11,25 @@ namespace Wox.Helper
|
|||||||
{
|
{
|
||||||
private const int GWL_STYLE = -16; //WPF's Message code for Title Bar's Style
|
private const int GWL_STYLE = -16; //WPF's Message code for Title Bar's Style
|
||||||
private const int WS_SYSMENU = 0x80000; //WPF's Message code for System Menu
|
private const int WS_SYSMENU = 0x80000; //WPF's Message code for System Menu
|
||||||
|
private static IntPtr _hwnd_shell;
|
||||||
|
private static IntPtr _hwnd_desktop;
|
||||||
|
|
||||||
|
//Accessors for shell and desktop handlers
|
||||||
|
//Will set the variables once and then will return them
|
||||||
|
private static IntPtr HWND_SHELL
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _hwnd_shell != null ? _hwnd_shell : _hwnd_shell = GetShellWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static IntPtr HWND_DESKTOP
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _hwnd_desktop != null ? _hwnd_desktop : _hwnd_desktop = GetDesktopWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
||||||
@ -18,14 +37,56 @@ namespace Wox.Helper
|
|||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern IntPtr GetForegroundWindow();
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern IntPtr GetDesktopWindow();
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern IntPtr GetShellWindow();
|
||||||
|
|
||||||
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
|
private static extern int GetWindowRect(IntPtr hwnd, out RECT rc);
|
||||||
|
|
||||||
|
public static bool IsWindowFullscreen()
|
||||||
|
{
|
||||||
|
RECT foreWinBounds;
|
||||||
|
Rectangle screenBounds;
|
||||||
|
var hWnd = GetForegroundWindow();
|
||||||
|
if (!hWnd.Equals(IntPtr.Zero))
|
||||||
|
{
|
||||||
|
if (!(hWnd.Equals(HWND_DESKTOP) || hWnd.Equals(HWND_SHELL)))
|
||||||
|
{
|
||||||
|
GetWindowRect(hWnd, out foreWinBounds);
|
||||||
|
screenBounds = Screen.FromHandle(hWnd).Bounds;
|
||||||
|
if ((foreWinBounds.Bottom - foreWinBounds.Top) == screenBounds.Height && (foreWinBounds.Right - foreWinBounds.Left) == screenBounds.Width)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// disable windows toolbar's control box
|
/// disable windows toolbar's control box
|
||||||
/// this will also disable system menu with Alt+Space hotkey
|
/// this will also disable system menu with Alt+Space hotkey
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void DisableControlBox(Window win)
|
public static void DisableControlBox(Window win)
|
||||||
{
|
{
|
||||||
var hwnd = new System.Windows.Interop.WindowInteropHelper(win).Handle;
|
var hwnd = new WindowInteropHelper(win).Handle;
|
||||||
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
|
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct RECT
|
||||||
|
{
|
||||||
|
public int Left;
|
||||||
|
public int Top;
|
||||||
|
public int Right;
|
||||||
|
public int Bottom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,6 +23,7 @@
|
|||||||
<system:String x:Key="rememberLastLocation">Remember last launch location</system:String>
|
<system:String x:Key="rememberLastLocation">Remember last launch location</system:String>
|
||||||
<system:String x:Key="language">Language</system:String>
|
<system:String x:Key="language">Language</system:String>
|
||||||
<system:String x:Key="maxShowResults">Maximum show results</system:String>
|
<system:String x:Key="maxShowResults">Maximum show results</system:String>
|
||||||
|
<system:String x:Key="ignoreHotkeysOnFullscreen">Ignore hotkeys if window is fullscreen</system:String>
|
||||||
|
|
||||||
<!--Setting Plugin-->
|
<!--Setting Plugin-->
|
||||||
<system:String x:Key="plugin">Plugin</system:String>
|
<system:String x:Key="plugin">Plugin</system:String>
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
<system:String x:Key="rememberLastLocation">Запомнить последнее место запуска</system:String>
|
<system:String x:Key="rememberLastLocation">Запомнить последнее место запуска</system:String>
|
||||||
<system:String x:Key="language">Язык</system:String>
|
<system:String x:Key="language">Язык</system:String>
|
||||||
<system:String x:Key="maxShowResults">Максимальное количество результатов</system:String>
|
<system:String x:Key="maxShowResults">Максимальное количество результатов</system:String>
|
||||||
|
<system:String x:Key="ignoreHotkeysOnFullscreen">Игнорировать горячие клавиши, если окно в полноэкранном режиме</system:String>
|
||||||
|
|
||||||
<!--Setting Plugin-->
|
<!--Setting Plugin-->
|
||||||
<system:String x:Key="plugin">Плагины</system:String>
|
<system:String x:Key="plugin">Плагины</system:String>
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
<system:String x:Key="rememberLastLocation">记住上次启动位置</system:String>
|
<system:String x:Key="rememberLastLocation">记住上次启动位置</system:String>
|
||||||
<system:String x:Key="language">语言</system:String>
|
<system:String x:Key="language">语言</system:String>
|
||||||
<system:String x:Key="maxShowResults">最大结果显示个数</system:String>
|
<system:String x:Key="maxShowResults">最大结果显示个数</system:String>
|
||||||
|
<system:String x:Key="ignoreHotkeysOnFullscreen">Ignore hotkeys if foreground window is TopMost</system:String>
|
||||||
|
|
||||||
<!--设置,插件-->
|
<!--设置,插件-->
|
||||||
<system:String x:Key="plugin">插件</system:String>
|
<system:String x:Key="plugin">插件</system:String>
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
<system:String x:Key="rememberLastLocation">记住上次启动位置</system:String>
|
<system:String x:Key="rememberLastLocation">记住上次启动位置</system:String>
|
||||||
<system:String x:Key="language">語言</system:String>
|
<system:String x:Key="language">語言</system:String>
|
||||||
<system:String x:Key="maxShowResults">最大結果顯示個數</system:String>
|
<system:String x:Key="maxShowResults">最大結果顯示個數</system:String>
|
||||||
|
<system:String x:Key="ignoreHotkeysOnFullscreen">Ignore hotkeys if foreground window is TopMost</system:String>
|
||||||
|
|
||||||
<!--設置,插件-->
|
<!--設置,插件-->
|
||||||
<system:String x:Key="plugin">插件</system:String>
|
<system:String x:Key="plugin">插件</system:String>
|
||||||
|
@ -356,6 +356,20 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if Wox should ignore any hotkeys
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool ShouldIgnoreHotkeys()
|
||||||
|
{
|
||||||
|
//double if to omit calling win32 function
|
||||||
|
if (UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen)
|
||||||
|
if(WindowIntelopHelper.IsWindowFullscreen())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void SetCustomPluginHotkey()
|
private void SetCustomPluginHotkey()
|
||||||
{
|
{
|
||||||
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
|
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
|
||||||
@ -364,6 +378,7 @@ namespace Wox
|
|||||||
CustomPluginHotkey hotkey1 = hotkey;
|
CustomPluginHotkey hotkey1 = hotkey;
|
||||||
SetHotkey(hotkey.Hotkey, delegate
|
SetHotkey(hotkey.Hotkey, delegate
|
||||||
{
|
{
|
||||||
|
if (ShouldIgnoreHotkeys()) return;
|
||||||
ShowApp();
|
ShowApp();
|
||||||
ChangeQuery(hotkey1.ActionKeyword, true);
|
ChangeQuery(hotkey1.ActionKeyword, true);
|
||||||
});
|
});
|
||||||
@ -372,6 +387,7 @@ namespace Wox
|
|||||||
|
|
||||||
private void OnHotkey(object sender, HotkeyEventArgs e)
|
private void OnHotkey(object sender, HotkeyEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (ShouldIgnoreHotkeys()) return;
|
||||||
ToggleWox();
|
ToggleWox();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,9 @@
|
|||||||
<CheckBox x:Name="cbRememberLastLocation" Margin="10">
|
<CheckBox x:Name="cbRememberLastLocation" Margin="10">
|
||||||
<TextBlock Text="{DynamicResource rememberLastLocation}" ></TextBlock>
|
<TextBlock Text="{DynamicResource rememberLastLocation}" ></TextBlock>
|
||||||
</CheckBox>
|
</CheckBox>
|
||||||
|
<CheckBox x:Name="cbIgnoreHotkeysOnFullscreen" Margin="10">
|
||||||
|
<TextBlock Text="{DynamicResource ignoreHotkeysOnFullscreen}" ></TextBlock>
|
||||||
|
</CheckBox>
|
||||||
<StackPanel Margin="10" Orientation="Horizontal">
|
<StackPanel Margin="10" Orientation="Horizontal">
|
||||||
<TextBlock Text="{DynamicResource language}"></TextBlock>
|
<TextBlock Text="{DynamicResource language}"></TextBlock>
|
||||||
<ComboBox Margin="10 0 0 0" Width="120" x:Name="cbLanguages" />
|
<ComboBox Margin="10 0 0 0" Width="120" x:Name="cbLanguages" />
|
||||||
|
@ -49,7 +49,6 @@ namespace Wox
|
|||||||
private void Setting_Loaded(object sender, RoutedEventArgs ev)
|
private void Setting_Loaded(object sender, RoutedEventArgs ev)
|
||||||
{
|
{
|
||||||
#region General
|
#region General
|
||||||
|
|
||||||
cbHideWhenDeactive.Checked += (o, e) =>
|
cbHideWhenDeactive.Checked += (o, e) =>
|
||||||
{
|
{
|
||||||
UserSettingStorage.Instance.HideWhenDeactive = true;
|
UserSettingStorage.Instance.HideWhenDeactive = true;
|
||||||
@ -86,6 +85,20 @@ namespace Wox
|
|||||||
UserSettingStorage.Instance.Save();
|
UserSettingStorage.Instance.Save();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cbIgnoreHotkeysOnFullscreen.Checked += (o, e) =>
|
||||||
|
{
|
||||||
|
UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen = true;
|
||||||
|
UserSettingStorage.Instance.Save();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
cbIgnoreHotkeysOnFullscreen.Unchecked += (o, e) =>
|
||||||
|
{
|
||||||
|
UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen = false;
|
||||||
|
UserSettingStorage.Instance.Save();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
cbStartWithWindows.IsChecked = CheckApplicationIsStartupWithWindow();
|
cbStartWithWindows.IsChecked = CheckApplicationIsStartupWithWindow();
|
||||||
comboMaxResultsToShow.SelectionChanged += (o, e) =>
|
comboMaxResultsToShow.SelectionChanged += (o, e) =>
|
||||||
{
|
{
|
||||||
@ -97,6 +110,7 @@ namespace Wox
|
|||||||
cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive;
|
cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive;
|
||||||
cbDontPromptUpdateMsg.IsChecked = UserSettingStorage.Instance.DontPromptUpdateMsg;
|
cbDontPromptUpdateMsg.IsChecked = UserSettingStorage.Instance.DontPromptUpdateMsg;
|
||||||
cbRememberLastLocation.IsChecked = UserSettingStorage.Instance.RememberLastLaunchLocation;
|
cbRememberLastLocation.IsChecked = UserSettingStorage.Instance.RememberLastLaunchLocation;
|
||||||
|
cbIgnoreHotkeysOnFullscreen.IsChecked = UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen;
|
||||||
|
|
||||||
LoadLanguages();
|
LoadLanguages();
|
||||||
comboMaxResultsToShow.ItemsSource = Enumerable.Range(2, 16);
|
comboMaxResultsToShow.ItemsSource = Enumerable.Range(2, 16);
|
||||||
|
Loading…
Reference in New Issue
Block a user