LCDproc development and user support list

Text archives Help


[lcdproc] Suggested changes for client_add_key


Chronological Thread 
  • From: ppokorny AT penguincomputing.com (Philip Pokorny)
  • Subject: [lcdproc] Suggested changes for client_add_key
  • Date: Sat, 28 Apr 2001 16:20:50 -0700

I haven't heard anything, so here is my code to implement "client level"
key requests.

The idea here is that a client *must* request keys with either
client_add_key or screen_add_key. If requested using screen_add_key,
then if the current screen has requested a key, that screen/client will
be the only one to get that key event. Otherwise, all clients or
screens requesting a key will be notified.

Perhaps that's wrong. Perhaps if keys were requested using
screen_add_key, they should only be sent if the screen is active.
client_add_key will cause "left-over" keys to be sent to all requesting
clients. That probably makes more sense.

Comments?
:v)Index: server/client_data.c
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/server/client_data.c,v
retrieving revision 1.4
diff -c -r1.4 client_data.c
*** server/client_data.c 2000/04/03 22:13:57 1.4
--- server/client_data.c 2001/04/28 23:19:29
***************
*** 24,29 ****
--- 24,30 ----

d->ack = 0;
d->name = NULL;
+ d->client_keys = NULL;

d->screenlist = LL_new ();
if (!d->screenlist) {
***************
*** 56,61 ****
--- 57,66 ----
// Clean up the name...
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");
Index: server/client_data.h
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/server/client_data.h,v
retrieving revision 1.4
diff -c -r1.4 client_data.h
*** server/client_data.h 2000/04/03 22:13:57 1.4
--- server/client_data.h 2001/04/28 23:19:29
***************
*** 10,16 ****
char *name;
// and other stuff... doesn't matter yet
LL *screenlist;
! // list of accepted keys... (?)
LL *menulist;

} client_data;
--- 10,17 ----
char *name;
// and other stuff... doesn't matter yet
LL *screenlist;
! // list of accepted keys...
! char *client_keys ;
LL *menulist;

} client_data;
Index: server/client_functions.c
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/server/client_functions.c,v
retrieving revision 1.8
diff -c -r1.8 client_functions.c
*** server/client_functions.c 2001/04/27 02:20:38 1.8
--- server/client_functions.c 2001/04/28 23:19:29
***************
*** 142,152 ****
int
client_add_key_func (client * c, int argc, char **argv)
{

if (!c->data->ack)
return 1;

! sock_send_string (c->sock, "huh? Not implemented yet. Try using
screen_add_key.\n");

return 0;
}
--- 142,186 ----
int
client_add_key_func (client * c, int argc, char **argv)
{
+ char * keys ;

if (!c->data->ack)
return 1;

! 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,168 ****
int
client_del_key_func (client * c, int argc, char **argv)
{

if (!c->data->ack)
return 1;

! sock_send_string (c->sock, "huh? Not implemented yet. Try using
screen_del_key.\n");

return 0;
}
--- 192,236 ----
int
client_del_key_func (client * c, int argc, char **argv)
{
+ char * keys ;

if (!c->data->ack)
return 1;
+
+ 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;
}
Index: server/input.c
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/server/input.c,v
retrieving revision 1.6
diff -c -r1.6 input.c
*** server/input.c 2001/04/27 02:20:38 1.6
--- server/input.c 2001/04/28 23:19:29
***************
*** 80,85 ****
--- 80,92 ----
c = (client *)LL_GetFirst(clients);
while(c) {
// If the client should have this keypress...
+ 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);
+ continue ; // Client loop
+ };
+ // Loop through all screens for this client
s = (screen
*)LL_GetFirst(c->data->screenlist);
while(s) {
w = widget_find( s, KEYS_WIDGETID );


-----------------------------------------------------------
To unsubscribe from this list send a blank message to
lcdproc-unsubscribe AT lists.omnipotent.net


Archive powered by MHonArc 2.6.18.

Top of page