emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: x-export-frames for non-Cairo builds


From: Eli Zaretskii
Subject: Re: x-export-frames for non-Cairo builds
Date: Fri, 26 Jan 2018 10:08:26 +0200

> From: Clément Pit-Claudel <address@hidden>
> Date: Thu, 25 Jan 2018 18:25:55 -0500
> 
> I'd like to capture screenshots of Emacs frames from inside Emacs (currently 
> I use `import' or `xwd', but they don't always work well).
> On Cairo there's x-export-frame, but I don't think there's an equivalent 
> function for other builds.
> 
> The following draft seems to work nicely for me (on GTK3)
> 
>     DEFUN ("x-export-png", Fx_export_png, Sx_export_png, 0, 1, 0,
>            doc: /* Save FRAME as 'screenshot.png'. */)
>          (Lisp_Object frame)
>     {

Please, not another x-FOO function that is very likely to have 4
different implementations.  Instead, please define a single function
whose name does NOT start with "x-", and make it have a GTK-specific
and a Cairo-specific implementation, which (the implementations)
ideally should not be exported to Lisp.

>       struct frame *f = decode_window_system_frame(frame);
>       int width = FRAME_PIXEL_WIDTH (f);
>       int height = FRAME_PIXEL_HEIGHT (f);
>       printf("W, H: %d, %d\n", width, height);

"printf"?

>       GdkWindow *w = gtk_widget_get_window (FRAME_GTK_WIDGET (f));
>       GdkPixbuf *pb = gdk_pixbuf_get_from_window(w, 0, 0, width, height);
>       gdk_pixbuf_save (pb, "/tmp/screenshot.png", "png", NULL, NULL);

That hard-coded file name is a no-no.  The function should probably
accept an optional file name, and by default use some defcustom, which
I think should be a relative file name, i.e. created in the current
directory.  AFAIU, the image format should also be an optional
argument (even though not all GUI frames will support that).

> * Assuming proper error checking, documentation, and adjustments, would there 
> be interest in merging this?

Yes.  Implementations for other window-systems are welcome.

> * Where should this code go? Should it be merged into x-export-frames?

frame.c looks like the best place to me.

Thanks.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]