unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Clément Pit-Claudel" <cpitclaudel@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: x-export-frames for non-Cairo builds
Date: Thu, 25 Jan 2018 18:25:55 -0500	[thread overview]
Message-ID: <d383aa65-2845-d6d4-e4dc-8efa3cb6da88@gmail.com> (raw)

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	other threads:[~2018-01-25 23:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25 23:25 Clément Pit-Claudel [this message]
2018-01-26  8:08 ` x-export-frames for non-Cairo builds Eli Zaretskii
2018-01-26 14:45   ` Stefan Monnier
2018-01-26 16:08   ` Clément Pit-Claudel
2018-01-26 18:56     ` Eli Zaretskii
2018-01-26 23:13       ` Clément Pit-Claudel
2018-02-02 10:30         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d383aa65-2845-d6d4-e4dc-8efa3cb6da88@gmail.com \
    --to=cpitclaudel@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).