Beispiel #1
0
/* Startup calls and initializations */
static void clipit_init() {
	/* Create clipboard */
	primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
	clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
	g_timeout_add(CHECK_INTERVAL, item_check, NULL);

	/* Read preferences */
	read_preferences();

	/* Read history */
	if (prefs.save_history)
		read_history();

	/* Bind global keys */
	keybinder_init();
	keybinder_bind(prefs.history_key, history_hotkey, NULL);
	keybinder_bind(prefs.actions_key, actions_hotkey, NULL);
	keybinder_bind(prefs.menu_key, menu_hotkey, NULL);
	keybinder_bind(prefs.search_key, search_hotkey, NULL);
	keybinder_bind(prefs.offline_key, offline_hotkey, NULL);

	/* Create status icon */
	if (!prefs.no_icon)
	{
#ifdef HAVE_APPINDICATOR
	create_app_indicator(1);
#else
	status_icon = gtk_status_icon_new_from_icon_name("clipit-trayicon");
	gtk_status_icon_set_tooltip((GtkStatusIcon*)status_icon, _("Clipboard Manager"));
	g_signal_connect((GObject*)status_icon, "button_press_event", (GCallback)status_icon_clicked, NULL);
#endif
	}
}
Beispiel #2
0
gint init_keybinder(struct con_win *cwin)
{
	keybinder_init ();

	keybinder_bind("XF86AudioPlay", (KeybinderHandler) keybind_play_handler, cwin);
	keybinder_bind("XF86AudioStop", (KeybinderHandler) keybind_stop_handler, cwin);
	keybinder_bind("XF86AudioPrev", (KeybinderHandler) keybind_prev_handler, cwin);
	keybinder_bind("XF86AudioNext", (KeybinderHandler) keybind_next_handler, cwin);
	keybinder_bind("XF86AudioMedia", (KeybinderHandler) keybind_media_handler, cwin);

	return 0;
}
Beispiel #3
0
/* Apply the new preferences */
static void apply_preferences()
{
  /* Unbind the keys before binding new ones */
  keybinder_unbind(prefs.history_key, history_hotkey);
  g_free(prefs.history_key);
  prefs.history_key = NULL;
  keybinder_unbind(prefs.actions_key, actions_hotkey);
  g_free(prefs.actions_key);
  prefs.actions_key = NULL;
  keybinder_unbind(prefs.menu_key, menu_hotkey);
  g_free(prefs.menu_key);
  prefs.menu_key = NULL;
  keybinder_unbind(prefs.search_key, search_hotkey);
  g_free(prefs.search_key);
  prefs.search_key = NULL;
  keybinder_unbind(prefs.offline_key, offline_hotkey);
  g_free(prefs.offline_key);
  prefs.offline_key = NULL;
  
  /* Get the new preferences */
  prefs.use_copy = gtk_toggle_button_get_active((GtkToggleButton*)copy_check);
  prefs.use_primary = gtk_toggle_button_get_active((GtkToggleButton*)primary_check);
  prefs.synchronize = gtk_toggle_button_get_active((GtkToggleButton*)synchronize_check);
  prefs.automatic_paste = gtk_toggle_button_get_active((GtkToggleButton*)paste_check);
  prefs.show_indexes = gtk_toggle_button_get_active((GtkToggleButton*)show_indexes_check);
  prefs.save_uris = gtk_toggle_button_get_active((GtkToggleButton*)save_uris_check);
  prefs.use_rmb_menu = gtk_toggle_button_get_active((GtkToggleButton*)use_rmb_menu_check);
  prefs.save_history = gtk_toggle_button_get_active((GtkToggleButton*)save_check);
  prefs.history_limit = gtk_spin_button_get_value_as_int((GtkSpinButton*)history_spin);
  prefs.items_menu = gtk_spin_button_get_value_as_int((GtkSpinButton*)items_menu);
  prefs.statics_show = gtk_toggle_button_get_active((GtkToggleButton*)statics_show_check);
  prefs.statics_items = gtk_spin_button_get_value_as_int((GtkSpinButton*)statics_items_spin);
  prefs.hyperlinks_only = gtk_toggle_button_get_active((GtkToggleButton*)hyperlinks_check);
  prefs.confirm_clear = gtk_toggle_button_get_active((GtkToggleButton*)confirm_check);
  prefs.single_line = gtk_toggle_button_get_active((GtkToggleButton*)linemode_check);
  prefs.reverse_history = gtk_toggle_button_get_active((GtkToggleButton*)reverse_check);
  prefs.item_length = gtk_spin_button_get_value_as_int((GtkSpinButton*)charlength_spin);
  prefs.ellipsize = gtk_combo_box_get_active((GtkComboBox*)ellipsize_combo) + 1;
  prefs.history_key = g_strdup(gtk_entry_get_text((GtkEntry*)history_key_entry));
  prefs.actions_key = g_strdup(gtk_entry_get_text((GtkEntry*)actions_key_entry));
  prefs.menu_key = g_strdup(gtk_entry_get_text((GtkEntry*)menu_key_entry));
  prefs.search_key = g_strdup(gtk_entry_get_text((GtkEntry*)search_key_entry));
  prefs.offline_key = g_strdup(gtk_entry_get_text((GtkEntry*)offline_key_entry));
  
  /* Bind keys and apply the new history limit */
  keybinder_bind(prefs.history_key, history_hotkey, NULL);
  keybinder_bind(prefs.actions_key, actions_hotkey, NULL);
  keybinder_bind(prefs.menu_key, menu_hotkey, NULL);
  keybinder_bind(prefs.search_key, search_hotkey, NULL);
  keybinder_bind(prefs.offline_key, offline_hotkey, NULL);
  truncate_history();
}
Beispiel #4
0
/* lkeybinder library function 'bind' */
static int lkeybinder_bind (lua_State *L)
{
  int success;
  const char *keystr = luaL_checkstring(L, 1);
  if (!lua_isfunction(L, 2)) {
    return luaL_argerror(L, 2, "is not a function");
  }
  lkeybinder_check_init();
  lua_settop(L, 2);
  /* put table into stack pos 3 */
  lua_rawgeti(L, LUA_REGISTRYINDEX, lkeybinder_reg_key);
  lua_pushstring(L, keystr);
  lua_rawget(L, -2);
  if (!lua_isnil(L, -1)) {
    success = false;
  } else {
    success = keybinder_bind(keystr, lkeybinder_handler, L);
    if (success) {
      lua_pushstring(L, keystr);
      lua_pushvalue(L, 2);
      lua_rawset(L, 3);
    }
  }

  lua_pushboolean(L, success);
  return 1;
}
Beispiel #5
0
static PyObject *
GlobalHotkey_bind (GlobalHotkey *self,
                   PyObject     *args)
{
  const char *key;
  PyObject *extra;
  PyObject *tmp;
  CallableObject *co;

  extra = NULL;
  tmp = NULL;
  co = malloc (sizeof (CallableObject));

  co->callback = NULL;
  co->params = PyTuple_New (extra ? 2 : 1);

  if (!PyArg_ParseTuple (args, "sO|O", &key, &tmp, &extra))
    return NULL;

  Py_INCREF (tmp);
  co->callback = tmp;

  /* Already binded keys should be unbinded before binding again */
  if (PyDict_GetItemString (self->binded, key) != NULL)
    PyErr_Format (PyExc_Exception, "Key %s already binded", key);

  PyTuple_SetItem (co->params, 0, PyString_FromString (key));
  if (extra)
    PyTuple_SetItem (co->params, 1, extra);

  /* Is it a valid python callback? */
  if (PyCallable_Check (co->callback))
    {
      /* Let's try to bind the key, if it is not possible, a False
         python value is returned. */
      if (keybinder_bind (key, caller, co))
        {
          /* If it is not possible to add the entry to the binded
             dict, we should not bind the key */
          if (PyDict_SetItemString (self->binded, key, co->callback) != 0)
            {
              keybinder_unbind (key, caller);
              return Py_BuildValue ("i", 0);
            }
          else
            return Py_BuildValue ("i", 1);
        }
      else
        return Py_BuildValue ("i", 0);
    }

  PyErr_SetString (PyExc_TypeError, "First param must be callable.");
  Py_DECREF (extra);

  return NULL;
}
Beispiel #6
0
int main (int argc, char *argv[])
{
  gtk_init(&argc, &argv);

  keybinder_init();
  keybinder_bind(EXAMPLE_KEY, handler, NULL);
  printf("Press " EXAMPLE_KEY " to activate keybinding and quit\n");

  gtk_main();
  return 0;
}
Beispiel #7
0
static void
key_combination_key_changed_callback(GConfClient *client,
		    guint        cnxn_id,
		    GConfEntry  *entry,
		    gpointer     user_data)
{
	hasChanged = 1;
	keybinder_unbind(popupKey, keyhandler);
	GConfValue *value = gconf_entry_get_value(entry);
	popupKey = g_strdup(gconf_value_get_string(value));
	keybinder_bind(popupKey, keyhandler, NULL);
	gtk_tooltips_set_tip(toolTip, GTK_WIDGET(user_data), g_strdup_printf(_("Glipper (%s)\nClipboardmanager"),
						popupKey), "Glipper");
	gtk_entry_set_text((GtkEntry*)keyCombEntry, popupKey);
}
Beispiel #8
0
static void activate(GtkApplication *app, gpointer user_data) {
	GList *list = gtk_application_get_windows(app);

	if (list) {
		gtk_window_present(GTK_WINDOW(list->data));
	} else {
		HandyWindow *window = handy_window_new(app);

		handy_window_setup(window);

		gtk_window_set_application(GTK_WINDOW(window), app);
		gtk_widget_show_all(GTK_WIDGET(window));

		keybinder_init();
		keybinder_bind("F10", handy_show_hide, window);
	}
}
/*
 *	NOTE: this is only used for initializing gsettings_ht.
 *	@gsettings_ht: gsettings key --> KeysAndCmd
 */
