[Xfce4-commits] [apps/xfce4-mixer] 02/03: Replace libunique with GApplication/GtkApplication

noreply at xfce.org noreply at xfce.org
Fri Jul 8 21:22:17 CEST 2016


This is an automated email from the git hooks/post-receive script.

landry pushed a commit to branch master
in repository apps/xfce4-mixer.

commit 7c207e69966e1ff576bf044bae1752cd8c1284fb
Author: Mike Gelfand <mikedld at mikedld.com>
Date:   Wed Jul 6 17:51:05 2016 +0300

    Replace libunique with GApplication/GtkApplication
---
 configure.ac.in                      |   3 -
 xfce4-mixer/Makefile.am              |   4 +-
 xfce4-mixer/main.c                   | 184 ++-------------------------
 xfce4-mixer/xfce-mixer-application.c | 232 +++++++++++++++++++++++++++++++++++
 xfce4-mixer/xfce-mixer-application.h |  42 +++++++
 xfce4-mixer/xfce-mixer-window.c      | 177 +++++++++++++++-----------
 xfce4-mixer/xfce-mixer-window.h      |   2 +-
 7 files changed, 391 insertions(+), 253 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 4b545a8..c66273c 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -108,8 +108,6 @@ dnl *** Check for optional packages ***
 dnl ***********************************
 XDT_CHECK_OPTIONAL_PACKAGE([KEYBINDER], [keybinder-3.0], [0.3], [keybinder],
                            [keybinder Support])
-XDT_CHECK_OPTIONAL_PACKAGE([UNIQUE], [unique-3.0], [3.0], [unique],
-                           [unique Support])
 
 dnl ***********************************
 dnl *** Check for debugging support ***
@@ -152,7 +150,6 @@ dnl ***************************
 echo
 echo "Build Configuration:"
 echo
-echo " * unique Support:                       ${UNIQUE_FOUND:-no}"
 echo " * keybinder Support:                    ${KEYBINDER_FOUND:-no}"
 echo " * Debug Support:                        $enable_debug"
 echo
diff --git a/xfce4-mixer/Makefile.am b/xfce4-mixer/Makefile.am
index f979b92..d7742df 100644
--- a/xfce4-mixer/Makefile.am
+++ b/xfce4-mixer/Makefile.am
@@ -5,6 +5,8 @@ bin_PROGRAMS =								\
 
 xfce4_mixer_SOURCES =							\
 	main.c								\
+	xfce-mixer-application.c					\
+	xfce-mixer-application.h					\
 	xfce-mixer-track.c						\
 	xfce-mixer-track.h						\
 	xfce-mixer-switch.c						\
@@ -29,7 +31,6 @@ xfce4_mixer_CPPFLAGS = 							\
 xfce4_mixer_CFLAGS = 							\
 	$(GLIB_CFLAGS)							\
 	$(GTK_CFLAGS)							\
-	$(UNIQUE_CFLAGS)						\
 	$(LIBXFCE4UTIL_CFLAGS)						\
 	$(LIBXFCE4UI_CFLAGS)						\
 	$(XFCONF_CFLAGS)						\
@@ -43,7 +44,6 @@ xfce4_mixer_LDFLAGS = 							\
 	$(GLIB_LIBS)							\
 	$(GTHREAD_LIBS)							\
 	$(GTK_LIBS)							\
-	$(UNIQUE_LIBS)							\
 	$(LIBXFCE4UTIL_LIBS)						\
 	$(LIBXFCE4UI_LIBS)						\
 	$(XFCONF_LIBS)							\
diff --git a/xfce4-mixer/main.c b/xfce4-mixer/main.c
index 7fda388..585c9e6 100644
--- a/xfce4-mixer/main.c
+++ b/xfce4-mixer/main.c
@@ -23,56 +23,11 @@
 #include <config.h>
 #endif
 
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#include <gst/gst.h>
-
 #include <gtk/gtk.h>
 
-#ifdef HAVE_UNIQUE
-#include <unique/unique.h>
-#endif
-
 #include <libxfce4util/libxfce4util.h>
