Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click on empty taskbar space v1.8 #1291

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions mods/taskbar-empty-space-clicks.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @id taskbar-empty-space-clicks
// @name Click on empty taskbar space
// @description Trigger custom action when empty space on a taskbar is double/middle clicked
// @version 1.7
// @version 1.8
// @author m1lhaus
// @github https://github.com/m1lhaus
// @include explorer.exe
Expand Down Expand Up @@ -2161,23 +2161,21 @@ void SendWinTabKeypress()
SendKeypress({VK_LWIN, VK_TAB});
}

void SendWinKeypress()
bool ClickStartMenu()
{
LOG_TRACE();

const MouseClick &lastClick = g_mouseClickQueue[-1];
if (!lastClick.onEmptySpace)
{
LOG_ERROR(L"Failed to send Win keypress - last click was not on empty space");
return;
return false;
}

// Get the taskbar element from the last mouse click position
com_ptr<IUIAutomationElement> pWindowElement = NULL;
if (FAILED(g_pUIAutomation->ElementFromPoint(lastClick.position, pWindowElement.put())) || !pWindowElement)
{
LOG_ERROR(L"Failed to taskbar UI element from mouse click");
return;
return false;
}

com_ptr<IUIAutomationElement> pStartButton = NULL;
Expand All @@ -2195,7 +2193,7 @@ void SendWinKeypress()
!pControlTypeCondition)
{
LOG_ERROR(L"Failed to create ControlType condition for Start button search.");
return;
return false;
}

// Create Condition 2: ClassName == "Start"
Expand All @@ -2206,7 +2204,7 @@ void SendWinKeypress()
!pClassNameCondition)
{
LOG_ERROR(L"Failed to create ClassName condition for Start button search.");
return;
return false;
}

// Combine both conditions using AndCondition
Expand All @@ -2217,14 +2215,14 @@ void SendWinKeypress()
!pAndCondition)
{
LOG_ERROR(L"Failed to create ControlType&&ClassName condition for Start button search.");
return;
return false;
}

// Use the combined condition to find the Start button within the Taskbar
if (FAILED(pWindowElement->FindFirst(TreeScope_Children, pAndCondition.get(), pStartButton.put())) || !pStartButton)
{
LOG_ERROR(L"Failed to locate the Start button element for Windows 10 taskbar.");
return;
return false;
}
}
else
Expand All @@ -2239,14 +2237,14 @@ void SendWinKeypress()
!pCondition)
{
LOG_ERROR(L"Failed to create property condition for locating the Start button.");
return;
return false;
}

// Use the AutomationId condition to find the Start button within the Taskbar
if (FAILED(pWindowElement->FindFirst(TreeScope_Children, pCondition.get(), pStartButton.put())) || !pStartButton)
{
LOG_ERROR(L"Failed to locate the Start button element for Windows 11 taskbar.");
return;
return false;
}
}

Expand All @@ -2258,12 +2256,13 @@ void SendWinKeypress()
if (FAILED(pStartButton->GetCurrentPatternAs(UIA_InvokePatternId, IID_PPV_ARGS(pInvoke.put()))) || !pInvoke)
{
LOG_ERROR(L"Invoke pattern not supported by the Start button.");
return;
return false;
}

if (FAILED(pInvoke->Invoke()))
{
LOG_ERROR(L"Failed to invoke the Start button.");
return false;
}
else
{
Expand All @@ -2277,18 +2276,30 @@ void SendWinKeypress()
if (FAILED(pStartButton->GetCurrentPatternAs(UIA_TogglePatternId, IID_PPV_ARGS(pToggle.put()))) || !pToggle)
{
LOG_ERROR(L"Toggle pattern not supported by the Start button.");
return;
return false;
}

if (FAILED(pToggle->Toggle()))
{
LOG_ERROR(L"Failed to toggle the Start button.");
return false;
}
else
{
LOG_INFO(L"Start button toggled successfully on Windows 11 taskbar.");
}
}
return true;
}

void OpenStartMenu()
{
LOG_TRACE();
if (!ClickStartMenu()) // if user hide the start menu via other Windhawk mod, we can't click it
{
LOG_INFO(L"Sending Win keypress");
SendKeypress({VK_LWIN});
}
}

void OpenTaskManager(HWND taskbarhWnd)
Expand Down Expand Up @@ -2632,7 +2643,7 @@ void ExecuteTaskbarAction(TaskBarAction taskbarAction, HWND hWnd)
}
else if (taskbarAction == ACTION_OPEN_START_MENU)
{
SendWinKeypress();
OpenStartMenu();
}
else if (taskbarAction == ACTION_SEND_KEYPRESS)
{
Expand Down
Loading