changeset 2739:a03b5446e68f

Additional remote commands for layout windows Additional remote commands: --remote --id:<ID> --remote --open-window --remote --close-window The id:<ID> parameter sends subsequent commands to the specified window. The window titlebar show the window identifier.
author Colin Clark <colin.clark@cclark.uk>
date Sun, 01 Apr 2018 11:36:20 +0100
parents c6e5a43c87e5
children 808983eb036e
files doc/docbook/GuideReferenceCommandLine.xml geeqie.1 src/image.c src/layout_util.c src/layout_util.h src/main.c src/remote.c web/help/GuideReferenceCommandLine.html
diffstat 8 files changed, 168 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/doc/docbook/GuideReferenceCommandLine.xml	Thu Mar 29 17:10:58 2018 +0100
+++ b/doc/docbook/GuideReferenceCommandLine.xml	Sun Apr 01 11:36:20 2018 +0100
@@ -247,6 +247,26 @@
             <entry>Bring the geeqie window to the top</entry>
           </row>
           <row>
+            <entry />
+            <entry>--id:&lt;ID&gt;</entry>
+            <entry>
+              Window ID for following commands
+              <footnote id='ref3'>
+                <para>The ID is shown in the titlebar of the window. If multiple windows are open, it can be used to direct commands to a particular window e.g. --remote --id:main --tell</para>
+              </footnote>
+            </entry>
+          </row>
+          <row>
+            <entry />
+            <entry>--new-window</entry>
+            <entry>Open new window</entry>
+          </row>
+          <row>
+            <entry />
+            <entry>--close-window</entry>
+            <entry>Close window</entry>
+          </row>
+          <row>
             <entry>-ct:clear|clean</entry>
             <entry>--cache-thumbs:clear|clean</entry>
             <entry>clear or clean thumbnail cache</entry>
--- a/geeqie.1	Thu Mar 29 17:10:58 2018 +0100
+++ b/geeqie.1	Sun Apr 01 11:36:20 2018 +0100
@@ -188,6 +188,18 @@
 Bring the Geeqie window to the top.
 .br
 .B
+.IP \-\-id:<ID>
+Window ID for following commands.
+.br
+.B
+.IP \-\-new-window
+Open new window.
+.br
+.B
+.IP \-\-close-window
+Close window.
+.br
+.B
 .IP \-ct:clear|clean,\-\-cache-thumbs:clear|clean
 Clear or clean thumbnail cache.
 .br
--- a/src/image.c	Thu Mar 29 17:10:58 2018 +0100
+++ b/src/image.c	Sun Apr 01 11:36:20 2018 +0100
@@ -178,6 +178,8 @@
 	gchar *title = NULL;
 	gchar *zoom = NULL;
 	gchar *collection = NULL;
+	LayoutWindow *lw;
+	gchar *lw_ident = NULL;
 
 	if (!imd->top_window) return;
 
@@ -195,13 +197,25 @@
 		g_free(buf);
 		}
 
-	title = g_strdup_printf("%s%s%s%s%s%s",
+	lw = layout_find_by_image(imd);
+	if (lw)
+		{
+		lw_ident = g_strconcat(" (", lw->options.id, ")", NULL);
+		}
+
+	title = g_strdup_printf("%s%s%s%s%s%s%s",
 		imd->title ? imd->title : "",
 		imd->image_fd ? imd->image_fd->name : "",
 		zoom ? zoom : "",
 		collection ? collection : "",
 		imd->image_fd ? " - " : "",
-		imd->title_right ? imd->title_right : "");
+		imd->title_right ? imd->title_right : "",
+		lw_ident ? lw_ident : ""
+		);
+	if (lw_ident)
+		{
+		g_free(lw_ident);
+		}
 
 	gtk_window_set_title(GTK_WINDOW(imd->top_window), title);
 
--- a/src/layout_util.c	Thu Mar 29 17:10:58 2018 +0100
+++ b/src/layout_util.c	Sun Apr 01 11:36:20 2018 +0100
@@ -207,7 +207,7 @@
 	layout_image_full_screen_stop(lw);
 }
 
