GUACAMOLE-313: Separate naming logic for keysyms. Align previously-pressed keys.
This commit is contained in:
parent
d39757b4dc
commit
df29735c83
@ -28,6 +28,7 @@ noinst_HEADERS = \
|
||||
guaclog.h \
|
||||
instructions.h \
|
||||
interpret.h \
|
||||
key-name.h \
|
||||
log.h \
|
||||
state.h
|
||||
|
||||
@ -36,6 +37,7 @@ guaclog_SOURCES = \
|
||||
instructions.c \
|
||||
instruction-key.c \
|
||||
interpret.c \
|
||||
key-name.c \
|
||||
log.c \
|
||||
state.c
|
||||
|
||||
|
43
src/guaclog/key-name.c
Normal file
43
src/guaclog/key-name.c
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "key-name.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int guaclog_key_name(char* key_name, int keysym) {
|
||||
|
||||
/* Fallback to using hex keysym as name */
|
||||
int name_length = snprintf(key_name, GUACLOG_MAX_KEY_NAME_LENGTH,
|
||||
"0x%X", keysym);
|
||||
|
||||
/* Truncate name if necessary */
|
||||
if (name_length >= GUACLOG_MAX_KEY_NAME_LENGTH) {
|
||||
name_length = GUACLOG_MAX_KEY_NAME_LENGTH - 1;
|
||||
key_name[name_length] = '\0';
|
||||
guaclog_log(GUAC_LOG_DEBUG, "Name for key 0x%X was "
|
||||
"truncated.", keysym);
|
||||
}
|
||||
|
||||
return name_length;
|
||||
|
||||
}
|
||||
|
50
src/guaclog/key-name.h
Normal file
50
src/guaclog/key-name.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef GUACLOG_KEY_NAME_H
|
||||
#define GUACLOG_KEY_NAME_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/**
|
||||
* The maximum size of the name of any key, in bytes.
|
||||
*/
|
||||
#define GUACLOG_MAX_KEY_NAME_LENGTH 64
|
||||
|
||||
/**
|
||||
* Copies the name of the key having the given keysym into the given buffer,
|
||||
* which must be at least GUACLOG_MAX_KEY_NAME_LENGTH bytes long. This function
|
||||
* always succeeds, ultimately resorting to using the hex value of the keysym
|
||||
* as the name if no other human-readable name is known.
|
||||
*
|
||||
* @param key_name
|
||||
* The buffer to copy the key name into, which must be at least
|
||||
* GUACLOG_MAX_KEY_NAME_LENGTH.
|
||||
*
|
||||
* @param keysym
|
||||
* The X11 keysym of the key whose name should be stored in
|
||||
* key_name.
|
||||
*
|
||||
* @return
|
||||
* The length of the name, in bytes, excluding null terminator.
|
||||
*/
|
||||
int guaclog_key_name(char* key_name, int keysym);
|
||||
|
||||
#endif
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "key-name.h"
|
||||
#include "log.h"
|
||||
#include "state.h"
|
||||
|
||||
@ -174,15 +175,28 @@ int guaclog_state_update_key(guaclog_state* state, int keysym, bool pressed) {
|
||||
/* Output new log entries only when keys are pressed */
|
||||
if (pressed) {
|
||||
|
||||
/* STUB: Output raw hex log entry */
|
||||
/* Compose log entry by inspecting the state of each tracked key */
|
||||
for (i = 0; i < state->active_keys; i++) {
|
||||
|
||||
guaclog_key_state* key = &state->key_states[i];
|
||||
|
||||
/* Translate keysym into human-readable name */
|
||||
char key_name[GUACLOG_MAX_KEY_NAME_LENGTH];
|
||||
int name_length = guaclog_key_name(key_name, key->keysym);
|
||||
|
||||
/* If not the final key, omit the name (it was printed earlier) */
|
||||
if (i < state->active_keys - 1) {
|
||||
memset(key_name, ' ', name_length);
|
||||
if (key->pressed)
|
||||
key_name[name_length / 2] = '*';
|
||||
}
|
||||
|
||||
/* Separate each key by a single space */
|
||||
if (i != 0)
|
||||
fprintf(state->output, " ");
|
||||
|
||||
guaclog_key_state* key = &state->key_states[i];
|
||||
fprintf(state->output, "0x%X:%s", key->keysym,
|
||||
key->pressed ? "*" : " ");
|
||||
/* Print name of key */
|
||||
fprintf(state->output, "%s", key_name);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user