Fully implement the tabbing and switching

This commit is contained in:
2024-11-03 14:56:47 +01:00
parent bd24acde46
commit 197f098f67

View File

@@ -27,12 +27,14 @@ internal static class Program {
private static void AdjustAffinities() { private static void AdjustAffinities() {
for (int i = 0; i < NumProc; i++) { for (int i = 0; i < NumProc; i++) {
var window = windows[i]; var window = windows[i];
if (window == null) continue;
if (window.MainWindowHandle == IntPtr.Zero) { if (window.MainWindowHandle == IntPtr.Zero) {
Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows"); Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows");
windows[i] = null; windows[i] = null;
continue; continue;
} }
if (window != null && i != ActiveIndex) {
if (i != ActiveIndex) {
try { try {
window.ProcessorAffinity = defaultAffinity; window.ProcessorAffinity = defaultAffinity;
} }
@@ -56,12 +58,14 @@ internal static class Program {
private static void AdjustPriorities() { private static void AdjustPriorities() {
for (int i = 0; i < NumProc; i++) { for (int i = 0; i < NumProc; i++) {
var window = windows[i]; var window = windows[i];
if (window == null) continue;
if (window.MainWindowHandle == IntPtr.Zero) { if (window.MainWindowHandle == IntPtr.Zero) {
Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows"); Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows");
windows[i] = null; windows[i] = null;
continue; continue;
} }
if (window != null && i != ActiveIndex) {
if (i != ActiveIndex) {
try { try {
window.PriorityClass = ProcessPriorityClass.Idle; window.PriorityClass = ProcessPriorityClass.Idle;
} }
@@ -70,7 +74,7 @@ internal static class Program {
} }
} }
} }
var active = windows[ActiveIndex]; var active = windows[ActiveIndex];
if (active != null) { if (active != null) {
try { try {
@@ -173,10 +177,10 @@ internal static class Program {
AdjustPriorities(); AdjustPriorities();
} }
} }
[STAThread] [STAThread]
private static void Main() { private static void Main() {
AllocConsole(); //AllocConsole();
var processes = Process.GetProcesses(); var processes = Process.GetProcesses();
var currentProcess = Process.GetCurrentProcess(); var currentProcess = Process.GetCurrentProcess();
@@ -188,16 +192,12 @@ internal static class Program {
} }
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
windows.Add(null); windows[i] = null;
HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt); HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt);
HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt | KeyModifiers.Shift); HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt | KeyModifiers.Shift);
} }
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt); HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
// HotKeyManager.RegisterHotKey(Keys.Q, KeyModifiers.Alt);
// HotKeyManager.RegisterHotKey(Keys.W, KeyModifiers.Alt);
// HotKeyManager.RegisterHotKey(Keys.R, KeyModifiers.Alt);
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed; HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) { static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {