Skip to content

Commit

Permalink
PowerToys interface: remove powertoys events and system_menu_helper f…
Browse files Browse the repository at this point in the history
…unctionality (#5323)
  • Loading branch information
yuyoyuppe committed Jul 31, 2020
1 parent cff654a commit 49b56d9
Show file tree
Hide file tree
Showing 42 changed files with 116 additions and 1,163 deletions.
106 changes: 0 additions & 106 deletions doc/devdocs/modules/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public:
virtual void enable() = 0;
virtual void disable() = 0;
virtual bool is_enabled() = 0;
virtual intptr_t signal_event(const wchar_t* name, intptr_t data) = 0;
virtual void register_system_menu_helper(PowertoySystemMenuIface* helper) = 0;
virtual void signal_system_menu_action(const wchar_t* name) = 0;
virtual void destroy() = 0;
};

Expand All @@ -28,7 +25,6 @@ The PowerToys runner will, for each PowerToy DLL:
On the received object, the runner will call:
- [`get_name()`](#get_name) to get the name of the PowerToy,
- [`get_events()`](#get_events) to get the list of the events the PowerToy wants to subscribe to,
- [`enable()`](#enable) to initialize the PowerToy.
While running, the runner might call the following methods between create_powertoy()
Expand All @@ -37,9 +33,6 @@ and destroy():
- [`get_config()`](#get_config) to get the available configuration settings,
- [`set_config()`](#set_config) to set settings after they have been edited in the Settings editor,
- [`call_custom_action()`](#call_custom_action) when the user selects a custom action in the Settings editor,
- [`signal_event()`](#signal_event) to send an event the PowerToy registered to.
- [`register_system_menu_helper()`](#register_system_menu_helper) to pass object, responsible for handling customized system menus, to module.
- [`signal_system_menu_action()`](#signal_system_menu_action) to send an event when action is taken on system menu item.
When terminating, the runner will:
- call [`disable()`](#disable),
Expand Down Expand Up @@ -75,18 +68,6 @@ virtual const wchar_t* get_name()

Returns the name of the PowerToy, it will be cached by the runner.

## get_events

```cpp
virtual const wchar_t** get_events()
```

Returns a null-terminated table of the names of the events the PowerToy wants to subscribe to. Available events:
* ll_keyboard
* win_hook_event

A nullptr can be returned to signal that the PowerToy does not want to subscribe to any event.

## get_config

```
Expand Down Expand Up @@ -140,101 +121,14 @@ Disables the PowerToy, should free as much memory as possible.

Returns the PowerToy state.

## signal_event

```cpp
virtual intptr_t signal_event(const wchar_t* name, intptr_t data) = 0;
```
Handle event. Only the events the PowerToy subscribed to will be signaled.
The data argument and return value meaning are event-specific:
* ll_keyboard: see [`lowlevel_keyboard_event_data.h`](./lowlevel_keyboard_event_data.h).
* win_hook_event: see [`win_hook_event_data.h`](./win_hook_event_data.h)
Please note that some of the events are currently being signalled from a separate thread.
## register_system_menu_helper
```cpp
virtual void register_system_menu_helper(PowertoySystemMenuIface* helper) = 0;
```

Register helper class to handle all system menu items related actions. Creation, deletion
and all other actions taken on system menu item will be handled by provided class.
Module will be informed when action is taken on any item created on request of the module.

## signal_system_menu_action

```cpp
virtual void signal_system_menu_action(const wchar_t* name) = 0;
```
Runner invokes this API when action is taken on item created on request from the module.
Item name is passed as an argument, so that module can distinguish between different menu items.
## destroy

```cpp
virtual void destroy()
```
Destroy the PowerToy and free all memory.

## Powertoys system menu helper interface

Interface for helper class responsible for handling all system menu related actions.
```cpp
class PowertoySystemMenuIface {
public:
struct ItemInfo {
std::wstring name{};
bool enable{ false };
bool checkBox{ false };
};
virtual void SetConfiguration(PowertoyModuleIface* module, const std::vector<ItemInfo>& config) = 0;
virtual void ProcessSelectedItem(PowertoyModuleIface* module, HWND window, const wchar_t* itemName) = 0;
};
```
## ItemInfo
```cpp
struct ItemInfo {
std::wstring name{};
bool enable{ false };
bool checkBox{ false };
};
```

Structure containing all relevant information for system menu item: name (and hotkey if available), item
status at creation (enabled/disabled) and whether check box will appear next to item name when action is taken.

## SetConfiguration

```cpp
virtual void SetConfiguration(PowertoyModuleIface* module, const std::vector<ItemInfo>& config) = 0;
```
Module should use this interface to inform system menu helper class which custom system menu items to create.
## ProcessSelectedItem
```cpp
virtual void ProcessSelectedItem(PowertoyModuleIface* module, HWND window, const wchar_t* itemName) = 0;
```

Process action taken on specific system menu item.

# Code organization

### [`powertoy_module_interface.h`](/src/modules/interface/powertoy_module_interface.h)
Contains the PowerToys interface definition.

### [`powertoy_system_menu.h`](/src/modules/interface/powertoy_system_module.h)
Contains the PowerToys system menu helper interface definition.

### [`lowlevel_keyboard_event_data.h`](/src/modules/interface/lowlevel_keyboard_event_data.h)
Contains the `LowlevelKeyboardEvent` structure that's passed to `signal_event` for `ll_keyboard` events.

### [`win_hook_event_data.h`](/src/modules/interface/win_hook_event_data.h)
Contains the `WinHookEvent` structure that's passed to `signal_event` for `win_hook_event` events.

85 changes: 0 additions & 85 deletions doc/devdocs/shared-hooks.md

This file was deleted.

9 changes: 9 additions & 0 deletions src/common/LowlevelKeyboardEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

struct LowlevelKeyboardEvent
{
KBDLLHOOKSTRUCT* lParam;
WPARAM wParam;
};
14 changes: 14 additions & 0 deletions src/common/WinHookEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

struct WinHookEvent
{
DWORD event;
HWND hwnd;
LONG idObject;
LONG idChild;
DWORD idEventThread;
DWORD dwmsEventTime;
};
2 changes: 2 additions & 0 deletions src/common/common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<ClInclude Include="com_object_factory.h" />
<ClInclude Include="keyboard_layout.h" />
<ClInclude Include="keyboard_layout_impl.h" />
<ClInclude Include="LowlevelKeyboardEvent.h" />
<ClInclude Include="notifications.h" />
<ClInclude Include="processApi.h" />
<ClInclude Include="RcResource.h" />
Expand All @@ -153,6 +154,7 @@
<ClInclude Include="two_way_pipe_message_ipc_impl.h" />
<ClInclude Include="version.h" />
<ClInclude Include="windows_colors.h" />
<ClInclude Include="WinHookEvent.h" />
<ClInclude Include="winstore.h" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/common/common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
<ClInclude Include="processApi.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LowlevelKeyboardEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="WinHookEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="d2d_svg.cpp">
Expand Down
1 change: 0 additions & 1 deletion src/common/keyboard_layout_impl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "keyboard_layout.h"
#include "..\modules\interface\lowlevel_keyboard_event_data.h"
#include <string>
#include <map>
#include <mutex>
Expand Down

0 comments on commit 49b56d9

Please sign in to comment.