Sort headers using clang-tidy
[geeqie.git] / src / remote.cc
index df0bbbf..4ece932 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "remote.h"
 
+#include <config.h>
+
 #include "cache-maint.h"
-#include "collect.h"
 #include "collect-io.h"
+#include "collect.h"
+#include "compat.h"
+#include "debug.h"
 #include "exif.h"
 #include "filedata.h"
 #include "filefilter.h"
 #include "image.h"
 #include "img-view.h"
+#include "intl.h"
 #include "layout-image.h"
 #include "layout-util.h"
+#include "main-defines.h"
+#include "main.h"
 #include "misc.h"
 #include "pixbuf-renderer.h"
+#include "rcfile.h"
 #include "slideshow.h"
 #include "ui-fileops.h"
-#include "rcfile.h"
+#include "ui-misc.h"
+#include "utilops.h"
 #include "view-file.h"
 
+#include <csignal>
 #include <sys/socket.h>
 #include <sys/un.h>
-#include <signal.h>
 
 #include "glua.h"
 
-#define SERVER_MAX_CLIENTS 8
+enum {
+       SERVER_MAX_CLIENTS = 8
+};
 
-#define REMOTE_SERVER_BACKLOG 4
+enum {
+       REMOTE_SERVER_BACKLOG = 4
+};
 
 
 #ifndef UNIX_PATH_MAX
@@ -207,7 +219,7 @@ static void remote_server_clients_close(RemoteConnection *rc)
                }
 }
 
