Exemplo n.º 1
0
static void
_file_monitor_changed_cb (GFileMonitor      *monitor,
                          GFile             *file,
                          GFile             *other_file,
                          GFileMonitorEvent  event,
                          Rebinder          *rebinder)
{
  if (event == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT ||
      event == G_FILE_MONITOR_EVENT_DELETED ||
      event == G_FILE_MONITOR_EVENT_CREATED)
  load_bindings (rebinder);
}
Exemplo n.º 2
0
static inline bool enum_load_bindings(void *data,
		size_t idx, obs_hotkey_t *hotkey)
{
	UNUSED_PARAMETER(idx);

	obs_data_array_t *hotkey_data = obs_data_get_array(data, hotkey->name);
	if (!hotkey_data)
		return true;

	load_bindings(hotkey, hotkey_data);
	obs_data_array_release(hotkey_data);
	return true;
}
Exemplo n.º 3
0
void obs_hotkey_load(obs_hotkey_id id, obs_data_array_t *data)
{
	size_t idx;

	if (!lock())
		return;

	if (find_id(id, &idx)) {
		remove_bindings(id);
		load_bindings(&obs->hotkeys.hotkeys.array[idx], data);
	}
	unlock();
}
Exemplo n.º 4
0
void obs_hotkey_pair_load(obs_hotkey_pair_id id, obs_data_array_t *data0,
		obs_data_array_t *data1)
{
	if ((!data0 && !data1) || !lock())
		return;

	size_t idx;
	if (!find_pair_id(id, &idx))
		goto unlock;

	obs_hotkey_pair_t *pair = &obs->hotkeys.hotkey_pairs.array[idx];

	if (find_id(pair->id[0], &idx)) {
		remove_bindings(pair->id[0]);
		load_bindings(&obs->hotkeys.hotkeys.array[idx], data0);
	}
	if (find_id(pair->id[1], &idx)) {
		remove_bindings(pair->id[1]);
		load_bindings(&obs->hotkeys.hotkeys.array[idx], data1);
	}

unlock:
	unlock();
}
Exemplo n.º 5
0
static inline obs_hotkey_id obs_hotkey_register_internal(
		obs_hotkey_registerer_t type, void *registerer,
		struct obs_context_data *context,
		const char *name, const char *description,
		obs_hotkey_func func, void *data)
{
	if ((obs->hotkeys.next_id + 1) == OBS_INVALID_HOTKEY_ID)
		blog(LOG_WARNING, "obs-hotkey: Available hotkey ids exhausted");

	obs_hotkey_t *base_addr = obs->hotkeys.hotkeys.array;
	obs_hotkey_id result    = obs->hotkeys.next_id++;
	obs_hotkey_t *hotkey    = da_push_back_new(obs->hotkeys.hotkeys);

	hotkey->id              = result;
	hotkey->name            = bstrdup(name);
	hotkey->description     = bstrdup(description);
	hotkey->func            = func;
	hotkey->data            = data;
	hotkey->registerer_type = type;
	hotkey->registerer      = registerer;
	hotkey->pair_partner_id = OBS_INVALID_HOTKEY_PAIR_ID;

	if (context) {
		obs_data_array_t *data =
			obs_data_get_array(context->hotkey_data, name);
		load_bindings(hotkey, data);
		obs_data_array_release(data);

		context_add_hotkey(context, result);
	}

	if (base_addr != obs->hotkeys.hotkeys.array)
		fixup_pointers();

	hotkey_signal("hotkey_register", hotkey);

	return result;
}
Exemplo n.º 6
0
int
main(int argc, char *argv[])
{
  GOptionContext *context;
  GError *error = NULL;

  memset (&the_rebinder, 0, sizeof (Rebinder));

  g_type_init ();

  /* Options */
  context = g_option_context_new ("- key rebinder");

  g_option_context_add_main_entries (context, entries, NULL);
  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_print ("Failed to parse options: %s\n", error->message);
      g_error_free (error);
      return EXIT_FAILURE;
    }

#ifdef REBINDER_ENABLE_DEBUG
  rebinder_debug_init ();
#endif

  if (opt_configure)
    {
      /* lauched in configuration mode */

      if (request_dbus_name (MEX_REBINDER_CONFIGURE_DBUS_INTERFACE) == FALSE)
        {
          g_message ("Could not request DBus name");
          return EXIT_SUCCESS;
        }

      clutter_init (&argc, &argv);

      /* we expect to be build against clutter-glx */
      the_rebinder.dpy = clutter_x11_get_default_display ();

      the_rebinder.config = rebinder_configure (&the_rebinder,
						NULL,
                                                is_evdev_enabled (),
                                                is_fullscreen_enabled ());

      clutter_main ();

      rebinder_configure_free (the_rebinder.config);
    }
  else
    {
      /* launched in daemon mode */
      MexRebinder *rebinder;
      gboolean registered;

      rebinder = mex_rebinder_new ();
      registered = mex_rebinder_register (rebinder,
                                          MEX_REBINDER_DBUS_INTERFACE,
                                          MEX_REBINDER_DBUS_PATH,
                                          &error);
      if (registered == FALSE)
        {
          const gchar prefix[] = "Could not request DBus name";

          if (error)
            g_message ("%s: %s", prefix, error->message);
          else
            g_message ("%s", prefix);

          return EXIT_FAILURE;
        }

      g_signal_connect (rebinder, "quit",
                        G_CALLBACK (on_rebinder_quit), &the_rebinder);

      the_rebinder.dpy = XOpenDisplay (NULL);
      if (G_UNLIKELY (the_rebinder.dpy == NULL))
        {
          g_error ("Could not open display");
          return EXIT_FAILURE;
        }

      the_rebinder.fake = fakekey_init (the_rebinder.dpy);
      if (G_UNLIKELY (the_rebinder.fake == NULL))
        {
          g_error ("Could not initialize fakekey");
          return EXIT_FAILURE;
        }

      if (opt_no_daemon == FALSE)
        daemon (0, 0);

      signal (SIGINT, on_int_term_signaled);
      signal (SIGTERM, on_int_term_signaled);

      the_rebinder.original_bindings =
        g_array_new (FALSE, FALSE, sizeof (Binding));

      /* listens to evdev events and setup everything needed */
      if (is_evdev_enabled ())
        {
          the_rebinder.evdev_manager = rebinder_evdev_manager_get_default ();
          rebinder_evdev_manager_set_key_notifier (the_rebinder.evdev_manager,
                                                   on_evdev_key_pressed,
                                                   &the_rebinder);
          the_rebinder.evdev_bindings =
            g_ptr_array_new_with_free_func (free_binding);
        }

      load_bindings (&the_rebinder);
      setup_monitor (&the_rebinder);

      the_rebinder.mainloop = g_main_loop_new (NULL, TRUE);
      g_main_loop_run (the_rebinder.mainloop);

      restore_bindings (&the_rebinder);

      g_main_loop_unref (the_rebinder.mainloop);
      g_object_unref (the_rebinder.monitor);
    }

  return EXIT_SUCCESS;
}