diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index a049d527a9..82378c433c 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,11 @@ +2004-02-16 Federico Mena Quintero + + * gtk/migrating-checklist.sgml: Umm, I'm on crack. Use + gtk_accelerator_get_default_mod_mask(). + + * gdk/tmpl/windows.sgml: Removed the incorrect description from + GDK_MODIFIER_MASK. + 2004-02-16 Federico Mena Quintero * gdk/tmpl/windows.sgml: Added an example of how to use diff --git a/docs/reference/gdk/tmpl/windows.sgml b/docs/reference/gdk/tmpl/windows.sgml index 75441dda5c..4573dbe92d 100644 --- a/docs/reference/gdk/tmpl/windows.sgml +++ b/docs/reference/gdk/tmpl/windows.sgml @@ -1126,38 +1126,7 @@ Like the X Window System, GDK supports 8 modifier keys and 5 mouse buttons. @GDK_BUTTON5_MASK: the fifth mouse button. @GDK_RELEASE_MASK: not used in GDK itself. GTK+ uses it to differentiate between (keyval, modifiers) pairs from key press and release events. -@GDK_MODIFIER_MASK: Mask that can be used to see if modifier keys are - pressed. See for an example - of how to use this mask. - - - Testing for keys with modifiers - - - The following code shows how you should use GDK_MODIFIER_MASK to - test for - ControlF10 - being pressed. If you do something like testing for - event->state == GDK_CONTROL_MASK, your - program will not work correctly if some other modifier is - pressed, such as NumLock. - - - -static gboolean -my_widget_key_press_handler (GtkWidget *widget, GdkEventKey *event) -{ - if (event->keysym == GDK_F10 - && (event->state & GDK_MODIFIER_MASK) == GDK_CONTROL_MASK) - { - g_print ("Control-F10 was pressed\n"); - return TRUE; - } - - return FALSE; -} - - +@GDK_MODIFIER_MASK: diff --git a/docs/reference/gtk/migrating-checklist.sgml b/docs/reference/gtk/migrating-checklist.sgml index 9c83a7030a..375763f3fc 100644 --- a/docs/reference/gtk/migrating-checklist.sgml +++ b/docs/reference/gtk/migrating-checklist.sgml @@ -217,10 +217,12 @@ my_widget_expose_event_handler (GtkWidget *widget, GdkEventExpose *event) Why - With GDK_MODIFIER_MASK you can test for - modifier keys reliably; this way your key event handlers will - work correctly even if NumLock or - CapsLock are activated. + With + gtk_accelerator_get_default_mod_mask() + you can test for modifier keys reliably; this way your key + event handlers will work correctly even if + NumLock or CapsLock are + activated. @@ -228,27 +230,51 @@ my_widget_expose_event_handler (GtkWidget *widget, GdkEventExpose *event) In a GdkEventKey, the state field is a bit mask which indicates the modifier state at the time the key was pressed. - Modifiers are keys like Control, and + Modifiers are keys like Control and NumLock. When implementing a GtkWidget::key_press_event - handler, you should use the - GDK_MODIFIER_MASK constant to test against - modifier keys. This value encompasses all the modifiers which - the user may be actively pressing, such as - Control and Shift, but ignores + handler, you should use + gtk_accelerator_get_default_mod_mask() to + test against modifier keys. This function returns a bit mask + which encompasses all the modifiers which the user may be + actively pressing, such as Control, + Shift, and Alt, but ignores "inocuous" modifiers such as NumLock and - CapsLock. The following example tests for - - ControlF10 being - pressed. + CapsLock. - + + Say you want to see if + ControlF10 + was pressed. Doing a simple test like + event->keysym == GDK_F10 && + event->state == GDK_CONTROL_MASK is not + enough. If CapsLock is pressed, then + event->state will be equal to + GDK_CONTROL_MASK | GDK_LOCK_MASK, and the + simple test will fail. By taking the logical-and of + event->state and + gtk_accelerator_get_default_mod_mask(), you + can ignore the modifiers which are not actively pressed by the + user at the same time as the base key. + + + + The following example correctly tests for + ControlF10 + being pressed. + + + static gboolean -my_widget_key_press_handler (GtkWidget *widget, GdkEventKey *event) +my_widget_key_press_event_handler (GtkWidget *widget, GdkEventKey *event) { + guint modifiers; + + modifiers = gtk_accelerator_get_default_mod_mask (); + if (event->keysym == GDK_F10 - && (event->state & GDK_MODIFIER_MASK) == GDK_CONTROL_MASK) + && (event->state & modifiers) == GDK_CONTROL_MASK) { g_print ("Control-F10 was pressed\n"); return TRUE;