Skip to content

Commit

Permalink
Turn "Switch Task" into a built-in action calling Shell APIs instead …
Browse files Browse the repository at this point in the history
…of simulating input
  • Loading branch information
elvissteinjr committed Feb 8, 2022
1 parent 2923897 commit d36831e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 29 deletions.
32 changes: 13 additions & 19 deletions assets/config_default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DetachedTransformHMD=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
DetachedTransformRightHand=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
DetachedTransformLeftHand=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
DetachedTransformAux=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
ActionBarOrderCustom=1 1;2 0;1000 1;1001 0;1002 0;1003 1;
ActionBarOrderCustom=1 1;2 0;6 1;1000 0;1001 0;1002 1;

[Interface]
;Don't want DesktopPlusUI.exe to run automatically? Set this to true
Expand All @@ -72,7 +72,7 @@ WarningCompositorQualityHidden=false
WarningProcessElevationHidden=false
WarningElevatedModeHidden=false
WarningWelcomeHidden=false
ActionOrder=1 1;2 0;1000 1;1001 0;1002 0;1003 1;
ActionOrder=1 1;2 0;6 1;1000 0;1001 0;1002 1;

[Input]
GoHomeButtonActionID=1002
Expand Down Expand Up @@ -129,28 +129,22 @@ PerformanceMonitorShowViveWireless=false
PerformanceMonitorDisableGPUCounters=false

[CustomActions]
Count=4
Action0Name=Switch Task
Count=3
Action0Name=Middle Mouse Button
Action0FunctionType=PressKeys
Action0KeyCode1=91
Action0KeyCode2=9
Action0KeyCode1=4
Action0KeyCode2=0
Action0KeyCode3=0
Action0IconFilename=images/icons/task_switch.png
Action1Name=Middle Mouse Button
Action0IconFilename=
Action1Name=Back Mouse Button
Action1FunctionType=PressKeys
Action1KeyCode1=4
Action1KeyCode1=5
Action1KeyCode2=0
Action1KeyCode3=0
Action1IconFilename=
Action2Name=Back Mouse Button
Action2FunctionType=PressKeys
Action2KeyCode1=5
Action2KeyCode2=0
Action2KeyCode3=0
Action2Name=  Open ReadMe
Action2FunctionType=LaunchApplication
Action2ExecutablePath=readme.txt
Action2ExecutableArg=
Action2IconFilename=
Action3Name=  Open ReadMe
Action3FunctionType=LaunchApplication
Action3ExecutablePath=readme.txt
Action3ExecutableArg=
Action3IconFilename=

42 changes: 33 additions & 9 deletions src/DesktopPlus/OutputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <dwmapi.h>
#include <windowsx.h>
#include <ShlDisp.h>
using namespace DirectX;
#include <sstream>

Expand Down Expand Up @@ -2157,6 +2158,11 @@ void OutputManager::DoAction(ActionID action_id)
ToggleOverlayGroupEnabled(1 + ((int)action_id - action_toggle_overlay_enabled_group_1) );
break;
}
case action_switch_task:
{
ShowWindowSwitcher();
break;
}
default: break;
}
}
Expand Down Expand Up @@ -4066,6 +4072,17 @@ bool OutputManager::HandleOverlayProfileLoadMessage(LPARAM lparam)
return false;
}

void OutputManager::InitComIfNeeded()
{
if (!m_ComInitDone)
{
if (::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) != RPC_E_CHANGED_MODE)
{
m_ComInitDone = true;
}
}
}

void OutputManager::LaunchApplication(const std::string& path_utf8, const std::string& arg_utf8)
{
if (ConfigManager::Get().GetConfigBool(configid_bool_state_misc_elevated_mode_active))
Expand All @@ -4081,24 +4098,31 @@ void OutputManager::LaunchApplication(const std::string& path_utf8, const std::s
return;
}

if (!m_ComInitDone) //Let's only do this if really needed
{
if (::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) != RPC_E_CHANGED_MODE)
{
m_ComInitDone = true;
}
}

