Add multi hotkey

pull/197/head
Valters 4 years ago committed by jackun
parent 3a73d8cb30
commit 1afea91dab
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

5
.gitignore vendored

@ -40,3 +40,8 @@ lib32-mangohud*.tar.*
subprojects/packagecache/
subprojects/imgui-*/
subprojects/Vulkan-Headers-*/
#GNU Global Metadata
**/GPATH
**/GRTAGS
**/GTAGS

@ -120,7 +120,7 @@ A partial list of parameters are below. See the config file for a complete list.
| `offset_x` `offset_y` | Hud position offsets |
| `no_display` | Hide the hud by default |
| `toggle_hud=`<br>`toggle_logging=` | Modifiable toggle hotkeys. Default are F12 and F2, respectively. |
| `reload_cfg=` | Change keybind for reloading the config |
| `reload_cfg=` | Change keybind for reloading the config. Default = `Shift_L F4` |
| `time`<br>`time_format=%T` | Displays local time. See [std::put_time](https://en.cppreference.com/w/cpp/io/manip/put_time) for formatting help. |
| `gpu_color`<br>`gpu_color`<br>`vram_color`<br>`ram_color`<br>`io_color`<br>`engine_color`<br>`frametime_color`<br>`background_color`<br>`text_color` | Change default colors: `gpu_color=RRGGBB`|
| `alpha` | Set the opacity of all text and frametime graph `0.0-1.0` |

@ -101,9 +101,9 @@ background_alpha=0.5
################## INTERACTION #################
### Change toggle keybinds for the hud & logging
toggle_hud=F12
toggle_logging=F2
reload_cfg=F4
#toggle_hud=Shift_R F12
#toggle_logging=F2
#reload_cfg=Shift_L F4
################## LOG #################

@ -10,15 +10,29 @@ double elapsedF2, elapsedF12, elapsedReloadCfg;
uint64_t last_f2_press, last_f12_press, reload_cfg_press;
#ifdef HAVE_X11
bool key_is_pressed(KeySym ks) {
bool keys_are_pressed(const std::vector<KeySym>& keys) {
if (!init_x11())
return false;
char keys_return[32];
size_t pressed = 0;
g_x11->XQueryKeymap(get_xdisplay(), keys_return);
KeyCode kc2 = g_x11->XKeysymToKeycode(get_xdisplay(), ks);
bool isPressed = !!(keys_return[kc2 >> 3] & (1 << (kc2 & 7)));
return isPressed;
for (KeySym ks : keys) {
KeyCode kc2 = g_x11->XKeysymToKeycode(get_xdisplay(), ks);
bool isPressed = !!(keys_return[kc2 >> 3] & (1 << (kc2 & 7)));
if (isPressed)
pressed++;
}
if (pressed > 0 && pressed == keys.size()) {
return true;
}
return false;
}
#endif
#endif

@ -876,7 +876,7 @@ void check_keybinds(struct overlay_params& params){
if (elapsedF2 >= 500000 && !params.output_file.empty()){
#ifdef HAVE_X11
pressed = key_is_pressed(params.toggle_logging);
pressed = keys_are_pressed(params.toggle_logging);
#else
pressed = false;
#endif
@ -893,7 +893,7 @@ void check_keybinds(struct overlay_params& params){
if (elapsedF12 >= 500000){
#ifdef HAVE_X11
pressed = key_is_pressed(params.toggle_hud);
pressed = keys_are_pressed(params.toggle_hud);
#else
pressed = false;
#endif
@ -905,7 +905,7 @@ void check_keybinds(struct overlay_params& params){
if (elapsedReloadCfg >= 500000){
#ifdef HAVE_X11
pressed = key_is_pressed(params.reload_cfg);
pressed = keys_are_pressed(params.reload_cfg);
#else
pressed = false;
#endif

@ -6,6 +6,8 @@
#include <wordexp.h>
#include "imgui.h"
#include <iostream>
#include <string>
#include <sstream>
#include "overlay_params.h"
#include "overlay.h"
@ -71,28 +73,41 @@ parse_alpha(const char *str)
}
#ifdef HAVE_X11
static KeySym
static std::vector<KeySym>
parse_string_to_keysym_vec(const char *str)
{
std::vector<KeySym> keys;
if(g_x11->IsLoaded())
{
std::stringstream keyStrings(str);
std::string ks;
while (std::getline(keyStrings, ks, ' ')) {
KeySym xk = g_x11->XStringToKeysym(ks.c_str());
if (xk)
keys.push_back(xk);
else
std::cerr << "MANGOHUD: Unrecognized key: '" << ks << "'\n";
}
}
return keys;
}
static std::vector<KeySym>
parse_toggle_hud(const char *str)
{
if (g_x11->IsLoaded())
return g_x11->XStringToKeysym(str);
return 0;
return parse_string_to_keysym_vec(str);
}
static KeySym
static std::vector<KeySym>
parse_toggle_logging(const char *str)
{
if (g_x11->IsLoaded())
return g_x11->XStringToKeysym(str);
return 0;
return parse_string_to_keysym_vec(str);
}
static KeySym
static std::vector<KeySym>
parse_reload_cfg(const char *str)
{
if (g_x11->IsLoaded())
return g_x11->XStringToKeysym(str);
return 0;
return parse_string_to_keysym_vec(str);
}
#else
#define parse_toggle_hud(x) 0
@ -348,9 +363,9 @@ parse_overlay_config(struct overlay_params *params,
params->text_color = strtol("ffffff", NULL, 16);
#ifdef HAVE_X11
params->toggle_hud = XK_F12;
params->toggle_logging = XK_F2;
params->reload_cfg = XK_F4;
params->toggle_hud = { XK_F12 };
params->toggle_logging = { XK_F2 };
params->reload_cfg = { XK_Shift_L, XK_F4 };
#endif
// first pass with env var

@ -2,6 +2,7 @@
#define OVERLAY_PARAMS_H
#include <string>
#include <vector>
#include <unordered_map>
#ifdef __cplusplus
@ -122,9 +123,9 @@ struct overlay_params {
unsigned tableCols;
float font_size;
float background_alpha, alpha;
KeySym toggle_hud;
KeySym toggle_logging;
KeySym reload_cfg;
std::vector<KeySym> toggle_hud;
std::vector<KeySym> toggle_logging;
std::vector<KeySym> reload_cfg;
std::string time_format, output_file, font_file;
std::string pci_dev;

Loading…
Cancel
Save