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:
Bartosz Sosnowski
2019-09-04 18:26:26 +02:00
committed by Bartosz Sosnowski
parent 10c5396099
commit 8431b80e48
341 changed files with 54766 additions and 62 deletions

View File

@@ -0,0 +1,54 @@
#include "pch.h"
#include "powertoys_events.h"
#include "lowlevel_keyboard_event.h"
#include "win_hook_event.h"
void first_subscribed(const std::wstring& event) {
if (event == ll_keyboard)
start_lowlevel_keyboard_hook();
else if (event == win_hook_event)
start_win_hook_event();
}
void last_unsubscribed(const std::wstring& event) {
if (event == ll_keyboard)
stop_lowlevel_keyboard_hook();
else if (event == win_hook_event)
stop_win_hook_event();
}
PowertoysEvents& powertoys_events() {
static PowertoysEvents powertoys_events;
return powertoys_events;
}
void PowertoysEvents::register_receiver(const std::wstring & event, PowertoyModuleIface* module) {
std::unique_lock lock(mutex);
auto& subscribers = receivers[event];
if (subscribers.empty()) {
first_subscribed(event);
}
subscribers.push_back(module);
}
void PowertoysEvents::unregister_receiver(PowertoyModuleIface* module) {
std::unique_lock lock(mutex);
for (auto&[event, subscribers] : receivers) {
subscribers.erase(remove(begin(subscribers), end(subscribers), module), end(subscribers));
if (subscribers.empty()) {
last_unsubscribed(event);
}
}
}
intptr_t PowertoysEvents::signal_event(const std::wstring & event, intptr_t data) {
intptr_t rvalue = 0;
std::shared_lock lock(mutex);
if (auto it = receivers.find(event); it != end(receivers)) {
for (auto& module : it->second) {
if (module)
rvalue |= module->signal_event(event.c_str(), data);
}
}
return rvalue;
}