Updating branch refs/heads/master to cc9fae3e09f877f470a5131329f240cb38603f77 (commit) from 5a2c9e5e1d64e24490c46666111dd7bd0a33e64e (commit)
commit cc9fae3e09f877f470a5131329f240cb38603f77 Author: David Schneider <dnschn...@gmail.com> Date: Sat Dec 31 02:27:51 2011 -0500 Added command launching, optionally with socket id. TODO | 2 - panel-plugin/embed-dialogs.c | 57 +++++++++++++++++++++++++++++++++++++---- panel-plugin/embed.c | 48 +++++++++++++++++++++++++++++++++-- panel-plugin/embed.h | 4 +++ 4 files changed, 100 insertions(+), 11 deletions(-) diff --git a/TODO b/TODO index 0dd630d..02654fc 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -Launching with parameters, delayed relaunch - * Including %s or something with the GtkSocket id Fake socket no longer necessary? * Doesn't require manual plug size updates * Can create a socket at the start and don't need to replace it until the diff --git a/panel-plugin/embed-dialogs.c b/panel-plugin/embed-dialogs.c index acddb99..abec1ee 100644 --- a/panel-plugin/embed-dialogs.c +++ b/panel-plugin/embed-dialogs.c @@ -94,12 +94,12 @@ embed_entry_set_good (GtkEntry *edit, gboolean good) { if (good) { gtk_entry_set_icon_tooltip_text (edit, GTK_ENTRY_ICON_SECONDARY, - _("The REGEX is valid")); + _("Input is valid")); gtk_entry_set_icon_from_stock (edit, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_YES); } else { gtk_entry_set_icon_tooltip_text (edit, GTK_ENTRY_ICON_SECONDARY, - _("The REGEX is invalid")); + _("Input is invalid")); gtk_entry_set_icon_from_stock (edit, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_NO); } @@ -132,6 +132,31 @@ embed_window_regex_changed (GtkEditable *edit, EmbedPlugin *embed) static void +embed_launch_cmd_changed (GtkEditable *edit, EmbedPlugin *embed) +{ + const gchar *text; + gint argc; + gchar **argv; + + /* Confirm that the command line is okay before saving. */ + text = gtk_entry_get_text (GTK_ENTRY (edit)); + if (*text) { + if (!g_shell_parse_argv (text, &argc, &argv, NULL)) { + embed_entry_set_good (GTK_ENTRY (edit), FALSE); + return; + } + g_strfreev (argv); + } + + g_free (embed->launch_cmd); + embed->launch_cmd = g_strdup (text); + embed->criteria_updated = TRUE; + embed_entry_set_good (GTK_ENTRY (edit), TRUE); +} + + + +static void embed_label_fmt_changed (GtkEditable *edit, EmbedPlugin *embed) { g_free (embed->label_fmt); @@ -199,6 +224,9 @@ embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed) tooltip = tooltiptext; \ gtk_widget_set_tooltip_text (widgetA, tooltip); \ gtk_widget_set_tooltip_text (widgetB, tooltip) +#define LABEL(row, labeltext) \ + widget = gtk_label_new (labeltext); \ + gtk_table_attach_defaults (GTK_TABLE (table), widget, 0, 2, row, row+1) #define ENTRY(row, labeltext, tooltiptext, value, callback) \ label = gtk_label_new_with_mnemonic (labeltext); \ widget = gtk_entry_new (); \ @@ -238,20 +266,36 @@ embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed) widget = xfce_gtk_frame_box_new_with_content (title, table); \ gtk_box_pack_start_defaults (GTK_BOX (content), widget) - START_FRAME(_("Selection Criteria"), 3); + START_FRAME(_("Application Launching"), 2); + LABEL(0, + _("If a window is not found (or there are no criteria), a command can\n" + "optionally be launched. The command can either result in a window\n" + "that matches the below criteria, or it can use the socket ID passed\n" + "to it (" EMBED_LAUNCH_CMD_SOCKET ") to embed itself automatically.")); + /* launch_cmd */ + ENTRY(1, _("L_aunch command"), + _("Leave blank to not launch anything\n" + EMBED_LAUNCH_CMD_SOCKET " expands to the socket ID"), + embed->launch_cmd, embed_launch_cmd_changed); + embed_entry_set_good (GTK_ENTRY (widget), TRUE); + + START_FRAME(_("Selection Criteria"), 4); + LABEL(0, + _("The window to embed must match all of the non-blank criteria.\n" + "Leave everything blank to rely on a launch command with socket ID.")); /* proc_name */ - ENTRY(0, _("_Process name"), + ENTRY(1, _("_Process name"), _("Match the window's application's process name\n" "Leave blank if it is not a criterion"), embed->proc_name, embed_proc_name_changed); /* window_class */ - ENTRY(1, _("_Window class"), _("Match the window's class\n" + ENTRY(2, _("_Window class"), _("Match the window's class\n" "Leave blank if it is not a criterion"), embed->window_class, embed_window_class_changed); /* window_regex */ - ENTRY(2, _("Window _title"), _("Match the window's title using a REGEX\n" + ENTRY(3, _("Window _title"), _("Match the window's title using a REGEX\n" "Leave blank if it is not a criterion"), embed->window_regex, embed_window_regex_changed); embed_entry_set_good (GTK_ENTRY (widget), TRUE); @@ -289,6 +333,7 @@ embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed) #undef ADD #undef TOOLTIP2 +#undef LABEL #undef ENTRY #undef FONTBUTTON #undef SPIN diff --git a/panel-plugin/embed.c b/panel-plugin/embed.c index 381f951..8b23a20 100644 --- a/panel-plugin/embed.c +++ b/panel-plugin/embed.c @@ -37,6 +37,7 @@ #define DEFAULT_PROC_NAME NULL #define DEFAULT_WINDOW_REGEX NULL #define DEFAULT_WINDOW_CLASS NULL +#define DEFAULT_LAUNCH_CMD NULL #define DEFAULT_LABEL_FMT _("Embed") #define DEFAULT_LABEL_FONT NULL #define DEFAULT_POLL_DELAY 0 @@ -90,6 +91,8 @@ embed_save (XfcePanelPlugin *plugin, EmbedPlugin *embed) xfce_rc_write_entry (rc, "window_regex", embed->window_regex); if (embed->window_class) xfce_rc_write_entry (rc, "window_class", embed->window_class); + if (embed->launch_cmd) + xfce_rc_write_entry (rc, "launch_cmd", embed->launch_cmd); if (embed->label_fmt) xfce_rc_write_entry (rc, "label_fmt", embed->label_fmt); if (embed->label_font) @@ -130,6 +133,8 @@ embed_read (EmbedPlugin *embed) "window_regex", DEFAULT_WINDOW_REGEX)); embed->window_class = g_strdup (xfce_rc_read_entry (rc, "window_class", DEFAULT_WINDOW_CLASS)); + embed->launch_cmd = g_strdup (xfce_rc_read_entry (rc, + "launch_cmd", DEFAULT_LAUNCH_CMD)); embed->label_fmt = g_strdup (xfce_rc_read_entry (rc, "label_fmt", DEFAULT_LABEL_FMT)); embed->label_font = g_strdup (xfce_rc_read_entry (rc, @@ -155,6 +160,7 @@ embed_read (EmbedPlugin *embed) embed->proc_name = g_strdup (DEFAULT_PROC_NAME); embed->window_regex = g_strdup (DEFAULT_WINDOW_REGEX); embed->window_class = g_strdup (DEFAULT_WINDOW_CLASS); + embed->launch_cmd = g_strdup (DEFAULT_LAUNCH_CMD); embed->label_fmt = g_strdup (DEFAULT_LABEL_FMT); embed->label_font = g_strdup (DEFAULT_LABEL_FONT); embed->poll_delay = DEFAULT_POLL_DELAY; @@ -264,6 +270,7 @@ embed_free (XfcePanelPlugin *plugin, EmbedPlugin *embed) g_free (embed->proc_name); g_free (embed->window_regex); g_free (embed->window_class); + g_free (embed->launch_cmd); g_free (embed->label_fmt); g_free (embed->label_font); @@ -480,6 +487,36 @@ embed_search (EmbedPlugin *embed) +/* Runs the desired command, if one is provided. */ +static void +embed_launch_command (EmbedPlugin *embed) +{ + gchar *socketpos; + g_assert (embed->socket); + if (embed->launch_cmd && embed->launch_cmd[0]) { + /* See if we need to perform a substitution */ + if ((socketpos = strstr (embed->launch_cmd, EMBED_LAUNCH_CMD_SOCKET))) { + /* Construct the launch command, replacing the EMBED_LAUNCH_CMD_SOCKET + * with the actual socket id. */ + socketpos = g_strdup_printf ("%.*s%lu%s", + (gint)(socketpos - embed->launch_cmd), embed->launch_cmd, + (intptr_t)gtk_socket_get_id (GTK_SOCKET (embed->socket)), + socketpos + strlen (EMBED_LAUNCH_CMD_SOCKET)); + if (!g_spawn_command_line_async (socketpos, NULL)) { + DBG ("launch failed"); + } + g_free (socketpos); + } else { + /* Othewise just launch directly. */ + if (!g_spawn_command_line_async (embed->launch_cmd, NULL)) { + DBG ("launch failed"); + } + } + } +} + + + /* Starts the search for a viable plug. Does one initial search, and then sets * up X11 monitoring and possibly polling if no plug is found right away. * Does not start a search if there are no criteria, as that would be stupid. */ @@ -498,11 +535,13 @@ embed_start_search (GtkWidget *socket, EmbedPlugin *embed) (embed->window_class && embed->window_class[0]) )) { DBG ("no search criteria specified"); + /* Run the command if it is provided. */ + embed_launch_command (embed); return; } - /* TODO: handle the case where we want to launch an application that will - * generate a plug */ + /* See if we can't immediately find a window. */ if (embed_search (embed)) { + /* Didn't find one. */ /* Reset the _NET_CLIENT_LIST detector */ embed->monitor_saw_net_client_list = FALSE; /* Watch for property changes (primarily the window list ones) on the root @@ -516,6 +555,9 @@ embed_start_search (GtkWidget *socket, EmbedPlugin *embed) if (embed->poll_delay > 0) embed->search_timer = g_timeout_add (embed->poll_delay, (GSourceFunc)embed_search, embed); + + /* Run the command if it is provided. */ + embed_launch_command (embed); } } @@ -831,7 +873,7 @@ void embed_search_again (EmbedPlugin *embed) { embed_popout (GTK_MENU_ITEM (embed->popout_menu), embed); - embed_embed_menu (GTK_MENU_ITEM (embed->embed_menu), embed); + embed->disable_search = FALSE; } diff --git a/panel-plugin/embed.h b/panel-plugin/embed.h index 5a919a2..3d2d462 100644 --- a/panel-plugin/embed.h +++ b/panel-plugin/embed.h @@ -57,6 +57,7 @@ typedef struct gchar *proc_name; gchar *window_regex; gchar *window_class; + gchar *launch_cmd; gchar *label_fmt; gchar *label_font; gint poll_delay; @@ -68,6 +69,9 @@ EmbedPlugin; /* Special values for EmbedPlugin::min_size */ #define EMBED_MIN_SIZE_MATCH_WINDOW 0 +/* Special contents of launch_cmd */ +#define EMBED_LAUNCH_CMD_SOCKET "%s" + /* Special contents of label_fmt */ #define EMBED_LABEL_FMT_TITLE "%t" _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits