comparison finch/libgnt/gntwm.c @ 17540:b242187b3591

Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
author Eric Polino <aluink@pidgin.im>
date Mon, 04 Jun 2007 02:49:22 +0000
parents c609b4009dbe
children aeb8c9fbb577
comparison
equal deleted inserted replaced
17539:c609b4009dbe 17540:b242187b3591
8 #include <ctype.h> 8 #include <ctype.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 #include <time.h> 11 #include <time.h>
12 12
13 #include "gntbutton.h"
13 #include "gntwm.h" 14 #include "gntwm.h"
15 #include "gntentry.h"
14 #include "gntstyle.h" 16 #include "gntstyle.h"
15 #include "gntmarshal.h" 17 #include "gntmarshal.h"
16 #include "gnt.h" 18 #include "gnt.h"
17 #include "gntbox.h" 19 #include "gntbox.h"
18 #include "gntlabel.h" 20 #include "gntlabel.h"
56 static int write_timeout; 58 static int write_timeout;
57 static time_t last_active_time; 59 static time_t last_active_time;
58 static gboolean idle_update; 60 static gboolean idle_update;
59 61
60 static gboolean ignore_keys = FALSE; 62 static gboolean ignore_keys = FALSE;
63
64 typedef struct {
65 char * keys; /* Keystrokes being bound to the action */
66 GntBindableClass * klass; /* Class of the object that's getting keys rebound */
67 char * name; /* Name of the action ie:window-close, wm-quit, refresh-screen */
68 void * params; /* Parameters to pass to the callback */
69 } RebindInfo;
70
71 RebindInfo * rebind_info;
61 72
62 static GList * 73 static GList *
63 g_list_bring_to_front(GList *list, gpointer data) 74 g_list_bring_to_front(GList *list, gpointer data)
64 { 75 {
65 list = g_list_remove(list, data); 76 list = g_list_remove(list, data);
484 495
485 return TRUE; 496 return TRUE;
486 } 497 }
487 498
488 static gboolean 499 static gboolean
500 free_rebind_info(){
501 g_free(rebind_info->keys);
502 g_free(rebind_info->name);
503 g_free(rebind_info->params);
504 g_free(rebind_info);
505
506 }
507
508 static gboolean
509 help_for_widget_cancel_button_activate(GntBindable *bindable, gpointer data){
510 free_rebind_info();
511
512 gnt_widget_destroy(GNT_WIDGET(data));
513 return TRUE;
514 }
515
516 static gboolean
517 help_for_widget_bind_button_activate(GntBindable *bindable, gpointer data){
518
519 /* This will be where the rebinding happens */
520 /* if(rebind_info->keys){
521 gnt_bindable_class_register_action(rebind_info->klass,rebind_info->name,NULL,rebind_info->keys,rebind_info->params);
522 } */
523
524 free_rebind_info();
525
526 gnt_widget_destroy(GNT_WIDGET(data));
527
528 return TRUE;
529 }
530
531 static gboolean
532 help_for_widget_grab_key(GntBindable *bindable, const char *text, gpointer *data){
533
534 GntLabel *label = GNT_LABEL(data);
535 char *newText;
536
537 if(text && *text){
538
539 fprintf(stderr,"%d %d\n",*text,text[1]);
540
541 if(!strcmp(text, GNT_KEY_CTRL_I) || !strcmp(text, GNT_KEY_ENTER)){
542 return FALSE;
543 }
544
545 newText = g_strdup_printf("KEY: \"%s\"",text);
546 gnt_label_set_text(label,newText);
547
548 g_free(newText);
549
550 return TRUE;
551 }
552 return FALSE;
553 }
554 static void
555 help_for_widget_activate(GntBindable *bindable, gpointer widget){
556
557
558 GntTree * tree = GNT_TREE(bindable);
559
560 GntWidget *vbox = gnt_box_new(FALSE,TRUE);
561
562 GntWidget *label;
563 const char * widgetName = g_type_name(G_OBJECT_TYPE(widget));
564
565 GntWidget *key_label;
566
567 GntWidget *bind_button, *cancel_button;
568 GntWidget *button_box;
569
570 GntWidget *win = gnt_window_new();
571 GList * currentRowData,*itr;
572 char * tmp;
573
574 rebind_info = (RebindInfo*)malloc(sizeof(RebindInfo));
575 rebind_info->keys = NULL;
576 rebind_info->klass = GNT_BINDABLE_GET_CLASS(widget);
577 currentRowData = gnt_tree_get_selection_text_list(tree);
578 rebind_info->name = g_list_nth_data(currentRowData,1);
579 rebind_info->params = NULL;
580
581 itr = currentRowData;
582 while(itr){
583 g_free(itr->data);
584 itr = itr->next;
585 }
586 g_list_free(currentRowData);
587
588 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID);
589
590 gnt_box_set_title(GNT_BOX(win),"Key Capture");
591
592 tmp = g_strdup_printf("Type the new bindings for %s in a %s.",rebind_info->name,widgetName);
593 label = gnt_label_new(tmp);
594 g_free(tmp);
595 gnt_box_add_widget(GNT_BOX(vbox),label);
596
597 key_label = gnt_label_new("KEY:\"\"");
598 gnt_widget_set_name(key_label,"keystroke");
599 gnt_box_add_widget(GNT_BOX(vbox),key_label);
600
601 g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(help_for_widget_grab_key),key_label);
602
603 button_box = gnt_box_new(FALSE,FALSE);
604
605 bind_button = gnt_button_new("BIND");
606 gnt_widget_set_name(bind_button,"bind");
607 gnt_box_add_widget(GNT_BOX(button_box), bind_button);
608
609 cancel_button = gnt_button_new("Cancel");
610 gnt_widget_set_name(cancel_button,"cancel");
611 gnt_box_add_widget(GNT_BOX(button_box),cancel_button);
612
613 g_signal_connect(G_OBJECT(bind_button), "activate", G_CALLBACK(help_for_widget_bind_button_activate),win);
614 g_signal_connect(G_OBJECT(cancel_button), "activate", G_CALLBACK(help_for_widget_cancel_button_activate),win);
615
616
617 gnt_box_add_widget(GNT_BOX(vbox),button_box);
618
619 gnt_box_add_widget(GNT_BOX(win),vbox);
620 gnt_widget_show(win);
621
622 }
623
624 static gboolean
489 help_for_widget(GntBindable *bindable, GList *null) 625 help_for_widget(GntBindable *bindable, GList *null)
490 { 626 {
491 GntWM *wm = GNT_WM(bindable); 627 GntWM *wm = GNT_WM(bindable);
492 GntWidget *widget, *tree, *win, *active; 628 GntWidget *widget, *tree, *win, *active;
493 char *title; 629 char *title;
499 if (!GNT_IS_BOX(widget)) 635 if (!GNT_IS_BOX(widget))
500 return TRUE; 636 return TRUE;
501 active = GNT_BOX(widget)->active; 637 active = GNT_BOX(widget)->active;
502 638
503 tree = gnt_widget_bindings_view(active); 639 tree = gnt_widget_bindings_view(active);
640 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(help_for_widget_activate), active);
641
504 win = gnt_window_new(); 642 win = gnt_window_new();
505 title = g_strdup_printf("Bindings for %s", g_type_name(G_OBJECT_TYPE(active))); 643 title = g_strdup_printf("Bindings for %s", g_type_name(G_OBJECT_TYPE(active)));
506 gnt_box_set_title(GNT_BOX(win), title); 644 gnt_box_set_title(GNT_BOX(win), title);
507 if (tree) 645 if (tree)
508 gnt_box_add_widget(GNT_BOX(win), tree); 646 gnt_box_add_widget(GNT_BOX(win), tree);