Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

Replace Windows Taskbar with DisplayFusion Taskbar

Description
This script will set the opacity of the Windows taskbar to 0 and then enable the DisplayFusion taskbar on that monitor.
Language
C#.net
Minimum Version
Created By
XTheocharis
Contributors
-
Date Created
5d ago
Date Last Modified
5d ago

Scripted Function (Macro) Code

using System;
using System.Linq;
using Microsoft.Win32;

public static class DisplayFusionFunction
{
    // Replaces the Windows taskbar with a DisplayFusion taskbar by exploiting transparency behavior.
    // When Windows taskbar is fully transparent, it stops receiving input.
    // Requires "Show DisplayFusion taskbar on Windows taskbar monitor" setting to be enabled.
	//
	// Note: Taskbar movement is required to avoid DF taskbar remaining the height of the Windows taskbar away from the edge of the screen.
	// Note: Initialization delay is required for DF to realize that we've moved prior to moving back.
	// Note: Initialization delay needs to exceed 350ms on an i9-9900k to work reliably; padded to 1000ms for compatibility.
    public static void Run(IntPtr windowHandle)
    {   
        var taskbarHandle = BFS.Window.GetWindowByClass("Shell_TrayWnd");
        if (taskbarHandle == IntPtr.Zero) return;

        var monitorId = BFS.Monitor.GetMonitorIDByWindow(taskbarHandle);
        var monitorBounds = BFS.Monitor.GetMonitorBoundsByID(monitorId);

        // Parse Windows taskbar position from Registry
        var taskbarPosition = (Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3")?.GetValue("Settings") as byte[])?[12] switch
            { 0x00 => "L", 0x01 => "T", 0x02 => "R", _ => "B" };

        // Find existing DF taskbar on this monitor (if one exists)
        var existingClass = BFS.Window.GetAllWindowHandles()
            .Select(w => BFS.Window.GetClass(w))
            .FirstOrDefault(c => c.StartsWith("DFTaskbar:") && 
                BFS.Window.GetBounds(BFS.Window.GetWindowByClass(c)).IntersectsWith(monitorBounds));

        // Create temporary taskbar opposite the Windows taskbar
        var tempPosition = taskbarPosition switch { "L" => "R", "R" => "L", "T" => "B", _ => "T" };
        BFS.DisplayFusion.EnableTaskbarOnSide(monitorId, tempPosition);

        // Wait for temporary taskbar to appear
        string newTaskbarClass;
        while ((newTaskbarClass = BFS.Window.GetAllWindowHandles()
            .Select(w => BFS.Window.GetClass(w))
            .FirstOrDefault(c => c.StartsWith("DFTaskbar:") && 
                BFS.Window.GetBounds(BFS.Window.GetWindowByClass(c)).IntersectsWith(monitorBounds))) == existingClass || newTaskbarClass == null)
        {
            BFS.General.Sleep(100);
        }

        // Hide temporary taskbar and wait for initialization
        BFS.Window.SetTransparency(BFS.Window.GetWindowByClass(newTaskbarClass), 0);
        BFS.General.Sleep(1000);

        // Disable Windows taskbar and move DF taskbar to final position
        BFS.Window.SetTransparency(taskbarHandle, 0);
        BFS.DisplayFusion.EnableTaskbarOnSide(monitorId, taskbarPosition);
    }
}