1+ #if HAVE_SCRIPTING
2+
13#include < linux/input-event-codes.h>
24
35#include < span>
46
57#include " hotkey.h"
6- #include " convar.h"
78
89// TODO: Consolidate
910#define WAYLAND_NULL () []<typename ... Args> ( void *pData, Args... args ) { }
@@ -16,20 +17,15 @@ namespace gamescope
1617 class CHotkeyBinding
1718 {
1819 public:
19- bool Init ( gamescope_action_binding_manager *pManager, std::span<uint32_t > pKeySyms, std::vector<std::string> args )
20+ bool Init ( gamescope_action_binding_manager *pManager, std::span<uint32_t > pKeySyms, sol::function func )
2021 {
2122 Shutdown ();
2223
2324 m_pBinding = gamescope_action_binding_manager_create_action_binding ( pManager );
2425 if ( !m_pBinding )
2526 return false ;
2627
27- m_args = args;
28- for ( std::string_view sv : args )
29- {
30- m_sDescription += sv;
31- m_sDescription += " " ;
32- }
28+ m_func = func;
3329
3430 wl_array array;
3531 wl_array_init (&array);
@@ -41,7 +37,7 @@ namespace gamescope
4137
4238 gamescope_action_binding_add_listener ( m_pBinding, &s_BindingListener, (void *)this );
4339 gamescope_action_binding_add_keyboard_trigger ( m_pBinding, &array );
44- gamescope_action_binding_set_description ( m_pBinding, m_sDescription. c_str () );
40+ gamescope_action_binding_set_description ( m_pBinding, " TODO: for debugging " );
4541 gamescope_action_binding_arm ( m_pBinding, 0 );
4642
4743 return true ;
@@ -58,23 +54,12 @@ namespace gamescope
5854
5955 void Wayland_Triggered ( gamescope_action_binding *pBinding, uint32_t uSequence, uint32_t uTriggerFlags, uint32_t uTimeLo, uint32_t uTimeHi )
6056 {
61- // eugh
62- std::vector<std::string_view> vec;
63- for ( std::string_view sv : m_args )
64- {
65- vec.push_back ( sv );
66- }
67-
68- if ( !gamescope::ConCommand::Exec ( std::span<std::string_view>{ vec } ) )
69- {
70- fprintf ( stderr, " Failed to exec: %s\n " , m_sDescription.c_str () );
71- }
57+ m_func ();
7258 }
7359
7460 private:
7561 gamescope_action_binding *m_pBinding = nullptr ;
76- std::vector<std::string> m_args;
77- std::string m_sDescription;
62+ sol::function m_func;
7863
7964 static const gamescope_action_binding_listener s_BindingListener;
8065 };
@@ -119,10 +104,10 @@ namespace gamescope
119104 return true ;
120105 }
121106
122- bool HotkeyHandler::Bind ( std::vector<uint32_t > pKeySyms, std::vector<std::string> args )
107+ bool HotkeyHandler::Bind ( std::vector<uint32_t > pKeySyms, sol::function func )
123108 {
124109 std::shared_ptr<CHotkeyBinding> binding = std::make_shared<CHotkeyBinding>();
125- auto success = binding->Init ( m_pActionBindingManager, pKeySyms, args );
110+ auto success = binding->Init ( m_pActionBindingManager, pKeySyms, func );
126111 if ( success )
127112 {
128113 m_bindings.push_back (binding);
@@ -145,3 +130,5 @@ namespace gamescope
145130 .global_remove = WAYLAND_NULL (),
146131 };
147132}
133+
134+ #endif // HAVE_SCRIPTING
0 commit comments