Exemplo n.º 1
0
        public DPDesktopOverlay NewDPMonitorOverlay(UDDMonitor monitor)
        {
            int index = GetValidOverlayIndex();

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

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

            monitorDP.PreInitialize();

            string key = "DPMonitor-" + index;

            monitorDP.dpAppParent.appKey = key;

            monitorDP.SetTargetCapture(monitor);

            monitorDP.dpAppParent.iconTex = desktopIcon;

            overlays.Add(monitorDP);

            TheBarManager.I.AddLoadedApp(monitorDP.dpAppParent);

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

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

            return(monitorDP);
        }
Exemplo n.º 2
0
        public static IEnumerator UpdateWeirdOffset(UDDMonitor monitor, UwcWindow window)
        {
            WinNative.SetCursorPos(0, 0);
            WinNative.SetWindowPos(window.handle, 0, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOSIZE);

            int size = Marshal.SizeOf(typeof(RECT));

            WinNative.SetThreadDpiAwarenessContext(PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE);
            RECT rect  = new RECT();
            RECT frame = new RECT();

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


            WinNative.DwmGetWindowAttribute(window.handle, DWMWINDOWATTRIBUTE.ExtendedFrameBounds, out frame, size);

//rect should be `0, 0, 1280, 1024`
//frame should be `7, 0, 1273, 1017`

            RECT border = new RECT();

            border.Left   = frame.Left - rect.Left;
            border.Top    = frame.Top - rect.Top;
            border.Right  = rect.Right - frame.Right;
            border.Bottom = rect.Bottom - frame.Bottom;


            Debug.Log(border.Left);



            yield return(new WaitForSeconds(0.1f));

            WinNative.MoveOverWindow(window.handle, new Point(0, 0), true);



            WinNative.POINT curCursorPos = new WinNative.POINT();
            WinNative.GetCursorPos(ref curCursorPos);

            //window.weirdOffset = Math.Abs(curCursorPos.x);


            yield break;

            while (true)
            {
                RECT yay = new RECT();
                WinNative.GetWindowRect(window.handle, ref yay);

                Debug.Log(yay.Left);

                yield return(null);
            }

            //Debug.Log(window.weirdOffset);
        }
Exemplo n.º 3
0
        public void SetTargetCapture(UDDMonitor newMonitor)
        {
            window  = null;
            monitor = newMonitor;


            isTargetingWindow = false;
            loaded            = true;

            OnInteractedWith(true);
        }
Exemplo n.º 4
0
        public void SetTargetCapture(UwcWindow newWindow)
        {
            //Remove events
            if (window != null)
            {
                //window.onSizeChanged.RemoveListener(HandleWindowSizeChange);
                window.onCaptured.RemoveListener(C_OnWindowCaptured);
            }

            if (monitor != null)
            {
                monitor.RemoveDependentDP(this);
            }

            window = newWindow;


            if (DPSettings.config.useDDA)
            {
                //IntPtr monitorHandle = WinNative.MonitorFromWindow(window.handle, WinNative.MONITOR_DEFAULTTONEAREST);

                monitor = UDDManager.GetMonitor(window);

                monitor.AddDependentDP(this);

                //Fit the window on the monitor, don't resize
                WindowManager.FitWindowOnMonitor(monitor, window, false);
            }


            isTargetingWindow = true;
            loaded            = true;
            //isPrimary = true;

            OnInteractedWith(true);


            //StartCoroutine(C_UpdateOverlayUVs());

            window.onCaptured.AddListener(C_OnWindowCaptured);

            RequestRendering(true);
        }
Exemplo n.º 5
0
        public static void FitWindowOnMonitor(UDDMonitor monitor, UwcWindow window, bool resize = false, int widthRatio = 0, int heightRatio = 0, float maxWidthFill = 0.9f, float maxHeightFill = 1f)
        {
            //IntPtr monitorHandle = WinNative.MonitorFromWindow(handle, WinNative.MONITOR_DEFAULTTONEAREST);
            //WinNative.MonitorInfoEx monitorInfo = FetchMonitorInfo(handle);

            WinNative.SetForegroundWindow(window.handle);

            //WM_GETMINMAXINFO
            //WinNative.SendMessage(window.handle, 0x0024, )



            if (monitor == null)
            {
                Debug.LogError("Monitor was null!");
                return;
            }

            int potentialWidth = 0, potentialHeight = 0;

            if (resize)
            {
                bool found = false;
                int  i     = 0;

                while (!found && i < 3000)
                {
                    potentialWidth  += widthRatio;
                    potentialHeight += heightRatio;

                    if (potentialWidth > monitor.workingArea.Width * maxWidthFill)
                    {
                        found = true;
                    }
                    if (potentialHeight > monitor.workingArea.Height * maxHeightFill)
                    {
                        found = true;
                    }

                    //Fallback:
                    i++;
                }
            }

            RECT border = GetExtensionSizeForWindow(window);

            int xPos = monitor.left + monitor.workingArea.Left - border.Left;
            int yPos = monitor.top + monitor.workingArea.Top;


            if (resize)
            {
                //int xPos = monitor.workingArea.Left;
                //int yPos = monitor.workingArea.Top;

                potentialWidth  += border.Left + border.Right;
                potentialHeight += border.Bottom;

                WinNative.SetWindowPos(window.handle, 0, xPos, yPos, potentialWidth, potentialHeight, SetWindowPosFlags.SWP_NOSENDCHANGING | SetWindowPosFlags.SWP_SHOWWINDOW);
            }
            else
            {
                //int xPos = monitor.workingArea.Left - border.Left;
                //int yPos = monitor.workingArea.Top;

                //WinNative.SetWindowPos(window.handle, 0, xPos, yPos, 0, 0, SetWindowPosFlags.SWP_NOSENDCHANGING | SetWindowPosFlags.SWP_SHOWWINDOW | SetWindowPosFlags.SWP_NOSIZE);
            }
        }
