unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 51674@debbugs.gnu.org
Subject: bug#51674: 29.0.50; [PATCH] Fix hang when displaying xwidget script dialog
Date: Mon, 08 Nov 2021 10:10:44 +0800	[thread overview]
Message-ID: <87fss7s8gr.fsf@yahoo.com> (raw)
In-Reply-To: 87fss7s8gr.fsf.ref@yahoo.com

[-- Attachment #1: Type: text/plain, Size: 9 bytes --]

Thanks!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-hang-when-displaying-xwidget-script-dialog.patch --]
[-- Type: text/x-patch, Size: 3374 bytes --]

From 1ce79e6631678dd0c98718bbb0882cc6c169d2b0 Mon Sep 17 00:00:00 2001
From: Po Lu <luangruo@yahoo.com>
Date: Mon, 8 Nov 2021 10:07:55 +0800
Subject: [PATCH] Fix hang when displaying xwidget script dialog

* src/xwidget.c (webkit_script_dialog_cb): New function.
(Fmake_xwidget): Attach script callback signal.
---
 src/xwidget.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/src/xwidget.c b/src/xwidget.c
index f95f5f1d7f..ecb973f485 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -50,6 +50,8 @@ Copyright (C) 2011-2021 Free Software Foundation, Inc.
 static gboolean offscreen_damage_event (GtkWidget *, GdkEvent *, gpointer);
 static void synthesize_focus_in_event (GtkWidget *);
 static GdkDevice *find_suitable_keyboard (struct frame *);
+static gboolean webkit_script_dialog_cb (WebKitWebView *, WebKitScriptDialog *,
+					 gpointer);
 #endif
 
 static struct xwidget *
@@ -240,6 +242,10 @@ DEFUN ("make-xwidget",
 			    "create",
 			    G_CALLBACK (webkit_create_cb),
 			    xw);
+	  g_signal_connect (G_OBJECT (xw->widget_osr),
+			    "script-dialog",
+			    G_CALLBACK (webkit_script_dialog_cb),
+			    NULL);
         }
 
       g_signal_connect (G_OBJECT (xw->widgetwindow_osr), "damage-event",
@@ -1242,6 +1248,66 @@ webkit_decide_policy_cb (WebKitWebView *webView,
     return FALSE;
   }
 }
+
+static gboolean
+webkit_script_dialog_cb (WebKitWebView *webview,
+			 WebKitScriptDialog *script_dialog,
+			 gpointer user)
+{
+  struct frame *f = SELECTED_FRAME ();
+  WebKitScriptDialogType type;
+  GtkWidget *widget;
+  GtkWidget *dialog;
+  GtkWidget *entry;
+  GtkWidget *content_area;
+  const gchar *content;
+  const gchar *message;
+  gint result;
+
+  /* Return TRUE to prevent WebKit from showing the default script
+     dialog in the offscreen window, which runs a nested main loop
+     Emacs can't respond to, and as such can't pass X events to.  */
+  if (!FRAME_WINDOW_P (f))
+    return TRUE;
+
+  type = webkit_script_dialog_get_dialog_type (script_dialog);;
+  widget = FRAME_GTK_OUTER_WIDGET (f);
+  content = webkit_script_dialog_get_message (script_dialog);
+
+  if (type == WEBKIT_SCRIPT_DIALOG_ALERT)
+    dialog = gtk_dialog_new_with_buttons (content, GTK_WINDOW (widget),
+					  GTK_DIALOG_MODAL,
+					  "Dismiss", 1, NULL);
+  else
+    dialog = gtk_dialog_new_with_buttons (content, GTK_WINDOW (widget),
+					  GTK_DIALOG_MODAL,
+					  "OK", 0, "Cancel", 1, NULL);
+
+  if (type == WEBKIT_SCRIPT_DIALOG_PROMPT)
+    {
+      entry = gtk_entry_new ();
+      message = webkit_script_dialog_prompt_get_default_text (script_dialog);
+      content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+      gtk_widget_show (entry);
+      gtk_entry_set_text (GTK_ENTRY (entry), message);
+      gtk_container_add (GTK_CONTAINER (content_area), entry);
+    }
+
+  result = gtk_dialog_run (GTK_DIALOG (dialog));
+
+  if (type == WEBKIT_SCRIPT_DIALOG_CONFIRM
+      || type == WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM)
+    webkit_script_dialog_confirm_set_confirmed (script_dialog, result == 0);
+
+  if (type == WEBKIT_SCRIPT_DIALOG_PROMPT)
+    webkit_script_dialog_prompt_set_text (script_dialog,
+					  gtk_entry_get_text (GTK_ENTRY (entry)));
+
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+
+  return TRUE;
+}
 #endif /* USE_GTK */
 
 
-- 
2.31.1


       reply	other threads:[~2021-11-08  2:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87fss7s8gr.fsf.ref@yahoo.com>
2021-11-08  2:10 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-11-08  5:24   ` bug#51674: 29.0.50; [PATCH] Fix hang when displaying xwidget script dialog Lars Ingebrigtsen
2021-11-08  5:38     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-08  5:40       ` Lars Ingebrigtsen
2021-11-08  5:45         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-08  6:25           ` Lars Ingebrigtsen
2021-11-08  6:29             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-08  6:50               ` Lars Ingebrigtsen
2021-11-08  6:56                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-08  7:01                   ` Lars Ingebrigtsen
2021-11-09  4:31                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-09  4:45                       ` Lars Ingebrigtsen
2021-11-09  4:59                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-09  5:30                           ` Lars Ingebrigtsen
2021-11-09  5:34                             ` Lars Ingebrigtsen
2021-11-09  5:46                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-09  6:10                                 ` Lars Ingebrigtsen
2021-11-09  4:45                   ` Lars Ingebrigtsen

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=87fss7s8gr.fsf@yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=51674@debbugs.gnu.org \
    --cc=luangruo@yahoo.com \
    /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).