Skip to content

Fix/hotkey uiaccess #460

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

Merged
merged 2 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions IntelPresentMon/AppCef/CefNano.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<ClCompile Include="source\util\cact\CefActionRegistration.cpp" />
<ClCompile Include="source\util\CefValues.cpp" />
<ClCompile Include="source\util\FontEnumerator.cpp" />
<ClCompile Include="source\util\HotkeyListener.cpp" />
<ClCompile Include="source\util\IpcInvocationManager.cpp" />
<ClCompile Include="source\util\KernelActionRegistration.cpp" />
<ClCompile Include="source\util\LogSetup.cpp" />
Expand All @@ -44,6 +43,7 @@
<ClInclude Include="source\SchemeFileHandler.h" />
<ClInclude Include="source\SchemeHandlerFactory.h" />
<ClInclude Include="source\util\ActionClientServer.h" />
<ClInclude Include="source\util\cact\HotkeyFiredAction.h" />
<ClInclude Include="source\util\cact\OverlayDiedAction.h" />
<ClInclude Include="source\util\cact\PresentmonInitFailedAction.h" />
<ClInclude Include="source\util\cact\StalePidAction.h" />
Expand All @@ -60,8 +60,6 @@
<ClInclude Include="source\util\async\StoreFile.h" />
<ClInclude Include="source\util\async\BrowseReadSpec.h" />
<ClInclude Include="source\util\async\BrowseStoreSpec.h" />
<ClInclude Include="source\util\async\BindHotkey.h" />
<ClInclude Include="source\util\async\ClearHotkey.h" />
<ClInclude Include="source\util\async\EnumerateKeys.h" />
<ClInclude Include="source\util\async\EnumerateModifiers.h" />
<ClInclude Include="source\util\async\EnumerateProcesses.h" />
Expand All @@ -75,7 +73,6 @@
<ClInclude Include="source\util\PathSanitaryCheck.h" />
<ClInclude Include="source\util\SignalManager.h" />
<ClInclude Include="source\util\FontEnumerator.h" />
<ClInclude Include="source\util\HotkeyListener.h" />
<ClInclude Include="source\util\ThreadCompass.h" />
<ClInclude Include="source\util\V8Transfer.h" />
</ItemGroup>
Expand Down
7 changes: 2 additions & 5 deletions IntelPresentMon/AppCef/ipm-ui-vue/src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ export class Api {
return adapters;
}
static async bindHotkey(binding: Binding): Promise<void> {
await this.invokeEndpointFuture('bindHotkey', binding);
await this.invokeEndpointFuture('BindHotkey', binding);
}
static async clearHotkey(action: Action): Promise<void> {
await this.invokeEndpointFuture('clearHotkey', {action});
}
static async launchKernel(): Promise<void> {
await this.invokeEndpointFuture('launchKernel', {});
await this.invokeEndpointFuture('ClearHotkey', {action});
}
static async pushSpecification(spec: Spec): Promise<void> {
await this.invokeEndpointFuture('PushSpecification', spec);
Expand Down
47 changes: 1 addition & 46 deletions IntelPresentMon/AppCef/source/DataBindAccessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ namespace p2c::client::cef
:
pBrowser{ std::move(pBrowser) },
pKernelWrapper{ pKernelWrapper_ }
{
pKernelWrapper->pHotkeys = std::make_unique<util::Hotkeys>();
// set the hotkey listener component to call hotkey signal on the signal manager when a hotkey chord is detected
pKernelWrapper->pHotkeys->SetHandler([this](Action action) {
CefPostTask(TID_RENDERER, base::BindOnce(&util::SignalManager::SignalHotkeyFired,
base::Unretained(&pKernelWrapper->signals), uint32_t(action)));
});
}
{}

bool DataBindAccessor::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
Expand Down Expand Up @@ -88,44 +81,6 @@ namespace p2c::client::cef
}
}

bool DataBindAccessor::BindHotkey(CefValue& pArgObj)
{
// {action:int, combination: {modifiers:[], key:int}}

std::shared_lock lk{ kernelMtx };
if (pKernelWrapper) {
const auto payload = pArgObj.GetDictionary();
const auto comboJs = payload->GetDictionary("combination");
const auto modsJs = comboJs->GetList("modifiers");

auto mods = win::Mod::Null;
for (int i = 0; i < modsJs->GetSize(); i++) {
const auto modCode = modsJs->GetValue(i)->GetInt();
mods = mods | *win::ModSet::SingleModFromCode(modCode);
}

return pKernelWrapper->pHotkeys->BindAction(
(Action)payload->GetInt("action"),
win::Key{ (win::Key::Code)comboJs->GetInt("key") },
mods
);
}
return false;
}