-static void layout_menu_new_window_cb(GtkAction *action, gpointer data)
+LayoutWindow *layout_menu_new_window(GtkAction *action, gpointer data)
 {
 	LayoutWindow *lw = data;
 	LayoutWindow *nw;
@@ -227,6 +227,13 @@
 	layout_sort_set(nw, options->file_sort.method, options->file_sort.ascending);
 	layout_set_fd(nw, lw->dir_fd);
 	options->save_window_positions = tmp;
+
+	return nw;
+}
+
+static void layout_menu_new_window_cb(GtkAction *action, gpointer data)
+{
+	layout_menu_new_window(action, data);
 }
 
 static void layout_menu_new_cb(GtkAction *action, gpointer data)
@@ -349,7 +356,7 @@
 	file_data_disable_grouping_list(layout_selection_list(lw), FALSE);
 }
 
-static void layout_menu_close_cb(GtkAction *action, gpointer data)
+void layout_menu_close_cb(GtkAction *action, gpointer data)
 {
 	LayoutWindow *lw = data;
 
--- a/src/layout_util.h	Thu Mar 29 17:10:58 2018 +0100
+++ b/src/layout_util.h	Sun Apr 01 11:36:20 2018 +0100
@@ -72,6 +72,7 @@
 void layout_exif_window_new(LayoutWindow *lw);
 
 gboolean is_help_key(GdkEventKey *event);
-
+LayoutWindow *layout_menu_new_window(GtkAction *action, gpointer data);
+void layout_menu_close_cb(GtkAction *action, gpointer data);
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/main.c	Thu Mar 29 17:10:58 2018 +0100
+++ b/src/main.c	Sun Apr 01 11:36:20 2018 +0100
@@ -221,6 +221,7 @@
 	GList *remote_errors = NULL;
 	gboolean remote_do = FALSE;
 	gchar *first_dir = NULL;
+	gchar *app_lock;
 
 	command_line = g_new0(CommandLine, 1);
 
@@ -412,6 +413,17 @@
 		}
 	g_free(first_dir);
 
+	/* If Geeqie is already running, prevent a second instance
+	 * from being started. Open a new window instead.
+	 */
+	app_lock = g_build_filename(get_rc_dir(), ".command", NULL);
+	if (remote_server_exists(app_lock) && !remote_do)
+		{
+		remote_do = TRUE;
+		remote_list = g_list_append(remote_list, "--new-window");
+	}
+	g_free(app_lock);
+
 	if (remote_do)
 		{
 		if (remote_errors)
@@ -858,16 +870,6 @@
 	DEBUG_1("%s main: parse_command_line", get_exec_time());
 	parse_command_line(argc, argv);
 
-	/* If Geeqie is already running, prevent a second instance
-	 * from being started
-	 */
-	app_lock = g_build_filename(get_rc_dir(), ".command", NULL);
-	if (remote_server_exists(app_lock))
-		{
-		_exit(0);
-		}
-	g_free(app_lock);
-
 	DEBUG_1("%s main: mkdir_if_not_exists", get_exec_time());
 	/* these functions don't depend on config file */
 	mkdir_if_not_exists(get_rc_dir());
--- a/src/remote.c	Thu Mar 29 17:10:58 2018 +0100
+++ b/src/remote.c	Sun Apr 01 11:36:20 2018 +0100
@@ -29,6 +29,7 @@
 #include "img-view.h"
 #include "layout.h"
 #include "layout_image.h"
+#include "layout_util.h"
 #include "misc.h"
 #include "pixbuf-renderer.h"
 #include "slideshow.h"
@@ -56,6 +57,7 @@
 static gint remote_client_send(RemoteConnection *rc, const gchar *text);
 static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data);
 
