emacs-devel
[Top][All Lists]
Advanced

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

x-export-frames for non-Cairo builds


From: Clément Pit-Claudel
Subject: x-export-frames for non-Cairo builds
Date: Thu, 25 Jan 2018 18:25:55 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

Hi emacs-devel,

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)
    {
      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);

      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);

      return Qnil;
    }

However, I have multiple questions:

* Assuming proper error checking, documentation, and adjustments, would there 
be interest in merging this?
* IIUC, this code is GTK3-only.  On GTK2, it should be possible to use 
gdk_pixbuf_get_from_drawable, right? (or is it 
gdk_pixbuf_xlib_get_from_drawable?).  Both of these gave me linker errors, 
however.
* Where should this code go? Should it be merged into x-export-frames?
* Is this the right way to capture a screenshot of an Emacs frame in GTK?  Or 
is there a faster way? (for example, can I defer part of the work of creating 
the pixbuf, maybe by getting a GdkImage first, and converting later?  I'm 
hoping to reduce the latency of the screenshot-taking process, even if it 
requires some post-processing)

Thanks!
Clément.



reply via email to

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