mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-26 07:23:40 +00:00
[client] keybind: display help overlay while ScrollLock is held
This overlay will show the list of keybindings.
This commit is contained in:
parent
ead8069dae
commit
96dc8c602c
@ -110,5 +110,9 @@ void app_releaseKeybind(KeybindHandle * handle);
|
|||||||
*/
|
*/
|
||||||
void app_releaseAllKeybinds(void);
|
void app_releaseAllKeybinds(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes whether the help message is displayed or not.
|
||||||
|
*/
|
||||||
|
void app_showHelp(bool show);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -189,6 +189,7 @@ void app_handleKeyPress(int sc)
|
|||||||
{
|
{
|
||||||
g_state.escapeActive = true;
|
g_state.escapeActive = true;
|
||||||
g_state.escapeAction = -1;
|
g_state.escapeAction = -1;
|
||||||
|
app_showHelp(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +241,10 @@ void app_handleKeyRelease(int sc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sc == g_params.escapeKey)
|
if (sc == g_params.escapeKey)
|
||||||
|
{
|
||||||
g_state.escapeActive = false;
|
g_state.escapeActive = false;
|
||||||
|
app_showHelp(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!core_inputEnabled())
|
if (!core_inputEnabled())
|
||||||
@ -496,3 +500,55 @@ void app_releaseAllKeybinds(void)
|
|||||||
g_state.bindings[i] = NULL;
|
g_state.bindings[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char * build_help_str()
|
||||||
|
{
|
||||||
|
size_t size = 50;
|
||||||
|
size_t offset = 0;
|
||||||
|
char * buffer = malloc(size);
|
||||||
|
|
||||||
|
if (!buffer)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
const char * escapeName = xfree86_to_display[g_params.escapeKey];
|
||||||
|
|
||||||
|
offset += snprintf(buffer, size, "%s %-10s Toggle capture mode\n", escapeName, "");
|
||||||
|
if (offset >= size)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Help string somehow overflowed. This should be impossible.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < KEY_MAX; ++i)
|
||||||
|
{
|
||||||
|
if (g_state.keyDescription[i])
|
||||||
|
{
|
||||||
|
const char * keyName = xfree86_to_display[i];
|
||||||
|
const char * desc = g_state.keyDescription[i];
|
||||||
|
int needed = snprintf(buffer + offset, size - offset, "%s+%-10s %s\n", escapeName, keyName, desc);
|
||||||
|
if (offset + needed < size)
|
||||||
|
offset += needed;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = size * 2 + needed;
|
||||||
|
void * new = realloc(buffer, size);
|
||||||
|
if (!new) {
|
||||||
|
free(buffer);
|
||||||
|
DEBUG_ERROR("Out of memory when constructing help text");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
buffer = new;
|
||||||
|
offset += snprintf(buffer + offset, size - offset, "%s+%-10s %s\n", escapeName, keyName, desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_showHelp(bool show)
|
||||||
|
{
|
||||||
|
char * help = show ? build_help_str() : NULL;
|
||||||
|
g_state.lgr->on_help(g_state.lgrData, help);
|
||||||
|
free(help);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user