+static LayoutWindow *lw_id = NULL; /* points to the window set by the --id option */
 
 typedef struct _RemoteClient RemoteClient;
 struct _RemoteClient {
@@ -76,6 +78,7 @@
 	RemoteConnection *rc;
 	GIOStatus status = G_IO_STATUS_NORMAL;
 
+	lw_id = NULL;
 	rc = client->rc;
 
 	if (condition & G_IO_IN)
@@ -388,37 +391,70 @@
 
 static void gr_image_next(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_next(NULL);
+	layout_image_next(lw_id);
+}
+
+static void gr_new_window(const gchar *text, GIOChannel *channel, gpointer data)
+{
+	LayoutWindow *lw = NULL;
+
+	if (!layout_valid(&lw)) return;
+
+	lw_id = layout_menu_new_window(NULL, lw);
+}
+
+static gboolean gr_close_window_cb()
+{
+	if (!layout_valid(&lw_id)) return FALSE;
+
+	layout_menu_close_cb(NULL, lw_id);
+
+	return FALSE;
+}
+
+static void gr_close_window(const gchar *text, GIOChannel *channel, gpointer data)
+{
+	g_idle_add(gr_close_window_cb, NULL);
 }
 
 static void gr_image_prev(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_prev(NULL);
+	layout_image_prev(lw_id);
 }
 
 static void gr_image_first(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_first(NULL);
+	layout_image_first(lw_id);
 }
 
 static void gr_image_last(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_last(NULL);
+	layout_image_last(lw_id);
 }
 
 static void gr_fullscreen_toggle(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_full_screen_toggle(NULL);
+	layout_image_full_screen_toggle(lw_id);
 }
 
 static void gr_fullscreen_start(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_full_screen_start(NULL);
+	layout_image_full_screen_start(lw_id);
 }
 
 static void gr_fullscreen_stop(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_full_screen_stop(NULL);
+	layout_image_full_screen_stop(lw_id);
+}
+
+static void gr_lw_id(const gchar *text, GIOChannel *channel, gpointer data)
+{
+	lw_id = layout_find_by_layout_id(text);
+	if (!lw_id)
+		{
+		log_printf("remote sent window ID that does not exist:\"%s\"\n",text);
+		}
+	layout_valid(&lw_id);
 }
 
 static void gr_slideshow_start_rec(const gchar *text, GIOChannel *channel, gpointer data)
@@ -429,8 +465,8 @@
 	file_data_unref(dir_fd);
 	if (!list) return;
 //printf("length: %d\n", g_list_length(list));
-	layout_image_slideshow_stop(NULL);
-	layout_image_slideshow_start_from_list(NULL, list);
+	layout_image_slideshow_stop(lw_id);
+	layout_image_slideshow_start_from_list(lw_id, list);
 }
 
 static void gr_cache_thumb(const gchar *text, GIOChannel *channel, gpointer data)
@@ -478,17 +514,17 @@
 
 static void gr_slideshow_toggle(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_slideshow_toggle(NULL);
+	layout_image_slideshow_toggle(lw_id);
 }
 
 static void gr_slideshow_start(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_slideshow_start(NULL);
+	layout_image_slideshow_start(lw_id);
 }
 
 static void gr_slideshow_stop(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	layout_image_slideshow_stop(NULL);
+	layout_image_slideshow_stop(lw_id);
 }
 
 static void gr_slideshow_delay(const gchar *text, GIOChannel *channel, gpointer data)
@@ -542,9 +578,9 @@
 	gboolean popped;
 	gboolean hidden;
 
-	if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
+	if (layout_tools_float_get(lw_id, &popped, &hidden) && hidden)
 		{
-		layout_tools_float_set(NULL, popped, FALSE);
+		layout_tools_float_set(lw_id, popped, FALSE);
 		}
 }
 
@@ -553,9 +589,9 @@
 	gboolean popped;
 	gboolean hidden;
 
-	if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
+	if (layout_tools_float_get(lw_id, &popped, &hidden) && !hidden)
 		{
-		layout_tools_float_set(NULL, popped, TRUE);
+		layout_tools_float_set(lw_id, popped, TRUE);
 		}
 }
 