-#include <libxfce4ui/libxfce4ui.h>
-#include <xfconf/xfconf.h>
-
-#include "libxfce4mixer/libxfce4mixer.h"
 
-#include "xfce-mixer-window.h"
-
-
-
-#ifdef HAVE_UNIQUE
-static UniqueResponse
-message_received (UniqueApp         *app,
-                  UniqueCommand      command,
-                  UniqueMessageData *message,
-                  guint              time_,
-                  GtkWidget         *window)
-{
-  UniqueResponse response;
-
-  switch (command)
-    {
-      case UNIQUE_ACTIVATE:
-        /* Move window to the screen the command was started on */
-        gtk_window_set_screen (GTK_WINDOW (window), unique_message_data_get_screen (message));
-        /* Bring window to the foreground */
-        gtk_window_present_with_time (GTK_WINDOW (window), time_);
-        response = UNIQUE_RESPONSE_OK;
-        break;
-      default:
-        /* Invalid command */
-        response = UNIQUE_RESPONSE_FAIL;
-        break;
-    }
-
-  return response;
-}
-#endif
+#include "xfce-mixer-application.h"
 
 
 
@@ -80,145 +35,20 @@ int
 main (int    argc,
       char **argv)
 {
-#ifdef HAVE_UNIQUE
-  UniqueApp          *app;
-#endif
-  GtkWidget          *window;
-  GError             *error = NULL;
-  gboolean            debug_mode = FALSE;
-  gboolean            show_version = FALSE;
-  GOptionContext     *option_context;
-  GOptionEntry        option_entries[] =
-  {
-    { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_mode, N_("Enable debugging output"), NULL },
-    { "version", 'V', 0, G_OPTION_ARG_NONE, &show_version, N_("Show version and exit"), NULL },
-    { NULL, 0, 0, 0, NULL, NULL, NULL }
-  };
+  GApplication *app;
+  gint          status;
 
   /* Setup translation domain */
   xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
-#if !GLIB_CHECK_VERSION(2, 32, 0)
-  /* Initialize the threading system */
-  if (G_LIKELY (!g_thread_supported ()))
-    g_thread_init (NULL);
-#endif
-
   /* Set application name */
   g_set_application_name (_("Audio Mixer"));
 
-  /* Parse commandline options */
-  option_context = g_option_context_new ("- Adjust volume levels");
-  g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
-  g_option_context_add_group (option_context, gtk_get_option_group (FALSE));
-  g_option_context_add_group (option_context, gst_init_get_option_group ());
-  g_option_context_parse (option_context, &argc, &argv, &error);
-  g_option_context_free (option_context);
-  if (error != NULL)
-    {
-      g_printerr ("xfce4-mixer: %s\n", error->message);
-
-      return EXIT_FAILURE;
-    }
-
-  if (show_version)
-    {
-      g_print ("xfce4-mixer " VERSION "\n");
-
-      return EXIT_SUCCESS;
-    }
-
-  /* Initialize GTK+ fully */
-  gtk_init (NULL, NULL);
-
-  /* Initialize Xfconf */
-  if (G_UNLIKELY (!xfconf_init (&error)))
-    {
-      if (G_LIKELY (error != NULL))
-        {
-          g_printerr (_("xfce4-mixer: Failed to initialize xfconf: %s\n"), error->message);
-          g_error_free (error);
-        }
-
-      return EXIT_FAILURE;
-    }
-
-  /* Initialize the mixer library */
-  xfce_mixer_init ();
-
-  /* Use volume control icon for all mixer windows */
-  gtk_window_set_default_icon_name ("multimedia-volume-control");
-
-  /* Warn users if there were no sound cards detected by GStreamer */
-  if (G_UNLIKELY (g_list_length (xfce_mixer_get_cards ()) <= 0))
-    {
-      xfce_dialog_show_error (NULL,
-                              NULL,
-                              _("GStreamer was unable to detect any sound devices. "
-                              "Some sound system specific GStreamer packages may "
-                              "be missing. It may also be a permissions problem."));
-
-      return EXIT_FAILURE;
-    }
-
-  /* Initialize debugging code */
-  xfce_mixer_debug_init (G_LOG_DOMAIN, debug_mode);
-
-  xfce_mixer_debug ("xfce4-mixer version " VERSION " starting up");
-
-  if (debug_mode)
-    xfce_mixer_dump_gst_data ();
-
-#ifdef HAVE_UNIQUE
-  /* Create unique application */
-  app = unique_app_new ("org.xfce.xfce4-mixer", NULL);
-  if (unique_app_is_running (app))
-    {
-      unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
-
-      g_object_unref (app);
-    }
-  else
-    {
-      /* Create the mixer window */
-      window = xfce_mixer_window_new ();
-
-      /* Display the mixer window */
-      gtk_widget_show (window);
-
-      /* Watch mixer window */
-      unique_app_watch_window (app, GTK_WINDOW (window));
-
-      /* Handle messages */
-      g_signal_connect (app, "message-received", G_CALLBACK (message_received), window);
-
-      /* Enter the GTK+ main loop */
-      gtk_main ();
-
-      g_object_unref (app);
-
-      /* Destroy the window */
-      gtk_widget_destroy (window);
-    }
-#else
-  /* Create the mixer window */
-  window = xfce_mixer_window_new ();
-
-  /* Display the mixer window */
-  gtk_widget_show (window);
-
-  /* Enter the GTK+ main loop */
-  gtk_main ();
-
-  /* Destroy the window */
-  gtk_widget_destroy (window);
-#endif
+  app = xfce_mixer_application_new ();
 
-  /* Shutdown the mixer library */
-  xfce_mixer_shutdown ();
+  status = g_application_run (app, argc, argv);
 
-  /* Shutdown Xfconf */
-  xfconf_shutdown ();
+  g_object_unref (app);
 
-  return EXIT_SUCCESS;
+  return status;
 }
