gboolean
match_xi2_key (Key *key, XIDeviceEvent *event)
{
	guint keyval;
	GdkModifierType consumed;
	gint group;
	guint keycode, state;

	if (key == NULL)
		return FALSE;

	setup_modifiers ();

	state = device_xi2_translate_state (&event->mods, &event->group);

	if (have_xkb (event->display))
		group = XkbGroupForCoreState (state);
	else
		group = (state & GDK_KEY_Mode_switch) ? 1 : 0;

	keycode = event->detail;

	/* Check if we find a keysym that matches our current state */
	if (gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), keycode,
						 state, group,
						 &keyval, NULL, NULL, &consumed)) {
		guint lower, upper;
		guint mask;

		/* The Key structure contains virtual modifiers, whereas
		 * the XEvent will be using the real modifier, so translate those */
		mask = key->state;
		gdk_keymap_map_virtual_modifiers (gdk_keymap_get_default (), &mask);

		gdk_keyval_convert_case (keyval, &lower, &upper);

		/* If we are checking against the lower version of the
		 * keysym, we might need the Shift state for matching,
		 * so remove it from the consumed modifiers */
		if (lower == key->keysym)
			consumed &= ~GDK_SHIFT_MASK;

		return ((lower == key->keysym || upper == key->keysym)
			&& (state & ~consumed & gsd_used_mods) == mask);
	}

	/* The key we passed doesn't have a keysym, so try with just the keycode */
        return (key != NULL
                && key->state == (state & gsd_used_mods)
                && key_uses_keycode (key, keycode));
}
/* Given a hardware keycode, return the keyval which would have been returned if
   the key were unshifted */
static guint
unshift_keysym( guint keycode, gint group )
{
  GdkKeymapKey *maps;
  guint *keyvals, i, r = GDK_KEY_VoidSymbol, r2 = GDK_KEY_VoidSymbol;
  gint count;

  gdk_keymap_get_entries_for_keycode( gdk_keymap_get_default(), keycode,
                                      &maps, &keyvals, &count );

  for( i = 0; i < count; i++ ) {
    if( maps[i].group == group && maps[i].level == 0 ) {
      r = keyvals[i];
      break;
    }
    if( maps[i].group == 0 && maps[i].level == 0 ) {
      r2 = keyvals[i];
    }
  }
  if (i == count)
	  r = r2;

  g_free( keyvals ); g_free( maps );

  return r;
}
static gboolean
key_pressed_cb (GtkWidget *widget,
                GdkEvent *event,
                gpointer user_data)
{
#if !GDK_KEY_Tab
	#define GDK_KEY_Tab GDK_Tab
#endif

	GdkKeymapKey *keys = NULL;
	gint n_keys;

	/*
	 * Tab should behave the same way as Enter (cycling on cells).
	 *
	 * Previously, we had finished cell editing, which appeared to work:
	 *   gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (widget));
	 * But unfortunately, it showed up crash occurred with XIM input (GTK_IM_MODULE=xim).
	 * https://bugzilla.redhat.com/show_bug.cgi?id=747368
	 */
	if (event->type == GDK_KEY_PRESS && event->key.keyval == GDK_KEY_Tab) {
		/* Get hardware keycode for GDK_KEY_Return */
		if (gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), GDK_KEY_Return, &keys, &n_keys)) {
			/* Change 'Tab' to 'Enter' key */
			event->key.keyval = GDK_KEY_Return;
			event->key.hardware_keycode = keys[0].keycode;
		}
		g_free (keys);
	}

	return FALSE;
}
Exemple #4
0
gboolean
on_mainwin_key_press_event             (GtkWidget       *widget,
                                        GdkEventKey     *event,
                                        gpointer         user_data)
{
    // local hotkeys
    GdkModifierType consumed;
    guint accel_key;
    gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), event->hardware_keycode, event->state, 0, &accel_key, NULL, NULL, &consumed);
    if (accel_key == GDK_ISO_Left_Tab)
        accel_key = GDK_Tab;
    int mods = event->state & gtk_accelerator_get_default_mod_mask ();
    mods &= ~(consumed&~GDK_SHIFT_MASK);
    int lower = gdk_keyval_to_lower (accel_key);
    if (lower != accel_key) {
        accel_key = lower;
    }
    trace ("pressed: keycode: %x, mods: %x, hw: %x, translated: %x\n", event->keyval, mods, event->hardware_keycode, accel_key);

    DB_plugin_t *hkplug = deadbeef->plug_get_for_id ("hotkeys");
    if (hkplug) {
        int ctx;
        DB_plugin_action_t *act = ((DB_hotkeys_plugin_t *)hkplug)->get_action_for_keycombo (accel_key, mods, 0, &ctx);
        if (act && act->callback2) {
            trace ("executing action %s in ctx %d\n", act->name, ctx);
            act->callback2 (act, ctx);
            return TRUE;
        }
        else if (act && act->callback) {
            gtkui_exec_action_14 (act, -1);
        }
    }
    trace ("action not found\n");
    return FALSE;
}
Exemple #5
0
  bool XKeybinder::get_accel_keys(const std::string & key, guint & keyval, 
                              Gdk::ModifierType & mods)
  {
    keyval = 0;
    mods = (Gdk::ModifierType)0;

    try {
      std::string binding = Preferences::obj().get_schema_settings(
          Preferences::SCHEMA_KEYBINDINGS)->get_string(key);
      if (binding.empty() || binding == "disabled") {
        return false;
      }

      EggVirtualModifierType virtual_mods = (EggVirtualModifierType)0;
      if (!egg_accelerator_parse_virtual (binding.c_str(),
                                          &keyval,
                                          &virtual_mods)) {
        return false;
      }

      GdkKeymap *keymap = gdk_keymap_get_default();
      GdkModifierType pmods = (GdkModifierType)0;
      egg_keymap_resolve_virtual_modifiers (keymap,
                                            virtual_mods,
                                            &pmods);
      mods = (Gdk::ModifierType)pmods;
    } 
    catch  (...) {
      return false;
    }
    return true;
  }
