[Xfce4-commits] <xfce4-notes-plugin:master> gtk3: Implement popup command with Gtk.Application

Mike Massonnet noreply at xfce.org
Mon May 13 20:14:16 CEST 2013


Updating branch refs/heads/master
         to 4cfd09b46a24ea468fcbe5b87c86126ef5a1ab01 (commit)
       from 92e14fa7ea78da2e7e5dc578dcf3741321820037 (commit)

commit 4cfd09b46a24ea468fcbe5b87c86126ef5a1ab01
Author: Mike Massonnet <mmassonnet at gmail.com>
Date:   Sat Mar 9 21:35:02 2013 +0100

    gtk3: Implement popup command with Gtk.Application
    
    Instead of depending on oldish X11 code to show/hide the notes, use
    Gtk.Application. For GTK3, the binary xfce4-popup-notes is build out of
    main-popup.vala, while xfce4-popup-notes.c is kept as-is for GTK2.
    
    Both xfce4-popup-notes and xfce4-notes binaries define a unique ID
    org.xfce.Notes and send an activate signal in case a primary instance of
    xfce4-notes is already running.

 src/Makefile.am                    |   25 ++++++++++++++++---
 lib/color.h => src/main-popup.vala |   45 ++++++++++++++++++++----------------
 src/main-status-icon.vala          |   17 ++++++++++++-
 3 files changed, 62 insertions(+), 25 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index ad720b6..032eba4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,4 @@
+BUILT_SOURCES =
 INCLUDES =								\
 	-I$(top_srcdir)							\
 	-I$(top_srcdir)/lib						\
@@ -10,7 +11,25 @@ INCLUDES =								\
 #
 
 if ENABLE_GTK3
-bin_PROGRAMS = 
+bin_PROGRAMS = xfce4-popup-notes
+
+if MAINTAINER_MODE
+xfce4_popup_notes_VALAFLAGS =						\
+	--pkg=gtk+-3.0
+
+BUILT_SOURCES += main-popup.c
+main-popup.c: main-popup.vala
+	$(AM_V_GEN) $(VALAC) $(xfce4_popup_notes_VALAFLAGS) $< -C
+endif
+
+xfce4_popup_notes_SOURCES =						\
+	main-popup.c
+
+xfce4_popup_notes_CFLAGS =						\
+	@GTK_CFLAGS@
+
+xfce4_popup_notes_LDADD =						\
+	@GTK_LIBS@
 else
 bin_PROGRAMS = xfce4-popup-notes
 
@@ -79,7 +98,7 @@ notes_VALAFLAGS +=							\
 	--pkg=gtk+-2.0
 endif
 
-BUILT_SOURCES = main-panel-plugin.c
+BUILT_SOURCES += main-panel-plugin.c
 main-panel-plugin.c: main-panel-plugin.vala
 	$(AM_V_GEN) $(VALAC) $(notes_VALAFLAGS) $< -C
 endif
@@ -103,8 +122,6 @@ libnotes_la_LIBADD =							\
 	@LIBXFCE4UTIL_LIBS@						\
 	@XFCONF_LIBS@
 
-else
-BUILT_SOURCES =
 endif
 
 #
diff --git a/lib/color.h b/src/main-popup.vala
similarity index 52%
copy from lib/color.h
copy to src/main-popup.vala
index 031b5ba..e52f7ac 100644
--- a/lib/color.h
+++ b/src/main-popup.vala
@@ -1,6 +1,6 @@
 /*
  *  Notes - panel plugin for Xfce Desktop Environment
- *  Copyright (C) 2009-2010  Mike Massonnet <mmassonnet at xfce.org>
+ *  Copyright (C) 2006-2013  Mike Massonnet <mmassonnet at xfce.org>
  *
  *  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
@@ -17,22 +17,27 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#ifndef COLOR_H
-#define COLOR_H
-
-#include <glib.h>
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
-
-void                    color_set_background            (const gchar *background);
-void                    __gdk_color_contrast            (GdkColor *color,
-                                                         gdouble contrast);
-#if !GTK_CHECK_VERSION (2,12,0)
-gchar *                 gdk_color_to_string             (const GdkColor *color);
-#endif
-#if !GTK_CHECK_VERSION (2,14,0)
-GtkWidget*              gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel);
-#endif
-
-#endif
-
+static int main (string[] args) {
+	Gtk.init (ref args);
+	var app = new GLib.Application ("org.xfce.Notes", 0);
+	try {
+		app.register ();
+	} catch (GLib.Error e) {
+		warning ("Unable to register: %s", e.message);
+		return -1;
+	}
+	if (!app.get_is_remote ()) {
+		// We are the primary instance, in that case start xfce4-notes
+		try {
+			message ("xfce4-notes isn't currently running, trying to start it...");
+			GLib.Process.spawn_command_line_async ("xfce4-notes");
+		} catch (GLib.Error e) {
+			critical ("%s", e.message);
+			return -1;
+		}
+	} else {
+		// Send an activate signal which is used to show/hide the notes
+		app.activate ();
+	}
+	return 0;
+}
diff --git a/src/main-status-icon.vala b/src/main-status-icon.vala
index 6f3b247..429b6d8 100644
--- a/src/main-status-icon.vala
+++ b/src/main-status-icon.vala
@@ -102,7 +102,22 @@ static bool set_x_selection () {
 static int main (string[] args) {
 	Gtk.init (ref args);
 #if ENABLE_GTK3
-	// TODO: Gtk.Application
+	Gtk.Application app = new Gtk.Application ("org.xfce.Notes", 0);
+
+	try {
+		app.register ();
+	} catch (GLib.Error e) {
+		warning ("Application cannot be registered: %s", e.message);
+	}
+
+	if (app.get_is_remote ()) {
+		app.activate ();
+		return 0;
+	}
+
+	app.activate.connect (() => {
+		application.show_hide_notes ();
+	});
 #else
 	Unique.App app = new Unique.App ("org.xfce.Notes", null);
 	if (app.is_running) {


More information about the Xfce4-commits mailing list