feat: linux support
This commit is contained in:
parent
04ebe3f606
commit
d996ca0efb
3 changed files with 80 additions and 1 deletions
|
@ -1,13 +1,32 @@
|
|||
#if OS_LINUX
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ControllerSlidePresenter.InputSender;
|
||||
|
||||
public class LinuxInputSender : IInputSender {
|
||||
public void NextSlide() {
|
||||
private const string PageUp = "0xff55";
|
||||
private const string PageDown = "0xff56";
|
||||
|
||||
public void NextSlide() {
|
||||
SendKeys(PageDown);
|
||||
}
|
||||
|
||||
public void PreviousSlide() {
|
||||
SendKeys(PageUp);
|
||||
}
|
||||
|
||||
private static void SendKeys(string keycode) {
|
||||
Process proc = new() {
|
||||
StartInfo = {
|
||||
FileName = "xdotool",
|
||||
Arguments = $"key {keycode}",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardError = false,
|
||||
RedirectStandardInput = false,
|
||||
RedirectStandardOutput = false
|
||||
}
|
||||
};
|
||||
proc.Start();
|
||||
}
|
||||
}
|
||||
#endif
|
55
SlidePresenter/Linux.cs
Normal file
55
SlidePresenter/Linux.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
#if OS_LINUX
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ControllerSlidePresenter;
|
||||
|
||||
public static class Linux {
|
||||
public static bool CanRun() {
|
||||
if (getuid() != 0) {
|
||||
Console.WriteLine("On Linux you need tu run as 'sudo'");
|
||||
return false;
|
||||
}
|
||||
if (!IsXdoToolInstalled())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsXdoToolInstalled() {
|
||||
string result = RunShellCommand("which xdotool");
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
return true;
|
||||
|
||||
Console.WriteLine("xdotool is not installed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string RunShellCommand(string command) {
|
||||
try {
|
||||
ProcessStartInfo procStartInfo = new("bash", "-c \"" + command + "\"") {
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
|
||||
using Process process = new();
|
||||
process.StartInfo = procStartInfo;
|
||||
process.Start();
|
||||
|
||||
string result = process.StandardOutput.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
|
||||
return result.Trim();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Console.WriteLine("Error: " + ex.Message);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DllImport("libc")]
|
||||
private static extern uint getuid();
|
||||
}
|
||||
#endif
|
|
@ -3,6 +3,11 @@
|
|||
namespace ControllerSlidePresenter {
|
||||
internal abstract class Program {
|
||||
private static async Task Main() {
|
||||
#if OS_LINUX
|
||||
if (!Linux.CanRun())
|
||||
return;
|
||||
#endif
|
||||
|
||||
IGamepadReader? reader = ControllerSelector.GetReader();
|
||||
if (reader == null) {
|
||||
Console.WriteLine("Invalid Controller Selected.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue