Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Oct 13, 2024
1 parent e230ea8 commit efa8ed1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public static void ApplyPreferences()
? MainWindowBackgroundOpacityOnUnhover / 100
: MainWindow.Instance.OpacitySlider.Value / 100;

WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
KeyGestureUtils.GlobalKeyGestureDict.Clear();
KeyGestureUtils.GlobalKeyGestureNameToIntDict.Clear();

Expand Down Expand Up @@ -520,7 +520,7 @@ public static void ApplyPreferences()

if (GlobalHotKeys && !DisableHotkeys)
{
WinApi.RegisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.RegisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}

MainWindow.Instance.AddNameMenuItem.SetInputGestureText(ShowAddNameWindowKeyGesture);
Expand Down
12 changes: 6 additions & 6 deletions JL.Windows/GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,16 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)
{
if (KeyGestureUtils.GlobalKeyGestureNameToIntDict.TryGetValue(nameof(ConfigManager.DisableHotkeys), out int id))
{
WinApi.UnregisterAllHotKeys(WindowHandle, id);
WinApi.UnregisterAllGlobalHotKeys(WindowHandle, id);
}
else
{
WinApi.UnregisterAllHotKeys(WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(WindowHandle);
}
}
else
{
WinApi.RegisterAllHotKeys(WindowHandle);
WinApi.RegisterAllGlobalHotKeys(WindowHandle);
}
}
}
Expand Down Expand Up @@ -1624,11 +1624,11 @@ private void Window_StateChanged(object sender, EventArgs e)

if (keyGestureIdsToIgnore.Count > 0)
{
WinApi.UnregisterAllHotKeys(WindowHandle, keyGestureIdsToIgnore);
WinApi.UnregisterAllGlobalHotKeys(WindowHandle, keyGestureIdsToIgnore);
}
else
{
WinApi.UnregisterAllHotKeys(WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(WindowHandle);
}
}
}
Expand All @@ -1643,7 +1643,7 @@ private void Window_StateChanged(object sender, EventArgs e)

if (ConfigManager.GlobalHotKeys)
{
WinApi.RegisterAllHotKeys(WindowHandle);
WinApi.RegisterAllGlobalHotKeys(WindowHandle);
}