diff --git a/xfce4-mixer/xfce-mixer-application.c b/xfce4-mixer/xfce-mixer-application.c
new file mode 100644
index 0000000..1559675
--- /dev/null
+++ b/xfce4-mixer/xfce-mixer-application.c
@@ -0,0 +1,232 @@
+/* vi:set expandtab sw=2 sts=2: */
+/*-
+ * Copyright (c) 2008 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2012 Guido Berhoerster <guido+xfce at berhoerster.name>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include <gst/gst.h>
+#include <gtk/gtk.h>
+
+#include <libxfce4util/libxfce4util.h>
+#include <libxfce4ui/libxfce4ui.h>
+#include <xfconf/xfconf.h>
+
+#include "libxfce4mixer/libxfce4mixer.h"
+
+#include "xfce-mixer-application.h"
+#include "xfce-mixer-window.h"
+
+
+
+static void xfce_mixer_application_dispose              (GObject      *object);
+static void xfce_mixer_application_finalize             (GObject      *object);
+static void xfce_mixer_application_startup              (GApplication *app);
+static void xfce_mixer_application_activate             (GApplication *app);
+static void xfce_mixer_application_shutdown             (GApplication *app);
+static gint xfce_mixer_application_handle_local_options (GApplication *app,
+                                                         GVariantDict *options,
+                                                         gpointer      user_data);
+
+
+
+struct _XfceMixerApplicationClass
+{
+  GtkApplicationClass __parent__;
+};
+
+struct _XfceMixerApplication
+{
+  GtkApplication  __parent__;
+
+  GtkWidget    *main_window;
+};
+
+
+
+G_DEFINE_TYPE (XfceMixerApplication, xfce_mixer_application, GTK_TYPE_APPLICATION)
+
+
+
+static gboolean debug_mode = FALSE;
+static gboolean show_version = FALSE;
+
+static GOptionEntry option_entries[] =
+{
+  { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_mode, N_("Enable debugging output"), NULL },
+  { "version", 'V', 0, G_OPTION_ARG_NONE, &show_version, N_("Show version and exit"), NULL },
+  { NULL, 0, 0, 0, NULL, NULL, NULL }
+};
+
+
+
+static void
+xfce_mixer_application_class_init (XfceMixerApplicationClass *klass)
+{
+  GObjectClass      *gobject_class;
+  GApplicationClass *g_application_class;
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->dispose = xfce_mixer_application_dispose;
+  gobject_class->finalize = xfce_mixer_application_finalize;
+
+  g_application_class = G_APPLICATION_CLASS (klass);
+  g_application_class->startup = xfce_mixer_application_startup;
+  g_application_class->activate = xfce_mixer_application_activate;
+  g_application_class->shutdown = xfce_mixer_application_shutdown;
+}
+
+
+
+static void
+xfce_mixer_application_init (XfceMixerApplication *app)
+{
+  app->main_window = NULL;
+
+  g_application_add_main_option_entries (G_APPLICATION (app), option_entries);
+  g_application_add_option_group (G_APPLICATION (app), gst_init_get_option_group ());
+
+  g_signal_connect (app, "handle-local-options", G_CALLBACK (xfce_mixer_application_handle_local_options), NULL);
+}
+
+
+
+static void
+xfce_mixer_application_dispose (GObject *object)
+{
+  (*G_OBJECT_CLASS (xfce_mixer_application_parent_class)->dispose) (object);
+}
+
+
+
+static void
+xfce_mixer_application_finalize (GObject *object)
+{
+  (*G_OBJECT_CLASS (xfce_mixer_application_parent_class)->finalize) (object);
+}
+
+
+
+static void
+xfce_mixer_application_startup (GApplication *app)
+{
+  GError      *error = NULL;
+
+  (*G_APPLICATION_CLASS (xfce_mixer_application_parent_class)->startup) (app);
+
+  /* Initialize Xfconf */
+  if (G_UNLIKELY (!xfconf_init (&error)))
+    {
+      if (G_LIKELY (error != NULL))
+        {
+          g_printerr (_("xfce4-mixer: Failed to initialize xfconf: %s\n"), error->message);
+          g_error_free (error);
+        }
+
+      exit (EXIT_FAILURE);
+    }
+
+  /* Initialize the mixer library */
+  xfce_mixer_init ();
+
+  /* Use volume control icon for all mixer windows */
+  gtk_window_set_default_icon_name ("multimedia-volume-control");
+
+  /* Warn users if there were no sound cards detected by GStreamer */
+  if (G_UNLIKELY (g_list_length (xfce_mixer_get_cards ()) <= 0))
+    {
+      xfce_dialog_show_error (NULL,
+                              NULL,
+                              _("GStreamer was unable to detect any sound devices. "
+                              "Some sound system specific GStreamer packages may "
+                              "be missing. It may also be a permissions problem."));
+      exit (EXIT_FAILURE);
+    }
+
+  /* Initialize debugging code */
+  xfce_mixer_debug_init (G_LOG_DOMAIN, debug_mode);
+
+  xfce_mixer_debug ("xfce4-mixer version " VERSION " starting up");
+
+  if (debug_mode)
+    xfce_mixer_dump_gst_data ();
+}
+
+
+
+static void
+xfce_mixer_application_activate (GApplication *app_)
+{
+  XfceMixerApplication *app = XFCE_MIXER_APPLICATION (app_);
+
+  /* Create the mixer window */
+  if (app->main_window == NULL)
+    app->main_window = xfce_mixer_window_new (app_);
+
+  /* Display the mixer window */
+  gtk_window_present (GTK_WINDOW (app->main_window));
+}
+
+
+
+static void
+xfce_mixer_application_shutdown (GApplication *app)
+{
+  /* Shutdown the mixer library */
+  xfce_mixer_shutdown ();
+
+  /* Shutdown Xfconf */
+  xfconf_shutdown ();
+
+  (*G_APPLICATION_CLASS (xfce_mixer_application_parent_class)->shutdown) (app);
+}
+
+
+
+static gint
+xfce_mixer_application_handle_local_options (GApplication *app,
+                                             GVariantDict *options,
+                                             gpointer      user_data)
+{
+  if (show_version)
+    {
+      g_print ("xfce4-mixer " VERSION "\n");
+      return EXIT_SUCCESS;
+    }
+
+  return -1;
+}
+
+
+
+GApplication*
+xfce_mixer_application_new (void)
+{
+  XfceMixerApplication *app;
+
+  app = g_object_new (TYPE_XFCE_MIXER_APPLICATION, "application-id", "org.xfce.xfce4-mixer", NULL);
+
+  return G_APPLICATION (app);
+}
diff --git a/xfce4-mixer/xfce-mixer-application.h b/xfce4-mixer/xfce-mixer-application.h
new file mode 100644
index 0000000..e4a5534
--- /dev/null
+++ b/xfce4-mixer/xfce-mixer-application.h
@@ -0,0 +1,42 @@
+/* vi:set expandtab sw=2 sts=2: */
+/*-
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __XFCE_MIXER_APPLICATION_H__
+#define __XFCE_MIXER_APPLICATION_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _XfceMixerApplicationClass XfceMixerApplicationClass;
+typedef struct _XfceMixerApplication      XfceMixerApplication;
+
+#define TYPE_XFCE_MIXER_APPLICATION            (xfce_mixer_application_get_type ())
+#define XFCE_MIXER_APPLICATION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_XFCE_MIXER_APPLICATION, XfceMixerApplication))
+#define XFCE_MIXER_APPLICATION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_XFCE_MIXER_APPLICATION, XfceMixerApplicationClass))
+#define IS_XFCE_MIXER_APPLICATION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_XFCE_MIXER_APPLICATION))
+#define IS_XFCE_MIXER_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_XFCE_MIXER_APPLICATION))
+#define XFCE_MIXER_APPLICATION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_XFCE_MIXER_APPLICATION, XfceMixerApplicationClass))
+
+GType         xfce_mixer_application_get_type        (void) G_GNUC_CONST;
+
+GApplication *xfce_mixer_application_new             (void);
+
+G_END_DECLS
+
+#endif /* !__XFCE_MIXER_APPLICATION_H__ */
diff --git a/xfce4-mixer/xfce-mixer-window.c b/xfce4-mixer/xfce-mixer-window.c
index 32cbb28..248236b 100644
--- a/xfce4-mixer/xfce-mixer-window.c
+++ b/xfce4-mixer/xfce-mixer-window.c
@@ -40,22 +40,26 @@
 
 static void     xfce_mixer_window_dispose                     (GObject              *object);
 static void     xfce_mixer_window_finalize                    (GObject              *object);
