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:
ppokorny
2001-05-11 17:55:36 +00:00
parent f0276139d0
commit 3e4ce08d43
5 changed files with 104 additions and 34 deletions
+5
View File
@@ -24,6 +24,7 @@ client_data_init (client_data * d)
d->ack = 0;
d->name = NULL;
d->client_keys = NULL;
d->screenlist = LL_new ();
if (!d->screenlist) {
@@ -57,6 +58,10 @@ client_data_destroy (client_data * d)
if (d->name)
free (d->name);
// Clean up the key list...
if (d->client_keys)
free (d->client_keys);
// Clean up the screenlist...
debug ("client_data_destroy: Cleaning screenlist\n");
LL_Rewind (d->screenlist);
+2 -1
View File
@@ -10,7 +10,8 @@ typedef struct client_data {
char *name;
// and other stuff... doesn't matter yet
LL *screenlist;
// list of accepted keys... (?)
// list of requested keys...
char *client_keys ;
LL *menulist;
} client_data;
+71 -3
View File
@@ -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
+14 -12
View File
@@ -141,6 +141,8 @@ int glk_init(struct lcd_logical_driver *driver, char *args)
width = 20 ; height = 4 ; gpo_count = 2 ; break ;
case 0x23 : // GLK12232-25SM
width = 20 ; height = 4 ; gpo_count = 2 ; break ;
case 0x24 : // GLK12232-25SM-Penguin
width = 20 ; height = 4 ; gpo_count = 2 ; break ;
default :
fprintf( stderr, "glk: Unrecognized module type: 0x%02x\n", i );
return( -1 );
@@ -635,18 +637,18 @@ char glk_getkey()
/* Remap keys according to what LCDproc expects */
switch( c ) {
default : break ;
case 'U' : c = 'A' ; break ;
case 'Q' : c = 'B' ; break ;
case 'P' : c = 'C' ; break ;
case 'K' : c = 'D' ; break ;
case 'V' : c = 'E' ; break ;
case 'L' : c = 'F' ; break ;
case 'u' : c = 'N' ; break ;
case 'q' : c = 'O' ; break ;
case 'p' : c = 'P' ; break ;
case 'k' : c = 'Q' ; break ;
case 'v' : c = 'R' ; break ;
case 'l' : c = 'S' ; break ;
case 'V' : c = 'A' ; break ; /* Hold/Select */
case 'P' : c = 'B' ; break ; /* Left -- Minus */
case 'Q' : c = 'C' ; break ; /* Right -- Plus */
case 'L' : c = 'D' ; break ; /* Menu/Exit */
case 'U' : c = 'E' ; break ; /* Up */
case 'K' : c = 'F' ; break ; /* Down */
case 'v' : c = 'N' ; break ;
case 'p' : c = 'O' ; break ;
case 'q' : c = 'P' ; break ;
case 'l' : c = 'Q' ; break ;
case 'u' : c = 'R' ; break ;
case 'k' : c = 'S' ; break ;
};
// if( c ) {
+12 -18
View File
@@ -11,17 +11,17 @@
Normal "normal" context is handled in this source file.
A Pause/Continue
B Back(Go to previous screen)
C Forward(Go to next screen)
D Open main menu
C Forward(Go to next screen)
D Open main menu
E-Z Sent to client, if any; ignored otherwise
(menu keys are not handled here, but in the menu code)
Menu
A Enter/select
B Up/Left
C Down/Right
D Exit/Cancel
E-Z Ignored
B Up/Left
C Down/Right
D Exit/Cancel
E-Z Ignored
*/
#include <stdlib.h>
@@ -76,21 +76,15 @@ handle_input ()
sock_send_string(s->parent->sock, str);
// Nobody else gets this key
} else {
// Give key to anyone who wants it
// Give key to clients who want it
c = (client *)LL_GetFirst(clients);
while(c) {
// If the client should have this keypress...
s = (screen *)LL_GetFirst(c->data->screenlist);
while(s) {
w = widget_find( s, KEYS_WIDGETID );
if( s->parent && w && w->text && strchr( w->text, key ) ) {
// Send keypress to client
sprintf(str, "key %c\n", key);
sock_send_string(c->sock, str);
break ; // Screen loop
}
s = (screen *)LL_GetNext(c->data->screenlist);
} // while screens
if( c->data->client_keys && strchr(c->data->client_keys, key) ) {
// Send keypress to client
sprintf(str, "key %c\n", key);
sock_send_string(c->sock, str);
};
c = (client *)LL_GetNext(clients);
} // while clients