[Xfce4-commits] <exo:master> Send startup-id to child instead of using it (bug #7093).
Nick Schermer
noreply at xfce.org
Mon Mar 26 19:28:01 CEST 2012
Updating branch refs/heads/master
to cefcc4ff870e9a7f1835762e34a29d842a4f33cb (commit)
from 68b7a21e41cd3090b0b96d5e55b60a86faa26788 (commit)
commit cefcc4ff870e9a7f1835762e34a29d842a4f33cb
Author: Nick Schermer <nick at xfce.org>
Date: Mon Mar 26 19:25:52 2012 +0200
Send startup-id to child instead of using it (bug #7093).
This should fix focus stealing for applications launched
by exo-open. Previously Gtk grabbed the DESKTOP_STARTUP_ID
while initializing exo-open (and the exo-helper), take it
and restore the variable, so it is not unset by Gtk but
ends up at the application.
exo-helper/main.c | 18 +++++++++++++++++-
exo-open/main.c | 19 ++++++++++++++++++-
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/exo-helper/main.c b/exo-helper/main.c
index f67d8b2..4f8fa7e 100644
--- a/exo-helper/main.c
+++ b/exo-helper/main.c
@@ -57,6 +57,7 @@ main (int argc, char **argv)
gint result = EXIT_SUCCESS;
GtkWidget *plug;
GtkWidget *plug_child;
+ gchar *startup_id;
gboolean opt_version = FALSE;
gboolean opt_configure = FALSE;
@@ -81,6 +82,11 @@ main (int argc, char **argv)
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
#endif
+ /* steal the startup id, before gtk tries to grab it */
+ startup_id = g_strdup (g_getenv ("DESKTOP_STARTUP_ID"));
+ if (startup_id != NULL)
+ g_unsetenv ("DESKTOP_STARTUP_ID");
+
/* set up options */
opt_ctx = g_option_context_new (NULL);
@@ -115,6 +121,10 @@ main (int argc, char **argv)
/* initialize Gtk+ */
gtk_init (&argc, &argv);
+ /* restore the startup-id for the child environment */
+ if (startup_id)
+ g_setenv ("DESKTOP_STARTUP_ID", startup_id, TRUE);
+
/* setup default window icon */
gtk_window_set_default_icon_name ("preferences-desktop-default-applications");
@@ -134,12 +144,14 @@ main (int argc, char **argv)
gtk_widget_show (plug_child);
/* End startup notification */
- gdk_notify_startup_complete ();
+ gdk_notify_startup_complete_with_id (startup_id);
gtk_main ();
}
else
{
+ if (startup_id != NULL)
+ gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
gtk_dialog_run (GTK_DIALOG (dialog));
}
@@ -163,6 +175,8 @@ main (int argc, char **argv)
{
/* ask the user to choose a default helper for category */
dialog = exo_helper_launcher_dialog_new (category);
+ if (startup_id != NULL)
+ gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
helper = exo_helper_database_get_default (database, category);
gtk_widget_destroy (dialog);
@@ -184,6 +198,8 @@ main (int argc, char **argv)
dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"%s.", _(CATEGORY_EXEC_ERRORS[category]));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
+ if (startup_id != NULL)
+ gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_error_free (error);
diff --git a/exo-open/main.c b/exo-open/main.c
index f2581f5..0bdf49c 100644
--- a/exo-open/main.c
+++ b/exo-open/main.c
@@ -77,6 +77,8 @@ static gboolean opt_version = FALSE;
static gchar *opt_launch = NULL;
static gchar *opt_working_directory = NULL;
+static gchar *startup_id = NULL;
+
static GOptionEntry entries[] =
{
{ "help", '?', 0, G_OPTION_ARG_NONE, &opt_help, NULL, NULL, },
@@ -256,6 +258,8 @@ exo_open_launch_category (const gchar *category,
/* display an error dialog */
dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
_("Failed to launch preferred application for category \"%s\"."), category);
+ if (startup_id != NULL)
+ gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
@@ -437,7 +441,7 @@ exo_open_uri (const gchar *uri,
return retval;
}
-
+#include <gdk/gdkx.h>
gint
main (gint argc, gchar **argv)
@@ -456,6 +460,11 @@ main (gint argc, gchar **argv)
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
#endif
+ /* steal the startup id, before gtk tries to grab it */
+ startup_id = g_strdup (g_getenv ("DESKTOP_STARTUP_ID"));
+ if (startup_id != NULL)
+ g_unsetenv ("DESKTOP_STARTUP_ID");
+
/* try to parse the command line parameters */
context = g_option_context_new (NULL);
g_option_context_set_help_enabled (context, FALSE);
@@ -469,6 +478,10 @@ main (gint argc, gchar **argv)
return EXIT_FAILURE;
}
+ /* restore the startup-id for the child environment */
+ if (startup_id != NULL)
+ g_setenv ("DESKTOP_STARTUP_ID", startup_id, TRUE);
+
/* setup default icon for windows */
gtk_window_set_default_icon_name ("preferences-desktop-default-applications");
@@ -562,6 +575,8 @@ main (gint argc, gchar **argv)
/* display an error dialog */
dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
_("Unable to detect the URI-scheme of \"%s\"."), *argv);
+ if (startup_id != NULL)
+ gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
@@ -574,6 +589,8 @@ main (gint argc, gchar **argv)
/* display an error dialog */
dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
_("Failed to open URI \"%s\"."), uri);
+ if (startup_id != NULL)
+ gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", err->message);
g_error_free (err);
gtk_dialog_run (GTK_DIALOG (dialog));
More information about the Xfce4-commits
mailing list