Skip to content

Commit a232b4e

Browse files
feat(ffi): add a client example using Avalonia (#443)
1 parent fefcdc4 commit a232b4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2094
-40
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Ignore directories
2+
bin/
3+
obj/
4+
5+
# Ignore files
6+
*.user
7+
*.userosscache
8+
*.suo
9+
*.userprefs
10+
*.dll
11+
*.exe
12+
*.pdb
13+
*.cache
14+
*.vsp
15+
*.vspx
16+
*.sap
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Application xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="Devolutions.IronRdp.AvaloniaExample.App"
4+
RequestedThemeVariant="Default">
5+
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
6+
7+
<Application.Styles>
8+
<FluentTheme />
9+
</Application.Styles>
10+
</Application>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using Avalonia;
3+
using Avalonia.Controls.ApplicationLifetimes;
4+
using Avalonia.Markup.Xaml;
5+
6+
namespace Devolutions.IronRdp.AvaloniaExample;
7+
8+
public partial class App : Application
9+
{
10+
public override void Initialize()
11+
{
12+
AvaloniaXamlLoader.Load(this);
13+
}
14+
15+
public override void OnFrameworkInitializationCompleted()
16+
{
17+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
18+
{
19+
desktop.MainWindow = new MainWindow();
20+
}
21+
22+
base.OnFrameworkInitializationCompleted();
23+
}
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
7+
<ApplicationManifest>app.manifest</ApplicationManifest>
8+
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
9+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Avalonia" Version="11.0.10" />
14+
<PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
15+
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
16+
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" />
17+
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
18+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
19+
<ProjectReference Include="../Devolutions.IronRdp/Devolutions.IronRdp.csproj" />
20+
</ItemGroup>
21+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Devolutions.IronRdp.AvaloniaExample", "Devolutions.IronRdp.AvaloniaExample.csproj", "{B374556F-70F4-4B70-90AE-6DF00C532240}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B374556F-70F4-4B70-90AE-6DF00C532240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B374556F-70F4-4B70-90AE-6DF00C532240}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B374556F-70F4-4B70-90AE-6DF00C532240}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B374556F-70F4-4B70-90AE-6DF00C532240}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {1DD5DE59-5AB4-4F5F-A2AC-CA4D7012F56E}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using Avalonia.Input;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
public static class KeyCodeMapper
6+
{
7+
private static readonly Dictionary<PhysicalKey, ushort> KeyToScancodeMap = new Dictionary<PhysicalKey, ushort>
8+
{
9+
{PhysicalKey.Escape, 0x01},
10+
{PhysicalKey.Digit1, 0x02},
11+
{PhysicalKey.Digit2, 0x03},
12+
{PhysicalKey.Digit3, 0x04},
13+
{PhysicalKey.Digit4, 0x05},
14+
{PhysicalKey.Digit5, 0x06},
15+
{PhysicalKey.Digit6, 0x07},
16+
{PhysicalKey.Digit7, 0x08},
17+
{PhysicalKey.Digit8, 0x09},
18+
{PhysicalKey.Digit9, 0x0A},
19+
{PhysicalKey.Digit0, 0x0B},
20+
{PhysicalKey.Minus, 0x0C},
21+
{PhysicalKey.Equal, 0x0D},
22+
{PhysicalKey.Backspace, 0x0E},
23+
{PhysicalKey.Tab, 0x0F},
24+
{PhysicalKey.Q, 0x10},
25+
{PhysicalKey.W, 0x11},
26+
{PhysicalKey.E, 0x12},
27+
{PhysicalKey.R, 0x13},
28+
{PhysicalKey.T, 0x14},
29+
{PhysicalKey.Y, 0x15},
30+
{PhysicalKey.U, 0x16},
31+
{PhysicalKey.I, 0x17},
32+
{PhysicalKey.O, 0x18},
33+
{PhysicalKey.P, 0x19},
34+
{PhysicalKey.BracketLeft, 0x1A},
35+
{PhysicalKey.BracketRight, 0x1B},
36+
{PhysicalKey.Enter, 0x1C},
37+
{PhysicalKey.ControlLeft, 0x1D},
38+
{PhysicalKey.A, 0x1E},
39+
{PhysicalKey.S, 0x1F},
40+
{PhysicalKey.D, 0x20},
41+
{PhysicalKey.F, 0x21},
42+
{PhysicalKey.G, 0x22},
43+
{PhysicalKey.H, 0x23},
44+
{PhysicalKey.J, 0x24},
45+
{PhysicalKey.K, 0x25},
46+
{PhysicalKey.L, 0x26},
47+
{PhysicalKey.Semicolon, 0x27},
48+
{PhysicalKey.Quote, 0x28},
49+
{PhysicalKey.ShiftLeft, 0x2A},
50+
{PhysicalKey.Backslash, 0x2B},
51+
{PhysicalKey.Z, 0x2C},
52+
{PhysicalKey.X, 0x2D},
53+
{PhysicalKey.C, 0x2E},
54+
{PhysicalKey.V, 0x2F},
55+
{PhysicalKey.B, 0x30},
56+
{PhysicalKey.N, 0x31},
57+
{PhysicalKey.M, 0x32},
58+
{PhysicalKey.Comma, 0x33},
59+
{PhysicalKey.Period, 0x34},
60+
{PhysicalKey.Slash, 0x35},
61+
{PhysicalKey.ShiftRight, 0x36},
62+
{PhysicalKey.PrintScreen, 0x37},
63+
{PhysicalKey.AltLeft, 0x38},
64+
{PhysicalKey.Space, 0x39},
65+
{PhysicalKey.CapsLock, 0x3A},
66+
{PhysicalKey.F1, 0x3B},
67+
{PhysicalKey.F2, 0x3C},
68+
{PhysicalKey.F3, 0x3D},
69+
{PhysicalKey.F4, 0x3E},
70+
{PhysicalKey.F5, 0x3F},
71+
{PhysicalKey.F6, 0x40},
72+
{PhysicalKey.F7, 0x41},
73+
{PhysicalKey.F8, 0x42},
74+
{PhysicalKey.F9, 0x43},
75+
{PhysicalKey.F10, 0x44},
76+
{PhysicalKey.NumLock, 0x45},
77+
{PhysicalKey.ScrollLock, 0x46},
78+
{PhysicalKey.Home, 0x47},
79+
{PhysicalKey.ArrowUp, 0x48},
80+
{PhysicalKey.PageUp, 0x49},
81+
{PhysicalKey.NumPadSubtract, 0x4A},
82+
{PhysicalKey.ArrowLeft, 0x4B},
83+
{PhysicalKey.NumPad5, 0x4C},
84+
{PhysicalKey.ArrowRight, 0x4D},
85+
{PhysicalKey.NumPadAdd, 0x4E},
86+
{PhysicalKey.End, 0x4F},
87+
{PhysicalKey.ArrowDown, 0x50},
88+
{PhysicalKey.PageDown, 0x51},
89+
{PhysicalKey.Insert, 0x52},
90+
{PhysicalKey.Delete, 0x53},
91+
{PhysicalKey.F11, 0x57},
92+
{PhysicalKey.F12, 0x58}
93+
};
94+
95+
96+
public static ushort? GetScancode(PhysicalKey key)
97+
{
98+
if (KeyToScancodeMap.TryGetValue(key, out ushort scancode))
99+
{
100+
return scancode;
101+
}
102+
return null;
103+
}
104+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Window xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
mc:Ignorable="d" d:DesignWidth="1980" d:DesignHeight="1080"
6+
x:Class="Devolutions.IronRdp.AvaloniaExample.MainWindow"
7+
Title="Devolutions.IronRdp.AvaloniaExample">
8+
9+
<Canvas Name="MainCanvas" Width="1280" Height="800" Background="Black"
10+
PointerPressed="Canvas_OnPointerPressed" PointerMoved="Canvas_PointerMoved" PointerReleased="Canvas_PointerReleased"
11+
HorizontalAlignment="Center"
12+
VerticalAlignment="Center"
13+
/>
14+
</Window>

0 commit comments

Comments
 (0)