Skip to content

Commit

Permalink
Workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingpie committed Jan 22, 2024
1 parent 54f0d5c commit 2322050
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 35 deletions.
1 change: 0 additions & 1 deletion windows-terminal-quake/NativeMethods.json

This file was deleted.

4 changes: 0 additions & 4 deletions windows-terminal-quake/NativeMethods.txt

This file was deleted.

16 changes: 10 additions & 6 deletions windows-terminal-quake/Services/Toggler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public void Toggle(Process process)

public void Toggle(Process process, bool open, int durationMs)
{
// TODO: Change it so that this method doesn't even get called if we don't have a valid process.
if (process == null)
{
return;
}

var animationFn = _animTypeProvider.GetAnimationFunction();
//var frameTimeMs = QSettings.Instance.ToggleAnimationFrameTimeMs;
var frameTimeMs = 25;
Expand Down Expand Up @@ -75,9 +81,7 @@ public void Toggle(Process process, bool open, int durationMs)
}
stopwatch.Stop();



// To ensure sure we end up in exactly the correct final position
// To ensure we end up in exactly the correct final position
var finalBounds = _termBoundsProvider.GetTerminalBounds(open, screen, process.GetBounds(), open ? 1.0 : 0.0);
process.MoveWindow(bounds: finalBounds);

Expand All @@ -96,9 +100,9 @@ public void Toggle(Process process, bool open, int durationMs)
// Minimize first, so the last window gets focus
process.SetWindowState(WindowShowStyle.Minimize);

//// Then hide, so the terminal windows doesn't linger on the desktop
//if (QSettings.Instance.TaskbarIconVisibility == TaskBarIconVisibility.AlwaysHidden || QSettings.Instance.TaskbarIconVisibility == TaskBarIconVisibility.WhenTerminalVisible)
// Process.SetWindowState(WindowShowStyle.Hide);
// Then hide, so the terminal windows doesn't linger on the desktop
// if (QSettings.Instance.TaskbarIconVisibility == TaskBarIconVisibility.AlwaysHidden || QSettings.Instance.TaskbarIconVisibility == TaskBarIconVisibility.WhenTerminalVisible)
process.SetWindowState(WindowShowStyle.Hide);
}
}

Expand Down
33 changes: 31 additions & 2 deletions windows-terminal-quake/Services/WtqProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,30 @@ public void Dispose()
{
if (Process != null)
{
var bounds = Process.GetBounds(); // TODO: Restore to original position (when we got a hold of the process).
bounds.Width = 1280;
bounds.Height = 800;
bounds.X = 0;
bounds.Y = 0;

_log.LogInformation("Restoring process '{Process}' to its original bounds of '{Bounds}'", ProcessDescription, bounds);

Process.SetWindowState(WindowShowStyle.Restore);
Process.MoveWindow(bounds);
Process.SetTaskbarIconVisibility(true);
Process.SetWindowState(WindowShowStyle.Maximize);
}
}

public string? ProcessDescription
{
get
{
if (Process == null)
{
return "<no process attached>";
}

return $"[{Process?.Id}] {Process?.ProcessName}";
}
}

Expand All @@ -28,14 +50,21 @@ public void Toggle(bool isVisible)

public override string ToString()
{
return $"[{App}] {(Process?.ProcessName ?? "<no process>")}";
return $"[App:{App}] [ProcessID:{Process?.Id}] {(Process?.ProcessName ?? "<no process>")}";
}

/// <summary>
/// Updates the state of the <see cref="WtqProcess"/> object to reflect running processes on the system.
/// </summary>
public async Task UpdateAsync(IEnumerable<Process> processes)
{
// Check that if we have a process handle, the process is still active.
if (Process?.HasExited ?? false)
{
_log.LogInformation("Process with name '{ProcessName}' and id '{ProcessId}' exited, releasing handle", Process.ProcessName, Process.Id);
Process = null;
}

if (Process == null)
{
// TODO: Handle multiple processes coming back?
Expand Down
16 changes: 10 additions & 6 deletions windows-terminal-quake/WtqService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public Task StartAsync(CancellationToken cancellationToken)

private void ToggleStuff(HotKeyEventArgs args)
{
const int openTimeMs = 100;
const int switchTimeMs = 50;

_log.LogInformation("Pressed hot key ['{Modifiers}'] + '{HotKey}'", args.Modifiers, args.Key);

var app = _opts.Value.Apps.FirstOrDefault(a => a.HasHotkey(args.Key, args.Modifiers));
Expand All @@ -59,7 +62,7 @@ private void ToggleStuff(HotKeyEventArgs args)
{
if (open != null)
{
_toggler.Toggle(open.Process, false, 200);
_toggler.Toggle(open.Process, false, openTimeMs);
_lastOpen = open;
open = null;
return;
Expand All @@ -73,7 +76,7 @@ private void ToggleStuff(HotKeyEventArgs args)
}

open = _lastOpen;
_toggler.Toggle(open.Process, true, 200);
_toggler.Toggle(open.Process, true, openTimeMs);
return;
}

Expand All @@ -99,21 +102,22 @@ private void ToggleStuff(HotKeyEventArgs args)
{
if (open == process)
{
_toggler.Toggle(open.Process, false, 200);
_toggler.Toggle(open.Process, false, openTimeMs);
_lastOpen = open;
open = null;
}
else
{
_toggler.Toggle(open.Process, false, 100);
_toggler.Toggle(process.Process, true, 100);
_toggler.Toggle(open.Process, false, switchTimeMs);
_toggler.Toggle(process.Process, true, switchTimeMs);
open = process;
}

return;
}

_log.LogInformation("Toggling process {Process}", process);
_toggler.Toggle(process.Process, true, 200);
_toggler.Toggle(process.Process, true, openTimeMs);

open = process;
}
Expand Down
23 changes: 7 additions & 16 deletions windows-terminal-quake/windows-terminal-quake.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,33 @@
{
"HotKeys": [ { "Modifiers": "Control", "Key": "1" } ],
"StartNew": {
// TODO: StartNew doesn't work yet.
"FileName": "wt.exe"
},
"FindExisting": {
//"ProcessName": "WindowsTerminal"
"ProcessName": "wezterm-gui"
"ProcessName": "WindowsTerminal"
}
},
{
"HotKeys": [
{
"Modifiers": "Control",
"Key": "2"
}
],
"HotKeys": [ { "Modifiers": "Control", "Key": "2" } ],
"StartNew": {
"FileName": "D:/syncthing/apps/qdir/Q-Dir_x64.exe"
// TODO: StartNew doesn't work yet.
//"FileName": "D:/syncthing/apps/qdir/Q-Dir_x64.exe"
},
"FindExisting": {
"ProcessName": "Q-Dir_x64"
}
},
{
"HotKeys": [
{
"Modifiers": "Control",
"Key": "3"
}
],
"HotKeys": [ { "Modifiers": "Control", "Key": "3" } ],
"StartNew": {
//"FileName": "D:/syncthing/apps/qdir/Q-Dir_x64.exe"
},
"FindExisting": {
"ProcessName": "ProcessHacker"
}
},
{
{
"HotKeys": [ { "Modifiers": "Control", "Key": "4" } ],
"StartNew": {
"FileName": ""
Expand Down

0 comments on commit 2322050

Please sign in to comment.