Exemplo n.º 1
0
        public async Task Initialize()
        {
            await inputManager.StartAsync();

            localCursorPosition = await inputManager.MouseListener.GetCursorPosition();

            await mutableStateLock.WaitAsync();

            selfDesktop = new Desktop()
            {
                Name = selfName, Displays = inputManager.DisplayAdapter.GetDisplays(), PrimaryDisplay = inputManager.DisplayAdapter.GetPrimaryDisplay()
            };
            mouseDeltaDebounceValueX = selfDesktop.PrimaryDisplay.Value.Width / 3;
            mouseDeltaDebounceValueY = selfDesktop.PrimaryDisplay.Value.Height / 3;
            desktops = new List <Desktop>()
            {
                selfDesktop
            };
            displayLayout = new DisplayLayout(desktops);

            var(_, display) = displayLayout.FindPoint(TranslateLocalToGlobal(localCursorPosition)) !.Value;
            localState      = new LocalState.Uncontrolled(display, selfDesktop.PrimaryDisplay.Value);
            mutableStateLock.Release();

            initialized.TrySetResult(null);
        }
Exemplo n.º 2
0
        private async void OnClientDisplaysChanged(object sender, ClientDisplaysChangedEventArgs e)
        {
            await EnsureInitialized();

            await mutableStateLock.WaitAsync();

            var desktopName = e.DesktopName.NormalizeDesktopName();
            var desktop     = desktops.Find(d => d.Name == desktopName);

            if (desktop != null)
            {
                LocalState.Controlling?controlling = localState as LocalState.Controlling;
                string?activeDisplayId             = null;
                if (controlling != null)
                {
                    activeDisplayId = displayLayout.DisplayIds[controlling.ActiveDisplay];
                }

                DebugMessage($"displays for {desktopName} changed");
                desktop.Displays = e.Displays;
                displayLayout    = new DisplayLayout(desktops);
                DebugPrintDisplays();

                if (controlling != null && activeDisplayId != null)
                {
                    if (displayLayout.DisplayById.TryGetValue(activeDisplayId, out Rectangle nextDisplay))
                    {
                        DebugMessage($"moving from display {controlling.ActiveDisplay} to {nextDisplay}");
                        var displayOriginDeltaX = nextDisplay.X - controlling.ActiveDisplay.X;
                        var displayOriginDeltaY = nextDisplay.Y - controlling.ActiveDisplay.Y;
                        localState = new LocalState.Controlling(controlling.ActiveDesktop, nextDisplay, controlling.CursorPosition.Offset(displayOriginDeltaX, displayOriginDeltaY));
                    }
                    else
                    {
                        DebugMessage($"display {activeDisplayId} not found. Returning to local primary display");
                        await ReturnToPrimaryDisplay();
                    }
                }
            }

            mutableStateLock.Release();
        }
Exemplo n.º 3
0
        private async void OnClientDisconnected(object sender, ClientConnectionChangedEventArgs e)
        {
            await EnsureInitialized();

            await mutableStateLock.WaitAsync();

            string desktopName = e.DesktopName.NormalizeDesktopName();

            LocalState.Controlling?controlling = localState as LocalState.Controlling;
            string?activeDisplayId             = null;

            if (controlling != null && controlling.ActiveDesktop.Name != desktopName)
            {
                activeDisplayId = displayLayout.DisplayIds[controlling.ActiveDisplay];
            }

            DebugMessage($"removing client {desktopName}");
            desktops      = desktops.Where(d => d.Name != desktopName).ToList();
            displayLayout = new DisplayLayout(desktops);
            DebugPrintDisplays();

            if (controlling != null)
            {
                if (activeDisplayId != null)
                {
                    var nextDisplay = displayLayout.DisplayById[activeDisplayId];
                    DebugMessage($"moving from display {controlling.ActiveDisplay} to {nextDisplay}");
                    var displayOriginDeltaX = nextDisplay.X - controlling.ActiveDisplay.X;
                    var displayOriginDeltaY = nextDisplay.Y - controlling.ActiveDisplay.Y;
                    localState = new LocalState.Controlling(controlling.ActiveDesktop, nextDisplay, controlling.CursorPosition.Offset(displayOriginDeltaX, displayOriginDeltaY));
                }
                else
                {
                    DebugMessage($"active desktop disconnected. Returning to local primary display");
                    await ReturnToPrimaryDisplay();
                }
            }

            mutableStateLock.Release();
        }
Exemplo n.º 4
0
        private async void OnDisplaysChanged(object sender, DisplaysChangedEventArgs e)
        {
            await EnsureInitialized();

            await mutableStateLock.WaitAsync();

            LocalState.Controlling?controlling = localState as LocalState.Controlling;
            string?activeDisplayId             = null;

            if (controlling != null)
            {
                activeDisplayId = displayLayout.DisplayIds[controlling.ActiveDisplay];
            }

            DebugMessage("own displays changed");
            selfDesktop.Displays       = e.Displays;
            selfDesktop.PrimaryDisplay = e.PrimaryDisplay;
            mouseDeltaDebounceValueX   = e.PrimaryDisplay.Width / 2;
            mouseDeltaDebounceValueY   = e.PrimaryDisplay.Height / 2;
            displayLayout = new DisplayLayout(desktops);
            var allClients = await workspaceNetwork.GetAllClientDesktops();

            await allClients.DisplaysChanged(e.Displays);

            DebugPrintDisplays();

            if (controlling != null && activeDisplayId != null)
            {
                var nextDisplay = displayLayout.DisplayById[activeDisplayId];
                DebugMessage($"moving from display {controlling.ActiveDisplay} to {nextDisplay}");
                var displayOriginDeltaX = nextDisplay.X - controlling.ActiveDisplay.X;
                var displayOriginDeltaY = nextDisplay.Y - controlling.ActiveDisplay.Y;
                DebugMessage(controlling.CursorPosition.Offset(displayOriginDeltaX, displayOriginDeltaY).ToString());
                localState = new LocalState.Controlling(controlling.ActiveDesktop, nextDisplay, controlling.CursorPosition.Offset(displayOriginDeltaX, displayOriginDeltaY));
            }

            mutableStateLock.Release();
        }