+static void     xfce_mixer_window_size_allocate               (GtkWidget            *widget,
+                                                               GtkAllocation        *allocation);
+static gboolean xfce_mixer_window_state_event                 (GtkWidget            *widget,
+                                                               GdkEventWindowState  *event);
+static void     xfce_mixer_window_destroy                     (GtkWidget            *widget);
 static void     xfce_mixer_window_soundcard_changed           (XfceMixerCardCombo   *combo,
                                                                GstElement           *card,
                                                                XfceMixerWindow      *window);
 static void     xfce_mixer_window_soundcard_property_changed  (XfceMixerWindow      *window,
                                                                GParamSpec           *pspec,
                                                                GObject              *object);
-static void     xfce_mixer_window_action_select_controls      (GtkAction            *action,
-                                                               XfceMixerWindow      *window);
+static void     xfce_mixer_window_action_select_controls      (GSimpleAction        *action,
+                                                               GVariant             *parameter,
+                                                               gpointer              user_data);
 static void     xfce_mixer_window_controls_property_changed   (XfceMixerWindow *window,
                                                                GParamSpec      *pspec,
                                                                GObject         *object);
-static void     xfce_mixer_window_close                       (GtkAction            *action,
-                                                               XfceMixerWindow      *window);
-static gboolean xfce_mixer_window_closed                      (GtkWidget            *window,
-                                                               GdkEvent             *event,
-                                                               XfceMixerWindow      *mixer_window);
+static void     xfce_mixer_window_close                       (GSimpleAction        *action,
+                                                               GVariant             *parameter,
+                                                               gpointer              user_data);
 static void     xfce_mixer_window_update_contents             (XfceMixerWindow      *window);
 
 
