summaryrefslogtreecommitdiff
path: root/_windows/VirtualDesktopSwitcher/Program.cs
blob: eba2e44dcbc803828e3fef445294ad2fa9d2019c (plain)
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
using System.Runtime.InteropServices;
using WindowsDesktop;



class Program
{
    [DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow();

    private static int RealIndex(int index)
    {
        if (index == 0)
            return 9;

        return index - 1;
    }

    [STAThread]
    public static int Main(string[] args)
    {
        if (args[0] == "prepare")
        {
            while (VirtualDesktop.GetDesktops().Length < 10)
                VirtualDesktop.Create();
            return 0;
        }
        if (args[0] == "switch")
        {
            var desktops = VirtualDesktop.GetDesktops();
            desktops[RealIndex(int.Parse(args[1]))].Switch();
            return 0;
        }
        if (args[0] == "move")
        {
            var desktops = VirtualDesktop.GetDesktops();
            var targetDesktop = desktops[RealIndex(int.Parse(args[1]))];
            VirtualDesktop.MoveToDesktop(GetForegroundWindow(), targetDesktop);
        }

        return 1;
    }
}