@@ -586,17 +622,17 @@
 			}
 		else
 			{
-			layout_set_path(NULL, filename);
+			layout_set_path(lw_id, filename);
 			}
 		}
 	else if (isdir(filename))
 		{
-		layout_set_path(NULL, filename);
+		layout_set_path(lw_id, filename);
 		}
 	else
 		{
 		log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
-		layout_set_path(NULL, homedir());
+		layout_set_path(lw_id, homedir());
 		}
 
 	g_free(filename);
@@ -618,9 +654,9 @@
 	PixbufRenderer *pr;
 	LayoutWindow *lw = NULL;
 
-	if (!layout_valid(&lw)) return;
+	if (!layout_valid(&lw_id)) return;
 
-	pr = (PixbufRenderer*)lw->image->pr;
+	pr = (PixbufRenderer*)lw_id->image->pr;
 
 	if (pr)
 		{
@@ -656,11 +692,11 @@
 
 static void gr_file_tell(const gchar *text, GIOChannel *channel, gpointer data)
 {
-	LayoutWindow *lw = NULL; /* NULL to force layout_valid() to do some magic */
-	if (!layout_valid(&lw)) return;
-	if (image_get_path(lw->image))
+	if (!layout_valid(&lw_id)) return;
+
+	if (image_get_path(lw_id->image))
 		{
-		g_io_channel_write_chars(channel, image_get_path(lw->image), -1, NULL, NULL);
+		g_io_channel_write_chars(channel, image_get_path(lw_id->image), -1, NULL, NULL);
 		g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
 		}
 }
@@ -771,9 +807,9 @@
 {
 	LayoutWindow *lw = NULL;
 
-	if (layout_valid(&lw))
+	if (layout_valid(&lw_id))
 		{
-		gtk_window_present(GTK_WINDOW(lw->window));
+		gtk_window_present(GTK_WINDOW(lw_id->window));
 		}
 }
 
@@ -849,6 +885,9 @@
 	{ NULL, "--list-clear",         gr_list_clear,          FALSE, FALSE, NULL, N_("clear command line collection list") },
 	{ NULL, "--list-add:",          gr_list_add,            TRUE,  FALSE, N_("<FILE>"), N_("add FILE to command line collection list") },
 	{ NULL, "raise",                gr_raise,               FALSE, FALSE, NULL, N_("bring the Geeqie window to the top") },
+	{ NULL, "--id:",                gr_lw_id,               TRUE, FALSE, N_("<ID>"), N_("window id for following commands") },
+	{ NULL, "--new-window",         gr_new_window,          FALSE, FALSE, NULL, N_("new window") },
+	{ NULL, "--close-window",       gr_close_window,        FALSE, FALSE, NULL, N_("close window") },
 	{ "-ct:", "--cache-thumbs:",    gr_cache_thumb,         TRUE, FALSE, N_("clear|clean"), N_("clear or clean thumbnail cache") },
 	{ "-cs:", "--cache-shared:",    gr_cache_shared,        TRUE, FALSE, N_("clear|clean"), N_("clear or clean shared thumbnail cache") },
 	{ "-cm","--cache-metadata",      gr_cache_metadata,               FALSE, FALSE, NULL, N_("    clean the metadata cache") },
--- a/web/help/GuideReferenceCommandLine.html	Thu Mar 29 17:10:58 2018 +0100
+++ b/web/help/GuideReferenceCommandLine.html	Sun Apr 01 11:36:20 2018 +0100
@@ -699,44 +699,62 @@
 <td class="td-rowsep">Bring the geeqie window to the top</td>
 </tr>
 <tr>
+<td class="td-colsep td-rowsep"></td>
+<td class="td-colsep td-rowsep">--id:&lt;ID&gt;</td>
+<td class="td-rowsep">
+              Window ID for following commands
+              <a name="-noteref-ref3"></a><sup><a class="footnote" href="#ref3">2</a></sup>
+            </td>
+</tr>
+<tr class="tr-shade">
+<td class="td-colsep td-rowsep"></td>
+<td class="td-colsep td-rowsep">--new-window</td>
+<td class="td-rowsep">Open new window</td>
+</tr>
+<tr>
+<td class="td-colsep td-rowsep"></td>
+<td class="td-colsep td-rowsep">--close-window</td>
+<td class="td-rowsep">Close window</td>
+</tr>
+<tr class="tr-shade">
 <td class="td-colsep td-rowsep">-ct:clear|clean</td>
 <td class="td-colsep td-rowsep">--cache-thumbs:clear|clean</td>
 <td class="td-rowsep">clear or clean thumbnail cache</td>
 </tr>
-<tr class="tr-shade">
+<tr>
 <td class="td-colsep td-rowsep">-cs:clear|clean</td>
 <td class="td-colsep td-rowsep">--cache-shared:clear|clean</td>
 <td class="td-rowsep">clear or clean shared thumbnail cache</td>
 </tr>
-<tr>
+<tr class="tr-shade">
 <td class="td-colsep td-rowsep">-cm</td>
 <td class="td-colsep td-rowsep">--cache-metadata</td>
 <td class="td-rowsep">clean the metadata cache</td>
 </tr>
-<tr class="tr-shade">
+<tr>
 <td class="td-colsep td-rowsep">-cr:&lt;folder&gt;</td>
 <td class="td-colsep td-rowsep">--cache-render:&lt;folder&gt;</td>
 <td class="td-rowsep">render thumbnails</td>
 </tr>
-<tr>
+<tr class="tr-shade">
 <td class="td-colsep td-rowsep">-crr:&lt;folder&gt;</td>
 <td class="td-colsep td-rowsep">--cache-render-recurse:&lt;folder&gt;</td>
 <td class="td-rowsep">render thumbnails recursively</td>
 </tr>
-<tr class="tr-shade">
+<tr>
 <td class="td-colsep td-rowsep">-crs:&lt;folder&gt;</td>
 <td class="td-colsep td-rowsep">--cache-render-shared:&lt;folder&gt;</td>
 <td class="td-rowsep">
               render thumbnails
-              <a name="-noteref-ref2"></a><sup><a class="footnote" href="#ref2">2</a></sup>
+              <a name="-noteref-ref2"></a><sup><a class="footnote" href="#ref2">3</a></sup>
             </td>
 </tr>
-<tr>
+<tr class="tr-shade">
 <td class="td-colsep td-rowsep">-crsr:&lt;folder&gt;</td>
 <td class="td-colsep td-rowsep">--cache-render-shared-recurse:&lt;folder&gt;</td>
 <td class="td-rowsep">render thumbnails recursively</td>
 </tr>
-<tr class="tr-shade">
+<tr>
 <td class="td-colsep"></td>
 <td class="td-colsep">--lua:&lt;file&gt;,&lt;lua script&gt;</td>
 <td>run lua script on file</td>
@@ -749,7 +767,11 @@
 <div class="footnote">
 <a name="ref1"></a><span class="footnote-number"><a class="footnote-ref" href="#-noteref-ref1">1</a></span>The name of a collection, with or without either path or extension (.gqv) may be used. If a path is not used and there is a name conflict with a file or folder, that will take precedence.</div>
 <div class="footnote">
-<a name="ref2"></a><span class="footnote-number"><a class="footnote-ref" href="#-noteref-ref2">2</a></span>
+<a name="ref3"></a><span class="footnote-number"><a class="footnote-ref" href="#-noteref-ref3">2</a></span>
+                <p class="para block block-first">The ID is shown in the titlebar of the window. If multiple windows are open, it can be used to direct commands to a particular window e.g. --remote --id:main --tell</p>
+              </div>
+<div class="footnote">
+<a name="ref2"></a><span class="footnote-number"><a class="footnote-ref" href="#-noteref-ref2">3</a></span>
                 <p class="para block block-first">If standard thumbnail cache is not enabled, this command will be ignored.</p>
               </div>
 </div>