Files
PowerToys/src/modules/powerdisplay/PowerDisplayModuleInterface/PowerDisplayProcessManager.h
Yu Leng e90c4273f7 Refactor PowerDisplay IPC and add hotkey support
Refactored IPC initialization to handle window visibility based on
launch mode (standalone or IPC). Added `IsWindowVisible` P/Invoke
method and implemented IPC commands for window control, monitor
refresh, and settings updates.

Fixed bidirectional pipe creation and adjusted process startup
order in `PowerDisplayProcessManager`. Made `ShowWindow` and
`HideWindow` methods public and added `IsWindowVisible` to
`MainWindow.xaml.cs`.

Introduced activation hotkey parsing and configuration with a
default of `Win+Alt+M`. Exposed hotkey to PowerToys runner and
integrated it into the dashboard with localization and a launch
button. Renamed module DLL for consistency.
2025-11-12 13:18:36 +08:00

78 lines
2.0 KiB
C++

// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#pragma once
#include <functional>
#include <memory>
#include <atlfile.h>
#include <common/utils/OnThreadExecutor.h>
/// <summary>
/// Manages PowerDisplay.exe process lifecycle and bidirectional IPC communication
/// </summary>
class PowerDisplayProcessManager
{
private:
HANDLE m_hProcess = nullptr;
std::unique_ptr<CAtlFile> m_write_pipe; // Write to PowerDisplay (OUT pipe)
HANDLE m_read_pipe = nullptr; // Read from PowerDisplay (IN pipe) - for bidirectional support
OnThreadExecutor m_thread_executor;
bool m_enabled = false;
// Pipe names for this session
std::wstring m_pipe_name_out;
std::wstring m_pipe_name_in;
public:
PowerDisplayProcessManager() = default;
~PowerDisplayProcessManager();
/// <summary>
/// Start PowerDisplay.exe process
/// </summary>
void start();
/// <summary>
/// Stop PowerDisplay.exe process
/// </summary>
void stop();
/// <summary>
/// Send message to PowerDisplay.exe
/// </summary>
void send_message_to_powerdisplay(const std::wstring& message);
private:
/// <summary>
/// Submit task to thread executor
/// </summary>
void submit_task(std::function<void()> task);
/// <summary>
/// Check if PowerDisplay.exe is running
/// </summary>
bool is_process_running() const;
/// <summary>
/// Terminate PowerDisplay.exe process
/// </summary>
void terminate_process();
/// <summary>
/// Start PowerDisplay.exe with command line arguments
/// </summary>
HRESULT start_process(const std::wstring& pipe_uuid);
/// <summary>
/// Create named pipe for sending commands to PowerDisplay
/// </summary>
HRESULT start_command_pipe(const std::wstring& pipe_uuid);
/// <summary>
/// Refresh - start or stop process based on m_enabled state
/// </summary>
void refresh();
};