Added support for "client_add_key" and "client_delete_key" functions.
Clients must now request keys using either client_add_key or screen_add_key to receive key events. If a screen is active (on the display) and it has registered a key with "screen_add_key" it will be the only client to get that key. If the current screen doesn't want the key, it will be sent to all clients that have registered that key using "client_add_key". If you want to define a "hot button" for your client, you should probably register that "hot key" with "client_add_key" and then list the keys that control your client with "screen_add_key" on each screen. If you don't have a "hot key", then just register keys with "screen_add_key" and you'll get keystrokes only when your screen is active. Also fixed some formatting (spaces versus tabs) in a couple of places.
This commit is contained in:
@@ -142,11 +142,45 @@ client_set_func (client * c, int argc, char **argv)
|
||||
int
|
||||
client_add_key_func (client * c, int argc, char **argv)
|
||||
{
|
||||
char * keys ;
|
||||
|
||||
if (!c->data->ack)
|
||||
return 1;
|
||||
|
||||
sock_send_string (c->sock, "huh? Not implemented yet. Try using screen_add_key.\n");
|
||||
if (argc < 2) {
|
||||
sock_send_string (c->sock, "huh? You must specify a key list\n");
|
||||
return 0;
|
||||
}
|
||||
if (argc > 2) {
|
||||
sock_send_string (c->sock, "huh? Too many parameters...\n");
|
||||
return 0;
|
||||
}
|
||||
keys = argv[1];
|
||||
debug ("client_add_key: Adding key(s) %s to client_keys\n", keys);
|
||||
|
||||
if (!c->data->client_keys) {
|
||||
// No keys list, create a new one
|
||||
c->data->client_keys = strdup( keys );
|
||||
} else {
|
||||
// Add supplied keys to existing list
|
||||
// NOTE: There could be duplicates in the resulting list
|
||||
// That's OK, it's the existence of the key in the list
|
||||
// that's important. We'll be more careful in the delete
|
||||
// key function.
|
||||
char * new ;
|
||||
int new_len = strlen(c->data->client_keys) + strlen(keys) + 1 ;
|
||||
|
||||
new = realloc( c->data->client_keys, new_len );
|
||||
if( new ) {
|
||||
c->data->client_keys = new ;
|
||||
strcat( new, keys );
|
||||
}
|
||||
}
|
||||
|
||||
if (!c->data->client_keys) {
|
||||
sock_send_string(c->sock, "huh? failed\n");
|
||||
} else
|
||||
sock_send_string(c->sock, "success\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -158,11 +192,45 @@ client_add_key_func (client * c, int argc, char **argv)
|
||||
int
|
||||
client_del_key_func (client * c, int argc, char **argv)
|
||||
{
|
||||
char * keys ;
|
||||
|
||||
if (!c->data->ack)
|
||||
return 1;
|
||||
|
||||
sock_send_string (c->sock, "huh? Not implemented yet. Try using screen_del_key.\n");
|
||||
if (argc < 2) {
|
||||
sock_send_string (c->sock, "huh? You must specify a key list\n");
|
||||
return 0;
|
||||
}
|
||||
if (argc > 2) {
|
||||
sock_send_string (c->sock, "huh? Too many parameters...\n");
|
||||
return 0;
|
||||
}
|
||||
keys = argv[1] ;
|
||||
debug ("client_del_key: Deleting key(s) %s from client_keys\n", keys);
|
||||
|
||||
if (c->data->client_keys) {
|
||||
// Client has keys, remove keys from the list
|
||||
// NOTE: We let malloc/realloc remember the length
|
||||
// of the allocated storage. If keys are later
|
||||
// added, realloc (in add_key above) will make
|
||||
// sure there is enough space at c->data->client_keys
|
||||
char * from ;
|
||||
char * to ;
|
||||
|
||||
to = from = c->data->client_keys ;
|
||||
while( *from ) {
|
||||
// Is this key to be deleted from the list?
|
||||
if( strchr( keys, *from ) ) {
|
||||
// Yes, skip it
|
||||
++from ;
|
||||
} else {
|
||||
// No, save it
|
||||
*to++ = *from++ ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sock_send_string(c->sock, "success\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -222,7 +290,7 @@ screen_add_key_func (client * c, int argc, char **argv)
|
||||
if (!w->text) {
|
||||
// Save supplied key list
|
||||
w->text = strdup( keys );
|
||||
} else {
|
||||
} else {
|
||||
// Add supplied keys to existing list
|
||||
// NOTE: There could be duplicates in the resulting list
|
||||
// That's OK, it's the existence of the key in the list
|
||||
|
||||
Reference in New Issue
Block a user