//Convert path and arg to utf16
std::wstring path_wstr = WStringConvertFromUTF8(path_utf8.c_str());
std::wstring arg_wstr = WStringConvertFromUTF8(arg_utf8.c_str());

if (!path_wstr.empty())
{
{
InitComIfNeeded();

::ShellExecute(nullptr, nullptr, path_wstr.c_str(), arg_wstr.c_str(), nullptr, SW_SHOWNORMAL);
}
}

void OutputManager::ShowWindowSwitcher()
{
InitComIfNeeded();

Microsoft::WRL::ComPtr<IShellDispatch5> shell_dispatch;
HRESULT sc = ::CoCreateInstance(CLSID_Shell, nullptr, CLSCTX_SERVER, IID_IDispatch, &shell_dispatch);

if (SUCCEEDED(sc))
{
shell_dispatch->WindowSwitcher();
}
}

void OutputManager::ResetMouseLastLaserPointerPos()
{
//Set last pointer values to current to not trip the movement detection up
Expand Down
2 changes: 2 additions & 0 deletions src/DesktopPlus/OutputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class OutputManager
void HandleKeyboardHelperMessage(LPARAM lparam);
bool HandleOverlayProfileLoadMessage(LPARAM lparam);

void InitComIfNeeded();
void LaunchApplication(const std::string& path_utf8, const std::string& arg_utf8);
void ShowWindowSwitcher();
void ResetMouseLastLaserPointerPos();
void CropToActiveWindow();
void CropToDisplay(int display_id, bool do_not_apply_setting = false);
Expand Down
1 change: 1 addition & 0 deletions src/DesktopPlusUI/TextureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const wchar_t* TextureManager::s_TextureFilenames[] =
L"images/icons/desktop_previous.png",
L"images/icons/settings.png",
L"images/icons/keyboard.png",
L"images/icons/task_switch.png",
L"images/icons/small_close.png",
L"images/icons/small_move.png",
L"images/icons/small_actionbar.png",
Expand Down
1 change: 1 addition & 0 deletions src/DesktopPlusUI/TextureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum TMNGRTexID
tmtex_icon_desktop_prev,
tmtex_icon_settings,
tmtex_icon_keyboard,
tmtex_icon_switch_task,
tmtex_icon_small_close,
tmtex_icon_small_move,
tmtex_icon_small_actionbar,
Expand Down
3 changes: 2 additions & 1 deletion src/DesktopPlusUI/WindowMainBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ void WindowMainBar::UpdateActionButtons(unsigned int overlay_id)
//Button action is always the same but we want to use icons if available
switch (order_data.action_id)
{
case action_show_keyboard: TextureManager::Get().GetTextureInfo(tmtex_icon_keyboard, b_size, b_uv_min, b_uv_max); break;
case action_show_keyboard: TextureManager::Get().GetTextureInfo(tmtex_icon_keyboard, b_size, b_uv_min, b_uv_max); break;
case action_switch_task: TextureManager::Get().GetTextureInfo(tmtex_icon_switch_task, b_size, b_uv_min, b_uv_max); break;
default: has_icon = false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Shared/Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const char* g_ActionNames[] =
"Toggle Overlay Group 1 Enabled State",
"Toggle Overlay Group 2 Enabled State",
"Toggle Overlay Group 3 Enabled State",
"Switch Task",
//Custom
};

Expand All @@ -24,6 +25,7 @@ const char* g_ActionButtonLabel[] =
"Toggle Overlay Group 1",
"Toggle Overlay Group 2",
"Toggle Overlay Group 3 ",
"",
//Custom
};

Expand Down
1 change: 1 addition & 0 deletions src/Shared/Actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum ActionID: int
action_toggle_overlay_enabled_group_1,
action_toggle_overlay_enabled_group_2,
action_toggle_overlay_enabled_group_3,
action_switch_task,
action_built_in_MAX,
//Leaving some room here, as we don't want to mess with user order later
action_custom = 1000 //+ Custom Action ID
Expand Down

0 comments on commit d36831e

Please sign in to comment.