/// <summary>
        /// Returns the desktop assignment type for a window.
        /// </summary>
        /// <param name="hWindow">Handle of the window.</param>
        /// <param name="desktop">Optional the desktop id if known</param>
        /// <returns>Type of <see cref="VirtualDesktopAssignmentType"/>.</returns>
        public VirtualDesktopAssignmentType GetWindowDesktopAssignmentType(IntPtr hWindow, Guid?desktop = null)
        {
            if (_virtualDesktopManager == null)
            {
                Log.Error("VirtualDesktopHelper.GetWindowDesktopAssignmentType() failed: The instance of <IVirtualDesktopHelper> isn't available.", typeof(VirtualDesktopHelper));
                return(VirtualDesktopAssignmentType.Unknown);
            }

            _ = _virtualDesktopManager.IsWindowOnCurrentVirtualDesktop(hWindow, out int isOnCurrentDesktop);
            Guid windowDesktopId = desktop ?? Guid.Empty; // Prepare variable in case we have no input parameter for desktop
            int  hResult         = desktop is null?GetWindowDesktopId(hWindow, out windowDesktopId) : 0;

            if (hResult != (int)HRESULT.S_OK)
            {
                return(VirtualDesktopAssignmentType.Unknown);
            }
            else if (windowDesktopId == Guid.Empty)
            {
                return(VirtualDesktopAssignmentType.NotAssigned);
            }
            else if (isOnCurrentDesktop == 1 && !GetDesktopIdList().Contains(windowDesktopId))
            {
                // These windows are marked as visible on the current desktop, but the desktop id doesn't belongs to an existing desktop.
                // In this case the desktop id belongs to the generic view 'AllDesktops'.
                return(VirtualDesktopAssignmentType.AllDesktops);
            }
            else if (isOnCurrentDesktop == 1)
            {
                return(VirtualDesktopAssignmentType.CurrentDesktop);
            }
            else
            {
                return(VirtualDesktopAssignmentType.OtherDesktop);
            }
        }
Beispiel #2
0
 private void watchVirtualDesktopTimer_Tick(object sender, EventArgs e)
 {
     if (_VirtualDesktopManager.IsWindowOnCurrentVirtualDesktop(this.Handle) == false)
     {
         var currentDesktopID = _GetCurrentDesktop().GetID();
         _VirtualDesktopManager.MoveWindowToDesktop(this.Handle, ref currentDesktopID);
     }
 }
Beispiel #3
0
        public bool IsWindowOnCurrentVirtualDesktop(IntPtr TopLevelWindow)
        {
            int result;
            int hr;

            if ((hr = manager.IsWindowOnCurrentVirtualDesktop(TopLevelWindow, out result)) != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            return(result != 0);
        }
Beispiel #4
0
        public bool IsWindowOnCurrentVirtualDesktop(IntPtr TopLevelWindow)
        {
            if (manager == null)
            {
                return(true);
            }

            int result;
            int hresult = manager.IsWindowOnCurrentVirtualDesktop(TopLevelWindow, out result);

            return(result != 0 && hresult == 0);
        }
Beispiel #5
0
 public static bool IsWindowOnCurrentVirtualDesktop(IntPtr window)
 {
     if (IsInitialized)
     {
         return(s_manager.IsWindowOnCurrentVirtualDesktop(window));
         //bool isWndOnDekstop = false;
         //ref bool pointer = ref isWndOnDekstop;
         //vdmType.InvokeMember("IsWindowOnCurrentVirtualDesktop", System.Reflection.BindingFlags.InvokeMethod, null, vdmObject, new object[] { window, pointer });
         //return isWndOnDekstop;
     }
     return(true);
 }
Beispiel #6
0
        public async Task <bool> IsWindowOnCurrentVirtualDesktop(IntPtr TopLevelWindow)
        {
            return(await Window.Dispatch <bool>(() =>
            {
                int hr;
                if ((hr = manager.IsWindowOnCurrentVirtualDesktop(TopLevelWindow, out var result)) != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                return result != 0;
            }));
        }