From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?No=C3=A9_Lopez?= via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: Calling interactive lisp functions from C Date: Sun, 22 Sep 2024 22:22:15 +0200 Message-ID: <87ed5be8w8.fsf@xn--no-cja.eu> References: <86r09bh8gf.fsf@gnu.org> Reply-To: =?utf-8?Q?No=C3=A9_Lopez?= Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9028"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 23 04:21:03 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ssYhD-0002Bf-5x for ged-emacs-devel@m.gmane-mx.org; Mon, 23 Sep 2024 04:21:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ssYgV-0004e7-UT; Sun, 22 Sep 2024 22:20:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ssT5N-0001vK-O6 for emacs-devel@gnu.org; Sun, 22 Sep 2024 16:21:38 -0400 Original-Received: from smtp.domeneshop.no ([2a01:5b40:0:3006::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ssT5J-0004gX-Tt; Sun, 22 Sep 2024 16:21:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xn--no-cja.eu; s=ds202402; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:In-Reply-To:Subject:Cc:To:From:From:Sender: Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=WW2SQlWxw2onTKR3XUvigK7ZqNd+NjXpzIkeeVC7wa8=; b=P pmziwiNGGhS6IKf/wHhRf7Q7hsl3/RygiQci5z2CHWG3sAcwhKhBGAjysYUdYnR6lBa1sQQRU/3lY 3oHGpz55XL3jDsVUi2/uAuQBgKpC/UHL9HoQ2xxwio3gJ5Txhdoo/4egL/aXWVETCirs/VP9IFnMq bpMm6d58tcK99Ec/4pJSx3FM8jtg4+OlwODiu+dGfA1iD1TSpkTi2I7wcJj1JghGN1WQY6a/A4VTM PxVMO43/WKg5ql1rPr8mvzfXM7TheYKij3LhFMpENwZ7KNSRwMz5QOehzYc9qEwwTW5a2+RyifAVz AZAO Original-Received: from [2a01:e0a:990:a960:b4f3:8f44:ec4:5af5] (port=45864 helo=lignux) by smtp.domeneshop.no with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ssT5E-002KUk-AB; Sun, 22 Sep 2024 22:21:28 +0200 In-Reply-To: <86r09bh8gf.fsf@gnu.org> (message from Eli Zaretskii on Sun, 22 Sep 2024 21:03:28 +0300) Received-SPF: pass client-ip=2a01:5b40:0:3006::1; envelope-from=noe@xn--no-cja.eu; helo=smtp.domeneshop.no X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 22 Sep 2024 22:20:17 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:323938 Archived-At: Eli Zaretskii writes: >> Date: Sun, 22 Sep 2024 18:38:53 +0200 >> From: No=C3=A9 Lopez via "Emacs development discussions." >>=20 >> I am trying to call the read-file-name function from a C WebKit >> callback, in this case it is the =C2=AB=E2=80=AFrun-file-chooser=E2=80= =AF=C2=BB signal. >>=20 >> I came up with this code which works when selecting a file, but aborts >> emacs when hitting the =C2=AB=E2=80=AFcancel=E2=80=AF=C2=BB button of th= e file chooser dialog. >>=20 >> static gboolean wpe_run_file_chooser_cb (WebKitWebView *webview, >> WebKitFileChooserRequest *request, >> struct xwidget *xw) >> { >> /* use read-file-name if only one file is needed, useful for keyboard >> only usage. */ >> if (!webkit_file_chooser_request_get_select_multiple (request)) >> { >> /* TODO: we can use webkit_file_chooser_request_get_selected_files >> * to find a default file name for the prompt. */ >> Lisp_Object file =3D call4 (Qread_file_name, >> build_string ("Select file"), >> Qnil, >> Qnil, >> Qt); >> if (EQ (file, Qnil)) >> { >> webkit_file_chooser_request_cancel (request); >> g_message ("canceled file request"); >> } >> const char *const selected_files[] =3D { SSDATA (file), NULL }; >> webkit_file_chooser_request_select_files (request, selected_files); >> return TRUE; >> } >> return TRUE; >> } >>=20 >> The callback is activated from a click action in the WebKit buffer, so >> =C2=AB=E2=80=AFwaiting_for_input=E2=80=AF=C2=BB is true, causing signal_= or_quit to abort. Using >> clear_waiting_for_input changes it to a segmentation fault. >>=20 >> What can I do to catch the quit signal? Ideally I need to call a >> function to notify WebKit of the cancelation, or it will hang. > > Did you try to bind inhibit-quit to the value t? Yes, but Fx_file_dialox, called from read-file-name calls quit directly without checking inhibit-quit. > An alternative is not to call read-file-name directly, but instead > queue an input event that will invoke a command when processed, and > the command will call read-file-name. That is probably best, if WebKit supports asynchronous answering for that signal. I will look into it. Thanks.