bool DataBindAccessor::ClearHotkey(CefValue& pArgObj)
{
// {action:int}

std::shared_lock lk{ kernelMtx };
if (pKernelWrapper) {
return pKernelWrapper->pHotkeys->ClearAction(
(Action)pArgObj.GetDictionary()->GetInt("action")
);
}
return false;
}

void DataBindAccessor::ClearKernelWrapper()
{
std::lock_guard lk{ kernelMtx };
Expand Down
2 changes: 0 additions & 2 deletions IntelPresentMon/AppCef/source/DataBindAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace p2c::client::cef
CefRefPtr<CefV8Value>& retval,
CefString& exception) override;
void ResolveAsyncEndpoint(uint64_t uid, bool success, CefRefPtr<CefValue> pArgs);
bool BindHotkey(CefValue& pArgObj);
bool ClearHotkey(CefValue& pArgObj);
void ClearKernelWrapper();
private:
// data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include "async/BrowseReadSpec.h"
#include "async/BrowseStoreSpec.h"
#include "async/BindHotkey.h"
#include "async/ClearHotkey.h"
#include "async/EnumerateProcesses.h"
#include "async/EnumerateKeys.h"
#include "async/EnumerateModifiers.h"
Expand All @@ -34,8 +32,6 @@ namespace p2c::client::util
using namespace async;
AddEndpoint<BrowseReadSpec>();
AddEndpoint<BrowseStoreSpec>();
AddEndpoint<BindHotkey>();
AddEndpoint<ClearHotkey>();
AddEndpoint<EnumerateProcesses>();
AddEndpoint<EnumerateKeys>();
AddEndpoint<EnumerateModifiers>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ namespace p2c::client::util::kact {
IpcActionRegistrator<kproc::kact::PushSpecification> reg_ibind_PushSpecification_;
IpcActionRegistrator<kproc::kact::SetAdapter> reg_ibind_SetAdapter_;
IpcActionRegistrator<kproc::kact::SetCapture> reg_ibind_SetCapture_;
IpcActionRegistrator<kproc::kact::BindHotkey> reg_ibind_BindHotkey_;
IpcActionRegistrator<kproc::kact::ClearHotkey> reg_ibind_ClearHotkey_;
}