Exemple #6
0
static gboolean
window_key_press_event (GtkWidget *win, GdkEventKey *event, GsShell *shell)
{
	GsShellPrivate *priv = gs_shell_get_instance_private (shell);
	GdkKeymap *keymap;
	GdkModifierType state;
	gboolean is_rtl;
	GtkWidget *button;

	button = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_back"));
	if (!gtk_widget_is_visible (button) || !gtk_widget_is_sensitive (button))
	    	return GDK_EVENT_PROPAGATE;

	state = event->state;
	keymap = gdk_keymap_get_default ();
	gdk_keymap_add_virtual_modifiers (keymap, &state);
	state = state & gtk_accelerator_get_default_mod_mask ();
	is_rtl = gtk_widget_get_direction (button) == GTK_TEXT_DIR_RTL;

	if ((!is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Left) ||
	    (is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Right) ||
	    event->keyval == GDK_KEY_Back) {
		gtk_widget_activate (button);
		return GDK_EVENT_STOP;
	}

	return GDK_EVENT_PROPAGATE;
}
Exemple #7
0
void cell_renderer_key_set_scancode (CellRendererKey *key, gint scancode)
{
  gboolean changed;

  g_return_if_fail (IS_CELL_RENDERER_KEY(key));

  g_object_freeze_notify(G_OBJECT(key));

  changed = FALSE;
  
  if (scancode != key->scancode) {
    key->scancode = scancode;
    g_object_notify(G_OBJECT(key), "scancode");
    changed = TRUE;
  }

  g_object_thaw_notify(G_OBJECT(key));

  if (changed) {
      const gchar *text;
      /* sync string to the key values */
      if (scancode <= 0) {
      	text = "None";
      } else {
        guint keyval = 0;

        gdk_keymap_translate_keyboard_state(gdk_keymap_get_default(),
      	  scancode, 0, 0, &keyval, NULL, NULL, NULL);
        text = gdk_keyval_name(keyval);
      }
      g_object_set(key, "text", text, NULL);
  }
}
Exemple #8
0
static gboolean emitKeyStroke(WebKitWebView* webView)
{
    GdkEvent* pressEvent = gdk_event_new(GDK_KEY_PRESS);
    pressEvent->key.keyval = GDK_KEY_f;
    GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(webView));
    pressEvent->key.window = window;
    g_object_ref(pressEvent->key.window);

#ifndef GTK_API_VERSION_2
    GdkDeviceManager* manager = gdk_display_get_device_manager(gdk_window_get_display(window));
    gdk_event_set_device(pressEvent, gdk_device_manager_get_client_pointer(manager));
