Пример #1
0
    public static void FocusActiveGame()
    {
        //if (!DPSettings.config.returnFocusWhenBarClosed) return;


        if (activePID == 0 || activeProcess == null)
        {
            return;
        }


        //Debug.Log("Focusing game....");

        IntPtr[] gameHandles = WinNative.GetProcessWindows(activePID);

        foreach (IntPtr handle in gameHandles)
        {
            if (handle == IntPtr.Zero)
            {
                WinNative.ShowWindow(handle, ShowWindowCommands.Restore);
            }

            WinNative.SetForegroundWindow(handle);
        }
    }
Пример #2
0
 public void Minimize()
 {
     if (SteamVRManager.isWearingHeadset && startupScreenDPApp.dpMain.overlay.shouldRender)
     {
         TheBarManager.I.MinimizeApp(startupScreenDPApp.appKey);
     }
     else
     {
         WinNative.ShowWindow(WinNative.GetForegroundWindow(), ShowWindowCommands.Minimize);
     }
 }
Пример #3
0
        /// <summary>
        /// Used internally for making a new overlay.
        /// </summary>
        /// <param name="window"></param>
        /// <returns>The created overlay</returns>
        public DPDesktopOverlay NewDPWindowOverlay(UwcWindow window)
        {
            if (window == null)
            {
                return(null);
            }

            int index = GetValidOverlayIndex();

            if (DemoManager.isDemo)
            {
                if (DPDesktopOverlay.overlays.Count >= 3)
                {
                    return(null);
                }
            }


            DPDesktopOverlay dpWindow = Instantiate(dpRenderWindowPF, _overlaysHolderTransform).GetComponentInChildren <DPDesktopOverlay>();

            dpWindow.PreInitialize();

            string key = "DPWindow-" + index;

            dpWindow.dpAppParent.appKey = key;

            //dpWindow.InitWindow(window);


            if (WinNative.IsIconic(window.handle))
            {
                WinNative.ShowWindow(window.handle, ShowWindowCommands.Restore);
            }

            //WinNative.SetForegroundWindow(window.handle);

            dpWindow.SetTargetCapture(window);


            dpWindow.dpAppParent.iconTex = window.iconTexture;


            overlays.Add(dpWindow);

            TheBarManager.I.AddLoadedApp(dpWindow.dpAppParent);

            //OverlayInteractionManager.I.StartPreviewDrag(key);
            //TheBarManager.I.LaunchAppToMainSnap(key);

            Debug.Log(dpWindow.overlay.handle + " : " + dpWindow.overlay.overlayKey + " : " + dpWindow.window.handle);

            return(dpWindow);
        }
Пример #4
0
        private void HandleMinimizeAtStartup()
        {
            if (DPSettings.config.minimizeAtStartup)
            {
                int currentPID = System.Diagnostics.Process.GetCurrentProcess().Id;

                WinNative.EnumWindows(delegate(IntPtr wnd, IntPtr param)                                        {
                    int returnVal = WinNative.GetWindowThreadProcessId(wnd, out int procid);

                    //We found it
                    if (procid == currentPID)
                    {
                        WinNative.ShowWindow(wnd, ShowWindowCommands.Minimize);
                        return(false);
                    }


                    return(true);
                }, IntPtr.Zero);
            }
        }
Пример #5
0
        private void OnInteractedWith(bool interacting)
        {
            if (!loaded)
            {
                return;
            }

            //Debug.Log("Interaction state: " + interacting);

            isInteractingVirtually = interacting;

            if (interacting && isTargetingWindow)
            {
                if (isTargetingWindow && window.isIconic)
                {
                    WinNative.ShowWindow(window.handle, ShowWindowCommands.Restore);
                }

                WinNative.SetForegroundWindow(window.handle);

                if (primaryWindowDP != this)
                {
                    //Clear the previous
                    if (primaryWindowDP != null)
                    {
                        primaryWindowDP.isPrimary = false;

                        //if (primaryWindowDP.isTargetingWindow) {

                        //}

                        primaryWindowDP.RequestRendering();
                        //primaryWindowDP.UpdateOverlayUVs();
                    }

                    //StartCoroutine(C_Lock());

                    primaryWindowDP = this;
                    isPrimary       = true;

                    UDDManager.instance.gameObject.SetActive(false);
                    UDDManager.instance.gameObject.SetActive(true);

                    //UpdateOverlayUVs();
                }
            }

            //Update the title
            if (interacting)
            {
                if (!isTargetingWindow)
                {
                    dpAppParent.title = monitor.name;
                }
                else
                {
                    dpAppParent.title = window.title;
                }
            }

            //This only runs when the bar is closed and the config option is enabled
            if (DPSettings.config.focusGameWhenNotInteracting && !interacting)
            {
                GamingManager.FocusActiveGame();
            }
        }