-static gboolean remote_server_read_cb(GIOChannel *UNUSED(source), GIOCondition UNUSED(condition), gpointer data)
+static gboolean remote_server_read_cb(GIOChannel *, GIOCondition, gpointer data)
 {
        auto rc = static_cast<RemoteConnection *>(data);
        gint fd;
@@ -244,10 +256,15 @@ static RemoteConnection *remote_server_open(const gchar *path)
 {
        RemoteConnection *rc;
        struct sockaddr_un addr;
-       gint sun_path_len;
        gint fd;
        GIOChannel *channel;
 
+       if (strlen(path) >= sizeof(addr.sun_path))
+               {
+               log_printf("Address is too long: %s\n", path);
+               return nullptr;
+               }
+
        if (remote_server_exists(path))
                {
                log_printf("Address already in use: %s\n", path);
@@ -258,8 +275,10 @@ static RemoteConnection *remote_server_open(const gchar *path)
        if (fd == -1) return nullptr;
 
        addr.sun_family = AF_UNIX;
-       sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX);
-       strncpy(addr.sun_path, path, sun_path_len);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+       strncpy(addr.sun_path, path, sizeof(addr.sun_path));
+#pragma GCC diagnostic pop
        if (bind(fd, reinterpret_cast<const struct sockaddr*>(&addr), sizeof(addr)) == -1 ||
            listen(fd, REMOTE_SERVER_BACKLOG) == -1)
                {
@@ -284,7 +303,7 @@ static RemoteConnection *remote_server_open(const gchar *path)
        return rc;
 }
 
-static void remote_server_subscribe(RemoteConnection *rc, RemoteReadFunc *func, gpointer data)
+static void remote_server_subscribe(RemoteConnection *rc, RemoteConnection::ReadFunc *func, gpointer data)
 {
        if (!rc || !rc->server) return;
 
@@ -298,17 +317,20 @@ static RemoteConnection *remote_client_open(const gchar *path)
        RemoteConnection *rc;
        struct stat st;
        struct sockaddr_un addr;
-       gint sun_path_len;
        gint fd;
 
+       if (strlen(path) >= sizeof(addr.sun_path)) return nullptr;
+
        if (stat(path, &st) != 0 || !S_ISSOCK(st.st_mode)) return nullptr;
 
        fd = socket(PF_UNIX, SOCK_STREAM, 0);
        if (fd == -1) return nullptr;
 
        addr.sun_family = AF_UNIX;
-       sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX);
-       strncpy(addr.sun_path, path, sun_path_len);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+       strncpy(addr.sun_path, path, sizeof(addr.sun_path));
+#pragma GCC diagnostic pop
        if (connect(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) == -1)
                {
                DEBUG_1("error connecting to socket: %s", strerror(errno));
@@ -326,14 +348,15 @@ static RemoteConnection *remote_client_open(const gchar *path)
 
 static sig_atomic_t sigpipe_occurred = FALSE;
 
-static void sighandler_sigpipe(gint UNUSED(sig))
+static void sighandler_sigpipe(gint)
 {
        sigpipe_occurred = TRUE;
 }
 
 static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
 {
-       struct sigaction new_action, old_action;
+       struct sigaction new_action;
+       struct sigaction old_action;
        gboolean ret = FALSE;
        GError *error = nullptr;
        GIOChannel *channel;
@@ -445,12 +468,12 @@ void remote_close(RemoteConnection *rc)
  *-----------------------------------------------------------------------------
  */
 
-static void gr_image_next(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_image_next(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_next(lw_id);
 }
 
-static void gr_new_window(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_new_window(const gchar *, GIOChannel *, gpointer)
 {
        LayoutWindow *lw = nullptr;
 
@@ -461,7 +484,7 @@ static void gr_new_window(const gchar *UNUSED(text), GIOChannel *UNUSED(channel)
        layout_set_path(lw_id, pwd);
 }
 
-static gboolean gr_close_window_cb(gpointer UNUSED(data))
+static gboolean gr_close_window_cb(gpointer)
 {
        if (!layout_valid(&lw_id)) return FALSE;
 
@@ -470,42 +493,42 @@ static gboolean gr_close_window_cb(gpointer UNUSED(data))
        return G_SOURCE_REMOVE;
 }
 
-static void gr_close_window(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_close_window(const gchar *, GIOChannel *, gpointer)
 {
        g_idle_add((gr_close_window_cb), nullptr);
 }
 
-static void gr_image_prev(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_image_prev(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_prev(lw_id);
 }
 
-static void gr_image_first(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_image_first(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_first(lw_id);
 }
 
-static void gr_image_last(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_image_last(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_last(lw_id);
 }
 
-static void gr_fullscreen_toggle(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_fullscreen_toggle(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_full_screen_toggle(lw_id);
 }
 
-static void gr_fullscreen_start(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_fullscreen_start(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_full_screen_start(lw_id);
 }
 
-static void gr_fullscreen_stop(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_fullscreen_stop(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_full_screen_stop(lw_id);
 }
 
-static void gr_lw_id(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_lw_id(const gchar *text, GIOChannel *, gpointer)
 {
        lw_id = layout_find_by_layout_id(text);
        if (!lw_id)
@@ -515,7 +538,7 @@ static void gr_lw_id(const gchar *text, GIOChannel *UNUSED(channel), gpointer UN
        layout_valid(&lw_id);
 }
 
-static void gr_slideshow_start_rec(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_slideshow_start_rec(const gchar *text, GIOChannel *, gpointer)
 {
        GList *list;
        gchar *tilde_filename;
@@ -526,15 +549,15 @@ static void gr_slideshow_start_rec(const gchar *text, GIOChannel *UNUSED(channel
        g_free(tilde_filename);
 
        layout_valid(&lw_id);
-       list = filelist_recursive_full(dir_fd, lw_id->sort_method, lw_id->sort_ascend);
+       list = filelist_recursive_full(dir_fd, lw_id->options.file_view_list_sort.method, lw_id->options.file_view_list_sort.ascend, lw_id->options.file_view_list_sort.case_sensitive);
        file_data_unref(dir_fd);
        if (!list) return;
-//printf("length: %d\n", g_list_length(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 *UNUSED(channel), gpointer UNUSED(data))
+static void gr_cache_thumb(const gchar *text, GIOChannel *, gpointer)
 {
        if (!g_strcmp0(text, "clear"))
                {
@@ -546,7 +569,7 @@ static void gr_cache_thumb(const gchar *text, GIOChannel *UNUSED(channel), gpoin
                }
 }
 
-static void gr_cache_shared(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_cache_shared(const gchar *text, GIOChannel *, gpointer)
 {
        if (!g_strcmp0(text, "clear"))
                cache_manager_standard_process_remote(TRUE);
@@ -554,22 +577,22 @@ static void gr_cache_shared(const gchar *text, GIOChannel *UNUSED(channel), gpoi
                cache_manager_standard_process_remote(FALSE);
 }
 
-static void gr_cache_metadata(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_cache_metadata(const gchar *, GIOChannel *, gpointer)
 {
        cache_maintain_home_remote(TRUE, FALSE, nullptr);
 }
 
-static void gr_cache_render(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_cache_render(const gchar *text, GIOChannel *, gpointer)
 {
        cache_manager_render_remote(text, FALSE, FALSE, nullptr);
 }
 
-static void gr_cache_render_recurse(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_cache_render_recurse(const gchar *text, GIOChannel *, gpointer)
 {
        cache_manager_render_remote(text, TRUE, FALSE, nullptr);
 }
 
-static void gr_cache_render_standard(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_cache_render_standard(const gchar *text, GIOChannel *, gpointer)
 {
        if(options->thumbnails.spec_standard)
                {
@@ -577,7 +600,7 @@ static void gr_cache_render_standard(const gchar *text, GIOChannel *UNUSED(chann
                }
 }
 
-static void gr_cache_render_standard_recurse(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_cache_render_standard_recurse(const gchar *text, GIOChannel *, gpointer)
 {
        if(options->thumbnails.spec_standard)
                {
@@ -585,24 +608,27 @@ static void gr_cache_render_standard_recurse(const gchar *text, GIOChannel *UNUS
                }
 }
 
-static void gr_slideshow_toggle(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_slideshow_toggle(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_slideshow_toggle(lw_id);
 }
 
-static void gr_slideshow_start(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_slideshow_start(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_slideshow_start(lw_id);
 }
 
-static void gr_slideshow_stop(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_slideshow_stop(const gchar *, GIOChannel *, gpointer)
 {
        layout_image_slideshow_stop(lw_id);
 }
 
-static void gr_slideshow_delay(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_slideshow_delay(const gchar *text, GIOChannel *, gpointer)
 {
-       gdouble t1, t2, t3, n;
+       gdouble t1;
+       gdouble t2;
+       gdouble t3;
+       gdouble n;
        gint res;
 
        res = sscanf(text, "%lf:%lf:%lf", &t1, &t2, &t3);
@@ -646,7 +672,7 @@ static void gr_slideshow_delay(const gchar *text, GIOChannel *UNUSED(channel), g
        options->slideshow.delay = static_cast<gint>(n * 10.0 + 0.01);
 }
 
-static void gr_tools_show(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_tools_show(const gchar *, GIOChannel *, gpointer)
 {
        gboolean popped;
        gboolean hidden;
@@ -657,7 +683,7 @@ static void gr_tools_show(const gchar *UNUSED(text), GIOChannel *UNUSED(channel)
                }
 }
 
-static void gr_tools_hide(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_tools_hide(const gchar *, GIOChannel *, gpointer)
 {
        gboolean popped;
        gboolean hidden;
@@ -668,14 +694,14 @@ static void gr_tools_hide(const gchar *UNUSED(text), GIOChannel *UNUSED(channel)
                }
 }
 
-static gboolean gr_quit_idle_cb(gpointer UNUSED(data))
+static gboolean gr_quit_idle_cb(gpointer)
 {
        exit_program();
 
        return G_SOURCE_REMOVE;
 }
 
-static void gr_quit(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_quit(const gchar *, GIOChannel *, gpointer)
 {
        /* schedule exit when idle, if done from within a
         * remote handler remote_close will crash
@@ -683,7 +709,7 @@ static void gr_quit(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpoi
        g_idle_add(gr_quit_idle_cb, nullptr);
 }
 
-static void gr_file_load_no_raise(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_file_load_no_raise(const gchar *text, GIOChannel *, gpointer)
 {
        gchar *filename;
        gchar *tilde_filename;
@@ -726,12 +752,16 @@ static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data)
        gr_raise(text, channel, data);
 }
 
-static void gr_pixel_info(const gchar *UNUSED(text), GIOChannel *channel, gpointer UNUSED(data))
+static void gr_pixel_info(const gchar *, GIOChannel *channel, gpointer)
 {
        gchar *pixel_info;
-       gint x_pixel, y_pixel;
-       gint width, height;
-       gint r_mouse, g_mouse, b_mouse;
+       gint x_pixel;
+       gint y_pixel;
+       gint width;
+       gint height;
+       gint r_mouse;
+       gint g_mouse;
+       gint b_mouse;
        PixbufRenderer *pr;
 
        if (!layout_valid(&lw_id)) return;
@@ -770,11 +800,14 @@ static void gr_pixel_info(const gchar *UNUSED(text), GIOChannel *channel, gpoint
                }
 }
 
-static void gr_rectangle(const gchar *UNUSED(text), GIOChannel *channel, gpointer UNUSED(data))
+static void gr_rectangle(const gchar *, GIOChannel *channel, gpointer)
 {
        gchar *rectangle_info;
        PixbufRenderer *pr;
-       gint x1, y1, x2, y2;
+       gint x1;
+       gint y1;
+       gint x2;
+       gint y2;
 
        if (!options->draw_rectangle) return;
        if (!layout_valid(&lw_id)) return;
@@ -797,7 +830,7 @@ static void gr_rectangle(const gchar *UNUSED(text), GIOChannel *channel, gpointe
                }
 }
 
-static void gr_render_intent(const gchar *UNUSED(text), GIOChannel *channel, gpointer UNUSED(data))
+static void gr_render_intent(const gchar *, GIOChannel *channel, gpointer)
 {
        gchar *render_intent;
 
@@ -832,7 +865,6 @@ static void get_filelist(const gchar *text, GIOChannel *channel, gboolean recurs
        FileFormatClass format_class;
        FileData *dir_fd;
        FileData *fd;
-       GString *out_string = g_string_new(nullptr);
        GList *work;
        gchar *tilde_filename;
 
@@ -871,11 +903,12 @@ static void get_filelist(const gchar *text, GIOChannel *channel, gboolean recurs
                filelist_read(dir_fd, &list, nullptr);
                }
 
+       GString *out_string = g_string_new(nullptr);
        work = list;
        while (work)
                {
                fd = static_cast<FileData *>(work->data);
-               g_string_append_printf(out_string, "%s", fd->path);
+               g_string_append(out_string, fd->path);
                format_class = filter_file_get_class(fd->path);
 
                switch (format_class)
@@ -920,7 +953,7 @@ static void get_filelist(const gchar *text, GIOChannel *channel, gboolean recurs
        file_data_unref(dir_fd);
 }
 
-static void gr_get_selection(const gchar *UNUSED(text), GIOChannel *channel, gpointer UNUSED(data))
+static void gr_get_selection(const gchar *, GIOChannel *channel, gpointer)
 {
        if (!layout_valid(&lw_id)) return;
 
@@ -947,7 +980,7 @@ static void gr_get_selection(const gchar *UNUSED(text), GIOChannel *channel, gpo
        g_string_free(out_string, TRUE);
 }
 
-static void gr_selection_add(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_selection_add(const gchar *text, GIOChannel *, gpointer)
 {
        if (!layout_valid(&lw_id)) return;
 
@@ -1008,12 +1041,12 @@ static void gr_selection_add(const gchar *text, GIOChannel *UNUSED(channel), gpo
                }
 }
 
-static void gr_selection_clear(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_selection_clear(const gchar *, GIOChannel *, gpointer)
 {
        layout_select_none(lw_id);  // Checks lw_id validity internally.
 }
 
-static void gr_selection_remove(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_selection_remove(const gchar *text, GIOChannel *, gpointer)
 {
        if (!layout_valid(&lw_id)) return;
 
@@ -1114,7 +1147,7 @@ static void gr_selection_remove(const gchar *text, GIOChannel *UNUSED(channel),
        g_free(path);
 }
 
-static void gr_collection(const gchar *text, GIOChannel *channel, gpointer UNUSED(data))
+static void gr_collection(const gchar *text, GIOChannel *channel, gpointer)
 {
        GString *contents = g_string_new(nullptr);
 
@@ -1133,7 +1166,7 @@ static void gr_collection(const gchar *text, GIOChannel *channel, gpointer UNUSE
        g_string_free(contents, TRUE);
 }
 
-static void gr_collection_list(const gchar *UNUSED(text), GIOChannel *channel, gpointer UNUSED(data))
+static void gr_collection_list(const gchar *, GIOChannel *channel, gpointer)
 {
 
        GList *collection_list = nullptr;
@@ -1146,7 +1179,7 @@ static void gr_collection_list(const gchar *UNUSED(text), GIOChannel *channel, g
        while (work)
                {
                auto collection_name = static_cast<const gchar *>(work->data);
-               out_string = g_string_append(out_string, g_strdup(collection_name));
+               out_string = g_string_append(out_string, collection_name);
                out_string = g_string_append(out_string, "\n");
 
                work = work->next;
@@ -1155,22 +1188,22 @@ static void gr_collection_list(const gchar *UNUSED(text), GIOChannel *channel, g
        g_io_channel_write_chars(channel, out_string->str, -1, nullptr, nullptr);
        g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
 
-       string_list_free(collection_list);
+       g_list_free_full(collection_list, g_free);
        g_string_free(out_string, TRUE);
 }
 
-static gboolean wait_cb(const gpointer data)
+static gboolean wait_cb(gpointer data)
 {
        gint position = GPOINTER_TO_INT(data);
        gint x = position >> 16;
        gint y = position - (x << 16);
 
-       gtk_window_move(GTK_WINDOW(lw_id->window), x, y);
+       gq_gtk_window_move(GTK_WINDOW(lw_id->window), x, y);
 
        return G_SOURCE_REMOVE;
 }
 
-static void gr_geometry(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_geometry(const gchar *text, GIOChannel *, gpointer)
 {
        gchar **geometry;
 
@@ -1184,7 +1217,7 @@ static void gr_geometry(const gchar *text, GIOChannel *UNUSED(channel), gpointer
                geometry = g_strsplit_set(text, "+", 3);
                if (geometry[1] != nullptr && geometry[2] != nullptr )
                        {
-                       gtk_window_move(GTK_WINDOW(lw_id->window), atoi(geometry[1]), atoi(geometry[2]));
+                       gq_gtk_window_move(GTK_WINDOW(lw_id->window), atoi(geometry[1]), atoi(geometry[2]));
                        }
                }
        else
@@ -1203,17 +1236,17 @@ static void gr_geometry(const gchar *text, GIOChannel *UNUSED(channel), gpointer
        g_strfreev(geometry);
 }
 
-static void gr_filelist(const gchar *text, GIOChannel *channel, gpointer UNUSED(data))
+static void gr_filelist(const gchar *text, GIOChannel *channel, gpointer)
 {
        get_filelist(text, channel, FALSE);
 }
 
-static void gr_filelist_recurse(const gchar *text, GIOChannel *channel, gpointer UNUSED(data))
+static void gr_filelist_recurse(const gchar *text, GIOChannel *channel, gpointer)
 {
        get_filelist(text, channel, TRUE);
 }
 
-static void gr_file_tell(const gchar *UNUSED(text), GIOChannel *channel, gpointer UNUSED(data))
+static void gr_file_tell(const gchar *, GIOChannel *channel, gpointer)
 {
        gchar *out_string;
        gchar *collection_name = nullptr;
@@ -1244,7 +1277,7 @@ static void gr_file_tell(const gchar *UNUSED(text), GIOChannel *channel, gpointe
        g_free(out_string);
 }
 
-static void gr_file_info(const gchar *UNUSED(text), GIOChannel *channel, gpointer UNUSED(data))
+static void gr_file_info(const gchar *, GIOChannel *channel, gpointer)
 {
        gchar *filename;
        FileData *fd;
@@ -1357,7 +1390,7 @@ static gboolean is_config_file(const gchar *param)
        return FALSE;
 }
 
-static void gr_config_load(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_config_load(const gchar *text, GIOChannel *, gpointer)
 {
        gchar *filename = expand_tilde(text);
 
@@ -1384,7 +1417,7 @@ static void gr_config_load(const gchar *text, GIOChannel *UNUSED(channel), gpoin
        g_free(filename);
 }
 
-static void gr_get_sidecars(const gchar *text, GIOChannel *channel, gpointer UNUSED(data))
+static void gr_get_sidecars(const gchar *text, GIOChannel *channel, gpointer)
 {
        gchar *filename = expand_tilde(text);
        FileData *fd = file_data_new_group(filename);
@@ -1407,7 +1440,7 @@ static void gr_get_sidecars(const gchar *text, GIOChannel *channel, gpointer UNU
        g_free(filename);
 }
 
-static void gr_get_destination(const gchar *text, GIOChannel *channel, gpointer UNUSED(data))
+static void gr_get_destination(const gchar *text, GIOChannel *channel, gpointer)
 {
        gchar *filename = expand_tilde(text);
        FileData *fd = file_data_new_group(filename);
@@ -1420,7 +1453,7 @@ static void gr_get_destination(const gchar *text, GIOChannel *channel, gpointer
        g_free(filename);
 }
 
-static void gr_file_view(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_file_view(const gchar *text, GIOChannel *, gpointer)
 {
        gchar *filename;
        gchar *tilde_filename = expand_tilde(text);
@@ -1432,7 +1465,7 @@ static void gr_file_view(const gchar *text, GIOChannel *UNUSED(channel), gpointe
        g_free(tilde_filename);
 }
 
-static void gr_list_clear(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer data)
+static void gr_list_clear(const gchar *, GIOChannel *, gpointer data)
 {
        auto remote_data = static_cast<RemoteData *>(data);
 
@@ -1441,7 +1474,7 @@ static void gr_list_clear(const gchar *UNUSED(text), GIOChannel *UNUSED(channel)
        remote_data->single_dir = TRUE;
 }
 
-static void gr_list_add(const gchar *text, GIOChannel *UNUSED(channel), gpointer data)
+static void gr_list_add(const gchar *text, GIOChannel *, gpointer data)
 {
        auto remote_data = static_cast<RemoteData *>(data);
        gboolean is_new = TRUE;
@@ -1528,7 +1561,74 @@ static void gr_list_add(const gchar *text, GIOChannel *UNUSED(channel), gpointer
                }
 }
 
-static void gr_raise(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_action(const gchar *text, GIOChannel *, gpointer)
+{
+       GtkAction *action;
+
+       if (!layout_valid(&lw_id))
+               {
+               return;
+               }
+
+       if (g_strstr_len(text, -1, ".desktop") != nullptr)
+               {
+               file_util_start_editor_from_filelist(text, layout_selection_list(lw_id), layout_get_path(lw_id), lw_id->window);
+               }
+       else
+               {
+               action = gtk_action_group_get_action(lw_id->action_group, text);
+               if (action)
+                       {
+                       gtk_action_activate(action);
+                       }
+               else
+                       {
+                       log_printf("Action %s unknown", text);
+                       }
+               }
+}
+
+static void gr_action_list(const gchar *, GIOChannel *channel, gpointer)
+{
+       ActionItem *action_item;
+       gint max_length = 0;
+       GList *list = nullptr;
+       GString *out_string = g_string_new(nullptr);
+
+       if (!layout_valid(&lw_id))
+               {
+               return;
+               }
+
+       list = get_action_items();
+
+       /* Get the length required for padding */
+       for (GList *work = list; work; work = work->next)
+               {
+               action_item = static_cast<ActionItem *>(work->data);
+               const auto length = g_utf8_strlen(action_item->name, -1);
+               max_length = MAX(length, max_length);
+               }
+
+       /* Pad the action names to the same column for readable output */
+       for (GList *work = list; work; work = work->next)
+               {
+               action_item = static_cast<ActionItem *>(work->data);
+
+               g_string_append_printf(out_string, "%-*s", max_length + 4, action_item->name);
+               out_string = g_string_append(out_string, action_item->label);
+               out_string = g_string_append(out_string, "\n");
+               }
+
+       action_items_free(list);
+
+       g_io_channel_write_chars(channel, out_string->str, -1, nullptr, nullptr);
+       g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
+
+       g_string_free(out_string, TRUE);
+}
+
+static void gr_raise(const gchar *, GIOChannel *, gpointer)
 {
        if (layout_valid(&lw_id))
                {
@@ -1536,7 +1636,7 @@ static void gr_raise(const gchar *UNUSED(text), GIOChannel *UNUSED(channel), gpo
                }
 }
 
-static void gr_pwd(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUSED(data))
+static void gr_pwd(const gchar *text, GIOChannel *, gpointer)
 {
        LayoutWindow *lw = nullptr;
 
@@ -1547,14 +1647,14 @@ static void gr_pwd(const gchar *text, GIOChannel *UNUSED(channel), gpointer UNUS
        lw_id = lw;
 }
 
-static void gr_print0(const gchar *UNUSED(text), GIOChannel *channel, gpointer UNUSED(data))
+static void gr_print0(const gchar *, GIOChannel *channel, gpointer)
 {
        g_io_channel_write_chars(channel, "print0", -1, nullptr, nullptr);
        g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
 }
 
 #ifdef HAVE_LUA
-static void gr_lua(const gchar *text, GIOChannel *channel, gpointer UNUSED(data))
+static void gr_lua(const gchar *text, GIOChannel *channel, gpointer)
 {
        gchar *result = nullptr;
        gchar **lua_command;
@@ -1598,6 +1698,8 @@ struct RemoteCommandEntry {
 
 static RemoteCommandEntry remote_commands[] = {
        /* short, long                  callback,               extra, prefer, parameter, description */
+       { nullptr, "--action:",          gr_action,            TRUE,  FALSE, N_("<ACTION>"), N_("execute keyboard action (See Help/Reference/Remote Keyboard Actions)") },
+       { nullptr, "--action-list",          gr_action_list,    FALSE,  FALSE, nullptr, N_("list available keyboard actions (some are redundant)") },
        { "-b", "--back",               gr_image_prev,          FALSE, FALSE, nullptr, N_("previous image") },
        { nullptr, "--close-window",       gr_close_window,        FALSE, FALSE, nullptr, N_("close window") },
        { nullptr, "--config-load:",       gr_config_load,         TRUE,  FALSE, N_("<FILE>|layout ID"), N_("load configuration from FILE") },
@@ -1674,7 +1776,8 @@ static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **
                                if (offset) *offset = text + strlen(remote_commands[i].opt_s);
                                return &remote_commands[i];
                                }
-                       else if (remote_commands[i].opt_l &&
+
+                       if (remote_commands[i].opt_l &&
                                 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0)
                                {
                                if (offset) *offset = text + strlen(remote_commands[i].opt_l);
@@ -1697,7 +1800,7 @@ static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **
        return nullptr;
 }
 
-static void remote_cb(RemoteConnection *UNUSED(rc), const gchar *text, GIOChannel *channel, gpointer data)
+static void remote_cb(RemoteConnection *, const gchar *text, GIOChannel *channel, gpointer data)
 {
        RemoteCommandEntry *entry;
        const gchar *offset;
@@ -1728,10 +1831,11 @@ void remote_help()
                        {
                        s_opt_param = g_strdup(remote_commands[i].opt_s  ? remote_commands[i].opt_s : "" );
                        l_opt_param = g_strconcat(remote_commands[i].opt_l, remote_commands[i].parameter, NULL);
-                       printf_term(FALSE, "  %-4s %-40s%-s\n",
-                                       s_opt_param,
-                                       l_opt_param,
-                                       _(remote_commands[i].description));
+
+                       if (g_str_has_prefix(l_opt_param, "--"))
+                               {
+                               printf_term(FALSE, "  %-4s %-40s%-s\n", s_opt_param, l_opt_param, _(remote_commands[i].description));
+                               }
                        g_free(s_opt_param);
                        g_free(l_opt_param);
                        }