[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gEDA-dev: New patch for bug #1553544,New pages inadvertantly created when adding nets in gschem



This patch fixes the behaviour where pressing the "Up" key after my
previous patch was applied, re-focusses away from the gtk_drawing_area
and onto the toolbar.

It is a more general patch which should fix mis-directed keypress events
which conflict between widgets' default signal handlers and any gschem
keybindings.

By returning TRUE from x_event_key_press(), we can prevent the
propogation of a key press to higher-level handers (such as those which
cause the keyboard focus to move on the "Up" and "Down" keys.)

A small modification to gschem.scm allows the (press-key ..) function to
return #f if no match is found for a given key. g_keys_execute() now
returns 0 for not matched, or 1 for matched, and hence
x_event_key_press() can return TRUE and absorb the keypress.

(The one line, two non-whitespace character scheme modification took me
more time than the rest of the patch!)

The patch re-applies the partial roll-back which Ales committed earlier,
so the key-press event is once again attached to the gtk_drawing_area.

The "Tab" key will still transfer focus between the gtk_drawing_area and
the toolbar, and no gschem key bindings work when the toolbar has focus.
I think this is the correct behaviour. (Certainly bindings like pan, add
net etc... must be disabled.)

If there is to be a sub-set of key-bindings active when the toolbar is
focused, a keypress event ought to be attached to the toolbar. (Or its
nearest parent with a gdk_window, perhaps the main window.)

The gtk_drawing_area handler should still get first "refusal" to the
key-press events if is focused.

Unless there is any objection to the new behaviour (or other errors
people spot in the patch), I intend to apply this to the CUED CD
release.

Regards

Peter Clifton

Index: include/prototype.h
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/include/prototype.h,v
retrieving revision 1.135
diff -U3 -p -r1.135 prototype.h
--- include/prototype.h	30 Aug 2006 11:06:16 -0000	1.135
+++ include/prototype.h	7 Sep 2006 15:48:36 -0000
@@ -42,7 +42,7 @@ SCM g_get_object_bounds (SCM object_smob
 SCM g_get_object_pins (SCM object_smob);
 /* g_keys.c */
 void set_window_current_key(TOPLEVEL *w_current);
-void g_keys_execute(int state, int keyval);
+int g_keys_execute(int state, int keyval);
 SCM g_keys_file_new(void);
 SCM g_keys_file_new_window(void);
 SCM g_keys_file_open(void);
@@ -845,7 +845,7 @@ void x_manual_resize(TOPLEVEL *w_current
 void x_event_hschanged(GtkAdjustment *adj, TOPLEVEL *w_current);
 void x_event_vschanged(GtkAdjustment *adj, TOPLEVEL *w_current);
 gint x_event_enter(GtkWidget *widget, GdkEventCrossing *event, TOPLEVEL *w_current);
-gint x_event_key_press(GtkWidget *widget, GdkEventKey *event, TOPLEVEL *w_current);
+gboolean x_event_key_press(GtkWidget *widget, GdkEventKey *event, TOPLEVEL *w_current);
 gint x_event_scroll(GtkWidget *widget, GdkEventScroll *event, TOPLEVEL *w_current);
 /* x_fileselect.c */
 void x_fileselect_destroy_window(GtkWidget *widget, FILEDIALOG *f_current);
Index: scheme/gschem.scm
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/scheme/gschem.scm,v
retrieving revision 1.6
diff -U3 -p -r1.6 gschem.scm
--- scheme/gschem.scm	10 Mar 2003 02:57:42 -0000	1.6
+++ scheme/gschem.scm	7 Sep 2006 15:48:36 -0000
@@ -51,6 +51,7 @@
                 (set! current-keymap global-keymap)
                 ;(display "No keymap found")
                 ;(newline)
+                #f
                 )))))
 
 (define (perform-action action)
Index: src/g_keys.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/g_keys.c,v
retrieving revision 1.3
diff -U3 -p -r1.3 g_keys.c
--- src/g_keys.c	6 Aug 2006 19:23:19 -0000	1.3
+++ src/g_keys.c	7 Sep 2006 15:48:37 -0000
@@ -57,26 +57,27 @@ void set_window_current_key(TOPLEVEL *w_
  *
  */
 /* for now this only supports single chars, not shift/alt/ctrl etc... */
-void g_keys_execute(int state, int keyval)
+int g_keys_execute(int state, int keyval)
 {
   char *guile_string = NULL;
   char *modifier = NULL;
+  SCM scm_retval;
 
   if (keyval == 0) {
-    return;
+    return 0;
   }
 
   /* don't pass the raw modifier key presses to the guile code */
   if (strstr(gdk_keyval_name(keyval), "Alt")) {
-    return;
+    return 0;
   }
 
   if (strstr(gdk_keyval_name(keyval), "Shift")) {
-    return;
+    return 0;
   }
 
   if (strstr(gdk_keyval_name(keyval), "Control")) {
-    return;
+    return 0;
   }
 
   if (state & GDK_SHIFT_MASK) {
@@ -95,7 +96,7 @@ void g_keys_execute(int state, int keyva
 #if DEBUG 
   printf("_%s_\n", guile_string);
 #endif
-  scm_c_eval_string (guile_string);
+  scm_retval = scm_c_eval_string (guile_string);
   g_free(guile_string);
   g_free(modifier);
 
@@ -103,6 +104,8 @@ void g_keys_execute(int state, int keyva
   gh_eval_str("(display (reverse last-command-sequence))");
   printf("\n");
 #endif
+
+  return (SCM_FALSEP (scm_retval)) ? 0 : 1;
 }
 
 /*! \brief
Index: src/x_event.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/x_event.c,v
retrieving revision 1.38
diff -U3 -p -r1.38 x_event.c
--- src/x_event.c	6 Aug 2006 16:45:29 -0000	1.38
+++ src/x_event.c	7 Sep 2006 15:48:37 -0000
@@ -1512,9 +1512,13 @@ gint x_event_enter(GtkWidget *widget, Gd
  *  \par Function Description
  *
  */
-gint x_event_key_press (GtkWidget *widget, GdkEventKey *event,
+gboolean x_event_key_press (GtkWidget *widget, GdkEventKey *event,
 			TOPLEVEL *w_current)
 {
+  int retval;
+  
+  retval = FALSE;
+  
   exit_if_null(w_current);
   global_window_current = w_current;
 
@@ -1524,10 +1528,10 @@ gint x_event_key_press (GtkWidget *widge
 #if DEBUG
     printf("x_event_key_pressed: Pressed key %i.\n", event->keyval);
 #endif
-    g_keys_execute(event->state, event->keyval);
+    retval = g_keys_execute(event->state, event->keyval) ? TRUE : FALSE;
   }
 
-  return(0);
+  return retval;
 }
 
 
Index: src/x_window.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/x_window.c,v
retrieving revision 1.39
diff -U3 -p -r1.39 x_window.c
--- src/x_window.c	7 Sep 2006 01:40:24 -0000	1.39
+++ src/x_window.c	7 Sep 2006 15:48:37 -0000
@@ -359,11 +359,11 @@ void x_window_setup_draw_events(TOPLEVEL
     { "button_release_event", G_CALLBACK(x_event_button_released) },
     { "motion_notify_event",  G_CALLBACK(x_event_motion)          },
     { "configure_event",      G_CALLBACK(x_event_configure)       },
+    { "key_press_event",      G_CALLBACK(x_event_key_press)       },
     { NULL,                   NULL                                } };
   struct event_reg_t main_window_events[] = {
     { "enter_notify_event",   G_CALLBACK(x_event_enter)           },
     { "scroll_event",         G_CALLBACK(x_event_scroll)          },
-    { "key_press_event",      G_CALLBACK(x_event_key_press)       },
     { NULL,                   NULL                                } };
   struct event_reg_t *tmp;
 


_______________________________________________
geda-dev mailing list
geda-dev@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev