From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: x-export-frames for non-Cairo builds Date: Fri, 26 Jan 2018 10:08:26 +0200 Message-ID: <83372tm491.fsf@gnu.org> References: Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1516954054 19572 195.159.176.226 (26 Jan 2018 08:07:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 26 Jan 2018 08:07:34 +0000 (UTC) Cc: emacs-devel@gnu.org To: =?utf-8?Q?Cl=C3=A9ment?= Pit-Claudel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 26 09:07:29 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eez2T-0003Wf-Qy for ged-emacs-devel@m.gmane.org; Fri, 26 Jan 2018 09:07:09 +0100 Original-Received: from localhost ([::1]:39484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eez4U-0005kV-B5 for ged-emacs-devel@m.gmane.org; Fri, 26 Jan 2018 03:09:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eez3p-0005jk-9L for emacs-devel@gnu.org; Fri, 26 Jan 2018 03:08:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eez3m-00039d-3e for emacs-devel@gnu.org; Fri, 26 Jan 2018 03:08:33 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:37686) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eez3m-00039Z-0R; Fri, 26 Jan 2018 03:08:30 -0500 Original-Received: from [176.228.60.248] (port=4552 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1eez3k-0005xV-UM; Fri, 26 Jan 2018 03:08:29 -0500 In-reply-to: (message from =?utf-8?Q?Cl=C3=A9ment?= Pit-Claudel on Thu, 25 Jan 2018 18:25:55 -0500) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:222247 Archived-At: > From: Clément Pit-Claudel > 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.