#endif

    // When synthesizing an event, an invalid hardware_keycode value
    // can cause it to be badly processed by Gtk+.
    GdkKeymapKey* keys;
    gint n_keys;
    if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), GDK_KEY_f, &keys, &n_keys)) {
        pressEvent->key.hardware_keycode = keys[0].keycode;
        g_free(keys);
    }

    GdkEvent* releaseEvent = gdk_event_copy(pressEvent);
    gtk_main_do_event(pressEvent);
    gdk_event_free(pressEvent);
    releaseEvent->key.type = GDK_KEY_RELEASE;
    gtk_main_do_event(releaseEvent);
    gdk_event_free(releaseEvent);

    return FALSE;
}
Exemple #9
0
void ripcurl_init(void)
{
	/* webkit settings */
	ripcurl->Global.webkit_settings = webkit_web_settings_new();

	/* libsoup session */
	ripcurl->Global.soup_session = webkit_get_default_session();

	/* browser list */
	ripcurl->Global.browsers = NULL;

	/* bookmarks list */
	ripcurl->Global.bookmarks = NULL;

	/* history list */
	ripcurl->Global.history = NULL;

	/* command history list */
	ripcurl->Global.command_history = NULL;

	/* GDK keymap */
	ripcurl->Global.keymap = gdk_keymap_get_default();

	/* create config dir */
	ripcurl->Files.config_dir = g_build_filename(g_get_user_config_dir(), "ripcurl", NULL);
	g_mkdir_with_parents(ripcurl->Files.config_dir, 0771);
}
Exemple #10
0
guint
gdk_keymap_lookup_key (GdkKeymap          *keymap,
                       const GdkKeymapKey *key)
{
  guint sym;

  g_return_val_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap), 0);
  g_return_val_if_fail (key != NULL, 0);
  g_return_val_if_fail (key->group < 4, 0);
  
  /* Accept only the default keymap */
  if (keymap != NULL && keymap != gdk_keymap_get_default ())
    return 0;

  update_keymap ();
  
  if (key->keycode >= 256 ||
      key->group < 0 || key->group >= 2 ||
      key->level < 0 || key->level >= 2)
    return 0;
  
  sym = keysym_tab[key->keycode*4 + key->group*2 + key->level];
  
  if (sym == GDK_VoidSymbol)
    return 0;
  else
    return sym;
}
void WebViewTest::keyStroke(unsigned keyVal, unsigned keyModifiers)
{
    g_assert(m_parentWindow);
    GtkWidget* viewWidget = GTK_WIDGET(m_webView);
    g_assert(gtk_widget_get_realized(viewWidget));

    GOwnPtr<GdkEvent> event(gdk_event_new(GDK_KEY_PRESS));
    event->key.keyval = keyVal;

    event->key.time = GDK_CURRENT_TIME;
    event->key.window = gtk_widget_get_window(viewWidget);
    g_object_ref(event->key.window);
    gdk_event_set_device(event.get(), gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(viewWidget))));
    event->key.state = keyModifiers;

    // When synthesizing an event, an invalid hardware_keycode value can cause it to be badly processed by GTK+.
    GOwnPtr<GdkKeymapKey> keys;
    int keysCount;
    if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), keyVal, &keys.outPtr(), &keysCount))
        event->key.hardware_keycode = keys.get()[0].keycode;

    gtk_main_do_event(event.get());
    event->key.type = GDK_KEY_RELEASE;
    gtk_main_do_event(event.get());
}
static void
setup_modifiers (void)
{
        if (msd_used_mods == 0 || msd_ignored_mods == 0) {
                GdkModifierType dynmods;

                /* default modifiers */
                msd_ignored_mods = \
                        0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | GDK_HYPER_MASK;
		msd_used_mods = \
                        GDK_SHIFT_MASK | GDK_CONTROL_MASK |\
                        GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK |\
                        GDK_MOD5_MASK | GDK_SUPER_MASK | GDK_META_MASK;

                /* NumLock can be assigned to varying keys so we need to
                 * resolve and ignore it specially */
                dynmods = 0;
                egg_keymap_resolve_virtual_modifiers (gdk_keymap_get_default (),
                                                      EGG_VIRTUAL_NUM_LOCK_MASK,
                                                      &dynmods);

                msd_ignored_mods |= dynmods;
                msd_used_mods &= ~dynmods;
	}
}
Exemple #13
0
void disp_win_kbm_capslock_init()
{
  old_capslock_on = gdk_keymap_get_caps_lock_state(gdk_keymap_get_default());
//  dbg("disp_win_kbm_capslock_init %d\n",old_capslock_on);

  if (b_show_win_kbm)
    win_kbm_disp_caplock();
}
Exemple #14
0
/**
 * Extract the keyval of the key event if no modifier keys were pressed -
 * in other words get the keyval of the key by itself. The other way around
 * would be to use the hardware keysyms directly rather than the keyvals,
 * but the mapping looks to be messier.
 */
