Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry PI arm32 support #432

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions Agent/Services/AppLauncherLinux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,26 @@ private int StartLinuxDesktopApp(string args)
{
try
{
var whoLine = whoString
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.First();

var whoSplit = whoLine.Split(' ', StringSplitOptions.RemoveEmptyEntries);
username = whoSplit[0];
display = whoSplit.Last().TrimStart('(').TrimEnd(')');
var whoLines = whoString
.Split('\n', StringSplitOptions.RemoveEmptyEntries);

for(int i = 0; i < whoLines.Length; i++)
{
var whoLine = whoLines[i];
var whoSplit = whoLine.Split(' ', StringSplitOptions.RemoveEmptyEntries);

username = whoSplit[0];
Logger.Write($"split last: {whoSplit.Last()}");

display = whoSplit.Last().TrimStart('(').TrimEnd(')');
Logger.Write($"display: {display}");

if(display.Length >0 && display[0] == ':')
{
break;
}

}
xauthority = $"/home/{username}/.Xauthority";
args = $"-u {username} {args}";
}
Expand Down
38 changes: 38 additions & 0 deletions Desktop.XPlat/Native/Linux/LibX11_32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*

Copyright 1985, 1986, 1987, 1991, 1998 The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.

*/

using System;
using System.Runtime.InteropServices;

namespace Remotely.Desktop.XPlat.Native.Linux
{
public static unsafe class LibX11_32
{

[DllImport("libX11")]
public static extern IntPtr XGetImage(IntPtr display, IntPtr drawable, int x, int y, int width, int height, uint plane_mask, int format);
}
}
15 changes: 15 additions & 0 deletions Desktop.XPlat/Native/Linux/LibXtst_32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Runtime.InteropServices;

namespace Remotely.Desktop.XPlat.Native.Linux
{
public class LibXtst_32
{
[DllImport("libXtst")]
public static extern void XTestFakeKeyEvent(IntPtr display, uint keycode, bool is_press, uint delay);
[DllImport("libXtst")]
public static extern void XTestFakeButtonEvent(IntPtr display, uint button, bool is_press, uint delay);
[DllImport("libXtst")]
public static extern void XTestFakeMotionEvent(IntPtr display, int screen_number, int x, int y, uint delay);
}
}
19 changes: 19 additions & 0 deletions Desktop.XPlat/Properties/PublishProfiles/desktop-linux-arm.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>arm</Platform>
<TargetFramework>net6.0</TargetFramework>
<PublishDir>..\Server\wwwroot\Content\Linux-arm\</PublishDir>
<RuntimeIdentifier>linux-arm</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishTrimmed>False</PublishTrimmed>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>
</Project>
17 changes: 17 additions & 0 deletions Desktop.XPlat/Properties/PublishProfiles/packaged-linux-arm.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>arm</Platform>
<TargetFramework>net6.0</TargetFramework>
<PublishDir>..\Agent\bin\Release\net6.0\linux-arm\publish\Desktop</PublishDir>
<RuntimeIdentifier>linux-arm</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>
81 changes: 69 additions & 12 deletions Desktop.XPlat/Services/KeyboardMouseInputLinux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ public void SendKeyDown(string key)
}

var keyCode = LibX11.XKeysymToKeycode(Display, keySim);
LibXtst.XTestFakeKeyEvent(Display, keyCode, true, 0);
if(EnvironmentHelper.Is64)
{
LibXtst.XTestFakeKeyEvent(Display, keyCode, true, 0);
}
else{
LibXtst_32.XTestFakeKeyEvent(Display, keyCode, true, 0);
}
LibX11.XSync(Display, false);
}
catch (Exception ex)
Expand All @@ -55,7 +61,13 @@ public void SendKeyUp(string key)
}

var keyCode = LibX11.XKeysymToKeycode(Display, keySim);
LibXtst.XTestFakeKeyEvent(Display, keyCode, false, 0);
if(EnvironmentHelper.Is64)
{
LibXtst.XTestFakeKeyEvent(Display, keyCode, false, 0);
}
else{
LibXtst_32.XTestFakeKeyEvent(Display, keyCode, false, 0);
}
LibX11.XSync(Display, false);
}
catch (Exception ex)
Expand All @@ -75,8 +87,14 @@ public void SendMouseButtonAction(int button, ButtonAction buttonAction, double
var mouseButton = (uint)(button + 1);

InitDisplay();
SendMouseMove(percentX, percentY, viewer);
LibXtst.XTestFakeButtonEvent(Display, mouseButton, isPressed, 0);
SendMouseMove(percentX, percentY, viewer);
if(EnvironmentHelper.Is64)
{
LibXtst.XTestFakeButtonEvent(Display, mouseButton, isPressed, 0);
}
else{
LibXtst_32.XTestFakeButtonEvent(Display, mouseButton, isPressed, 0);
}
LibX11.XSync(Display, false);
}
catch (Exception ex)
Expand All @@ -92,11 +110,22 @@ public void SendMouseMove(double percentX, double percentY, Viewer viewer)
InitDisplay();