void
gsd_kb_util_read_gsettings (GSettings* settings, GHashTable* gsettings_ht)
{
    //fixed by Long Wei
	//char* _gsettings_key_str = NULL;
	//char* _gsettings_value_str = NULL;
	KeysAndCmd* _kandc_ptr = NULL;
	//1. read default key 
	
	//2. read other keys.
	int i =0;
	for (; i < NUM_OF_KEY_BINDING_SLOTS; i++)
	{
	    //use macros defined in gsd-key-bindings-settings.h
	    gchar* _gsettings_key_str = NULL;
	    gchar* _gsettings_value_str = NULL;

	    _gsettings_key_str = g_strdup_printf (KEY_BINDING_KEY_PREFIX"%d", i + 1); 
	    g_debug ("gsettings key : %s", _gsettings_key_str);
	    _gsettings_value_str = g_settings_get_string (settings, _gsettings_key_str);
        if ( _gsettings_value_str == NULL ) {
            continue;
        }
	    _kandc_ptr = gsd_kb_util_parse_gsettings_value (_gsettings_key_str,
							    _gsettings_value_str);

        g_free (_gsettings_value_str);

	    if (_kandc_ptr == NULL)
	    {
		g_debug ("new KeysAndCmd is NULL");
		continue;
	    }

	    KeybinderHandler _handler = gsd_kb_handler_default;

	    g_debug ("bind %s -----> %s", _kandc_ptr->keystring, _kandc_ptr->cmdstring);
	    keybinder_bind (_kandc_ptr->keystring, _handler, _kandc_ptr->cmdstring);
	    
	    g_hash_table_insert (gsettings_ht, g_strdup (_gsettings_key_str), _kandc_ptr);

        g_free (_gsettings_key_str);
	}
}
Beispiel #10
0
void
xvd_keys_init(XvdInstance *Inst)
{
    keybinder_init();

    keybinder_bind ("XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Ctrl>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Alt>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Super>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Shift>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Ctrl><Shift>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Ctrl><Alt>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Ctrl><Super>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Alt><Shift>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Alt><Super>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Shift><Super>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Ctrl><Shift><Super>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Ctrl><Shift><Alt>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Ctrl><Alt><Super>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Shift><Alt><Super>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    keybinder_bind ("<Ctrl><Shift><Alt><Super>XF86AudioRaiseVolume", xvd_raise_handler, Inst);
    
    
    keybinder_bind ("XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Ctrl>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Alt>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Super>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Shift>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Ctrl><Shift>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Ctrl><Alt>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Ctrl><Super>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Alt><Shift>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Alt><Super>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Shift><Super>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Ctrl><Shift><Super>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Ctrl><Shift><Alt>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Ctrl><Alt><Super>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Shift><Alt><Super>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    keybinder_bind ("<Ctrl><Shift><Alt><Super>XF86AudioLowerVolume", xvd_lower_handler, Inst);
    
    
    keybinder_bind ("XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Ctrl>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Alt>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Super>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Shift>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Ctrl><Shift>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Ctrl><Alt>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Ctrl><Super>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Alt><Shift>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Alt><Super>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Shift><Super>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Ctrl><Shift><Super>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Ctrl><Shift><Alt>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Ctrl><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Shift><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst);
    keybinder_bind ("<Ctrl><Shift><Alt><Super>XF86AudioMute", xvd_mute_handler, Inst);
}