private async Task Connect(DisplayIdentifier displayIdentifier) { this._x11Client = await X11Client.ConnectAsync(displayIdentifier.Host, displayIdentifier.Display).ConfigureAwait(false); var s = this._x11Client.Screens[displayIdentifier.Screen]; this._screenRootWindow = s.Root; while (true) // ウィンドウが見つかるまでループ { await Task.Delay(1000).ConfigureAwait(false); var wagahighWindow = await FindWagahighWindow(this._x11Client, s.Root).ConfigureAwait(false); if (!wagahighWindow.HasValue) { continue; } var contentWindow = await FindContentWindow(this._x11Client, wagahighWindow.Value).ConfigureAwait(false); if (!contentWindow.HasValue) { continue; } this._contentWindow = contentWindow.Value; // ウィンドウの位置を左上に移動 await this._x11Client.ConfigureWindowAsync(wagahighWindow.Value, x : 0, y : 0).ConfigureAwait(false); return; } }
private static async Task Run() { using (var client = await X11Client.ConnectAsync("127.0.0.1", 0).ConfigureAwait(false)) { Console.WriteLine("Vender: " + client.ServerVendor); Console.WriteLine("Screen Count: " + client.Screens.Count); var screen = client.Screens[0]; //await PrintTree(client, screen.RootWindow, 0).ConfigureAwait(false); var wagahighWindow = await FindWagahighWindow(client, screen.Root).ConfigureAwait(false); await client.ConfigureWindowAsync(wagahighWindow, x : 0, y : 0).ConfigureAwait(false); using (var getImageResult = await client.GetImageAsync(screen.Root, 0, 0, screen.Width, screen.Height, uint.MaxValue, GetImageFormat.ZPixmap).ConfigureAwait(false)) { Console.WriteLine("Depth: " + getImageResult.Depth); Console.WriteLine("RGB: {0:x8}, {1:x8}, {2:x8}", getImageResult.Visual.RedMask, getImageResult.Visual.GreenMask, getImageResult.Visual.BlueMask); SaveImage(getImageResult.Data.Array, screen.Width, screen.Height); } /* * for (var i = 0; ; i++) * { * var cursor = await client.XFixes.GetCursorImageAsync().ConfigureAwait(false); * SaveCursor(cursor.CursorImage, cursor.Width, cursor.Height, $"cursor{i}.png"); * Console.WriteLine("{0}, {1}", cursor.X, cursor.Y); * await Task.Delay(500).ConfigureAwait(false); * } */ /* * var rng = new Random(); * * while (true) * { * await client.XTest.FakeInputAsync( * XTestFakeEventType.MotionNotify, * 0, 0, screen.Root, * (short)rng.Next(screen.Width), * (short)rng.Next(screen.Height) * ).ConfigureAwait(false); * * await Task.Delay(500).ConfigureAwait(false); * } */ } }