From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Cl=c3=a9ment_Pit-Claudel?= Newsgroups: gmane.emacs.devel Subject: x-export-frames for non-Cairo builds Date: Thu, 25 Jan 2018 18:25:55 -0500 Message-ID: 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 1516922667 10317 195.159.176.226 (25 Jan 2018 23:24:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 25 Jan 2018 23:24:27 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 26 00:24:23 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 1eeqsH-0001QH-BP for ged-emacs-devel@m.gmane.org; Fri, 26 Jan 2018 00:24:05 +0100 Original-Received: from localhost ([::1]:43769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eequH-0003Mz-U8 for ged-emacs-devel@m.gmane.org; Thu, 25 Jan 2018 18:26:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eequA-0003Mf-Em for emacs-devel@gnu.org; Thu, 25 Jan 2018 18:26:03 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eequ6-0002yH-G1 for emacs-devel@gnu.org; Thu, 25 Jan 2018 18:26:02 -0500 Original-Received: from mail-oi0-x232.google.com ([2607:f8b0:4003:c06::232]:36358) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eequ6-0002xq-AR for emacs-devel@gnu.org; Thu, 25 Jan 2018 18:25:58 -0500 Original-Received: by mail-oi0-x232.google.com with SMTP id w135so6790508oie.3 for ; Thu, 25 Jan 2018 15:25:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=EwxfIM9spM1vip0mh/Kgw9WClRDhx1RcgEgIlCf6ahg=; b=so5YPGSVKuxAg2uAaKP1jujZUZoC6UMrjo7NC+vhqbIMvOBnbdU4C/A5FmoQXV48rH 2dODvTDeBayC1KwsFx6kfeuBzuu50DUEcnQjl+OehP2+BiXKh6N+PoC3ZpJ20I7SFoSs EvbBgDC0RqNO0IjkIj1jUZz8aceaaED7MPNX2fgOXxWsQEggHSA0Kn65LojHFIWd5c/6 djnKNf6WhV8N4/XKKowmLuEa+pEqgpywjoucsLrYrT15YGV4UD72QKIcgmYsogai7Wdl bAniwNnGVwz1FVhJb0J7IqkCptCLqmTRJ7T6V+mL5GBHAR7iqPUG7TXgoOryYNzmf6uX 1apg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=EwxfIM9spM1vip0mh/Kgw9WClRDhx1RcgEgIlCf6ahg=; b=PBerESHY0KTdl6YpJHcBz7DghbZOOJ8GqWtdAX5pxmZRAD8wvTp3huE2YdnGhLjbsh DFIHNh3HByEaHQgQgC/ebGuLRYnEf3vMigX3mzQ90lLmz/ie2q487n1+D57byjqb1cPJ CkcH6wKAI970j1DUV20UqrRLSVI13EseFQdOI76oL7H8umEOCmS3Yg/6AqB/pssBldfp 6kc9oUdH1jvcAGaGIWPca2SE9aV/4LTxr5zRi4eR5ZurskFkQT3Y80zupdxtVEcP/h7e 7Q6ToWK6X9VDS6eU39/vC3iSd8GuXVkydiwYa9iQ0hlFHfybVkJQ5aGQmA/OUYJCRdgN UIeg== X-Gm-Message-State: AKwxytdY2jhIqR0RHLNpzhuc6MCyYp8r5gm6yrBFNhYc4k/9i7SlK4ZF cv3/2I5fBiyF6EbEiDdQCvOi4aX3 X-Google-Smtp-Source: AH8x227z+2xx7hGWluVCtw0g1Y2KQ0910S8eaVmSORwMl53d01q1TVEaNmxjzKrGQ3PFSupvkK0FdA== X-Received: by 10.202.3.67 with SMTP id 64mr1738554oid.205.1516922757275; Thu, 25 Jan 2018 15:25:57 -0800 (PST) Original-Received: from [18.26.2.123] (26-2-123.dynamic.csail.mit.edu. [18.26.2.123]) by smtp.gmail.com with ESMTPSA id c11sm1197193oic.10.2018.01.25.15.25.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jan 2018 15:25:56 -0800 (PST) Content-Language: en-GB X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::232 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:222245 Archived-At: 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.