--- gimp-2.8.4/app/app.c +++ gimp-2.8.4-1/app/app.c @@ -124,6 +124,45 @@ exit (status); } +static Gimp *gimp_cb; +static int fifo; +gboolean unique_socet_cb(GIOChannel *ioch, GIOCondition cond, gpointer data); +void unique_soket_init(); + +gboolean unique_socet_cb(GIOChannel *ioch, GIOCondition cond, gpointer data) { + gchar *str; + gsize length; + + g_io_channel_read_line(ioch, &str, &length, NULL, NULL); + if (length) { + str[length-1] = 0; + printf("CB: %s %i\n", str, length); + file_open_from_command_line (gimp_cb, str, 0); + g_free(str); + } + + return TRUE; +} + +#include +#include +#include + +void unique_soket_init() { + char* path = "/tmp/gimp.fifo"; + + /* create a read-only FIFO */ + if (mkfifo(path, S_IRUSR | S_IWUSR)) + printf("Failed to create program FIFO\n"); + if ((fifo = open(path, O_RDWR | O_NONBLOCK)) == -1) + printf("Failed to open FIFO for reading\n"); + + /* Open and watch the fifo to become readable */ + GIOChannel *ioch = g_io_channel_unix_new(fifo); + g_io_add_watch(ioch, G_IO_IN, unique_socet_cb, NULL); +} + + void app_run (const gchar *full_prog_name, const gchar **filenames, @@ -248,6 +287,9 @@ loop = g_main_loop_new (NULL, FALSE); + gimp_cb = gimp; + unique_soket_init(); + g_signal_connect_after (gimp, "exit", G_CALLBACK (app_exit_after_callback), loop); @@ -285,6 +327,9 @@ { if (gimp->be_verbose) g_print ("EXIT: %s\n", G_STRFUNC); + + close(fifo); + system("rm -f /tmp/gimp.fifo"); /* * In stable releases, we simply call exit() here. This speeds up --- gimp-2.8.4/app/unique.c +++ gimp-2.8.4-1/app/unique.c @@ -32,6 +32,8 @@ static gboolean gimp_unique_dbus_open (const gchar **filenames, gboolean as_new); +static gboolean gimp_unique_fifo_open (const gchar **filenames, + gboolean as_new); #ifdef G_OS_WIN32 static gboolean gimp_unique_win32_open (const gchar **filenames, gboolean as_new); @@ -44,8 +46,10 @@ #ifdef G_OS_WIN32 return gimp_unique_win32_open (filenames, as_new); #else - return gimp_unique_dbus_open (filenames, as_new); +// return gimp_unique_dbus_open (filenames, as_new); + return gimp_unique_fifo_open (filenames, as_new); #endif + } #ifndef GIMP_CONSOLE_COMPILATION @@ -174,6 +178,44 @@ #endif return FALSE; +} + +static gboolean +gimp_unique_fifo_open (const gchar **filenames, + gboolean as_new) +{ +#ifndef GIMP_CONSOLE_COMPILATION + FILE* fifo; + + if (g_file_test("/tmp/gimp.fifo", G_FILE_TEST_EXISTS) && (fifo = fopen("/tmp/gimp.fifo", "w"))) { + + if (filenames) { + gchar *cwd = g_get_current_dir (); + gint i; + + for (i = 0; filenames[i]; i++) { + GError *error = NULL; + gchar *uri = gimp_unique_filename_to_uri (filenames[i], cwd, &error); + if (uri) { + fwrite(uri, 1, strlen(uri) + 1, fifo); + g_free (uri); + } else { + g_printerr ("conversion to uri failed: %s\n", error->message); + g_clear_error (&error); + } + } + + g_free (cwd); + } + + fclose(fifo); + return TRUE; + } else { + g_printerr ("can't open fifo\n"); + } +#endif + + return FALSE; } #ifdef G_OS_WIN32