@@ -71,7 +75,11 @@ struct _XfceMixerWindow
 
   XfceMixerPreferences *preferences;
 
-  GtkActionGroup       *action_group;
+  /* Current window state */
+  gint                  current_width;
+  gint                  current_height;
+  gboolean              is_maximized;
+  gboolean              is_fullscreen;
 
   GtkWidget            *soundcard_combo;
 
@@ -86,12 +94,10 @@ struct _XfceMixerWindow
 
 
 
-static const GtkActionEntry action_entries[] = 
+static const GActionEntry action_entries[] =
 {
-  { "quit", GTK_STOCK_QUIT, N_ ("_Quit"), "<Control>q", N_ ("Exit the mixer"), 
-    G_CALLBACK (xfce_mixer_window_close) },
-  { "select-controls", NULL, N_ ("_Select Controls..."), "<Control>s", N_ ("Select which controls are displayed"), 
-    G_CALLBACK (xfce_mixer_window_action_select_controls) },
+  { "quit", &xfce_mixer_window_close, NULL, NULL, NULL },
+  { "select-controls", &xfce_mixer_window_action_select_controls, NULL, NULL, NULL },
 };
 
 
@@ -103,11 +109,17 @@ G_DEFINE_TYPE (XfceMixerWindow, xfce_mixer_window, XFCE_TYPE_TITLED_DIALOG)
 static void
 xfce_mixer_window_class_init (XfceMixerWindowClass *klass)
 {
-  GObjectClass *gobject_class;
+  GObjectClass   *gobject_class;
+  GtkWidgetClass *gtk_widget_class;
 
   gobject_class = G_OBJECT_CLASS (klass);
   gobject_class->dispose = xfce_mixer_window_dispose;
   gobject_class->finalize = xfce_mixer_window_finalize;
+
+  gtk_widget_class = GTK_WIDGET_CLASS (klass);
+  gtk_widget_class->size_allocate = xfce_mixer_window_size_allocate;
+  gtk_widget_class->window_state_event = xfce_mixer_window_state_event;
+  gtk_widget_class->destroy = xfce_mixer_window_destroy;
 }
 
 