uint16_t gtk_get_unmodified_keyval( GdkEventKey *event )
{
    GdkKeymap *keymap = gdk_keymap_get_default();
    guint keyval;

    gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval, 
                                         NULL, NULL, NULL );
    return keyval;
}
static guint32 get_keyboard_lock_modifiers(void)
{
    guint32 modifiers = 0;
#if GTK_CHECK_VERSION(3,18,0)
    GdkKeymap *keyboard = gdk_keymap_get_default();

    if (gdk_keymap_get_caps_lock_state(keyboard)) {
        modifiers |= SPICE_INPUTS_CAPS_LOCK;
    }

    if (gdk_keymap_get_num_lock_state(keyboard)) {
        modifiers |= SPICE_INPUTS_NUM_LOCK;
    }

    if (gdk_keymap_get_scroll_lock_state(keyboard)) {
        modifiers |= SPICE_INPUTS_SCROLL_LOCK;
    }
#else
#if HAVE_X11_XKBLIB_H
    Display *x_display = NULL;
    XKeyboardState keyboard_state;

    GdkScreen *screen = gdk_screen_get_default();
    if (!GDK_IS_X11_DISPLAY(gdk_screen_get_display(screen))) {
        SPICE_DEBUG("FIXME: gtk backend is not X11");
        return 0;
    }

    x_display = GDK_SCREEN_XDISPLAY(screen);
    XGetKeyboardControl(x_display, &keyboard_state);

    if (keyboard_state.led_mask & 0x01) {
        modifiers |= SPICE_INPUTS_CAPS_LOCK;
    }
    if (keyboard_state.led_mask & 0x02) {
        modifiers |= SPICE_INPUTS_NUM_LOCK;
    }
    if (keyboard_state.led_mask & 0x04) {
        modifiers |= SPICE_INPUTS_SCROLL_LOCK;
    }
#elif defined(G_OS_WIN32)
    if (GetKeyState(VK_CAPITAL) & 1) {
        modifiers |= SPICE_INPUTS_CAPS_LOCK;
    }
    if (GetKeyState(VK_NUMLOCK) & 1) {
        modifiers |= SPICE_INPUTS_NUM_LOCK;
    }
    if (GetKeyState(VK_SCROLL) & 1) {
        modifiers |= SPICE_INPUTS_SCROLL_LOCK;
    }
#else
    g_warning("get_keyboard_lock_modifiers not implemented");
#endif // HAVE_X11_XKBLIB_H
#endif // GTK_CHECK_VERSION(3,18,0)
    return modifiers;
}
Exemple #16
0
static bool
clean_mask(guint hardware_keycode, GdkModifierType state, gint group, guint* clean, guint* keyval)
{
  GdkModifierType consumed = 0;
  if ((gdk_keymap_translate_keyboard_state(
        gdk_keymap_get_default(),
        hardware_keycode,
        state, group,
        keyval,
        NULL,
        NULL,
        &consumed)
      ) == FALSE) {
    return false;
  }

  if (clean != NULL) {
    *clean = state & ~consumed & ALL_ACCELS_MASK;
  }

  /* numpad numbers */
  switch (*keyval) {
    case GDK_KEY_KP_0:
      *keyval = GDK_KEY_0;
      break;
    case GDK_KEY_KP_1:
      *keyval = GDK_KEY_1;
      break;
    case GDK_KEY_KP_2:
      *keyval = GDK_KEY_2;
      break;
    case GDK_KEY_KP_3:
      *keyval = GDK_KEY_3;
      break;
    case GDK_KEY_KP_4:
      *keyval = GDK_KEY_4;
      break;
    case GDK_KEY_KP_5:
      *keyval = GDK_KEY_5;
      break;
    case GDK_KEY_KP_6:
      *keyval = GDK_KEY_6;
      break;
    case GDK_KEY_KP_7:
      *keyval = GDK_KEY_7;
      break;
    case GDK_KEY_KP_8:
      *keyval = GDK_KEY_8;
      break;
    case GDK_KEY_KP_9:
      *keyval = GDK_KEY_9;
      break;
  }

  return true;
}
Exemple #17
0
/* Set the keymap entries */
void vnc_display_keyval_set_entries(void)
{
	size_t i;
	if (ref_count_for_untranslated_keys == 0)
		for (i = 0; i < sizeof(untranslated_keys) / sizeof(untranslated_keys[0]); i++)
			gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(),
							  untranslated_keys[i].keyval,
							  &untranslated_keys[i].keys,
							  &untranslated_keys[i].n_keys);
	ref_count_for_untranslated_keys++;
}
Exemple #18
0
GdkEventKey *
ide_gdk_synthesize_event_keyval (GdkWindow *window,
                                 guint      keyval)
{
  GdkDisplay *display;
  GdkDeviceManager *device_manager;
  GdkDevice *client_pointer;
  GdkEvent *ev;
  GdkKeymapKey *keys = NULL;
  gint n_keys = 0;
  gchar str[8] = { 0 };
  gunichar ch;

  g_assert (window != NULL);
  g_assert (GDK_IS_WINDOW (window));

  ch = gdk_keyval_to_unicode (keyval);
  g_unichar_to_utf8 (ch, str);

  ev = gdk_event_new (GDK_KEY_PRESS);
  ev->key.window = g_object_ref (window);
  ev->key.send_event = TRUE;
  ev->key.time = gtk_get_current_event_time ();
  ev->key.state = 0;
  ev->key.hardware_keycode = 0;
  ev->key.group = 0;
  ev->key.is_modifier = 0;
  ev->key.keyval = keyval;
  ev->key.string = g_strdup (str);
  ev->key.length = strlen (str);

  gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (),
                                     ev->key.keyval,
                                     &keys,
                                     &n_keys);

  if (n_keys > 0)
    {
      ev->key.hardware_keycode = keys [0].keycode;
      ev->key.group = keys [0].group;
      if (keys [0].level == 1)
        ev->key.state |= GDK_SHIFT_MASK;
      g_free (keys);
    }

  display = gdk_window_get_display (ev->any.window);
  device_manager = gdk_display_get_device_manager (display);
  client_pointer = gdk_device_manager_get_client_pointer (device_manager);
  gdk_event_set_device (ev, gdk_device_get_associated_device (client_pointer));

  return &ev->key;
}
/* Change key in @event to 'Enter' key. */
void
utils_fake_return_key (GdkEventKey *event)
{
	GdkKeymapKey *keys = NULL;
	gint n_keys;

	/* Get hardware keycode for GDK_KEY_Return */
	if (gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), GDK_KEY_Return, &keys, &n_keys)) {
		event->keyval = GDK_KEY_Return;
		event->hardware_keycode = keys[0].keycode;
		event->state = 0;
	}
	g_free (keys);
}
Exemple #20
0
void disp_win_kbm_capslock()
{
  if (!b_show_win_kbm)
    return;

  gboolean o_state = old_capslock_on;
  old_capslock_on = gdk_keymap_get_caps_lock_state(gdk_keymap_get_default());

//  dbg("%x %x\n", old_capslock_on, o_state);

  if (o_state != old_capslock_on) {
    win_kbm_disp_caplock();
  }
}
static gboolean
do_grab_key (Binding *binding)
{
	GdkKeymap *keymap = gdk_keymap_get_default ();
	GdkWindow *rootwin = gdk_get_default_root_window ();

	EggVirtualModifierType virtual_mods = 0;
	guint keysym = 0;

	if (keymap == NULL || rootwin == NULL)
		return FALSE;

	if (!egg_accelerator_parse_virtual (binding->keystring,
					    &keysym,
					    &virtual_mods))
		return FALSE;

	TRACE (g_print ("Got accel %d, %d\n", keysym, virtual_mods));

	binding->keycode = XKeysymToKeycode (GDK_WINDOW_XDISPLAY (rootwin),
					     keysym);
	if (binding->keycode == 0)
		return FALSE;

	TRACE (g_print ("Got keycode %d\n", binding->keycode));

	egg_keymap_resolve_virtual_modifiers (keymap,
					      virtual_mods,
					      &binding->modifiers);
	if (binding->modifiers == 0)
		return FALSE;

	TRACE (g_print ("Got modmask %d\n", binding->modifiers));

	gdk_error_trap_push ();

	grab_ungrab_with_ignorable_modifiers (rootwin,
					      binding,
					      TRUE /* grab */);

	gdk_flush ();

	if (gdk_error_trap_pop ()) {
	   g_warning ("Binding '%s' failed!\n", binding->keystring);
	   return FALSE;
	}

	return TRUE;
}
void
cd_keybinder_stop (void)
{
	GdkKeymap *keymap = gdk_keymap_get_default ();
	GdkWindow *rootwin = gdk_get_default_root_window ();

	num_lock_mask=0, caps_lock_mask=0, scroll_lock_mask=0;

	g_signal_handlers_disconnect_by_func (keymap,
		G_CALLBACK (keymap_changed),
		NULL);
	
	gdk_window_remove_filter (rootwin,
		filter_func,
		NULL);
}
static void spice_gtk_session_init(SpiceGtkSession *self)
{
    SpiceGtkSessionPrivate *s;
    GdkKeymap *keymap = gdk_keymap_get_default();

    s = self->priv = SPICE_GTK_SESSION_GET_PRIVATE(self);

    s->clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
    g_signal_connect(G_OBJECT(s->clipboard), "owner-change",
                     G_CALLBACK(clipboard_owner_change), self);
    s->clipboard_primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
    g_signal_connect(G_OBJECT(s->clipboard_primary), "owner-change",
                     G_CALLBACK(clipboard_owner_change), self);
    spice_g_signal_connect_object(keymap, "state-changed",
                                  G_CALLBACK(keymap_modifiers_changed), self, 0);
}
static gboolean
window_key_press_event (GtkWidget          *win,
			GdkEventKey        *event,
			GnomeControlCenter *self)
{
  GdkKeymap *keymap;
  gboolean retval;
  GdkModifierType state;

  if (event->state == 0)
    return FALSE;

  retval = FALSE;
  state = event->state;
  keymap = gdk_keymap_get_default ();
  gdk_keymap_add_virtual_modifiers (keymap, &state);
  state = state & gtk_accelerator_get_default_mod_mask ();

  if (state == GDK_CONTROL_MASK)
    {
      switch (event->keyval)
        {
          case GDK_KEY_s:
          case GDK_KEY_S:
          case GDK_KEY_f:
          case GDK_KEY_F:
            if (gtk_widget_get_visible (self->priv->search_entry))
              {
                gtk_widget_grab_focus (self->priv->search_entry);
                retval = TRUE;
              }
            break;
          case GDK_KEY_Q:
          case GDK_KEY_q:
            g_object_unref (self);
            retval = TRUE;
            break;
          case GDK_KEY_W:
          case GDK_KEY_w:
            if (notebook_get_selected_page (self->priv->notebook) != self->priv->scrolled_window)
              shell_show_overview_page (self);
            retval = TRUE;
            break;
        }
    }
  return retval;
}
/* Owen magic */
static GdkFilterReturn
filter (GdkXEvent *xevent,
        GdkEvent  *event,
        gpointer   data)
{
  XEvent *xev = (XEvent *) xevent;
  guint keyval;
  gint group;

  GdkScreen *screen = (GdkScreen *)data;

  if (xev->type == KeyPress || xev->type == KeyRelease)
    {
      /* get the keysym */
      group = (xev->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;
      gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (),
                                           xev->xkey.keycode,
                                           xev->xkey.state,
                                           group,
                                           &keyval,
                                           NULL, NULL, NULL);
      if (keyval == GDK_Control_L || keyval == GDK_Control_R)
        {
          if (xev->type == KeyPress)
            {
              XAllowEvents (xev->xkey.display,
                            SyncKeyboard,
                            xev->xkey.time);
            }
          else
            {
              XAllowEvents (xev->xkey.display,
                            AsyncKeyboard,
                            xev->xkey.time);
              gsd_locate_pointer (screen);
            }
        }
      else
        {
          XAllowEvents (xev->xkey.display,
                        ReplayKeyboard,
                        xev->xkey.time);
          XUngrabKeyboard (gdk_x11_get_default_xdisplay (),
                           xev->xkey.time);
        }
    }
void
tomboy_keybinder_init (void)
{
	GdkKeymap *keymap = gdk_keymap_get_default ();
	GdkWindow *rootwin = gdk_get_default_root_window ();

	lookup_ignorable_modifiers (keymap);

	gdk_window_add_filter (rootwin,
			       filter_func,
			       NULL);

	g_signal_connect (keymap,
			  "keys_changed",
			  G_CALLBACK (keymap_changed),
			  NULL);
}
    void sendKeyEventToFilter(unsigned gdkKeyValue, GdkEventType type, unsigned modifiers = 0)
    {
        GdkEvent* event = gdk_event_new(type);
        event->key.keyval = gdkKeyValue;
        event->key.state = modifiers;
        event->key.window = gtk_widget_get_window(m_testWindow);
        event->key.time = GDK_CURRENT_TIME;
        g_object_ref(event->key.window);
        gdk_event_set_device(event, gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_display_get_default())));

        GUniqueOutPtr<GdkKeymapKey> keys;
        gint nKeys;
        if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), gdkKeyValue, &keys.outPtr(), &nKeys))
            event->key.hardware_keycode = keys.get()[0].keycode;

        filterKeyEvent(&event->key);
        gdk_event_free(event);
    }
