2019-03-30 01:26:06 +00:00
|
|
|
/*
|
|
|
|
Looking Glass - KVM FrameRelay (KVMFR) Client
|
|
|
|
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
|
|
|
https://looking-glass.hostfission.com
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main.h"
|
2019-04-11 01:12:59 +00:00
|
|
|
#include "common/debug.h"
|
2019-03-30 01:26:06 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
void app_alert(LG_MsgAlert type, const char * fmt, ...)
|
|
|
|
{
|
2021-01-04 01:06:54 +00:00
|
|
|
if (!g_state.lgr || !params.showAlerts)
|
2019-03-30 01:26:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
const int length = vsnprintf(NULL, 0, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
char *buffer = malloc(length + 1);
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(buffer, length + 1, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
2021-01-04 01:06:54 +00:00
|
|
|
g_state.lgr->on_alert(
|
|
|
|
g_state.lgrData,
|
2019-03-30 01:26:06 +00:00
|
|
|
type,
|
|
|
|
buffer,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
KeybindHandle app_register_keybind(SDL_Scancode key, SuperEventFn callback, void * opaque)
|
|
|
|
{
|
|
|
|
// don't allow duplicate binds
|
2021-01-04 01:06:54 +00:00
|
|
|
if (g_state.bindings[key])
|
2019-03-30 01:26:06 +00:00
|
|
|
{
|
|
|
|
DEBUG_INFO("Key already bound");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeybindHandle handle = (KeybindHandle)malloc(sizeof(struct KeybindHandle));
|
|
|
|
handle->key = key;
|
|
|
|
handle->callback = callback;
|
|
|
|
handle->opaque = opaque;
|
|
|
|
|
2021-01-04 01:06:54 +00:00
|
|
|
g_state.bindings[key] = handle;
|
2019-03-30 01:26:06 +00:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void app_release_keybind(KeybindHandle * handle)
|
|
|
|
{
|
2019-05-30 10:24:51 +00:00
|
|
|
if (!*handle)
|
2019-03-30 01:26:06 +00:00
|
|
|
return;
|
|
|
|
|
2021-01-04 01:06:54 +00:00
|
|
|
g_state.bindings[(*handle)->key] = NULL;
|
2019-03-30 01:26:06 +00:00
|
|
|
free(*handle);
|
|
|
|
*handle = NULL;
|
2021-01-04 01:06:54 +00:00
|
|
|
}
|