@@ -115,8 +127,7 @@ xfce_mixer_window_class_init (XfceMixerWindowClass *klass)
 static void
 xfce_mixer_window_init (XfceMixerWindow *window)
 {
-  GtkAccelGroup *accel_group;
-  GtkAction     *action;
+  GApplication  *app = g_application_get_default ();
   GtkWidget     *label;
   GtkWidget     *button;
   GtkWidget     *vbox;
@@ -124,15 +135,18 @@ xfce_mixer_window_init (XfceMixerWindow *window)
   GtkWidget     *bbox;
   gchar         *card_name;
   GstElement    *card;
-  guint          i;
-  gint           width;
-  gint           height;
+  const gchar   *select_controls_accels[] = { "<Control>s", NULL };
+  const gchar   *quit_accels[] = { "<Control>q", NULL };
 
   window->controls_dialog = NULL;
 
   window->preferences = xfce_mixer_preferences_get ();
 
-  g_object_get (window->preferences, "window-width", &width, "window-height", &height, "sound-card", &card_name, NULL);
+  window->is_maximized = FALSE;
+  window->is_fullscreen = FALSE;
+
+  g_object_get (window->preferences, "window-width", &window->current_width, "window-height", &window->current_height,
+                "sound-card", &card_name, NULL);
   if (card_name != NULL)
     card = xfce_mixer_get_card (card_name);
   else
@@ -148,30 +162,16 @@ xfce_mixer_window_init (XfceMixerWindow *window)
   gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
   gtk_window_set_icon_name (GTK_WINDOW (window), "multimedia-volume-control");
   gtk_window_set_title (GTK_WINDOW (window), _("Audio Mixer"));
-  gtk_window_set_default_size (GTK_WINDOW (window), width, height);
+  gtk_window_set_default_size (GTK_WINDOW (window), window->current_width, window->current_height);
   gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
   xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (window), _("Configure sound card(s) and control the volume of selected tracks"));
 
