Skip to content

Commit

Permalink
Virtual Desktop Preserve Taskbar Order v1.0.4:
Browse files Browse the repository at this point in the history
* Added support for Windows 11 version 24H2.
  • Loading branch information
m417z committed Sep 9, 2024
1 parent 769a313 commit ca3e6ef
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions mods/virtual-desktop-taskbar-order.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @id virtual-desktop-taskbar-order
// @name Virtual Desktop Preserve Taskbar Order
// @description The order on the taskbar isn't preserved between virtual desktop switches, this mod fixes it
// @version 1.0.3
// @version 1.0.4
// @author m417z
// @github https://github.com/m417z
// @twitter https://twitter.com/m417z
Expand Down Expand Up @@ -127,6 +127,15 @@ size_t* EV_APP_VIEW_MGR_APP_ARRAY_SIZE(LONG_PTR lp) {

#pragma endregion // offsets

using CTaskBtnGroup_GetGroup_t = void*(WINAPI*)(void* pThis);
CTaskBtnGroup_GetGroup_t CTaskBtnGroup_GetGroup;

using CTaskBtnGroup_GetNumItems_t = int(WINAPI*)(void* pThis);
CTaskBtnGroup_GetNumItems_t CTaskBtnGroup_GetNumItems;

using CTaskBtnGroup_GetTaskItem_t = void*(WINAPI*)(void* pThis, int index);
CTaskBtnGroup_GetTaskItem_t CTaskBtnGroup_GetTaskItem;

using CTaskGroup_DoesWindowMatch_t =
HRESULT(WINAPI*)(LPVOID pThis,
HWND hCompareWnd,
Expand Down Expand Up @@ -283,32 +292,28 @@ void OnButtonGroupInserted(LONG_PTR lpTaskSwLongPtr,
LONG_PTR** button_groups = (LONG_PTR**)plp[1];
LONG_PTR* button_group = button_groups[nButtonGroupIndex];

plp = (LONG_PTR*)button_group[7];
if (!plp)
return;

int buttons_count = (int)plp[0];
LONG_PTR** buttons = (LONG_PTR**)plp[1];
if (buttons_count == 0)
int buttons_count = CTaskBtnGroup_GetNumItems(button_group);
if (buttons_count == 0) {
return;
}

LONG_PTR* task_group = (LONG_PTR*)button_group[4];
plp = (LONG_PTR*)task_group[4];
if (!plp)
LONG_PTR* task_group = (LONG_PTR*)CTaskBtnGroup_GetGroup(button_group);
if (!task_group) {
return;
}

int task_items_count = (int)plp[0];
if (task_items_count == 0)
LONG_PTR* first_task_item =
(LONG_PTR*)CTaskBtnGroup_GetTaskItem(button_group, 0);
if (!first_task_item) {
return;

LONG_PTR** task_items = (LONG_PTR**)plp[1];
}

plp = *(LONG_PTR**)task_group;
void** ppTaskGroupRelease = (void**)&plp[2];
PointerRedirectionAdd(ppTaskGroupRelease, (void*)TaskGroupReleaseHook,
&prTaskGroupRelease);

plp = *(LONG_PTR**)task_items[0];
plp = *(LONG_PTR**)first_task_item;
void** ppTaskItemRelease = (void**)&plp[2];
PointerRedirectionAdd(ppTaskItemRelease, (void*)TaskItemReleaseHook,
&prTaskItemRelease);
Expand Down Expand Up @@ -352,8 +357,9 @@ void OnButtonGroupInserted(LONG_PTR lpTaskSwLongPtr,
break;
}

if (!g_taskGroupVirtualDesktopReleased)
if (!g_taskGroupVirtualDesktopReleased) {
continue;
}

if (g_taskGroupVirtualDesktopReleased != task_group) {
if (nRightNeighbourItemIndex == nArraySize) {
Expand All @@ -375,12 +381,13 @@ void OnButtonGroupInserted(LONG_PTR lpTaskSwLongPtr,
continue;
}

if (!g_taskItemVirtualDesktopReleased)
if (!g_taskItemVirtualDesktopReleased) {
continue;
}

for (int j = 0; j < buttons_count; j++) {
LONG_PTR* button = buttons[j];
LONG_PTR* task_item = (LONG_PTR*)button[4];
LONG_PTR* task_item =
(LONG_PTR*)CTaskBtnGroup_GetTaskItem(button_group, j);

if (g_taskItemVirtualDesktopReleased == task_item) {
// The current item in lpArray matches one of the
Expand Down Expand Up @@ -943,6 +950,18 @@ BOOL Wh_ModInit() {
}

SYMBOL_HOOK taskbarDllHooks[] = {
{
{LR"(public: virtual struct ITaskGroup * __cdecl CTaskBtnGroup::GetGroup(void))"},
(void**)&CTaskBtnGroup_GetGroup,
},
{
{LR"(public: virtual int __cdecl CTaskBtnGroup::GetNumItems(void))"},
(void**)&CTaskBtnGroup_GetNumItems,
},
{
{LR"(public: virtual struct ITaskItem * __cdecl CTaskBtnGroup::GetTaskItem(int))"},
(void**)&CTaskBtnGroup_GetTaskItem,
},
{
{LR"(public: virtual long __cdecl CTaskGroup::DoesWindowMatch(struct HWND__ *,struct _ITEMIDLIST_ABSOLUTE const *,unsigned short const *,enum WINDOWMATCHCONFIDENCE *,struct ITaskItem * *))"},
(void**)&CTaskGroup_DoesWindowMatch_Original,
Expand Down

0 comments on commit ca3e6ef

Please sign in to comment.