mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 13:35:31 +02:00
Customize system menu items through dedicated API (#677)
Document new interface changes.
This commit is contained in:
committed by
Enrico Giordani
parent
9f78af29bf
commit
be86cd4028
@@ -2,6 +2,7 @@
|
||||
#include "powertoys_events.h"
|
||||
#include "lowlevel_keyboard_event.h"
|
||||
#include "win_hook_event.h"
|
||||
#include "system_menu_helper.h"
|
||||
|
||||
void first_subscribed(const std::wstring& event) {
|
||||
if (event == ll_keyboard)
|
||||
@@ -41,6 +42,37 @@ void PowertoysEvents::unregister_receiver(PowertoyModuleIface* module) {
|
||||
}
|
||||
}
|
||||
|
||||
void PowertoysEvents::register_system_menu_action(PowertoyModuleIface* module) {
|
||||
std::unique_lock lock(mutex);
|
||||
system_menu_receivers.insert(module);
|
||||
}
|
||||
|
||||
void PowertoysEvents::unregister_system_menu_action(PowertoyModuleIface* module) {
|
||||
std::unique_lock lock(mutex);
|
||||
auto it = system_menu_receivers.find(module);
|
||||
if (it != system_menu_receivers.end()) {
|
||||
SystemMenuHelperInstace().Reset(module);
|
||||
system_menu_receivers.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void PowertoysEvents::handle_system_menu_action(const WinHookEvent& data) {
|
||||
if (data.event == EVENT_SYSTEM_MENUSTART) {
|
||||
for (auto& module : system_menu_receivers) {
|
||||
SystemMenuHelperInstace().Customize(module, data.hwnd);
|
||||
}
|
||||
}
|
||||
else if (data.event == EVENT_OBJECT_INVOKED) {
|
||||
if (PowertoyModuleIface* module{ SystemMenuHelperInstace().ModuleFromItemId(data.idChild) }) {
|
||||
std::wstring itemName = SystemMenuHelperInstace().ItemNameFromItemId(data.idChild);
|
||||
// Process event on specified system menu item by responsible module.
|
||||
module->signal_system_menu_action(itemName.c_str());
|
||||
// Process event on specified system menu item by system menu helper (check/uncheck if needed).
|
||||
SystemMenuHelperInstace().ProcessSelectedItem(module, GetForegroundWindow(), itemName.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
intptr_t PowertoysEvents::signal_event(const std::wstring & event, intptr_t data) {
|
||||
intptr_t rvalue = 0;
|
||||
std::shared_lock lock(mutex);
|
||||
|
||||
Reference in New Issue
Block a user