Make ctrl-F16 track one window (instead of executable)
This commit is contained in:
@@ -17,21 +17,29 @@ namespace EveOPreview.Services.Implementation
|
|||||||
private readonly IDictionary<IntPtr, string> _processCache;
|
private readonly IDictionary<IntPtr, string> _processCache;
|
||||||
private IProcessInfo _currentProcessInfo;
|
private IProcessInfo _currentProcessInfo;
|
||||||
private readonly IThumbnailConfiguration _configuration;
|
private readonly IThumbnailConfiguration _configuration;
|
||||||
|
private readonly HashSet<int> _trackedPids; // Change to HashSet for multiple PIDs
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public ProcessMonitor(IThumbnailConfiguration configuration)
|
public ProcessMonitor(IThumbnailConfiguration configuration)
|
||||||
{
|
{
|
||||||
this._processCache = new Dictionary<IntPtr, string>(512);
|
this._processCache = new Dictionary<IntPtr, string>(512);
|
||||||
this._configuration = configuration;
|
this._configuration = configuration;
|
||||||
|
this._trackedPids = new HashSet<int>(); // Initialize empty set
|
||||||
|
|
||||||
// This field cannot be initialized properly in constructor
|
// This field cannot be initialized properly in constructor
|
||||||
// At the moment this code is executed the main application window is not yet initialized
|
// At the moment this code is executed the main application window is not yet initialized
|
||||||
this._currentProcessInfo = new ProcessInfo(IntPtr.Zero, "");
|
this._currentProcessInfo = new ProcessInfo(IntPtr.Zero, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsMonitoredProcess(string processName)
|
private bool IsMonitoredProcess(string processName, int processId)
|
||||||
{
|
{
|
||||||
// This is a possible extension point
|
// If we're tracking this specific PID, include it
|
||||||
|
if (_trackedPids.Contains(processId))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also include any processes that match executable tracking
|
||||||
return _configuration.IsExecutableToPreview(processName);
|
return _configuration.IsExecutableToPreview(processName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,8 +88,9 @@ namespace EveOPreview.Services.Implementation
|
|||||||
foreach (Process process in Process.GetProcesses())
|
foreach (Process process in Process.GetProcesses())
|
||||||
{
|
{
|
||||||
string processName = process.ProcessName;
|
string processName = process.ProcessName;
|
||||||
|
int processId = process.Id;
|
||||||
|
|
||||||
if (!this.IsMonitoredProcess(processName))
|
if (!this.IsMonitoredProcess(processName, processId))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -130,5 +139,37 @@ namespace EveOPreview.Services.Implementation
|
|||||||
this._processCache.Remove(index);
|
this._processCache.Remove(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update to handle multiple PIDs
|
||||||
|
public void SetTrackedPid(int pid)
|
||||||
|
{
|
||||||
|
if (pid == 0) // Special case: 0 means stop tracking all
|
||||||
|
{
|
||||||
|
this._trackedPids.Clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._trackedPids.Contains(pid))
|
||||||
|
{
|
||||||
|
this._trackedPids.Remove(pid); // Toggle off if already tracking
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this._trackedPids.Add(pid); // Toggle on if not tracking
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update to return currently tracked PID (for compatibility)
|
||||||
|
public int GetTrackedPid()
|
||||||
|
{
|
||||||
|
// Return the first tracked PID, or 0 if none
|
||||||
|
return this._trackedPids.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add method to get all tracked PIDs if needed
|
||||||
|
public IReadOnlyCollection<int> GetTrackedPids()
|
||||||
|
{
|
||||||
|
return this._trackedPids;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -132,6 +132,43 @@ namespace EveOPreview.Services
|
|||||||
};
|
};
|
||||||
var registered = this._toggleTrackingHotkey.Register();
|
var registered = this._toggleTrackingHotkey.Register();
|
||||||
System.Diagnostics.Debug.WriteLine($"Hotkey registration result: {registered}");
|
System.Diagnostics.Debug.WriteLine($"Hotkey registration result: {registered}");
|
||||||
|
|
||||||
|
// Setup single process tracking hotkey (Ctrl+F16)
|
||||||
|
var toggleSingleProcessHotkey = new HotkeyHandler(mainHandle, Keys.Control | Keys.F16);
|
||||||
|
toggleSingleProcessHotkey.Pressed += (object s, HandledEventArgs e) =>
|
||||||
|
{
|
||||||
|
var foregroundHandle = this._windowManager.GetForegroundWindowHandle();
|
||||||
|
if (foregroundHandle != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
uint processId;
|
||||||
|
GetWindowThreadProcessId(foregroundHandle, out processId);
|
||||||
|
var process = Process.GetProcessById((int)processId);
|
||||||
|
|
||||||
|
if (process != null)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Found process: {process.ProcessName} (PID: {process.Id})");
|
||||||
|
|
||||||
|
// Get the current tracked PID from ProcessMonitor
|
||||||
|
var currentTrackedPid = this._processMonitor.GetTrackedPid();
|
||||||
|
|
||||||
|
if (currentTrackedPid == process.Id)
|
||||||
|
{
|
||||||
|
// Stop tracking this process
|
||||||
|
this._processMonitor.SetTrackedPid(0);
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Stopped tracking process {process.Id}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Start tracking this process
|
||||||
|
this._processMonitor.SetTrackedPid(process.Id);
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Started tracking process {process.Id}");
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
registered = toggleSingleProcessHotkey.Register();
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Single process hotkey registration result: {registered}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public IThumbnailView GetClientByTitle(string title)
|
public IThumbnailView GetClientByTitle(string title)
|
||||||
@@ -996,7 +1033,6 @@ namespace EveOPreview.Services
|
|||||||
&& (width > ThumbnailManager.WINDOW_SIZE_THRESHOLD) && (height > ThumbnailManager.WINDOW_SIZE_THRESHOLD);
|
&& (width > ThumbnailManager.WINDOW_SIZE_THRESHOLD) && (height > ThumbnailManager.WINDOW_SIZE_THRESHOLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
|
private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
|
||||||
|
|
||||||
|
@@ -7,5 +7,7 @@ namespace EveOPreview.Services
|
|||||||
IProcessInfo GetMainProcess();
|
IProcessInfo GetMainProcess();
|
||||||
ICollection<IProcessInfo> GetAllProcesses();
|
ICollection<IProcessInfo> GetAllProcesses();
|
||||||
void GetUpdatedProcesses(out ICollection<IProcessInfo> addedProcesses, out ICollection<IProcessInfo> updatedProcesses, out ICollection<IProcessInfo> removedProcesses);
|
void GetUpdatedProcesses(out ICollection<IProcessInfo> addedProcesses, out ICollection<IProcessInfo> updatedProcesses, out ICollection<IProcessInfo> removedProcesses);
|
||||||
|
int GetTrackedPid();
|
||||||
|
void SetTrackedPid(int pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user