[Xfce4-commits] <thunar:nick/1.8> Start desktop in running instance or as daemon.
Nick Schermer
noreply at xfce.org
Sun Aug 4 21:52:19 CEST 2013
Updating branch refs/heads/nick/1.8
to fe3637773af03f236daff910d6ead16dd514d508 (commit)
from 66e8d46ea1d693dc62cbfaf250c07b05ca10de7b (commit)
commit fe3637773af03f236daff910d6ead16dd514d508
Author: Nick Schermer <nick at xfce.org>
Date: Fri Aug 2 23:48:49 2013 +0200
Start desktop in running instance or as daemon.
thunar/Makefile.am | 6 ++-
thunar/main.c | 31 +++++++------
thunar/thunar-application.c | 26 +++++++++++
thunar/thunar-application.h | 2 +
thunar/thunar-dbus-client.c | 66 ++++++++++++++++++++++++++++
thunar/thunar-dbus-client.h | 30 +++++++------
thunar/thunar-dbus-service-infos.xml | 22 ++++++++++
thunar/thunar-dbus-service.c | 55 +++++++++++++++++++++++
thunar/thunar-desktop-preferences-dialog.c | 14 +++++-
thunar/thunar-desktop-window.c | 54 ++++++++++++++++-------
thunar/thunar-desktop-window.h | 2 +-
thunar/thunar-settings | 8 +++-
12 files changed, 268 insertions(+), 48 deletions(-)
diff --git a/thunar/Makefile.am b/thunar/Makefile.am
index f9e77e5..7d94bd8 100644
--- a/thunar/Makefile.am
+++ b/thunar/Makefile.am
@@ -288,7 +288,9 @@ thunar_LDADD += \
endif
desktopdir = $(datadir)/applications
-desktop_in_files = thunar-settings.desktop.in
+desktop_in_files = \
+ thunar-settings.desktop.in \
+ thunar-desktop-settings.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@
@@ -301,7 +303,7 @@ clean-local:
rm -f *.core core core.*
DISTCLEANFILES = \
- thunar-settings.desktop
+ $(desktop_DATA)
if MAINTAINER_MODE
CLEANFILES = \
diff --git a/thunar/main.c b/thunar/main.c
index c9a5c94..4bdb296 100644
--- a/thunar/main.c
+++ b/thunar/main.c
@@ -123,7 +123,7 @@ main (int argc, char **argv)
gchar *working_directory;
gchar **filenames = NULL;
const gchar *startup_id;
- GtkWidget *window;
+ gboolean result;
/* setup translation domain */
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
@@ -206,14 +206,6 @@ main (int argc, char **argv)
}
#endif
- if (G_UNLIKELY (opt_desktop))
- {
- window = thunar_desktop_window_new ();
- gtk_widget_show (window);
- gtk_main ();
- return 0;
- }
-
/* determine the current working directory */
working_directory = g_get_current_dir ();
@@ -232,7 +224,7 @@ main (int argc, char **argv)
filenames = g_new (gchar *, 1);
filenames[0] = NULL;
}
- else if (!opt_daemon)
+ else if (!opt_daemon && !opt_desktop)
{
/* use the current working directory */
filenames = g_new (gchar *, 2);
@@ -242,8 +234,16 @@ main (int argc, char **argv)
#ifdef HAVE_DBUS
/* check if we can reuse an existing instance */
- if ((!opt_bulk_rename && filenames != NULL && thunar_dbus_client_launch_files (working_directory, filenames, NULL, startup_id, NULL))
- || (opt_bulk_rename && thunar_dbus_client_bulk_rename (working_directory, filenames, TRUE, NULL, startup_id, NULL)))
+ if (opt_bulk_rename)
+ result = thunar_dbus_client_bulk_rename (working_directory, filenames, TRUE, NULL, startup_id, NULL);
+ else if (opt_desktop)
+ result = thunar_dbus_client_manage_desktop (NULL);
+ else if (filenames != NULL)
+ result = thunar_dbus_client_launch_files (working_directory, filenames, NULL, startup_id, NULL);
+ else
+ result = FALSE;
+
+ if (result)
{
/* that worked, let's get outa here */
g_free (working_directory);
@@ -260,7 +260,7 @@ main (int argc, char **argv)
#ifdef HAVE_DBUS
/* setup daemon mode if requested and supported */
- thunar_application_set_daemon (application, opt_daemon);
+ thunar_application_set_daemon (application, opt_daemon || opt_desktop);
#endif
/* use the Thunar icon as default for new windows */
@@ -273,6 +273,11 @@ main (int argc, char **argv)
if (!thunar_application_bulk_rename (application, working_directory, filenames, TRUE, NULL, startup_id, &error))
goto error0;
}
+ else if (G_UNLIKELY (opt_desktop))
+ {
+ /* show desktop windows */
+ thunar_desktop_window_show_all ();
+ }
else if (filenames != NULL && !thunar_application_process_filenames (application, working_directory, filenames, NULL, startup_id, &error))
{
/* we failed to process the filenames or the bulk rename failed */
diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c
index f659906..71bb616 100644
--- a/thunar/thunar-application.c
+++ b/thunar/thunar-application.c
@@ -58,6 +58,7 @@
#include <thunar/thunar-thumbnailer.h>
#include <thunar/thunar-util.h>
#include <thunar/thunar-view.h>
+#include <thunar/thunar-desktop-window.h>
#define ACCEL_MAP_PATH "Thunar/accels.scm"
@@ -901,6 +902,7 @@ thunar_application_get_windows (ThunarApplication *application)
}
+
/**
* thunar_application_has_windows:
* @application : a #ThunarApplication.
@@ -919,6 +921,30 @@ thunar_application_has_windows (ThunarApplication *application)
/**
+ * thunar_application_has_desktop_windows:
+ * @application : a #ThunarApplication.
+ *
+ * Returns %TRUE if @application controls atleast one desktop window.
+ *
+ * Return value: %TRUE if @application controls atleast one desktop window.
+ **/
+gboolean
+thunar_application_has_desktop_windows (ThunarApplication *application)
+{
+ GList *lp;
+
+ _thunar_return_val_if_fail (THUNAR_IS_APPLICATION (application), FALSE);
+
+ for (lp = application->windows; lp != NULL; lp = lp->next)
+ if (THUNAR_IS_DESKTOP_WINDOW (lp->data))
+ break;
+
+ return (lp != NULL);
+}
+
+
+
+/**
* thunar_application_take_window:
* @application : a #ThunarApplication.
* @window : a #GtkWindow.
diff --git a/thunar/thunar-application.h b/thunar/thunar-application.h
index 3cd5628..ccc47d7 100644
--- a/thunar/thunar-application.h
+++ b/thunar/thunar-application.h
@@ -50,6 +50,8 @@ GList *thunar_application_get_windows (ThunarAppli
gboolean thunar_application_has_windows (ThunarApplication *application);
+gboolean thunar_application_has_desktop_windows (ThunarApplication *application);
+
void thunar_application_take_window (ThunarApplication *application,
GtkWindow *window);
diff --git a/thunar/thunar-dbus-client.c b/thunar/thunar-dbus-client.c
index 3d5a8a7..bc7e346 100644
--- a/thunar/thunar-dbus-client.c
+++ b/thunar/thunar-dbus-client.c
@@ -241,6 +241,72 @@ thunar_dbus_client_launch_files (const gchar *working_directory,
/**
+ * thunar_dbus_client_manage_desktop:
+ * @error : Return location for errors or %NULL.
+ *
+ * Tells a running Thunar instance, connected to the D-BUS
+ * session bus, to open the desktop.
+ *
+ * Return value: %TRUE if any desktop was started (or was already
+ * running) else %FALSE.
+ **/
+gboolean
+thunar_dbus_client_manage_desktop (GError **error)
+{
+ DBusConnection *connection;
+ DBusMessage *message;
+ DBusMessage *result;
+ DBusError derror;
+
+ _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ /* initialize the DBusError struct */
+ dbus_error_init (&derror);
+
+ /* try to connect to the session bus */
+ connection = dbus_bus_get (DBUS_BUS_SESSION, &derror);
+ if (G_UNLIKELY (connection == NULL))
+ {
+ dbus_set_g_error (error, &derror);
+ dbus_error_free (&derror);
+ return FALSE;
+ }
+
+ /* generate the LaunchFiles() method (disable activation!) */
+ message = dbus_message_new_method_call ("org.xfce.Thunar", "/org/xfce/FileManager", "org.xfce.Thunar", "ManageDesktop");
+ dbus_message_set_auto_start (message, FALSE);
+
+ /* send the message and release our references on connection and message */
+ dbus_error_init (&derror);
+ result = dbus_connection_send_with_reply_and_block (connection, message, -1, &derror);
+ dbus_message_unref (message);
+
+ /* check if no reply was received */
+ if (G_UNLIKELY (result == NULL))
+ {
+ dbus_set_g_error (error, &derror);
+ dbus_error_free (&derror);
+ return FALSE;
+ }
+
+ /* but maybe we received an error */
+ if (dbus_message_get_type (result) == DBUS_MESSAGE_TYPE_ERROR)
+ {
+ dbus_set_error_from_message (&derror, result);
+ dbus_set_g_error (error, &derror);
+ dbus_message_unref (result);
+ dbus_error_free (&derror);
+ return FALSE;
+ }
+
+ /* let's asume that it worked */
+ dbus_message_unref (result);
+ return TRUE;
+}
+
+
+
+/**
* thunar_dbus_client_terminate:
* @error : Return location for errors or %NULL.
*
diff --git a/thunar/thunar-dbus-client.h b/thunar/thunar-dbus-client.h
index 6542c88..c07b175 100644
--- a/thunar/thunar-dbus-client.h
+++ b/thunar/thunar-dbus-client.h
@@ -24,20 +24,22 @@
G_BEGIN_DECLS;
-gboolean thunar_dbus_client_bulk_rename (const gchar *working_directory,
- gchar **filenames,
- gboolean standalone,
- GdkScreen *screen,
- const gchar *startup_id,
- GError **error);
-
-gboolean thunar_dbus_client_launch_files (const gchar *working_directory,
- gchar **filenames,
- GdkScreen *screen,
- const gchar *startup_id,
- GError **error);
-
-gboolean thunar_dbus_client_terminate (GError **error);
+gboolean thunar_dbus_client_bulk_rename (const gchar *working_directory,
+ gchar **filenames,
+ gboolean standalone,
+ GdkScreen *screen,
+ const gchar *startup_id,
+ GError **error);
+
+gboolean thunar_dbus_client_launch_files (const gchar *working_directory,
+ gchar **filenames,
+ GdkScreen *screen,
+ const gchar *startup_id,
+ GError **error);
+
+gboolean thunar_dbus_client_manage_desktop (GError **error);
+
+gboolean thunar_dbus_client_terminate (GError **error);
G_END_DECLS;
diff --git a/thunar/thunar-dbus-service-infos.xml b/thunar/thunar-dbus-service-infos.xml
index 9322e29..24c644a 100644
--- a/thunar/thunar-dbus-service-infos.xml
+++ b/thunar/thunar-dbus-service-infos.xml
@@ -166,6 +166,20 @@
<!--
+ DisplayDesktopDialog (display : STRING) : VOID
+
+ display : the screen on which to display the preferences dialog
+ or "" to use the default screen of the file manager.
+ startup_id : the DESKTOP_STARTUP_ID environment variable for properly
+ handling startup notification and focus stealing.
+ -->
+ <method name="DisplayDesktopDialog">
+ <arg direction="in" name="display" type="s" />
+ <arg direction="in" name="startup_id" type="s" />
+ </method>
+
+
+ <!--
CopyTo (working_directory : STRING, source_filenames : ARRAY OF STRING, target_filenames : ARRAY OF STRING, display : STRING, startup_id : STRING) : VOID
working_directory : working directory used to resolve relative filenames.
@@ -478,6 +492,14 @@
</method>
<!--
+ ManageDesktop () : VOID
+
+ Tells a running Thunar instance to manage the desktop.
+ -->
+ <method name="ManageDesktop">
+ </method>
+
+ <!--
Terminate () : VOID
Tells a running Thunar instance to terminate immediately.
diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c
index 30eba1b..0423656 100644
--- a/thunar/thunar-dbus-service.c
+++ b/thunar/thunar-dbus-service.c
@@ -44,6 +44,8 @@
#include <thunar/thunar-file.h>
#include <thunar/thunar-gdk-extensions.h>
#include <thunar/thunar-preferences-dialog.h>
+#include <thunar/thunar-desktop-preferences-dialog.h>
+#include <thunar/thunar-desktop-window.h>
#include <thunar/thunar-private.h>
#include <thunar/thunar-properties-dialog.h>
#include <thunar/thunar-util.h>
@@ -114,6 +116,10 @@ static gboolean thunar_dbus_service_display_preferences_dialog (ThunarDBusServi
const gchar *display,
const gchar *startup_id,
GError **error);
+static gboolean thunar_dbus_service_display_desktop_dialog (ThunarDBusService *dbus_service,
+ const gchar *display,
+ const gchar *startup_id,
+ GError **error);
static gboolean thunar_dbus_service_display_trash (ThunarDBusService *dbus_service,
const gchar *display,
const gchar *startup_id,
@@ -194,6 +200,8 @@ static gboolean thunar_dbus_service_unlink_files (ThunarDBusServi
const gchar *display,
const gchar *startup_id,
GError **error);
+static gboolean thunar_dbus_service_manage_desktop (ThunarDBusService *dbus_service,
+ GError **error);
static gboolean thunar_dbus_service_terminate (ThunarDBusService *dbus_service,
GError **error);
@@ -674,6 +682,40 @@ thunar_dbus_service_display_preferences_dialog (ThunarDBusService *dbus_service,
static gboolean
+thunar_dbus_service_display_desktop_dialog (ThunarDBusService *dbus_service,
+ const gchar *display,
+ const gchar *startup_id,
+ GError **error)
+{
+ ThunarApplication *application;
+ GdkScreen *screen;
+ GtkWidget *dialog;
+
+ /* try to open the screen for the display name */
+ screen = thunar_gdk_screen_open (display, error);
+ if (G_UNLIKELY (screen == NULL))
+ return FALSE;
+
+ /* popup the preferences dialog... */
+ dialog = thunar_desktop_preferences_dialog_new (NULL);
+ gtk_window_set_screen (GTK_WINDOW (dialog), screen);
+ gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
+ gtk_widget_show (GTK_WIDGET (dialog));
+
+ /* ...and let the application take care of it */
+ application = thunar_application_get ();
+ thunar_application_take_window (application, GTK_WINDOW (dialog));
+ g_object_unref (G_OBJECT (application));
+
+ /* cleanup */
+ g_object_unref (G_OBJECT (screen));
+
+ return TRUE;
+}
+
+
+
+static gboolean
thunar_dbus_service_display_trash (ThunarDBusService *dbus_service,
const gchar *display,
const gchar *startup_id,
@@ -1313,6 +1355,19 @@ thunar_dbus_service_unlink_files (ThunarDBusService *dbus_service,
static gboolean
+thunar_dbus_service_manage_desktop (ThunarDBusService *dbus_service,
+ GError **error)
+{
+ /* show desktop windows */
+ thunar_desktop_window_show_all ();
+
+ /* we cannot fail */
+ return TRUE;
+}
+
+
+
+static gboolean
thunar_dbus_service_terminate (ThunarDBusService *dbus_service,
GError **error)
{
diff --git a/thunar/thunar-desktop-preferences-dialog.c b/thunar/thunar-desktop-preferences-dialog.c
index 666aea6..5f94edd 100644
--- a/thunar/thunar-desktop-preferences-dialog.c
+++ b/thunar/thunar-desktop-preferences-dialog.c
@@ -744,7 +744,17 @@ thunar_desktop_preferences_dialog_cycle_time_changed (ThunarDesktopPreferencesDi
GtkWidget *
thunar_desktop_preferences_dialog_new (GtkWindow *parent)
{
- return g_object_new (THUNAR_TYPE_DESKTOP_PREFERENCES_DIALOG,
- "screen", gtk_window_get_screen (parent), NULL);
+ GtkWidget *dialog;
+ GdkScreen *screen;
+
+ dialog = g_object_new (THUNAR_TYPE_DESKTOP_PREFERENCES_DIALOG, NULL);
+
+ if (parent != NULL)
+ {
+ screen = gtk_window_get_screen (parent);
+ gtk_window_set_screen (GTK_WINDOW (dialog), screen);
+ }
+
+ return dialog;
}
diff --git a/thunar/thunar-desktop-window.c b/thunar/thunar-desktop-window.c
index f9200d9..c0a6c76 100644
--- a/thunar/thunar-desktop-window.c
+++ b/thunar/thunar-desktop-window.c
@@ -26,7 +26,7 @@
#include <thunar/thunar-private.h>
#include <thunar/thunar-desktop-window.h>
#include <thunar/thunar-desktop-background.h>
-#include <thunar/thunar-desktop-preferences-dialog.h>
+#include <thunar/thunar-application.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
@@ -236,16 +236,14 @@ static gboolean
thunar_desktop_window_button_press_event (GtkWidget *widget,
GdkEventButton *event)
{
- ThunarDesktopWindow *window = THUNAR_DESKTOP_WINDOW (widget);
- GtkWidget *dialog;
+ //ThunarDesktopWindow *window = THUNAR_DESKTOP_WINDOW (widget);
if (event->type == GDK_BUTTON_PRESS)
{
if (event->button == 3
|| (event->button == 1 && (event->state & GDK_SHIFT_MASK) != 0))
{
- dialog = thunar_desktop_preferences_dialog_new (GTK_WINDOW (window));
- gtk_widget_show (dialog);
+
}
}
@@ -309,16 +307,35 @@ thunar_desktop_window_delete_event (GtkWidget *widget,
/**
- * thunar_desktop_window_new:
- *
- * Allocates a new #ThunarDesktopWindow instance.
+ * thunar_desktop_window_show_all:
*
- * Return value: the newly allocated #ThunarDesktopWindow.
+ * Create a new window for each screen.
**/
-GtkWidget*
-thunar_desktop_window_new (void)
+void
+thunar_desktop_window_show_all (void)
{
- return thunar_desktop_window_new_with_screen (gdk_screen_get_default ());
+ GdkDisplay *display = gdk_display_get_default ();
+ gint n_screens, n;
+ GdkScreen *screen;
+ GtkWidget *desktop;
+ ThunarApplication *application;
+ gboolean managing_desktop;
+
+ /* check if there are already desktop windows */
+ application = thunar_application_get ();
+ managing_desktop = thunar_application_has_desktop_windows (application);
+ g_object_unref (application);
+
+ if (!managing_desktop)
+ {
+ n_screens = gdk_display_get_n_screens (display);
+ for (n = 0; n < n_screens; n++)
+ {
+ screen = gdk_display_get_screen (display, n);
+ desktop = thunar_desktop_window_new_with_screen (screen);
+ gtk_widget_show (desktop);
+ }
+ }
}
@@ -335,8 +352,15 @@ thunar_desktop_window_new (void)
GtkWidget*
thunar_desktop_window_new_with_screen (GdkScreen *screen)
{
+ GtkWidget *desktop;
+ ThunarApplication *application;
+
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
- return g_object_new (THUNAR_TYPE_DESKTOP_WINDOW,
- "screen", screen,
- NULL);
+ desktop = g_object_new (THUNAR_TYPE_DESKTOP_WINDOW, "screen", screen, NULL);
+
+ application = thunar_application_get ();
+ thunar_application_take_window (application, GTK_WINDOW (desktop));
+ g_object_unref (application);
+
+ return desktop;
}
diff --git a/thunar/thunar-desktop-window.h b/thunar/thunar-desktop-window.h
index bcfb1d3..b1b962f 100644
--- a/thunar/thunar-desktop-window.h
+++ b/thunar/thunar-desktop-window.h
@@ -35,7 +35,7 @@ typedef struct _ThunarDesktopWindow ThunarDesktopWindow;
GType thunar_desktop_window_get_type (void) G_GNUC_CONST;
-GtkWidget *thunar_desktop_window_new (void);
+void thunar_desktop_window_show_all (void);
GtkWidget *thunar_desktop_window_new_with_screen (GdkScreen *screen);
diff --git a/thunar/thunar-settings b/thunar/thunar-settings
index 02b4cb0..334af2c 100755
--- a/thunar/thunar-settings
+++ b/thunar/thunar-settings
@@ -4,8 +4,14 @@
test "x$DISPLAY" != "x" || DISPLAY=:0
+if [ "x$1" == "x--desktop" ]; then
+ method="DisplayDesktopDialog"
+else
+ method="DisplayPreferencesDialog"
+fi
+
output=`dbus-send --session --print-reply --dest=org.xfce.FileManager \
- /org/xfce/FileManager org.xfce.FileManager.DisplayPreferencesDialog \
+ /org/xfce/FileManager org.xfce.FileManager.$method \
"string:$DISPLAY" "string:$DESKTOP_STARTUP_ID"`
if ! [ $? -eq 0 ]; then
More information about the Xfce4-commits
mailing list