mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 17:53:32 +00:00
Disable profile preview on main window focus loss
This commit is contained in:
parent
b936908274
commit
529c6c8314
@ -89,7 +89,7 @@ namespace Artemis.DAL
|
|||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllText(path + $@"\{prof.Slug}.json", json);
|
File.WriteAllText(path + $@"\{prof.Slug}.json", json);
|
||||||
Logger.Debug("Saved profile {0}/{1}/{2}", prof.KeyboardSlug, prof.GameName, prof.Name);
|
Logger.Trace("Saved profile {0}/{1}/{2}", prof.KeyboardSlug, prof.GameName, prof.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using System.Timers;
|
|||||||
using Artemis.DAL;
|
using Artemis.DAL;
|
||||||
using Artemis.Modules.Abstract;
|
using Artemis.Modules.Abstract;
|
||||||
using Artemis.Settings;
|
using Artemis.Settings;
|
||||||
|
using Artemis.Utilities;
|
||||||
using Ninject.Extensions.Logging;
|
using Ninject.Extensions.Logging;
|
||||||
|
|
||||||
namespace Artemis.Managers
|
namespace Artemis.Managers
|
||||||
@ -46,9 +47,10 @@ namespace Artemis.Managers
|
|||||||
if (string.IsNullOrEmpty(_generalSettings.LastKeyboard) || _deviceManager.ChangingKeyboard)
|
if (string.IsNullOrEmpty(_generalSettings.LastKeyboard) || _deviceManager.ChangingKeyboard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// If Artemis doesn't have focus, don't preview
|
||||||
var activePreview = PreviewViewModules.FirstOrDefault(
|
var activePreview = PreviewViewModules.FirstOrDefault(
|
||||||
vm => vm.IsActive && vm.UsesProfileEditor && vm.ModuleModel.Settings.IsEnabled);
|
vm => vm.IsActive && vm.UsesProfileEditor && vm.ModuleModel.Settings.IsEnabled);
|
||||||
if (activePreview != null)
|
if (activePreview != null && ActiveWindowHelper.MainWindowActive)
|
||||||
EnsurePreviewActive(activePreview);
|
EnsurePreviewActive(activePreview);
|
||||||
else
|
else
|
||||||
EnsurePreviewInactive();
|
EnsurePreviewInactive();
|
||||||
|
|||||||
@ -8,10 +8,13 @@ namespace Artemis.Utilities
|
|||||||
{
|
{
|
||||||
#region DLL-Imports
|
#region DLL-Imports
|
||||||
|
|
||||||
private delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
|
private delegate void WinEventDelegate(
|
||||||
|
IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread,
|
||||||
|
uint dwmsEventTime);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);
|
private static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc,
|
||||||
|
WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern bool UnhookWinEvent(IntPtr hWinEventHook);
|
private static extern bool UnhookWinEvent(IntPtr hWinEventHook);
|
||||||
@ -49,8 +52,9 @@ namespace Artemis.Utilities
|
|||||||
|
|
||||||
private static IntPtr _activeWindow;
|
private static IntPtr _activeWindow;
|
||||||
|
|
||||||
public static string ActiveWindowProcessName { get; private set; }
|
public static string ActiveWindowProcessName { get; private set; } = string.Empty;
|
||||||
public static string ActiveWindowWindowTitle { get; private set; }
|
public static string ActiveWindowWindowTitle { get; private set; } = string.Empty;
|
||||||
|
public static bool MainWindowActive => ActiveWindowProcessName.Contains("Artemis");
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -91,7 +95,7 @@ namespace Artemis.Utilities
|
|||||||
{
|
{
|
||||||
uint pid;
|
uint pid;
|
||||||
GetWindowThreadProcessId(hwnd, out pid);
|
GetWindowThreadProcessId(hwnd, out pid);
|
||||||
return System.Diagnostics.Process.GetProcessById((int)pid).ProcessName;
|
return System.Diagnostics.Process.GetProcessById((int) pid).ProcessName;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -119,22 +123,28 @@ namespace Artemis.Utilities
|
|||||||
if (_activeWindowEventHook == IntPtr.Zero)
|
if (_activeWindowEventHook == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
_activeWindowChangedDelegate = ActiveWindowChanged;
|
_activeWindowChangedDelegate = ActiveWindowChanged;
|
||||||
_activeWindowEventHook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, _activeWindowChangedDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
|
_activeWindowEventHook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND,
|
||||||
|
IntPtr.Zero, _activeWindowChangedDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_windowTitleEventHook == IntPtr.Zero)
|
if (_windowTitleEventHook == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
_windowTitleChangedDelegate = WindowTitleChanged;
|
_windowTitleChangedDelegate = WindowTitleChanged;
|
||||||
_windowTitleEventHook = SetWinEventHook(EVENT_OBJECT_NAMECHANGE, EVENT_OBJECT_NAMECHANGE, IntPtr.Zero, _windowTitleChangedDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
|
_windowTitleEventHook = SetWinEventHook(EVENT_OBJECT_NAMECHANGE, EVENT_OBJECT_NAMECHANGE,
|
||||||
|
IntPtr.Zero, _windowTitleChangedDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_windowMinimizedEventHook == IntPtr.Zero)
|
if (_windowMinimizedEventHook == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
_windowMinimizedChangedDelegate = WindowMinimizedChanged;
|
_windowMinimizedChangedDelegate = WindowMinimizedChanged;
|
||||||
_windowMinimizedEventHook = SetWinEventHook(EVENT_SYSTEM_MINIMIZEEND, EVENT_SYSTEM_MINIMIZEEND, IntPtr.Zero, _windowMinimizedChangedDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
|
_windowMinimizedEventHook = SetWinEventHook(EVENT_SYSTEM_MINIMIZEEND, EVENT_SYSTEM_MINIMIZEEND,
|
||||||
|
IntPtr.Zero, _windowMinimizedChangedDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { /* catch'em all - I don't want it to crash here */ }
|
catch
|
||||||
|
{
|
||||||
|
/* catch'em all - I don't want it to crash here */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Dispose()
|
public static void Dispose()
|
||||||
@ -162,7 +172,10 @@ namespace Artemis.Utilities
|
|||||||
_windowMinimizedEventHook = IntPtr.Zero;
|
_windowMinimizedEventHook = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { /* catch'em all - I don't want it to crash here */ }
|
catch
|
||||||
|
{
|
||||||
|
/* catch'em all - I don't want it to crash here */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -110,7 +110,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
KeyboardPreview = null;
|
KeyboardPreview = null;
|
||||||
|
|
||||||
// Setup layers for the next frame
|
// Setup layers for the next frame
|
||||||
if (ModuleModel.IsInitialized)
|
if (ModuleModel.IsInitialized && ActiveWindowHelper.MainWindowActive)
|
||||||
ModuleModel.PreviewLayers = new List<LayerModel>();
|
ModuleModel.PreviewLayers = new List<LayerModel>();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -177,7 +177,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
KeyboardPreview = drawnPreview;
|
KeyboardPreview = drawnPreview;
|
||||||
|
|
||||||
// Setup layers for the next frame
|
// Setup layers for the next frame
|
||||||
if (ModuleModel.IsInitialized)
|
if (ModuleModel.IsInitialized && ActiveWindowHelper.MainWindowActive)
|
||||||
ModuleModel.PreviewLayers = renderLayers;
|
ModuleModel.PreviewLayers = renderLayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user