forked from digitalcreations/VirtualDesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
125 lines (106 loc) · 2.88 KB
/
MainWindow.xaml.cs
File metadata and controls
125 lines (106 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using WindowsDesktop;
namespace VirtualDesktopShowcase
{
partial class MainWindow
{
private static readonly int _delay = 2000;
public MainWindow()
{
this.InitializeComponent();
foreach (var id in VirtualDesktop.GetDesktops().Select(x => x.Id))
{
System.Diagnostics.Debug.WriteLine(id);
}
}
private void CreateNew(object sender, RoutedEventArgs e)
{
VirtualDesktop.Create().Switch();
}
private async void CreateNewAndMove(object sender, RoutedEventArgs e)
{
var desktop = VirtualDesktop.Create();
if (this.ThisWindowMenu.IsChecked ?? false)
{
this.MoveToDesktop(desktop);
}
else
{
await Task.Delay(_delay);
VirtualDesktopHelper.MoveToDesktop(GetForegroundWindow(), desktop);
}
desktop.Switch();
}
private void SwitchLeft(object sender, RoutedEventArgs e)
{
this.GetCurrentDesktop().GetLeft()?.Switch();
}
private async void SwitchLeftAndMove(object sender, RoutedEventArgs e)
{
var left = this.GetCurrentDesktop().GetLeft();
if (left == null) return;
if (this.ThisWindowMenu.IsChecked ?? false)
{
this.MoveToDesktop(left);
}
else
{
await Task.Delay(_delay);
VirtualDesktopHelper.MoveToDesktop(GetForegroundWindow(), left);
}
left.Switch();
}
private void SwitchRight(object sender, RoutedEventArgs e)
{
this.GetCurrentDesktop().GetRight()?.Switch();
}
private async void SwitchRightAndMove(object sender, RoutedEventArgs e)
{
var right = this.GetCurrentDesktop().GetRight();
if (right == null) return;
if (this.ThisWindowMenu.IsChecked ?? false)
{
this.MoveToDesktop(right);
}
else
{
await Task.Delay(_delay);
VirtualDesktopHelper.MoveToDesktop(GetForegroundWindow(), right);
}
right.Switch();
}
private async void Pin(object sender, RoutedEventArgs e)
{
if (this.ThisWindowMenu.IsChecked ?? false)
{
this.TogglePin();
}
else
{
await Task.Delay(_delay);
var handle = GetForegroundWindow();
(VirtualDesktop.IsPinnedWindow(handle) ? VirtualDesktop.UnpinWindow : (Action<IntPtr>)VirtualDesktop.PinWindow)(handle);
}
}
private async void PinApp(object sender, RoutedEventArgs e)
{
if (this.ThisWindowMenu.IsChecked ?? false)
{
Application.Current.TogglePin();
}
else
{
await Task.Delay(_delay);
var appId = ApplicationHelper.GetAppId(GetForegroundWindow());
(VirtualDesktop.IsPinnedApplication(appId) ? VirtualDesktop.UnpinApplication : (Action<string>)VirtualDesktop.PinApplication)(appId);
}
}
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
}
}