Skip to content

Commit fb0c5a8

Browse files
committed
add app source code
1 parent 57438af commit fb0c5a8

34 files changed

+3013
-0
lines changed

app/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>

app/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="ParsecVDisplay.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:ParsecVDisplay"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

app/App.xaml.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using System.Threading;
4+
using System.Windows;
5+
using System.Linq;
6+
using System.Windows.Interop;
7+
using System.Windows.Media;
8+
9+
namespace ParsecVDisplay
10+
{
11+
public partial class App : Application
12+
{
13+
const string ID = "QpHOX8IBUHBznGtqk9xm1";
14+
public const string NAME = "ParsecVDisplay";
15+
public const string VERSION = "0.45.0";
16+
17+
public static bool Silent { get; private set; }
18+
19+
static App()
20+
{
21+
var displays = Display.GetAllDisplays();
22+
return;
23+
}
24+
25+
protected override void OnStartup(StartupEventArgs e)
26+
{
27+
if (e.Args.Length >= 2 && e.Args[0] == "-custom")
28+
{
29+
var modes = Display.ParseModes(e.Args[1]);
30+
ParsecVDD.SetCustomDisplayModes(modes);
31+
32+
Shutdown();
33+
return;
34+
}
35+
36+
Silent = e.Args.Contains("-silent");
37+
38+
var signal = new EventWaitHandle(false,
39+
EventResetMode.AutoReset, ID, out var isOwned);
40+
41+
if (!isOwned)
42+
{
43+
signal.Set();
44+
Shutdown();
45+
return;
46+
}
47+
48+
var status = ParsecVDD.QueryStatus();
49+
if (status != Device.Status.OK)
50+
{
51+
if (status == Device.Status.RESTART_REQUIRED)
52+
{
53+
MessageBox.Show("You must restart your PC to complete the driver setup.",
54+
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
55+
}
56+
else if (status == Device.Status.DISABLED)
57+
{
58+
MessageBox.Show($"{ParsecVDD.ADAPTER} is disabled, please enable it.",
59+
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
60+
}
61+
else if (status == Device.Status.NOT_INSTALLED)
62+
{
63+
MessageBox.Show("Please install the driver first.",
64+
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
65+
}
66+
else
67+
{
68+
MessageBox.Show($"The driver is not OK, please check again. Current status: {status}.",
69+
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
70+
}
71+
72+
Shutdown();
73+
return;
74+
}
75+
76+
if (ParsecVDD.Init() == false)
77+
{
78+
MessageBox.Show("Failed to obtain the device handle, please check the driver installation again.",
79+
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
80+
81+
Shutdown();
82+
return;
83+
}
84+
85+
Task.Run(() =>
86+
{
87+
while (signal.WaitOne())
88+
{
89+
Tray.ShowApp();
90+
}
91+
});
92+
93+
base.OnStartup(e);
94+
95+
// Disable GPU to prevent flickering when adding display
96+
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
97+
}
98+
99+
protected override void OnExit(ExitEventArgs e)
100+
{
101+
ParsecVDD.Uninit();
102+
base.OnExit(e);
103+
}
104+
}
105+
}

app/Components/Button.xaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<UserControl
2+
x:Class="ParsecVDisplay.Components.Button"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="clr-namespace:ParsecVDisplay.Components"
8+
mc:Ignorable="d"
9+
d:DesignHeight="120" d:DesignWidth="216"
10+
d:Background="Black"
11+
>
12+
<Border BorderThickness="1" BorderBrush="#FFF">
13+
<Button Foreground="White" Click="Button_Click">
14+
<Button.Content>
15+
<ContentPresenter Content="{Binding Children}" />
16+
</Button.Content>
17+
<Button.Style>
18+
<Style TargetType="{x:Type Button}">
19+
<Setter Property="Background" Value="#1FFF"/>
20+
<Setter Property="Template">
21+
<Setter.Value>
22+
<ControlTemplate TargetType="{x:Type Button}">
23+
<Border Background="{TemplateBinding Background}">
24+
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
25+
</Border>
26+
</ControlTemplate>
27+
</Setter.Value>
28+
</Setter>
29+
<Style.Triggers>
30+
<Trigger Property="IsMouseOver" Value="True">
31+
<Setter Property="Background" Value="#4FFF"/>
32+
</Trigger>
33+
<Trigger Property="IsPressed" Value="True">
34+
<Setter Property="Background" Value="#8FFF"/>
35+
</Trigger>
36+
</Style.Triggers>
37+
</Style>
38+
</Button.Style>
39+
</Button>
40+
</Border>
41+
<UserControl.Style>
42+
<Style TargetType="{x:Type UserControl}">
43+
<Style.Triggers>
44+
<Trigger Property="IsEnabled" Value="True">
45+
<Setter Property="Opacity" Value="1"/>
46+
</Trigger>
47+
<Trigger Property="IsEnabled" Value="False">
48+
<Setter Property="Opacity" Value="0.5"/>
49+
</Trigger>
50+
</Style.Triggers>
51+
</Style>
52+
</UserControl.Style>
53+
</UserControl>

app/Components/Button.xaml.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
5+
namespace ParsecVDisplay.Components
6+
{
7+
public partial class Button : UserControl
8+
{
9+
public event EventHandler Click;
10+
public object Children { get; set; }
11+
12+
public Button()
13+
{
14+
InitializeComponent();
15+
DataContext = this;
16+
}
17+
18+
private void Button_Click(object sender, RoutedEventArgs e)
19+
{
20+
Click?.Invoke(sender, e);
21+
}
22+
}
23+
}

app/Components/CloseButton.xaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<UserControl
2+
x:Class="ParsecVDisplay.Components.CloseButton"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="clr-namespace:ParsecVDisplay.Components"
8+
mc:Ignorable="d"
9+
d:DesignHeight="40" d:DesignWidth="60"
10+
d:Background="Black"
11+
>
12+
<Button Foreground="White" Content="" FontSize="16" Click="Button_Click">
13+
<Button.Style>
14+
<Style TargetType="{x:Type Button}">
15+
<Setter Property="Background" Value="Transparent"/>
16+
<Setter Property="Template">
17+
<Setter.Value>
18+
<ControlTemplate TargetType="{x:Type Button}">
19+
<Border Background="{TemplateBinding Background}">
20+
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
21+
</Border>
22+
</ControlTemplate>
23+
</Setter.Value>
24+
</Setter>
25+
<Style.Triggers>
26+
<Trigger Property="IsMouseOver" Value="True">
27+
<Setter Property="Background" Value="#4FFF"/>
28+
</Trigger>
29+
<Trigger Property="IsPressed" Value="True">
30+
<Setter Property="Background" Value="#8FFF"/>
31+
</Trigger>
32+
</Style.Triggers>
33+
</Style>
34+
</Button.Style>
35+
</Button>
36+
</UserControl>

app/Components/CloseButton.xaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
5+
namespace ParsecVDisplay.Components
6+
{
7+
public partial class CloseButton : UserControl
8+
{
9+
public CloseButton()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
private void Button_Click(object sender, RoutedEventArgs e)
15+
{
16+
var window = Window.GetWindow(this);
17+
window?.Close();
18+
}
19+
}
20+
}

app/Components/CustomPage.xaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<Page
2+
x:Class="ParsecVDisplay.Components.CustomPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="clr-namespace:ParsecVDisplay.Components"
8+
mc:Ignorable="d"
9+
10+
Loaded="Page_Loaded"
11+
Unloaded="Page_Unloaded"
12+
13+
d:DesignHeight="450" d:DesignWidth="800"
14+
d:Background="#222"
15+
>
16+
<Grid>
17+
<Label Content="Custom Display Modes" Foreground="White" Margin="5,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
18+
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
19+
<StackPanel.Resources>
20+
<Style TargetType="{x:Type StackPanel}">
21+
<Setter Property="Margin" Value="0,5,0,0"/>
22+
</Style>
23+
<Style TargetType="{x:Type Label}">
24+
<Setter Property="Foreground" Value="#DDD"/>
25+
</Style>
26+
<Style TargetType="{x:Type TextBox}">
27+
<Setter Property="HorizontalContentAlignment" Value="Center"/>
28+
<Setter Property="VerticalContentAlignment" Value="Center"/>
29+
<Setter Property="Background" Value="Transparent"/>
30+
<Setter Property="Foreground" Value="White"/>
31+
<Setter Property="CaretBrush" Value="White"/>
32+
</Style>
33+
</StackPanel.Resources>
34+
<StackPanel Orientation="Horizontal">
35+
<Label Width="50">Slot 1</Label>
36+
<TextBox Width="80" />
37+
<Label>×</Label>
38+
<TextBox Width="80" />
39+
<Label>@</Label>
40+
<TextBox Width="60" />
41+
<Label>Hz</Label>
42+
</StackPanel>
43+
<StackPanel Orientation="Horizontal">
44+
<Label Width="50">Slot 2</Label>
45+
<TextBox Width="80" />
46+
<Label>×</Label>
47+
<TextBox Width="80" />
48+
<Label>@</Label>
49+
<TextBox Width="60" />
50+
<Label>Hz</Label>
51+
</StackPanel>
52+
<StackPanel Orientation="Horizontal">
53+
<Label Width="50">Slot 3</Label>
54+
<TextBox Width="80" />
55+
<Label>×</Label>
56+
<TextBox Width="80" />
57+
<Label>@</Label>
58+
<TextBox Width="60" />
59+
<Label>Hz</Label>
60+
</StackPanel>
61+
<StackPanel Orientation="Horizontal">
62+
<Label Width="50">Slot 4</Label>
63+
<TextBox Width="80" />
64+
<Label>×</Label>
65+
<TextBox Width="80" />
66+
<Label>@</Label>
67+
<TextBox Width="60" />
68+
<Label>Hz</Label>
69+
</StackPanel>
70+
<StackPanel Orientation="Horizontal">
71+
<Label Width="50">Slot 5</Label>
72+
<TextBox Width="80" />
73+
<Label>×</Label>
74+
<TextBox Width="80" />
75+
<Label>@</Label>
76+
<TextBox Width="60" />
77+
<Label>Hz</Label>
78+
</StackPanel>
79+
</StackPanel>
80+
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal" Margin="0,0,25,25">
81+
<local:Button Click="ApplyChanges" Width="120" Height="36" Foreground="White">
82+
<local:Button.Children>
83+
<Grid>
84+
<Grid.ColumnDefinitions>
85+
<ColumnDefinition Width="*" />
86+
<ColumnDefinition Width="*" />
87+
<ColumnDefinition />
88+
</Grid.ColumnDefinitions>
89+
<Image Source="../Resources/admin.png" Width="16" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center" />
90+
<TextBlock Grid.Column="1" Text="APPLY" Margin="6,0,0,0" />
91+
</Grid>
92+
</local:Button.Children>
93+
</local:Button>
94+
</StackPanel>
95+
</Grid>
96+
</Page>

0 commit comments

Comments
 (0)