mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
FancyZones and Shortcut Guide initial commit
Co-authored-by: Alexis Campailla <alexis@janeasystems.com> Co-authored-by: Bret Anderson <bretan@microsoft.com> Co-authored-by: Enrico Giordani <enrico.giordani@gmail.com> Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Jeff Bogdan <jeffbog@microsoft.com> Co-authored-by: March Rogers <marchr@microsoft.com> Co-authored-by: Mike Harsh <mharsh@microsoft.com> Co-authored-by: Nachum Bundak <Nachum.Bundak@microsoft.com> Co-authored-by: Oliver Jones <ojones@microsoft.com> Co-authored-by: Patrick Little <plittle@microsoft.com>
This commit is contained in:
committed by
Bartosz Sosnowski
parent
10c5396099
commit
8431b80e48
93
src/common/tasklist_positions.cpp
Normal file
93
src/common/tasklist_positions.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "pch.h"
|
||||
#include "tasklist_positions.h"
|
||||
|
||||
void Tasklist::update() {
|
||||
// Get HWND of the tasklist
|
||||
auto tasklist_hwnd = FindWindowA("Shell_TrayWnd", nullptr);
|
||||
if (!tasklist_hwnd) return;
|
||||
tasklist_hwnd = FindWindowExA(tasklist_hwnd, 0, "ReBarWindow32", nullptr);
|
||||
if (!tasklist_hwnd) return;
|
||||
tasklist_hwnd = FindWindowExA(tasklist_hwnd, 0, "MSTaskSwWClass", nullptr);
|
||||
if (!tasklist_hwnd) return;
|
||||
tasklist_hwnd = FindWindowExA(tasklist_hwnd, 0, "MSTaskListWClass", nullptr);
|
||||
if (!tasklist_hwnd) return;
|
||||
if (!automation) {
|
||||
winrt::check_hresult(CoCreateInstance(CLSID_CUIAutomation,
|
||||
nullptr,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
IID_IUIAutomation,
|
||||
automation.put_void()));
|
||||
winrt::check_hresult(automation->CreateTrueCondition(true_condition.put()));
|
||||
}
|
||||
element = nullptr;
|
||||
winrt::check_hresult(automation->ElementFromHandle(tasklist_hwnd, element.put()));
|
||||
}
|
||||
|
||||
bool Tasklist::update_buttons(std::vector<TasklistButton>& buttons) {
|
||||
if (!automation || !element) {
|
||||
return false;
|
||||
}
|
||||
winrt::com_ptr<IUIAutomationElementArray> elements;
|
||||
if (element->FindAll(TreeScope_Children, true_condition.get(), elements.put()) < 0)
|
||||
return false;
|
||||
if (!elements)
|
||||
return false;
|
||||
int count;
|
||||
if (elements->get_Length(&count) < 0)
|
||||
return false;
|
||||
winrt::com_ptr<IUIAutomationElement> child;
|
||||
std::vector<TasklistButton> found_butttons;
|
||||
found_butttons.reserve(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
child = nullptr;
|
||||
if (elements->GetElement(i, child.put()) < 0)
|
||||
return false;
|
||||
TasklistButton button;
|
||||
if (VARIANT var_rect; child->GetCurrentPropertyValue(UIA_BoundingRectanglePropertyId, &var_rect) >= 0) {
|
||||
if (var_rect.vt == (VT_R8 | VT_ARRAY)) {
|
||||
LONG pos;
|
||||
double value;
|
||||
pos = 0; SafeArrayGetElement(var_rect.parray, &pos, &value);
|
||||
button.x = (long)value;
|
||||
pos = 1; SafeArrayGetElement(var_rect.parray, &pos, &value);
|
||||
button.y = (long)value;
|
||||
pos = 2; SafeArrayGetElement(var_rect.parray, &pos, &value);
|
||||
button.width = (long)value;
|
||||
pos = 3; SafeArrayGetElement(var_rect.parray, &pos, &value);
|
||||
button.height = (long)value;
|
||||
}
|
||||
VariantClear(&var_rect);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (BSTR automation_id; child->get_CurrentAutomationId(&automation_id) >= 0) {
|
||||
button.name = automation_id;
|
||||
SysFreeString(automation_id);
|
||||
}
|
||||
found_butttons.push_back(button);
|
||||
}
|
||||
// assign keynums
|
||||
buttons.clear();
|
||||
for (auto& button : found_butttons) {
|
||||
if (buttons.empty()) {
|
||||
button.keynum = 1;
|
||||
buttons.push_back(std::move(button));
|
||||
} else {
|
||||
if (button.x < buttons.back().x || button.y < buttons.back().y) // skip 2nd row
|
||||
break;
|
||||
if (button.name == buttons.back().name)
|
||||
continue; // skip buttons from the same app
|
||||
button.keynum = buttons.back().keynum + 1;
|
||||
buttons.push_back(std::move(button));
|
||||
if (button.keynum == 10)
|
||||
break; // no more than 10 buttons
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<TasklistButton> Tasklist::get_buttons() {
|
||||
std::vector<TasklistButton> buttons;
|
||||
update_buttons(buttons);
|
||||
return buttons;
|
||||
}
|
||||
Reference in New Issue
Block a user