2 changes: 0 additions & 2 deletions IntelPresentMon/AppCef/source/util/KernelWrapper.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include <memory>
#include "HotkeyListener.h"
#include "SignalManager.h"
#include "AsyncEndpointManager.h"
#include "ActionClientServer.h"
Expand All @@ -11,7 +10,6 @@ namespace p2c::client::util
{
struct KernelWrapper
{
std::unique_ptr<Hotkeys> pHotkeys;
util::SignalManager signals;
util::AsyncEndpointManager asyncEndpoints;
std::unique_ptr<CefClient> pClient;
Expand Down
24 changes: 0 additions & 24 deletions IntelPresentMon/AppCef/source/util/async/BindHotkey.h

This file was deleted.

24 changes: 0 additions & 24 deletions IntelPresentMon/AppCef/source/util/async/ClearHotkey.h

This file was deleted.

2 changes: 2 additions & 0 deletions IntelPresentMon/AppCef/source/util/async/EnumerateKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#pragma once
#include "../AsyncEndpoint.h"
#include "../CefValues.h"
#include <Core/source/win/Key.h>
#include <Core/source/win/ModSet.h>

namespace p2c::client::util::async
{
Expand Down
4 changes: 4 additions & 0 deletions IntelPresentMon/AppCef/source/util/async/EnumerateProcesses.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <Core/source/win/ProcessMapBuilder.h>
#include <Core/source/kernel/Kernel.h>
#include <CommonUtilities/win/Handle.h>
#include "../AsyncEndpoint.h"
#include "../CefValues.h"
#include <ranges>

namespace p2c::client::util::async
{
Expand All @@ -15,6 +18,7 @@ namespace p2c::client::util::async
// {} => {processes: [{name: string, pid: uint}]}
Result ExecuteOnRenderer(uint64_t uid, CefRefPtr<CefValue> pArgObj, cef::DataBindAccessor&) const override
{
namespace vi = std::views;
// enumerate processes on system
win::ProcessMapBuilder builder;
builder.FillWindowHandles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
#include "OverlayDiedAction.h"
#include "PresentmonInitFailedAction.h"
#include "StalePidAction.h"
#include "TargetLostAction.h"
#include "TargetLostAction.h"
#include "HotkeyFiredAction.h"
59 changes: 59 additions & 0 deletions IntelPresentMon/AppCef/source/util/cact/HotkeyFiredAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once
#include <Interprocess/source/act/ActionHelper.h>
#include "CefExecutionContext.h"
#include "../../Action.h"
#include <format>

#define ACT_NAME HotkeyFiredAction
#define ACT_EXEC_CTX CefExecutionContext
#define ACT_TYPE AsyncEventActionBase_
#define ACT_NS ::p2c::client::util::cact

namespace p2c::client::util::cact
{
using namespace ::pmon::ipc::act;

class ACT_NAME : public ACT_TYPE<ACT_NAME, ACT_EXEC_CTX>
{
public:
static constexpr const char* Identifier = STRINGIFY(ACT_NAME);
struct Params
{
int32_t actionId;

template<class A> void serialize(A& ar) {
ar(actionId);
}
};
private:
friend class ACT_TYPE<ACT_NAME, ACT_EXEC_CTX>;
static void Execute_(const ACT_EXEC_CTX& ctx, SessionContext& stx, Params&& in);
};
}

#ifdef PM_ASYNC_ACTION_REGISTRATION_
#include <include/cef_task.h>
#include <include/base/cef_callback.h>
#include <include/wrapper/cef_closure_task.h>
#include "../SignalManager.h"
namespace p2c::client::util::cact
{
ACTION_REG();
// need to put this function definition only in the cef-server-side since it contains
// references to CEF types we do not want to pollute other projects with
// TODO: consider a better approach to maintaining single-file actions like this
// while also enabling dependency decoupling more easily
void ACT_NAME::Execute_(const ACT_EXEC_CTX& ctx, SessionContext& stx, Params&& in)
{
CefPostTask(TID_RENDERER, base::BindOnce(&SignalManager::SignalHotkeyFired,
base::Unretained(ctx.pSignalManager), in.actionId));
}
}
#endif

ACTION_TRAITS_DEF();

#undef ACT_NAME
#undef ACT_EXEC_CTX
#undef ACT_NS
#undef ACT_TYPE
2 changes: 2 additions & 0 deletions IntelPresentMon/Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<ClInclude Include="source\win\EventHookHandler.h" />
<ClInclude Include="source\win\EventHookManager.h" />
<ClInclude Include="source\win\GpuUtilization.h" />
<ClInclude Include="source\win\HotkeyListener.h" />
<ClInclude Include="source\win\KernelWindow.h" />
<ClInclude Include="source\win\Key.h" />
<ClInclude Include="source\win\MessageBox.h" />
Expand Down Expand Up @@ -147,6 +148,7 @@
<ClCompile Include="source\win\com\ComManager.cpp" />
<ClCompile Include="source\win\EventHookManager.cpp" />
<ClCompile Include="source\win\GpuUtilization.cpp" />
<ClCompile Include="source\win\HotkeyListener.cpp" />
<ClCompile Include="source\win\Key.cpp" />
<ClCompile Include="source\win\MessageBox.cpp" />
<ClCompile Include="source\win\MessageMap.cpp" />
Expand Down
2 changes: 2 additions & 0 deletions IntelPresentMon/Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<ClInclude Include="source\gfx\Exception.h" />
<ClInclude Include="source\infra\LogSetup.h" />
<ClInclude Include="source\infra\Logging.h" />
<ClInclude Include="source\win\HotkeyListener.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\win\MessageMap.cpp" />
Expand Down Expand Up @@ -150,6 +151,7 @@
<ClCompile Include="source\pmon\DynamicQuery.cpp" />
<ClCompile Include="source\pmon\metric\DynamicPollingFetcher.cpp" />
<ClCompile Include="source\infra\LogSetup.cpp" />
<ClCompile Include="source\win\HotkeyListener.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
Expand Down
1 change: 1 addition & 0 deletions IntelPresentMon/Core/source/infra/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ namespace p2c::v
#else
inline constexpr bool metric = true;
#endif
inline constexpr bool hotkey2 = false;
}
Loading