static JSValueRef runPasteTestCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    gtk_widget_grab_focus(GTK_WIDGET(currentFixture->webView));

    // Simulate a paste keyboard sequence.
    GdkEvent* event = gdk_event_new(GDK_KEY_PRESS);
    event->key.keyval = gdk_unicode_to_keyval('v');
    event->key.state = GDK_CONTROL_MASK;
    event->key.window = gtk_widget_get_window(GTK_WIDGET(currentFixture->webView));
    g_object_ref(event->key.window);
#ifndef GTK_API_VERSION_2
    GdkDeviceManager* manager =  gdk_display_get_device_manager(gdk_window_get_display(event->key.window));
    gdk_event_set_device(event, gdk_device_manager_get_client_pointer(manager));
#endif

    GdkKeymapKey* keys;
    gint n_keys;
    if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), event->key.keyval, &keys, &n_keys)) {
        event->key.hardware_keycode = keys[0].keycode;
        g_free(keys);
    }

    gtk_main_do_event(event);
    event->key.type = GDK_KEY_RELEASE;
    gtk_main_do_event(event);
    gdk_event_free(event);

    JSStringRef scriptString = JSStringCreateWithUTF8CString("document.body.innerHTML;");
    JSValueRef value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
    JSStringRelease(scriptString);

    g_assert(JSValueIsString(context, value));
    JSStringRef actual = JSValueToStringCopy(context, value, exception);
    g_assert(!exception || !*exception);
    g_assert(currentFixture->info->expectedContent);
    JSStringRef expected = JSStringCreateWithUTF8CString(currentFixture->info->expectedContent);
    g_assert(JSStringIsEqual(expected, actual));

    JSStringRelease(expected);
    JSStringRelease(actual);
    g_main_loop_quit(currentFixture->loop);
    return JSValueMakeUndefined(context);
}
static void doKeyStroke(GtkWidget* viewWidget, unsigned int keyVal)
{
    GUniquePtr<GdkEvent> event(gdk_event_new(GDK_KEY_PRESS));
    event->key.keyval = keyVal;
    event->key.time = GDK_CURRENT_TIME;
    event->key.state = 0;
    event->key.window = gtk_widget_get_window(viewWidget);
    g_object_ref(event->key.window);
    gdk_event_set_device(event.get(), gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(viewWidget))));

    // When synthesizing an event, an invalid hardware_keycode value can cause it to be badly processed by GTK+.
    GOwnPtr<GdkKeymapKey> keys;
    int keysCount;
    if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), keyVal, &keys.outPtr(), &keysCount))
        event->key.hardware_keycode = keys.get()[0].keycode;

    gtk_main_do_event(event.get());
    event->key.type = GDK_KEY_RELEASE;
    gtk_main_do_event(event.get());
}
static void
keymap_changed (GdkKeymap *map)
{
	GdkKeymap *keymap = gdk_keymap_get_default ();
	GSList *iter;

	TRACE (g_print ("Keymap changed! Regrabbing keys..."));

	for (iter = bindings; iter != NULL; iter = iter->next) {
		Binding *binding = (Binding *) iter->data;
		do_ungrab_key (binding);
	}

	lookup_ignorable_modifiers (keymap);

	for (iter = bindings; iter != NULL; iter = iter->next) {
		Binding *binding = (Binding *) iter->data;
		do_grab_key (binding);
	}
}