if (SizeToContent is SizeToContent.Manual && (ConfigManager.MainWindowDynamicHeight || ConfigManager.MainWindowDynamicWidth))
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/GUI/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,11 +1299,11 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)
{
if (ConfigManager.DisableHotkeys)
{
WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}
else
{
WinApi.RegisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.RegisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/Utilities/KeyGestureUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static KeyGesture GetKeyGestureFromConfig(SqliteConnection connection, st
KeyGesture newKeyGesture = (KeyGesture)keyGestureConverter.ConvertFromInvariantString(keyGestureString)!;
if (ConfigManager.GlobalHotKeys)
{
WinApi.AddHotKeyToKeyGestureDict(keyGestureName, newKeyGesture);
WinApi.AddHotKeyToGlobalKeyGestureDict(keyGestureName, newKeyGesture);
}

return newKeyGesture;
Expand All @@ -190,7 +190,7 @@ public static KeyGesture GetKeyGestureFromConfig(SqliteConnection connection, st
ConfigDBManager.InsertSetting(connection, keyGestureName, defaultKeyGesture.ToFormattedString());
if (ConfigManager.GlobalHotKeys)
{
WinApi.AddHotKeyToKeyGestureDict(keyGestureName, defaultKeyGesture);
WinApi.AddHotKeyToGlobalKeyGestureDict(keyGestureName, defaultKeyGesture);
}

return defaultKeyGesture;
Expand Down
16 changes: 8 additions & 8 deletions JL.Windows/Utilities/WindowsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static void ShowAddNameWindow(Window owner, string? selectedText, string

if (ConfigManager.GlobalHotKeys && !ConfigManager.DisableHotkeys)
{
WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}

_ = addNameWindowInstance.ShowDialog();
Expand All @@ -166,7 +166,7 @@ public static void ShowAddWordWindow(Window owner, string? selectedText)

if (ConfigManager.GlobalHotKeys && !ConfigManager.DisableHotkeys)
{
WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}

_ = addWordWindowInstance.ShowDialog();
Expand All @@ -182,7 +182,7 @@ public static void ShowPreferencesWindow()

if (ConfigManager.GlobalHotKeys && !ConfigManager.DisableHotkeys)
{
WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}

_ = preferencesWindow.ShowDialog();
Expand Down Expand Up @@ -214,7 +214,7 @@ public static async Task ShowManageDictionariesWindow()

if (ConfigManager.GlobalHotKeys && !ConfigManager.DisableHotkeys)
{
WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}

_ = manageDictionariesWindow.ShowDialog();
Expand All @@ -234,7 +234,7 @@ public static async Task ShowManageFrequenciesWindow()

if (ConfigManager.GlobalHotKeys && !ConfigManager.DisableHotkeys)
{
WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}

_ = manageFrequenciesWindow.ShowDialog();
Expand All @@ -251,7 +251,7 @@ public static void ShowStatsWindow()

if (ConfigManager.GlobalHotKeys && !ConfigManager.DisableHotkeys)
{
WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}

_ = statsWindow.ShowDialog();
Expand All @@ -271,7 +271,7 @@ public static async Task ShowManageAudioSourcesWindow()

if (ConfigManager.GlobalHotKeys && !ConfigManager.DisableHotkeys)
{
WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.UnregisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}

_ = manageAudioSourcesWindow.ShowDialog();
Expand Down Expand Up @@ -702,7 +702,7 @@ public static void UpdateMainWindowVisibility()

if (ConfigManager.GlobalHotKeys && !ConfigManager.DisableHotkeys)
{
WinApi.RegisterAllHotKeys(MainWindow.Instance.WindowHandle);
WinApi.RegisterAllGlobalHotKeys(MainWindow.Instance.WindowHandle);
}
}

Expand Down
10 changes: 5 additions & 5 deletions JL.Windows/WinApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static ulong GetClipboardSequenceNo()
return GetClipboardSequenceNumber();
}

public static void AddHotKeyToKeyGestureDict(string hotkeyName, KeyGesture keyGesture)
public static void AddHotKeyToGlobalKeyGestureDict(string hotkeyName, KeyGesture keyGesture)
{
int id = KeyGestureUtils.GlobalKeyGestureDict.Count;

Expand All @@ -208,23 +208,23 @@ public static void AddHotKeyToKeyGestureDict(string hotkeyName, KeyGesture keyGe
}
}

public static void RegisterAllHotKeys(nint windowHandle)
public static void RegisterAllGlobalHotKeys(nint windowHandle)
{
foreach (KeyValuePair<int, KeyGesture> keyValuePair in KeyGestureUtils.GlobalKeyGestureDict)
{
_ = RegisterHotKey(windowHandle, keyValuePair.Key, (uint)keyValuePair.Value.Modifiers | MOD_NOREPEAT, (uint)KeyInterop.VirtualKeyFromKey(keyValuePair.Value.Key));
}
}

public static void UnregisterAllHotKeys(nint windowHandle)
public static void UnregisterAllGlobalHotKeys(nint windowHandle)
{
foreach (int id in KeyGestureUtils.GlobalKeyGestureDict.Keys)
{
_ = UnregisterHotKey(windowHandle, id);
}
}

public static void UnregisterAllHotKeys(nint windowHandle, int keyGestureIdToIgnore)
public static void UnregisterAllGlobalHotKeys(nint windowHandle, int keyGestureIdToIgnore)
{
foreach (int id in KeyGestureUtils.GlobalKeyGestureDict.Keys)
{
Expand All @@ -237,7 +237,7 @@ public static void UnregisterAllHotKeys(nint windowHandle, int keyGestureIdToIgn
}
}

public static void UnregisterAllHotKeys(nint windowHandle, List<int> keyGestureIdsToIgnore)
public static void UnregisterAllGlobalHotKeys(nint windowHandle, List<int> keyGestureIdsToIgnore)
{
foreach (int id in KeyGestureUtils.GlobalKeyGestureDict.Keys)
{
Expand Down

0 comments on commit efa8ed1

Please sign in to comment.