leafOfTree/WindowTabs

It combines the explorers in different desktops, but I want it to work independently on both.

Femtometer opened this issue · 1 comments

OS:Windows10

image

I've got an idea for this, but it isn't very easy and may take more time.

Meanwhile, you can drag any tab out of the group so it stays on the virtual desktop. Will this alternative method work for you?


For reference later. There is an interface for this

interface IVirtualDesktopManager: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ivirtualdesktopmanager?redirectedfrom=MSDN

method GetWindowDesktopId: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ivirtualdesktopmanager-getwindowdesktopid

We can use GetWindowDesktopId to group tabs for each desktop.

An example

open System
open System.Runtime.InteropServices

[<ComImport; Guid("A5CD92FF-29BE-454C-8D04-D82879FB3F1B"); InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>]
type IVirtualDesktopManager =
    abstract member IsWindowOnCurrentVirtualDesktop: IntPtr * byref<bool> -> int
    abstract member GetWindowDesktopId: IntPtr * byref<Guid> -> int
    abstract member MoveWindowToDesktop: IntPtr * byref<Guid> -> int

let getWindowDesktopId (windowHandle: IntPtr) =
    // Create an instance of IVirtualDesktopManager
    let clsid = new Guid("C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B")
    let vdmType = Type.GetTypeFromCLSID(clsid)
    let vdm = Activator.CreateInstance(vdmType) :?> IVirtualDesktopManager

    // Get the desktop ID
    let mutable desktopId = Guid.Empty
    let hr = vdm.GetWindowDesktopId(windowHandle, &desktopId)

    if hr = 0 then
        printfn "Window is on Desktop ID: %A" desktopId
    else
        printfn "Failed to get Desktop ID. HRESULT: %d" hr

// Example window handle (replace with actual handle)
let windowHandle = IntPtr.Zero
getWindowDesktopId windowHandle