Exemplo n.º 6
0
        public static bool LoadLayout(int index, bool force = false)
        {
            if (!layoutsFileLoaded)
            {
                return(false);
            }

            if (layoutsFile.layouts.Count <= 0)
            {
                return(false);
            }

            DPLayoutSerialized layoutToLoad = null;

            //Load the default layout:
            if (index == -1)
            {
                foreach (DPLayoutSerialized layout in layoutsFile.layouts)
                {
                    if (!layout.isDefault)
                    {
                        continue;
                    }

                    layoutToLoad = layout;

                    break;
                }

                //If there's no default, load the first layout
                if (layoutToLoad == null)
                {
                    layoutToLoad = layoutsFile.layouts[0];
                }
            }

            //Load a specific index:
            else
            {
                if (layoutsFile.layouts[index] != null)
                {
                    layoutToLoad = layoutsFile.layouts[index];
                }
            }

            if (layoutToLoad == null)
            {
                return(false);
            }

            //If it's the same layout return
            if (layoutToLoad == currentLayout && !force)
            {
                return(false);
            }


            //Load it

            //Put the bar in the right pos if needed
            if (!TheBarManager.hasBeenOpened)
            {
                TheBarManager.I.theBarDP.SetOverlayTransform(layoutToLoad.theBarPos, layoutToLoad.theBarRot);
            }



            foreach (DPAppSerialized state in layoutToLoad.overlays)
            {
                if (!state.isCapture)
                {
                    //Check to see if it's a built in app or a custom app
                    foreach (DPApp dpApp in TheBarManager.I.builtInApps)
                    {
                        if (dpApp.appKey == state.appKey)
                        {
                            ApplyState(dpApp.dpMain, state);
                        }
                    }

                    //TODO: Custom app check like the one above ^
                }

                //It's a desktop window:
                else
                {
                    bool          isNotFoundError = false;
                    DPOverlayBase dpBase;

                    //WINDOW
                    if (!string.IsNullOrEmpty(state.partialWindowTitle))
                    {
                        UwcWindow window = FindMatchingWindow(state.partialWindowTitle);
                        if (window == null)
                        {
                            //Adds to loaded in TheBarManager
                            dpBase = I.ShowNotFoundError(state, true);
                            dpBase.PreInitialize();
                            isNotFoundError = true;
                        }
                        else
                        {
                            //Adds to loaded in TheBarManager
                            dpBase = OverlayManager.I.NewDPWindowOverlay(window);
                        }
                    }

                    //MONITOR
                    else
                    {
                        UDDMonitor monitor = FindMatchingMonitor(state.displayName);
                        if (monitor == null)
                        {
                            //Adds to loaded in TheBarManager
                            dpBase = I.ShowNotFoundError(state, false);
                            dpBase.PreInitialize();
                            isNotFoundError = true;
                        }
                        else
                        {
                            //Adds to loaded in TheBarManager
                            dpBase = OverlayManager.I.NewDPMonitorOverlay(monitor);
                        }
                    }

                    //Don't spawn a window list icon for the not found error
                    TheBarManager.I.AddOpenApp(dpBase.dpAppParent, !isNotFoundError);

                    ApplyState(dpBase, state);

                    SyncNewDPAppVisibility(state, dpBase);
                }


                //DPSnapPoint snapPoint = null;

                /*if (!String.IsNullOrEmpty(dpAppSer.snapPointID)) {
                 *      snapPoint = TheBarManager.I.FindSnapPointFromID(dpAppSer.snapPointID);
                 * }*/

                //TheBarManager.I.LaunchApp(dpAppSer.appKey, snapPoint, dpAppSer.pos, dpAppSer.rot, dpAppSer.trackedDevice);
            }

            currentLayout = layoutToLoad;

            return(true);
        }