-  g_signal_connect (window, "delete-event", G_CALLBACK (xfce_mixer_window_closed), window);
-
-  /* Quit mixer when the main window is closed */
-  g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL);
-
-  /* Create window action group */
-  window->action_group = gtk_action_group_new ("XfceMixerWindow");
-  gtk_action_group_set_translation_domain (window->action_group, GETTEXT_PACKAGE);
-  gtk_action_group_add_actions (window->action_group, action_entries, G_N_ELEMENTS (action_entries), GTK_WIDGET (window));
+  /* Install actions */
+  g_action_map_add_action_entries (G_ACTION_MAP (app), action_entries, G_N_ELEMENTS (action_entries), window);
 
   /* Install action accelerators for the mixer window */
-  accel_group = gtk_accel_group_new ();
-  for (i = 0; i < G_N_ELEMENTS (action_entries); ++i)
-    {
-      action = gtk_action_group_get_action (window->action_group, action_entries[i].name);
-      gtk_action_set_accel_group (action, accel_group);
-      gtk_action_connect_accelerator (action);
-      gtk_action_set_sensitive (action, TRUE);
-    }
-  gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.select-controls", select_controls_accels);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels);
 
   vbox = gtk_dialog_get_content_area (GTK_DIALOG (window));
   gtk_widget_show (vbox);
@@ -201,23 +201,26 @@ xfce_mixer_window_init (XfceMixerWindow *window)
   gtk_container_add (GTK_CONTAINER (window->mixer_frame), window->mixer_container);
   gtk_widget_show (window->mixer_container);
 
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+  /* Single place still using deprecated API. GTK+ uses it internally as well, so why should we suffer?
+     Suffice it to say, new API is quite limited. */
   bbox = gtk_dialog_get_action_area (GTK_DIALOG (window));
+G_GNUC_END_IGNORE_DEPRECATIONS
   gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_EDGE);
   gtk_container_set_border_width (GTK_CONTAINER (bbox), 6);
 
-  window->select_controls_button = gtk_button_new ();
-  gtk_activatable_set_related_action (GTK_ACTIVATABLE (window->select_controls_button),
-                                      gtk_action_group_get_action (window->action_group, "select-controls"));
+  window->select_controls_button = gtk_button_new_with_mnemonic (_("_Select Controls..."));
   gtk_button_set_image (GTK_BUTTON (window->select_controls_button), 
                         gtk_image_new_from_icon_name ("preferences-desktop", GTK_ICON_SIZE_BUTTON));
+  gtk_actionable_set_action_name (GTK_ACTIONABLE (window->select_controls_button), "app.select-controls");
   gtk_widget_set_sensitive (window->select_controls_button, FALSE);
   gtk_box_pack_start (GTK_BOX (bbox), window->select_controls_button, FALSE, TRUE, 0);
   gtk_widget_show (window->select_controls_button);
 
-  button = gtk_button_new ();
-  gtk_activatable_set_related_action (GTK_ACTIVATABLE (button),
-                                      gtk_action_group_get_action (window->action_group, "quit"));
-  gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON));
+  button = gtk_button_new_with_mnemonic (_("_Quit"));
+  gtk_button_set_image (GTK_BUTTON (button),
+                        gtk_image_new_from_icon_name ("exit", GTK_ICON_SIZE_BUTTON));
+  gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.quit");
   gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
   gtk_widget_show (button);
 
@@ -251,10 +254,55 @@ xfce_mixer_window_finalize (GObject *object)
 
 
 
