|
1 | 1 | #include <linux/input-event-codes.h>
|
2 | 2 |
|
3 | 3 | #include "shortcut.h"
|
| 4 | +#include "convar.h" |
4 | 5 | #include "steamcompmgr_shared.hpp"
|
5 | 6 | #include "main.hpp"
|
6 | 7 |
|
@@ -87,4 +88,99 @@ namespace gamescope
|
87 | 88 |
|
88 | 89 | return true;
|
89 | 90 | }
|
| 91 | + |
| 92 | + static const char* ShortcutNames[GAMESCOPE_SHORTCUT_COUNT] = { |
| 93 | + "", |
| 94 | + "fullscreen", |
| 95 | + "filter_nearest", |
| 96 | + "filter_linear", |
| 97 | + "upscale_fsr", |
| 98 | + "upscale_nis", |
| 99 | + "upscale_sharpness_up", |
| 100 | + "upscale_sharpness_down", |
| 101 | + "screenshot", |
| 102 | + "keyboard_grab", |
| 103 | + }; |
| 104 | + |
| 105 | + static GamescopeShortcut ParseShortcut( std::string_view sv ) |
| 106 | + { |
| 107 | + if ( sv.length() > 0 ) |
| 108 | + { |
| 109 | + for ( auto i = 0; i < GAMESCOPE_SHORTCUT_COUNT; i++ ) |
| 110 | + { |
| 111 | + if ( sv == ShortcutNames[i] ) |
| 112 | + { |
| 113 | + return static_cast<GamescopeShortcut>( i ); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + return GAMESCOPE_SHORTCUT_NONE; |
| 119 | + } |
| 120 | + |
| 121 | + static ConCommand cc_bind( "bind", |
| 122 | + "Bind a shortcut to SUPER-<key> combination. e.g. 'bind 33,fullscreen'", |
| 123 | + [](std::span<std::string_view> svArgs ) |
| 124 | + { |
| 125 | + if ( svArgs.size() < 2 ) |
| 126 | + { |
| 127 | + console_log.errorf( "Invalid number of arguments." ); |
| 128 | + return; |
| 129 | + } |
| 130 | + |
| 131 | + // Space delimited args would be nice but requires |
| 132 | + // changes to gamescopectl / gamescope_private_execute. |
| 133 | + auto svBinds = gamescope::Split( svArgs[1], "," ); |
| 134 | + if ( svBinds.size() < 2 ) |
| 135 | + { |
| 136 | + console_log.errorf( "Invalid number of arguments." ); |
| 137 | + return; |
| 138 | + } |
| 139 | + |
| 140 | + // TODO: key names |
| 141 | + std::optional<uint32_t> ouKey = Parse<uint32_t>( svBinds[0] ); |
| 142 | + if ( !ouKey ) |
| 143 | + { |
| 144 | + console_log.errorf( "Failed to parse key." ); |
| 145 | + return; |
| 146 | + } |
| 147 | + |
| 148 | + uint32_t uKey = *ouKey; |
| 149 | + auto shortcut = ParseShortcut( svBinds[1] ); |
| 150 | + |
| 151 | + if ( shortcut != GAMESCOPE_SHORTCUT_NONE ) |
| 152 | + { |
| 153 | + g_shortcutHandler.Bind( uKey, shortcut ); |
| 154 | + } |
| 155 | + }); |
| 156 | + |
| 157 | + static ConCommand cc_unbind( "unbind", "Unbind a shortcut from SUPER-<key> combination.", |
| 158 | + [](std::span<std::string_view> svArgs ) |
| 159 | + { |
| 160 | + if ( svArgs.size() < 2 ) |
| 161 | + { |
| 162 | + console_log.errorf( "Invalid number of arguments." ); |
| 163 | + return; |
| 164 | + } |
| 165 | + |
| 166 | + // TODO: key names |
| 167 | + std::optional<uint32_t> ouKey = Parse<uint32_t>( svArgs[1] ); |
| 168 | + if ( !ouKey ) |
| 169 | + { |
| 170 | + console_log.errorf( "Failed to parse key." ); |
| 171 | + return; |
| 172 | + } |
| 173 | + |
| 174 | + g_shortcutHandler.Unbind( *ouKey ); |
| 175 | + }); |
| 176 | + |
| 177 | + static ConCommand cc_shortcuts( "shortcuts", "List shortcut names for use with 'bind'", |
| 178 | + [](std::span<std::string_view> svArgs ) |
| 179 | + { |
| 180 | + console_log.infof( "Shortcut names:" ); |
| 181 | + for ( auto i = 0; i < GAMESCOPE_SHORTCUT_COUNT; i++ ) |
| 182 | + { |
| 183 | + console_log.infof( " %s", ShortcutNames[i] ); |
| 184 | + } |
| 185 | + }); |
90 | 186 | }
|
0 commit comments