#include "config.h"
#include <glib.h>
-#include <glib-object.h>
-#include <glib/gi18n-lib.h>
-#include <gmodule.h>
#include <dbus/dbus-glib.h>
#include <string.h>
#include "ev-marshal.h"
+enum {
+ KEY_PRESSED,
+ LAST_SIGNAL
+};
+
struct _EvMediaPlayerKeys
{
GObject parent;
- DBusGProxy *media_player_keys_proxy;
- EvWindow *window;
+
+ DBusGProxy *proxy;
};
struct _EvMediaPlayerKeysClass
{
GObjectClass parent_class;
+
+ /* Signals */
+ void (* key_pressed) (EvMediaPlayerKeys *keys,
+ const gchar *key);
};
+static guint signals[LAST_SIGNAL] = { 0 };
+
G_DEFINE_TYPE (EvMediaPlayerKeys, ev_media_player_keys, G_TYPE_OBJECT)
-static void ev_media_player_keys_init (EvMediaPlayerKeys *keys);
-static void ev_media_player_keys_finalize (GObject *object);
+static void ev_media_player_keys_finalize (GObject *object);
static void
ev_media_player_keys_class_init (EvMediaPlayerKeysClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ signals[KEY_PRESSED] =
+ g_signal_new ("key_pressed",
+ EV_TYPE_MEDIA_PLAYER_KEYS,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EvMediaPlayerKeysClass, key_pressed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE,
+ 1, G_TYPE_STRING);
+
object_class->finalize = ev_media_player_keys_finalize;
}
static void
-proxy_destroy (DBusGProxy *proxy,
- EvMediaPlayerKeys* keys)
+on_media_player_key_pressed (DBusGProxy *proxy,
+ const gchar *application,
+ const gchar *key,
+ EvMediaPlayerKeys *keys)
{
- keys->media_player_keys_proxy = NULL;
+ if (strcmp ("Evince", application) == 0) {
+ g_signal_emit (keys, signals[KEY_PRESSED], 0, key);
+ }
}
static void
-on_media_player_key_pressed (DBusGProxy *proxy, const gchar *application, const gchar *key, EvMediaPlayerKeys *keys)
+ev_media_player_keys_grab_keys (EvMediaPlayerKeys *keys)
{
- if (strcmp ("Evince", application) == 0 && keys->window != NULL) {
- /* Note how Previous/Next only go to the
- * next/previous page despite their icon telling you
- * they should go to the beginning/end.
- *
- * There's very few keyboards with FFW/RWD though,
- * so we stick the most useful keybinding on the most
- * often seen keys
- */
- if (strcmp ("Play", key) == 0) {
- ev_window_start_presentation (keys->window);
- } else if (strcmp ("Previous", key) == 0) {
- ev_window_go_previous_page (keys->window);
- } else if (strcmp ("Next", key) == 0) {
- ev_window_go_next_page (keys->window);
- } else if (strcmp ("FastForward", key) == 0) {
- ev_window_go_last_page (keys->window);
- } else if (strcmp ("Rewind", key) == 0) {
- ev_window_go_first_page (keys->window);
- }
- }
+ dbus_g_proxy_call (keys->proxy,
+ "GrabMediaPlayerKeys", NULL,
+ G_TYPE_STRING, "Evince",
+ G_TYPE_UINT, 0,
+ G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+static void
+ev_media_player_keys_release_keys (EvMediaPlayerKeys *keys)
+{
+ dbus_g_proxy_call (keys->proxy,
+ "ReleaseMediaPlayerKeys", NULL,
+ G_TYPE_STRING, "Evince",
+ G_TYPE_INVALID, G_TYPE_INVALID);
}
static void
/* Try the gnome-settings-daemon version,
* then the gnome-control-center version of things */
- keys->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
- "org.gnome.SettingsDaemon",
- "/org/gnome/SettingsDaemon/MediaKeys",
- "org.gnome.SettingsDaemon.MediaKeys",
- NULL);
- if (keys->media_player_keys_proxy == NULL) {
- keys->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
- "org.gnome.SettingsDaemon",
- "/org/gnome/SettingsDaemon",
- "org.gnome.SettingsDaemon",
- &err);
+ keys->proxy = dbus_g_proxy_new_for_name_owner (connection,
+ "org.gnome.SettingsDaemon",
+ "/org/gnome/SettingsDaemon/MediaKeys",
+ "org.gnome.SettingsDaemon.MediaKeys",
+ NULL);
+ if (keys->proxy == NULL) {
+ keys->proxy = dbus_g_proxy_new_for_name_owner (connection,
+ "org.gnome.SettingsDaemon",
+ "/org/gnome/SettingsDaemon",
+ "org.gnome.SettingsDaemon",
+ &err);
}
dbus_g_connection_unref (connection);
g_warning ("Failed to create dbus proxy for org.gnome.SettingsDaemon: %s",
err->message);
g_error_free (err);
+
+ if (keys->proxy) {
+ g_object_unref (keys->proxy);
+ keys->proxy = NULL;
+ }
+
return;
- } else {
- g_signal_connect_object (keys->media_player_keys_proxy,
- "destroy",
- G_CALLBACK (proxy_destroy),
- keys, 0);
}
- dbus_g_proxy_call (keys->media_player_keys_proxy,
- "GrabMediaPlayerKeys", NULL,
- G_TYPE_STRING, "Evince", G_TYPE_UINT, 0, G_TYPE_INVALID,
- G_TYPE_INVALID);
+ g_object_add_weak_pointer (G_OBJECT (keys->proxy),
+ (gpointer) &(keys->proxy));
+
+ ev_media_player_keys_grab_keys (keys);
dbus_g_object_register_marshaller (ev_marshal_VOID__STRING_STRING,
G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_add_signal (keys->media_player_keys_proxy, "MediaPlayerKeyPressed",
+ dbus_g_proxy_add_signal (keys->proxy, "MediaPlayerKeyPressed",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (keys->media_player_keys_proxy, "MediaPlayerKeyPressed",
+ dbus_g_proxy_connect_signal (keys->proxy, "MediaPlayerKeyPressed",
G_CALLBACK (on_media_player_key_pressed), keys, NULL);
}
void
-ev_media_player_keys_focused (EvMediaPlayerKeys *keys, EvWindow *window)
+ev_media_player_keys_focused (EvMediaPlayerKeys *keys)
{
- if (keys->media_player_keys_proxy != NULL) {
- if (keys->window != NULL) {
- g_object_unref (keys->window);
- keys->window = NULL;
- }
- if (window != NULL) {
- dbus_g_proxy_call (keys->media_player_keys_proxy,
- "GrabMediaPlayerKeys", NULL,
- G_TYPE_STRING, "Evince", G_TYPE_UINT, 0, G_TYPE_INVALID,
- G_TYPE_INVALID);
- keys->window = g_object_ref (window);
- }
- }
+ if (!keys->proxy)
+ return;
+
+ ev_media_player_keys_grab_keys (keys);
}
static void
{
EvMediaPlayerKeys *keys = EV_MEDIA_PLAYER_KEYS (object);
- if (keys->media_player_keys_proxy != NULL) {
- dbus_g_proxy_call (keys->media_player_keys_proxy,
- "ReleaseMediaPlayerKeys", NULL,
- G_TYPE_STRING, "Ev", G_TYPE_INVALID, G_TYPE_INVALID);
- g_object_unref (keys->media_player_keys_proxy);
- keys->media_player_keys_proxy = NULL;
- }
-
- if (keys->window != NULL) {
- g_object_unref (keys->window);
- keys->window = NULL;
+ if (keys->proxy) {
+ ev_media_player_keys_release_keys (keys);
+ g_object_unref (keys->proxy);
+ keys->proxy = NULL;
}
G_OBJECT_CLASS (ev_media_player_keys_parent_class)->finalize (object);
static void ev_window_do_preview_print (EvWindow *window);
static void ev_window_load_file_remote (EvWindow *ev_window,
GFile *source_file);
+static void ev_window_media_player_key_pressed (EvWindow *window,
+ const gchar *key,
+ gpointer user_data);
G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
ev_view_previous_page (EV_VIEW (ev_window->priv->view));
}
-void
-ev_window_go_previous_page (EvWindow *ev_window)
-{
- ev_window_cmd_go_previous_page (NULL, ev_window);
-}
-
static void
ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
{
ev_view_next_page (EV_VIEW (ev_window->priv->view));
}
-void
-ev_window_go_next_page (EvWindow *ev_window)
-{
- ev_window_cmd_go_next_page (NULL, ev_window);
-}
-
static void
ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
{
ev_page_cache_set_current_page (ev_window->priv->page_cache, 0);
}
-void
-ev_window_go_first_page (EvWindow *ev_window)
-{
- ev_window_cmd_go_first_page (NULL, ev_window);
-}
-
static void
ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
{
ev_page_cache_set_current_page (ev_window->priv->page_cache, n_pages - 1);
}
-void
-ev_window_go_last_page (EvWindow *ev_window)
-{
- ev_window_cmd_go_last_page (NULL, ev_window);
-}
-
static void
ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
{
ev_window_run_presentation (window);
}
-void
-ev_window_start_presentation (EvWindow *ev_window)
-{
- ev_window_run_presentation (ev_window);
-}
-
static gboolean
ev_window_enumerate_printer_cb (GtkPrinter *printer,
EvWindow *window)
{
EvWindow *window = EV_WINDOW (object);
EvWindowPrivate *priv = window->priv;
-#ifdef ENABLE_DBUS
- GObject *keys;
+ GObject *mpkeys = ev_application_get_media_keys (EV_APP);
- keys = ev_application_get_media_keys (EV_APP);
- if (keys) {
- ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys), NULL);
- g_object_unref (keys);
+ if (mpkeys) {
+ g_signal_handlers_disconnect_by_func (mpkeys,
+ ev_window_media_player_key_pressed,
+ window);
}
-#endif /* ENABLE_DBUS */
-
+
if (priv->setup_document_idle > 0) {
g_source_remove (priv->setup_document_idle);
priv->setup_document_idle = 0;
GObject *keys;
keys = ev_application_get_media_keys (EV_APP);
- if (keys) {
- ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys), window);
- g_object_unref (keys);
- }
+ ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
#endif /* ENABLE_DBUS */
update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
gtk_widget_show (fc);
}
+static void
+ev_window_media_player_key_pressed (EvWindow *window,
+ const gchar *key,
+ gpointer user_data)
+{
+ if (!gtk_window_is_active (GTK_WINDOW (window)))
+ return;
+
+ /* Note how Previous/Next only go to the
+ * next/previous page despite their icon telling you
+ * they should go to the beginning/end.
+ *
+ * There's very few keyboards with FFW/RWD though,
+ * so we stick the most useful keybinding on the most
+ * often seen keys
+ */
+ if (strcmp (key, "Play") == 0) {
+ ev_window_run_presentation (window);
+ } else if (strcmp (key, "Previous") == 0) {
+ ev_window_cmd_go_previous_page (NULL, window);
+ } else if (strcmp (key, "Next") == 0) {
+ ev_window_cmd_go_next_page (NULL, window);
+ } else if (strcmp (key, "FastForward") == 0) {
+ ev_window_cmd_go_last_page (NULL, window);
+ } else if (strcmp (key, "Rewind") == 0) {
+ ev_window_cmd_go_first_page (NULL, window);
+ }
+}
+
static void
ev_window_init (EvWindow *ev_window)
{
GtkAccelGroup *accel_group;
GError *error = NULL;
GtkWidget *sidebar_widget;
+ GObject *mpkeys;
g_signal_connect (ev_window, "configure_event",
G_CALLBACK (window_configure_event_cb), NULL);
"/AttachmentPopup");
ev_window->priv->attach_list = NULL;
+ /* Media player keys */
+ mpkeys = ev_application_get_media_keys (EV_APP);
+ if (mpkeys) {
+ g_signal_connect_swapped (mpkeys, "key_pressed",
+ G_CALLBACK (ev_window_media_player_key_pressed),
+ ev_window);
+ }
+
/* Give focus to the document view */
gtk_widget_grab_focus (ev_window->priv->view);