+static void
+xfce_mixer_window_size_allocate (GtkWidget     *widget,
+                                 GtkAllocation *allocation)
+{
+  XfceMixerWindow *window = XFCE_MIXER_WINDOW (widget);
+
+  (*GTK_WIDGET_CLASS (xfce_mixer_window_parent_class)->size_allocate) (widget, allocation);
+
+  if (!window->is_maximized && !window->is_fullscreen)
+    gtk_window_get_size (GTK_WINDOW (window), &window->current_width, &window->current_height);
+}
+
+
+
+static gboolean
+xfce_mixer_window_state_event (GtkWidget           *widget,
+                               GdkEventWindowState *event)
+{
+  XfceMixerWindow *window = XFCE_MIXER_WINDOW (widget);
+  gboolean         result = GDK_EVENT_PROPAGATE;
+
+  if (GTK_WIDGET_CLASS (xfce_mixer_window_parent_class)->window_state_event != NULL)
+    result = (*GTK_WIDGET_CLASS (xfce_mixer_window_parent_class)->window_state_event) (widget, event);
+
+  window->is_maximized = (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
+  window->is_fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;
+
+  return result;
+}
+
+
+
+static void
+xfce_mixer_window_destroy (GtkWidget *widget)
+{
+  XfceMixerWindow *window = XFCE_MIXER_WINDOW (widget);
+
+  g_object_set (G_OBJECT (window->preferences), "window-width", window->current_width,
+                "window-height", window->current_height, NULL);
+
+  (*GTK_WIDGET_CLASS (xfce_mixer_window_parent_class)->destroy) (widget);
+}
+
+
+
 GtkWidget*
-xfce_mixer_window_new (void)
+xfce_mixer_window_new (GApplication *app)
 {
-  return g_object_new (TYPE_XFCE_MIXER_WINDOW, NULL);
+  return g_object_new (TYPE_XFCE_MIXER_WINDOW, "application", app, NULL);
 }
 
 
@@ -333,9 +381,12 @@ xfce_mixer_window_soundcard_property_changed (XfceMixerWindow *window,
 
 
 static void
-xfce_mixer_window_action_select_controls (GtkAction       *action,
-                                          XfceMixerWindow *window)
+xfce_mixer_window_action_select_controls (GSimpleAction *action,
+                                          GVariant      *parameter,
+                                          gpointer       user_data)
 {
+  XfceMixerWindow *window = XFCE_MIXER_WINDOW (user_data);
+
   g_return_if_fail (window->controls_dialog == NULL);
 
   window->controls_dialog = xfce_mixer_controls_dialog_new (window);
@@ -362,29 +413,15 @@ xfce_mixer_window_controls_property_changed (XfceMixerWindow *window,
 
 
 static void
-xfce_mixer_window_close (GtkAction       *action,
-                         XfceMixerWindow *window)
+xfce_mixer_window_close (GSimpleAction *action,
+                         GVariant      *parameter,
+                         gpointer       user_data)
 {
-  /* This is a nasty hack to save the settings before the application quits */
-  xfce_mixer_window_closed (GTK_WIDGET (window), NULL, window);
-}
-
-
-
-static gboolean 
-xfce_mixer_window_closed (GtkWidget       *window,
-                          GdkEvent        *event,
-                          XfceMixerWindow *mixer_window)
-{
-  gint width;
-  gint height;
-
-  gtk_window_get_size (GTK_WINDOW (mixer_window), &width, &height);
-  g_object_set (G_OBJECT (mixer_window->preferences), "window-width", width, "window-height", height, NULL);
+  XfceMixerWindow *window = XFCE_MIXER_WINDOW (user_data);
 
-  gtk_main_quit ();
+  gtk_widget_destroy (GTK_WIDGET (window));
 
-  return TRUE;
+  g_application_quit (g_application_get_default ());
 }
 
 
diff --git a/xfce4-mixer/xfce-mixer-window.h b/xfce4-mixer/xfce-mixer-window.h
index b2aba01..b9ff14a 100644
--- a/xfce4-mixer/xfce-mixer-window.h
+++ b/xfce4-mixer/xfce-mixer-window.h
@@ -38,7 +38,7 @@ typedef struct _XfceMixerWindow      XfceMixerWindow;
 
 GType       xfce_mixer_window_get_type        (void) G_GNUC_CONST;
 
-GtkWidget  *xfce_mixer_window_new             (void);
+GtkWidget  *xfce_mixer_window_new             (GApplication    *app);
 GstElement *xfce_mixer_window_get_active_card (XfceMixerWindow *window);
 
 G_END_DECLS

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list