diff --git a/ChangeLog b/ChangeLog index ce73bde5aa..9f02a50938 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-09-20 Matthias Clasen + + Avoid unnecessary XkbGetState() calls and XkbStateNotify + events. (#151555, Søren Sandmann) + + * gdk/x11/gdkdisplay-x11.c (gdk_display_open): Use + XkbSelectEventDetails() to select XkbStateNotify events + for only the state we care about. + + * gdk/x11/gdkprivate-x11.h: + * gdk/x11/gdkkeys-x11.c (_gdk_keymap_state_changed): Pass + the event into the function and update the keymap state from + the state information contained in the event. Adjust all callers. + 2005-09-19 Matthias Clasen * gtk/gtkiconview.c: Use g_list_nth_data() instead of g_list_nth()->data diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index ce73bde5aa..9f02a50938 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,17 @@ +2005-09-20 Matthias Clasen + + Avoid unnecessary XkbGetState() calls and XkbStateNotify + events. (#151555, Søren Sandmann) + + * gdk/x11/gdkdisplay-x11.c (gdk_display_open): Use + XkbSelectEventDetails() to select XkbStateNotify events + for only the state we care about. + + * gdk/x11/gdkprivate-x11.h: + * gdk/x11/gdkkeys-x11.c (_gdk_keymap_state_changed): Pass + the event into the function and update the keymap state from + the state information contained in the event. Adjust all callers. + 2005-09-19 Matthias Clasen * gtk/gtkiconview.c: Use g_list_nth_data() instead of g_list_nth()->data diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index fac1a5ef52..14a46deed5 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -281,6 +281,11 @@ gdk_display_open (const gchar *display_name) XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask, XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask); + /* keep this in sync with _gdk_keymap_state_changed() */ + XkbSelectEventDetails (display_x11->xdisplay, + XkbUseCoreKbd, XkbStateNotify, + XkbGroupLockMask, XkbGroupLockMask); + XkbSetDetectableAutoRepeat (display_x11->xdisplay, True, &detectable_autorepeat_supported); diff --git a/gdk/x11/gdkevents-x11.c b/gdk/x11/gdkevents-x11.c index d2e6a0d7c3..522e1cdf68 100644 --- a/gdk/x11/gdkevents-x11.c +++ b/gdk/x11/gdkevents-x11.c @@ -2050,7 +2050,7 @@ gdk_event_translate (GdkDisplay *display, break; case XkbStateNotify: - _gdk_keymap_state_changed (display); + _gdk_keymap_state_changed (display, xevent); break; } } diff --git a/gdk/x11/gdkkeys-x11.c b/gdk/x11/gdkkeys-x11.c index 48aa0383e9..bf0f39b1d0 100644 --- a/gdk/x11/gdkkeys-x11.c +++ b/gdk/x11/gdkkeys-x11.c @@ -536,16 +536,12 @@ get_direction (XkbDescRec *xkb, } static void -update_direction (GdkKeymapX11 *keymap_x11) +update_direction (GdkKeymapX11 *keymap_x11, + gint group) { XkbDescRec *xkb = get_xkb (keymap_x11); - XkbStateRec state_rec; - GdkDisplay *display = GDK_KEYMAP (keymap_x11)->display; - gint group; Atom group_atom; - XkbGetState (GDK_DISPLAY_XDISPLAY (display), XkbUseCoreKbd, &state_rec); - group = XkbGroupLock (&state_rec); group_atom = xkb->names->groups[group]; /* a group change? */ @@ -609,32 +605,29 @@ update_direction (GdkKeymapX11 *keymap_x11) } } -static void -_gdk_keymap_direction_changed (GdkKeymapX11 *keymap_x11) -{ - gboolean had_direction; - PangoDirection direction; - - had_direction = keymap_x11->have_direction; - direction = keymap_x11->current_direction; - - update_direction (keymap_x11); - - if (!had_direction || direction != keymap_x11->current_direction) - g_signal_emit_by_name (keymap_x11, "direction_changed"); -} - - +/* keep this in sync with the XkbSelectEventDetails() call + * in gdk_display_open() + */ void -_gdk_keymap_state_changed (GdkDisplay *display) +_gdk_keymap_state_changed (GdkDisplay *display, + XEvent *xevent) { GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display); + XkbEvent *xkb_event = (XkbEvent *)xevent; if (display_x11->keymap) { GdkKeymapX11 *keymap_x11 = GDK_KEYMAP_X11 (display_x11->keymap); + gboolean had_direction; + PangoDirection direction; - _gdk_keymap_direction_changed (keymap_x11); + had_direction = keymap_x11->have_direction; + direction = keymap_x11->current_direction; + + update_direction (keymap_x11, xkb_event->state.locked_group); + + if (!had_direction || direction != keymap_x11->current_direction) + g_signal_emit_by_name (keymap_x11, "direction_changed"); } } @@ -660,9 +653,16 @@ gdk_keymap_get_direction (GdkKeymap *keymap) if (KEYMAP_USE_XKB (keymap)) { GdkKeymapX11 *keymap_x11 = GDK_KEYMAP_X11 (keymap); - + if (!keymap_x11->have_direction) - update_direction (keymap_x11); + { + GdkDisplay *display = GDK_KEYMAP (keymap_x11)->display; + XkbStateRec state_rec; + + XkbGetState (GDK_DISPLAY_XDISPLAY (display), XkbUseCoreKbd, + &state_rec); + update_direction (keymap_x11, XkbGroupLock (&state_rec)); + } return keymap_x11->current_direction; } diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h index 26f94fe349..73f4410c32 100644 --- a/gdk/x11/gdkprivate-x11.h +++ b/gdk/x11/gdkprivate-x11.h @@ -139,7 +139,8 @@ gboolean _gdk_moveresize_handle_event (XEvent *event); gboolean _gdk_moveresize_configure_done (GdkDisplay *display, GdkWindow *window); -void _gdk_keymap_state_changed (GdkDisplay *display); +void _gdk_keymap_state_changed (GdkDisplay *display, + XEvent *event); void _gdk_keymap_keys_changed (GdkDisplay *display); gint _gdk_x11_get_group_for_state (GdkDisplay *display, GdkModifierType state);