Пример #6
0
        public static UDDMonitor GetMonitor(UwcWindow window)
        {
            if (window.isIconic)
            {
                WinNative.ShowWindow(window.handle, ShowWindowCommands.ShowMaximized);
            }

            RECT rect = new RECT();

            WinNative.GetWindowRect(window.handle, ref rect);

            UDDMonitor closestMonitor;

            int midX = 0, midY = 0;

            midX = window.rawX + (int)(window.rawWidth / 2f);
            midY = window.rawY + (int)(window.rawHeight / 2f);

            foreach (UDDMonitor monitor in monitors)
            {
                if (monitor.left > midX)
                {
                    continue;
                }
                if (monitor.top > midY)
                {
                    continue;
                }

                if (monitor.right <= midX)
                {
                    continue;
                }
                if (monitor.bottom <= midY)
                {
                    continue;
                }

                closestMonitor = monitor;

                return(closestMonitor);

                break;
            }

            //else, it failed, so return the biggest monitor:

            UDDMonitor biggestMonitor = null;


            foreach (UDDMonitor monitor in monitors)
            {
                if (biggestMonitor == null)
                {
                    biggestMonitor = monitor;
                }

                if (monitor.width > biggestMonitor.width && monitor.height > biggestMonitor.height)
                {
                    biggestMonitor = monitor;
                }
            }

            return(biggestMonitor);
        }
Пример #7
0
        private IEnumerator C_JoinDiscord()
        {
            //Clipboard.SetText("https://discord.gg/adVEQmY");

            Process.Start("https://discord.gg/adVEQmY");

            yield break;

            UwcWindow        discordWindow = null;
            DPDesktopOverlay discordDP     = null;
            DPApp            discordDPApp  = null;

            //See if discord is opened already
            foreach (DPDesktopOverlay desktopDP in DPDesktopOverlay.overlays)
            {
                if (desktopDP.isTargetingWindow && desktopDP.window.title.EndsWith("- Discord"))
                {
                    discordDP     = desktopDP;
                    discordWindow = desktopDP.window;

                    break;
                }
            }

            //If the overlay isn't already opened, we try to spawn a new one
            if (discordWindow == null)
            {
                //See if discord is opened
                foreach (UwcWindow window in UwcManager.windows.Values)
                {
                    if (window.title.EndsWith("- Discord"))
                    {
                        discordWindow = window;

                        discordDP = OverlayManager.I.NewDPWindowOverlay(discordWindow);

                        break;
                    }
                }
            }

//TODO: Launch discord
            //if (discordWindow == null || discordDP == null) {

            Process.Start("https://discord.gg/adVEQmY");

            yield break;
            //}


            //Find the DPApp
            foreach (DPApp app in TheBarManager.openApps.Values)
            {
                if (app.dpMain == discordDP)
                {
                    discordDPApp = app;
                    break;
                }
            }


            if (discordWindow.isIconic)
            {
                WinNative.ShowWindow(discordWindow.handle, ShowWindowCommands.Restore);
            }

            TheBarManager.I.LaunchAppToMainSnap(discordDPApp.appKey);

            WinNative.SetForegroundWindow(discordWindow.handle);

            yield return(new WaitForSeconds(0.2f));

            yield return(new WaitForSeconds(0.2f));

            //const int WM_KEYDOWN = 0x100;
            //const int WM_KEYUP = 0x101;

            //WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_LCONTROL, 0);
            //WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_LSHIFT, 0);
            //WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_N, 0);

            InputSimulator inputSimulator = new InputSimulator();

            //inputSimulator.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
            inputSimulator.Keyboard.ModifiedKeyStroke(new[] { VirtualKeyCode.LCONTROL, VirtualKeyCode.LSHIFT }, new[] { VirtualKeyCode.VK_N });

            yield return(new WaitForSeconds(0.2f));

            inputSimulator.Keyboard.KeyPress(VirtualKeyCode.TAB);
            inputSimulator.Keyboard.KeyPress(VirtualKeyCode.TAB);
            inputSimulator.Keyboard.KeyPress(VirtualKeyCode.TAB);

            inputSimulator.Keyboard.KeyPress(VirtualKeyCode.RETURN);

            yield return(new WaitForSeconds(0.2f));

            inputSimulator.Keyboard.TextEntry("https://discord.gg/adVEQmY");



            /*//Tab 3 times to the join server button:
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_TAB, 0);
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_TAB, 0);
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_TAB, 0);
             *
             * yield return null;
             *
             * //Enter
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_RETURN, 0);
             *
             * yield return new WaitForSeconds(0.2f);
             *
             * //Paste in the join link
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_LCONTROL, 0);
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_V, 0);
             * yield return null;
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYUP, (int)KeysEx.VK_V, 0);
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYUP, (int)KeysEx.VK_LCONTROL, 0);
             *
             * yield return null;
             *
             * //Enter to join:
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_RETURN, 0);*/
        }