var screenBounds = viewer.Capturer.CurrentScreenBounds;
LibXtst.XTestFakeMotionEvent(Display,
LibX11.XDefaultScreen(Display),
screenBounds.X + (int)(screenBounds.Width * percentX),
screenBounds.Y + (int)(screenBounds.Height * percentY),
if(EnvironmentHelper.Is64)
{
LibXtst.XTestFakeMotionEvent(Display,
LibX11.XDefaultScreen(Display),
screenBounds.X + (int)(screenBounds.Width * percentX),
screenBounds.Y + (int)(screenBounds.Height * percentY),
0);
}
else{
LibXtst_32.XTestFakeMotionEvent(Display,
LibX11.XDefaultScreen(Display),
screenBounds.X + (int)(screenBounds.Width * percentX),
screenBounds.Y + (int)(screenBounds.Height * percentY),
0);
}

LibX11.XSync(Display, false);
}
catch (Exception ex)
Expand All @@ -114,11 +143,27 @@ public void SendMouseWheel(int deltaY)
{
LibXtst.XTestFakeButtonEvent(Display, 4, true, 0);
LibXtst.XTestFakeButtonEvent(Display, 4, false, 0);
if(EnvironmentHelper.Is64)
{
LibXtst.XTestFakeButtonEvent(Display, 4, true, 0);
LibXtst.XTestFakeButtonEvent(Display, 4, false, 0);
}
else{
LibXtst_32.XTestFakeButtonEvent(Display, 4, true, 0);
LibXtst_32.XTestFakeButtonEvent(Display, 4, false, 0);
}
}
else
{
LibXtst.XTestFakeButtonEvent(Display, 5, true, 0);
LibXtst.XTestFakeButtonEvent(Display, 5, false, 0);
if(EnvironmentHelper.Is64)
{
LibXtst.XTestFakeButtonEvent(Display, 5, true, 0);
LibXtst.XTestFakeButtonEvent(Display, 5, false, 0);
}
else{
LibXtst_32.XTestFakeButtonEvent(Display, 5, true, 0);
LibXtst_32.XTestFakeButtonEvent(Display, 5, false, 0);
}
}
LibX11.XSync(Display, false);
}
Expand All @@ -134,7 +179,13 @@ public void SendRightMouseDown(double percentX, double percentY, Viewer viewer)
{
InitDisplay();
SendMouseMove(percentX, percentY, viewer);
LibXtst.XTestFakeButtonEvent(Display, 3, true, 0);
if(EnvironmentHelper.Is64)
{
LibXtst.XTestFakeButtonEvent(Display, 3, true, 0);
}
else{
LibXtst_32.XTestFakeButtonEvent(Display, 3, true, 0);
}
LibX11.XSync(Display, false);
}
catch (Exception ex)
Expand All @@ -149,7 +200,13 @@ public void SendRightMouseUp(double percentX, double percentY, Viewer viewer)
{
InitDisplay();
SendMouseMove(percentX, percentY, viewer);
LibXtst.XTestFakeButtonEvent(Display, 3, false, 0);
if(EnvironmentHelper.Is64)
{
LibXtst.XTestFakeButtonEvent(Display, 3, false, 0);
}
else{
LibXtst_32.XTestFakeButtonEvent(Display, 3, false, 0);
}
LibX11.XSync(Display, false);
}
catch (Exception ex)
Expand Down
37 changes: 29 additions & 8 deletions Desktop.XPlat/Services/ScreenCapturerLinux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,35 @@ private Bitmap GetX11Capture()

var window = LibX11.XDefaultRootWindow(Display);

var imagePointer = LibX11.XGetImage(Display,
window,
CurrentScreenBounds.X,
CurrentScreenBounds.Y,
CurrentScreenBounds.Width,
CurrentScreenBounds.Height,
~0,
2);
IntPtr imagePointer = IntPtr.Zero;

if(EnvironmentHelper.Is64)
{
imagePointer = LibX11.XGetImage(Display,
window,
CurrentScreenBounds.X,
CurrentScreenBounds.Y,
CurrentScreenBounds.Width,
CurrentScreenBounds.Height,
~0,
2);
}
else
{
imagePointer = LibX11_32.XGetImage(Display,
window,
CurrentScreenBounds.X,
CurrentScreenBounds.Y,
CurrentScreenBounds.Width,
CurrentScreenBounds.Height,
0xffffffff,
2);
}

if(imagePointer == IntPtr.Zero)
{
Logger.Write($"libX11 XGetImage error");
}

var image = Marshal.PtrToStructure<LibX11.XImage>(imagePointer);

Expand Down
3 changes: 2 additions & 1 deletion Server.Installer/Models/WebServerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum WebServerType
UbuntuNginx,
CentOsCaddy,
CentOsNginx,
IisWindows
IisWindows,
LinuxNginx
}
}
3 changes: 2 additions & 1 deletion Server.Installer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public static async Task Main(string[] args)
"Nginx on Ubuntu",
"Caddy on CentOS",
"Nginx on CentOS",
"IIS on Windows Server 2016+");
"IIS on Windows Server 2016+",
"Nginx on linux-arm");

if (Enum.TryParse<WebServerType>(webServerType, out var result))
{
Expand Down
Loading