Another approach could be to add an option to the screenshot plugin
which launches an external app. This could launch your helper app or
something else. I'm using this to upload screenshots to my flickr account.

Here is a patch for screenshot.c which adds a launch_app option.
What do you think?

Seems like a simple and useful solution. Some comments to the patch:

allocating storage for the command line using:

+ comm = malloc (sizeof(app) + sizeof(dir) + sizeof(name) + 2);

is not going to work well as "app" and "dir" are just pointers and the
size of the memory that they are pointing to is not known at compile
time. You also need to make sure that you allocate enough memory to
store the terminating `\0' character.

haha, yes of course.

I would change that line to:

+ comm = malloc (strlen (app) + strlen (dir) + strlen (name) + 3);

You should use:

runCommand (s, comm);

instead of calling execl directly. runCommand does things like exporting
the DISPLAY environment variable and setting the session id.

I don't like to have "eog" as the default. I'd rather like to see it be
set to nothing by default.

I thought eog is a good default, as it should be present on all distros,
but that's not true if you don't you use gnome.

btw, the patch wouldn't have worked anyway, cause I forgot to change 
SetDisplayOption.
I should have tested it before submitting. Sorry.

Here is another one.
Thanks, Gerd.
diff --git a/plugins/screenshot.c b/plugins/screenshot.c
index ddb9b52..5245c18 100644
--- a/plugins/screenshot.c
+++ b/plugins/screenshot.c
@@ -36,9 +36,10 @@
 
 static int displayPrivateIndex;
 
-#define SHOT_DISPLAY_OPTION_INITIATE 0
-#define SHOT_DISPLAY_OPTION_DIR      1
-#define SHOT_DISPLAY_OPTION_NUM	     2
+#define SHOT_DISPLAY_OPTION_INITIATE   0
+#define SHOT_DISPLAY_OPTION_DIR        1
+#define SHOT_DISPLAY_OPTION_LAUNCH_APP 2
+#define SHOT_DISPLAY_OPTION_NUM        3
 
 typedef struct _ShotDisplay {
     int		    screenPrivateIndex;
@@ -251,6 +252,7 @@ shotPaintScreen (CompScreen		 *s,
 		    if (n >= 0)
 		    {
 			char name[256];
+			char *app;
 			int  number = 0;
 
 			if (n > 0)
@@ -265,12 +267,30 @@ shotPaintScreen (CompScreen		 *s,
 
 			sprintf (name, "screenshot%d.png", number);
 
+			app = sd->opt[SHOT_DISPLAY_OPTION_LAUNCH_APP].value.s;
+
 			if (!writeImageToFile (s->display, dir, name, "png",
 					       w, h, buffer))
 			{
 			    fprintf (stderr, "%s: failed to write "
 				     "screenshot image", programName);
 			}
+			else if (*app != '\0')
+			{
+			    char *comm;
+
+			    comm = malloc (strlen (app)  +
+					   strlen (dir)  +
+					   strlen (name) + 3);
+			    if (comm)
+			    {
+				sprintf (comm, "%s %s/%s", app, dir, name);
+
+				runCommand (s, comm);
+
+				free (comm);
+			    }
+			}
 		    }
 		    else
 		    {
@@ -380,6 +400,15 @@ shotDisplayInitOptions (ShotDisplay *sd)
     o->value.s	      = strdup (SHOT_DIR_DEFAULT);
     o->rest.s.string  = 0;
     o->rest.s.nString = 0;
+
+    o = &sd->opt[SHOT_DISPLAY_OPTION_LAUNCH_APP];
+    o->name           = "launch_app";
+    o->shortDesc      = N_("Launch Application");
+    o->longDesc       = N_("Automatically open screenshot in this application");
+    o->type           = CompOptionTypeString;
+    o->value.s        = strdup ("");
+    o->rest.s.string  = NULL;
+    o->rest.s.nString = 0;
 }
 
 static CompOption *
@@ -414,6 +443,10 @@ shotSetDisplayOption (CompDisplay    *display,
     case SHOT_DISPLAY_OPTION_DIR:
 	if (compSetStringOption (o, value))
 	    return TRUE;
+	break;
+    case SHOT_DISPLAY_OPTION_LAUNCH_APP:
+	if (compSetStringOption (o, value))
+	    return TRUE;
     default:
 	break;
     }
_______________________________________________
compiz mailing list
compiz@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/compiz

Reply via email to