-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from FaithBeam/xdotool
Use xdotool to get foreground window on linux x11
- Loading branch information
Showing
4 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
YMouseButtonControl.Linux/Services/CurrentWindowServiceX11.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Diagnostics; | ||
using YMouseButtonControl.Core.Services.Processes; | ||
|
||
namespace YMouseButtonControl.Linux.Services; | ||
|
||
public class CurrentWindowServiceX11 : ICurrentWindowService | ||
{ | ||
public string ForegroundWindow => GetForegroundWindow(); | ||
|
||
private string GetForegroundWindow() | ||
{ | ||
var startInfo = new ProcessStartInfo | ||
{ | ||
FileName = "/bin/bash", | ||
Arguments = "-c \"xdotool getwindowfocus getwindowpid\"", | ||
RedirectStandardOutput = true, | ||
}; | ||
using var xdoProc = new Process(); | ||
xdoProc.StartInfo = startInfo; | ||
xdoProc.Start(); | ||
var pid = xdoProc.StandardOutput.ReadToEnd().TrimEnd(); | ||
xdoProc.WaitForExit(); | ||
|
||
if (string.IsNullOrWhiteSpace(pid)) | ||
{ | ||
return ""; | ||
} | ||
|
||
startInfo = new ProcessStartInfo | ||
{ | ||
FileName = "/bin/bash", | ||
Arguments = $"-c \"ls -l /proc/{pid}/exe\"", | ||
RedirectStandardOutput = true, | ||
}; | ||
using var proc = new Process(); | ||
proc.StartInfo = startInfo; | ||
proc.Start(); | ||
var path = proc.StandardOutput.ReadToEnd().Split("-> ")[1].Trim(); | ||
proc.WaitForExit(); | ||
return path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters