commit 78ecd67888566167fb4c881d8350f611fa039649 (HEAD, refs/remotes/origin/master) Author: Po Lu Date: Wed Apr 6 05:54:31 2022 +0000 Improve safety of haiku-drag-message * lisp/term/haiku-win.el (haiku-drag-and-drop): Ignore placeholder message. * src/frame.c (delete_frame): Prevent deleting drop source frame on Haiku. * src/haiku_support.cc (RELEASE_NOW, CANCEL_DROP): New message types. (class EmacsView, MessageReceived): Handle new message types. (be_drag_message): Drag CANCEL_DROP message on quit; also send RELEASE_NOW to view if quitting. * src/haikuselect.c (syms_of_haikuselect) (haiku_unwind_drag_message): Clear new frame variable. (Fhaiku_drag_message): Set new frame variable. * src/haikuterm.h: Update prototypes. diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el index 6f8f9ac519..955947fe6a 100644 --- a/lisp/term/haiku-win.el +++ b/lisp/term/haiku-win.el @@ -264,8 +264,11 @@ VALUE will be encoded as UTF-8 and stored under the type (if (multibyte-string-p text) text (decode-coding-string text 'undecided)))))) - (t (message "Don't know how to drop any of: %s" - (mapcar #'car string))))))) + ((not (eq (cdr (assq 'type string)) + 3003)) ; Type of the placeholder message Emacs uses + ; to cancel a drop on C-g. + (message "Don't know how to drop any of: %s" + (mapcar #'car string))))))) (define-key special-event-map [drag-n-drop] 'haiku-drag-and-drop) diff --git a/src/frame.c b/src/frame.c index 05b22ac72b..93028aa895 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1991,6 +1991,10 @@ delete_frame (Lisp_Object frame, Lisp_Object force) else if (x_dnd_in_progress && f == x_dnd_frame) error ("Attempt to delete the drop source frame"); #endif +#ifdef HAVE_HAIKU + else if (f == haiku_dnd_frame) + error ("Attempt to delete the drop source frame"); +#endif XSETFRAME (frame, f); diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 830255d3f0..cb38a572f7 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -81,8 +81,13 @@ along with GNU Emacs. If not, see . */ #include "haiku_support.h" -#define SCROLL_BAR_UPDATE 3000 -#define WAIT_FOR_RELEASE 3001 +enum + { + SCROLL_BAR_UPDATE = 3000, + WAIT_FOR_RELEASE = 3001, + RELEASE_NOW = 3002, + CANCEL_DROP = 3003, + }; static color_space dpy_color_space = B_NO_COLOR_SPACE; static key_map *key_map = NULL; @@ -1272,7 +1277,10 @@ class EmacsView : public BView ~EmacsView () { if (wait_for_release_message) - gui_abort ("Wait for release message still exists"); + { + wait_for_release_message->SendReply (wait_for_release_message); + delete wait_for_release_message; + } TearDownDoubleBuffering (); @@ -1307,6 +1315,14 @@ class EmacsView : public BView else wait_for_release_message = looper->DetachCurrentMessage (); } + else if (msg->what == RELEASE_NOW) + { + if (wait_for_release_message) + wait_for_release_message->SendReply (msg); + + delete wait_for_release_message; + wait_for_release_message = NULL; + } else BView::MessageReceived (msg); } @@ -4087,6 +4103,7 @@ be_drag_message (void *view, void *message, bool allow_same_view, BMessage *msg = (BMessage *) message; BMessage wait_for_release; BMessenger messenger (vw); + BMessage cancel_message (CANCEL_DROP); struct object_wait_info infos[2]; ssize_t stat; @@ -4142,6 +4159,16 @@ be_drag_message (void *view, void *message, bool allow_same_view, if (should_quit_function ()) { + /* Do the best we can to prevent something from being + dropped, since Haiku doesn't provide a way to actually + cancel drag-and-drop. */ + if (vw->LockLooper ()) + { + vw->DragMessage (&cancel_message, BRect (0, 0, 0, 0)); + vw->UnlockLooper (); + } + + messenger.SendMessage (CANCEL_DROP); drag_and_drop_in_progress = false; return true; } diff --git a/src/haikuselect.c b/src/haikuselect.c index c3053688f5..a186acc66f 100644 --- a/src/haikuselect.c +++ b/src/haikuselect.c @@ -27,6 +27,12 @@ along with GNU Emacs. If not, see . */ #include +/* The frame that is currently the source of a drag-and-drop + operation, or NULL if none is in progress. The reason for this + variable is to prevent it from being deleted, which really breaks + the nested event loop inside be_drag_message. */ +struct frame *haiku_dnd_frame; + static void haiku_lisp_to_message (Lisp_Object, void *); DEFUN ("haiku-selection-data", Fhaiku_selection_data, Shaiku_selection_data, @@ -726,6 +732,7 @@ haiku_should_quit_drag (void) static void haiku_unwind_drag_message (void *message) { + haiku_dnd_frame = NULL; BMessage_delete (message); } @@ -774,6 +781,7 @@ ignored if it is dropped on top of FRAME. */) if (!FRAME_VISIBLE_P (f)) error ("Frame is invisible"); + haiku_dnd_frame = f; be_message = be_create_simple_message (); record_unwind_protect_ptr (haiku_unwind_drag_message, be_message); @@ -852,4 +860,6 @@ used to retrieve the current position of the mouse. */); defsubr (&Shaiku_selection_put); defsubr (&Shaiku_selection_owner_p); defsubr (&Shaiku_drag_message); + + haiku_dnd_frame = NULL; } diff --git a/src/haikuterm.h b/src/haikuterm.h index 8f311b2ab1..586df28575 100644 --- a/src/haikuterm.h +++ b/src/haikuterm.h @@ -192,6 +192,7 @@ extern struct haiku_display_info *x_display_list; extern struct font_driver const haikufont_driver; extern Lisp_Object tip_frame; +extern struct frame *haiku_dnd_frame; struct scroll_bar { commit a6f7d0f4e38555080bbdb45dbb414e15d206f548 Author: Po Lu Date: Wed Apr 6 12:42:45 2022 +0800 ; * src/xterm.c: Improve commentary. diff --git a/src/xterm.c b/src/xterm.c index 102447ad7e..7eef2b488b 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -142,14 +142,22 @@ along with GNU Emacs. If not, see . */ draw text in inverse video, and the cursor graphics context is used to display the cursor in the most common case. + N.B. that some of the other window systems supported by use an + emulation of graphics contexts to hold the foreground and + background colors used in a glyph string, while the some others + ports compute those colors directly based on the colors of the + string's face and its highlight, but only on X are graphics + contexts a data structure inherent to the window system. + COLOR ALLOCATION - In X, pixel values for colors are not guaranteed to correspond to - their individual components. The rules for converting colors into - pixel values are defined by the visual class of each display opened - by Emacs. When a display is opened, a suitable visual is obtained - from the X server, and a colormap is created based on that visual, - which is then used for each frame created. + In (and only in) X, pixel values for colors are not guaranteed to + correspond to their individual components. The rules for + converting colors into pixel values are defined by the visual class + of each display opened by Emacs. When a display is opened, a + suitable visual is obtained from the X server, and a colormap is + created based on that visual, which is then used for each frame + created. The colormap is then used by the X server to convert pixel values from a frame created by Emacs into actual colors which are output @@ -202,6 +210,10 @@ along with GNU Emacs. If not, see . */ which is used to determine the color values for given pixel values. + In other window systems supported by Emacs, color allocation is + handled by the window system itself, to whom Emacs simply passes 24 + (or 32-bit) RGB values. + OPTIONAL FEATURES While X servers and client libraries tend to come with many commit 62eb57f43871dacb6c7ac1f6e2cdaf7add1414e2 Author: Po Lu Date: Wed Apr 6 12:27:57 2022 +0800 Clean up more PGTK code * lisp/term/pgtk-win.el (featurep): (pgtk): (pgtk-use-im-context): (pgtk-handle-nxopen): (pgtk-handle-nxopentemp): (pgtk-ignore-1-arg): ([C-drag-n-drop]): ([M-drag-n-drop]): ([C-M-drag-n-drop]): (pgtk-alternate-modifier): (pgtk-right-alternate-modifier): (pgtk-right-command-modifier): (pgtk-right-control-modifier): (pgtk-do-hide-emacs): (pgtk-hide-others): (pgtk-do-hide-others): (pgtk-emacs-info-panel): (pgtk-do-emacs-info-panel): (pgtk-next-frame): (pgtk-prev-frame): (after-make-frame-functions): (tool-bar-mode): (pgtk-toggle-toolbar): (pgtk-print-buffer): (scalable-fonts-allowed): (pgtk-standard-fontset-spec): (pgtk-store-cut-buffer-internal): (pgtk-copy-including-secondary): (pgtk-paste-secondary): (pgtk-suspend-error): (window-system-initialization): (after-init-hook): Remove code mindlessly copied from ns-win.el, delete unused custom group, write doc strings and rename variables duplicated from X to their names on X. Also reformat comments and code. (pgtk-use-im-context-handler): New function. * src/pgtkfns.c (syms_of_pgtkfns): Delete useless AppleScript (!) code copied from NS. * src/pgtkselect.c: Write FIXME about selection API usage. * src/pgtkterm.c (get_keysym_name): Implement correctly instead of sprintf'ing the numeric value of the keysym into a static buffer. (pgtk_set_window_size): (xg_scroll_callback): Delete code that was #if 0'd out and doesn't make sense on PGTK. (pgtk_delete_terminal): Remove misleading comment. diff --git a/lisp/term/pgtk-win.el b/lisp/term/pgtk-win.el index 495b4a1111..a9d6db2d45 100644 --- a/lisp/term/pgtk-win.el +++ b/lisp/term/pgtk-win.el @@ -23,10 +23,11 @@ ;;; Commentary: ;;; Code: + (eval-when-compile (require 'cl-lib)) -(or (featurep 'pgtk) - (error "%s: Loading pgtk-win.el but not compiled for pure Gtk+-3." - invocation-name)) +(unless (featurep 'pgtk) + (error "%s: Loading pgtk-win.el but not compiled with PGTK." + invocation-name)) ;; Documentation-purposes only: actually loaded in loadup.el. (require 'term/common-win) @@ -38,39 +39,14 @@ (require 'fontset) (require 'dnd) -(defgroup pgtk nil - "Pure-GTK specific features." - :group 'environment) - -;;;; Command line argument handling. - (defvar x-invocation-args) -;; Set in term/common-win.el; currently unused by Gtk's x-open-connection. (defvar x-command-line-resources) - -;; pgtkterm.c. (defvar pgtk-input-file) - -(declare-function pgtk-use-im-context "pgtkim.c") (defvar pgtk-use-im-context-on-new-connection) -(defun pgtk-handle-nxopen (_switch &optional temp) - (setq unread-command-events (append unread-command-events - (if temp '(pgtk-open-temp-file) - '(pgtk-open-file))) - pgtk-input-file (append pgtk-input-file (list (pop x-invocation-args))))) - -(defun pgtk-handle-nxopentemp (switch) - (pgtk-handle-nxopen switch t)) - -(defun pgtk-ignore-1-arg (_switch) - (setq x-invocation-args (cdr x-invocation-args))) - -;;;; File handling. - +(declare-function pgtk-use-im-context "pgtkim.c") (declare-function pgtk-hide-emacs "pgtkfns.c" (on)) - (defun pgtk-drag-n-drop (event &optional new-frame force-text) "Edit the files listed in the drag-n-drop EVENT. Switch to a buffer editing the last file dropped." @@ -91,7 +67,6 @@ Switch to a buffer editing the last file dropped." (dnd-insert-text window 'private data) (dnd-handle-one-url window 'private url-or-string)))) - (defun pgtk-drag-n-drop-other-frame (event) "Edit the files listed in the drag-n-drop EVENT, in other frames. May create new frames, or reuse existing ones. The frame editing @@ -110,132 +85,12 @@ the last file dropped is selected." (pgtk-drag-n-drop event t t)) (global-set-key [drag-n-drop] 'pgtk-drag-n-drop) -(global-set-key [C-drag-n-drop] 'pgtk-drag-n-drop-other-frame) -(global-set-key [M-drag-n-drop] 'pgtk-drag-n-drop-as-text) -(global-set-key [C-M-drag-n-drop] 'pgtk-drag-n-drop-as-text-other-frame) - -;;;; Frame-related functions. - -;; pgtkterm.c -(defvar pgtk-alternate-modifier) -(defvar pgtk-right-alternate-modifier) -(defvar pgtk-right-command-modifier) -(defvar pgtk-right-control-modifier) - -;; You say tomAYto, I say tomAHto.. -(with-no-warnings - (defvaralias 'pgtk-option-modifier 'pgtk-alternate-modifier) - (defvaralias 'pgtk-right-option-modifier 'pgtk-right-alternate-modifier)) - -(defun pgtk-do-hide-emacs () - (interactive) - (pgtk-hide-emacs t)) - -(declare-function pgtk-hide-others "pgtkfns.c" ()) - -(defun pgtk-do-hide-others () - (interactive) - (pgtk-hide-others)) - -(declare-function pgtk-emacs-info-panel "pgtkfns.c" ()) - -(defun pgtk-do-emacs-info-panel () - (interactive) - (pgtk-emacs-info-panel)) - -(defun pgtk-next-frame () - "Switch to next visible frame." - (interactive) - (other-frame 1)) - -(defun pgtk-prev-frame () - "Switch to previous visible frame." - (interactive) - (other-frame -1)) - -;; Frame will be focused anyway, so select it -;; (if this is not done, mode line is dimmed until first interaction) -;; FIXME: Sounds like we're working around a bug in the underlying code. -(add-hook 'after-make-frame-functions 'select-frame) - -(defvar tool-bar-mode) -(declare-function tool-bar-mode "tool-bar" (&optional arg)) - -;; Based on a function by David Reitter ; -;; see https://lists.gnu.org/archive/html/emacs-devel/2005-09/msg00681.html . -(defun pgtk-toggle-toolbar (&optional frame) - "Switches the tool bar on and off in frame FRAME. - If FRAME is nil, the change applies to the selected frame." - (interactive) - (modify-frame-parameters - frame (list (cons 'tool-bar-lines - (if (> (or (frame-parameter frame 'tool-bar-lines) 0) 0) - 0 1)) )) - (if (not tool-bar-mode) (tool-bar-mode t))) - - -;;;; Dialog-related functions. - -;; Ask user for confirm before printing. Due to Kevin Rodgers. -(defun pgtk-print-buffer () - "Interactive front-end to `print-buffer': asks for user confirmation first." - (interactive) - (if (and (called-interactively-p 'interactive) - (or (listp last-nonmenu-event) - (and (char-or-string-p (event-basic-type last-command-event)) - (memq 'super (event-modifiers last-command-event))))) - (let ((last-nonmenu-event (if (listp last-nonmenu-event) - last-nonmenu-event - ;; Fake it: - `(mouse-1 POSITION 1)))) - (if (y-or-n-p (format "Print buffer %s? " (buffer-name))) - (print-buffer) - (error "Canceled"))) - (print-buffer))) - -;;;; Font support. - -;; Needed for font listing functions under both backend and normal -(setq scalable-fonts-allowed t) - -;; Default fontset. This is mainly here to show how a fontset -;; can be set up manually. Ordinarily, fontsets are auto-created whenever -;; a font is chosen by -(defvar pgtk-standard-fontset-spec - ;; Only some code supports this so far, so use uglier XLFD version - ;; "-pgtk-*-*-*-*-*-10-*-*-*-*-*-fontset-standard,latin:Courier,han:Kai" - (mapconcat 'identity - '("-*-Monospace-*-*-*-*-10-*-*-*-*-*-fontset-standard" - "latin:-*-Courier-*-*-*-*-10-*-*-*-*-*-iso10646-1") - ",") - "String of fontset spec of the standard fontset. -This defines a fontset consisting of the Courier and other fonts. -See the documentation of `create-fontset-from-fontset-spec' for the format.") - - -;;;; Pasteboard support. - -(define-obsolete-function-alias 'pgtk-store-cut-buffer-internal - 'gui-set-selection "24.1") - - -(defun pgtk-copy-including-secondary () - (interactive) - (call-interactively 'kill-ring-save) - (gui-set-selection 'SECONDARY (buffer-substring (point) (mark t)))) - -(defun pgtk-paste-secondary () - (interactive) - (insert (gui-get-selection 'SECONDARY))) - (defun pgtk-suspend-error () - ;; Don't allow suspending if any of the frames are PGTK frames. + "Don't allow suspending if any of the frames are PGTK frames." (if (memq 'pgtk (mapcar 'window-system (frame-list))) (error "Cannot suspend Emacs while a PGTK GUI frame exists"))) - - (defvar pgtk-initialized nil "Non-nil if pure-GTK windowing has been initialized.") @@ -244,11 +99,13 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") (display &optional xrm-string must-succeed)) (declare-function pgtk-set-resource "pgtkfns.c" (owner name value)) -;; Do the actual pure-GTK Windows setup here; the above code just -;; defines functions and variables that we use now. +;; Do the actual window system setup here; the above code just defines +;; functions and variables that we use now. (cl-defmethod window-system-initialization (&context (window-system pgtk) &optional display) - "Initialize Emacs for pure-GTK windowing." + "Initialize the PGTK window system. +WINDOW-SYSTEM is, aptly, `pgtk'. +DISPLAY is the name of the display Emacs should connect to." (cl-assert (not pgtk-initialized)) ;; PENDING: not needed? @@ -269,7 +126,7 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") (create-default-fontset) ;; Create the standard fontset. (condition-case err - (create-fontset-from-fontset-spec pgtk-standard-fontset-spec t) + (create-fontset-from-fontset-spec standard-fontset-spec t) (error (display-warning 'initialization (format "Creation of the standard fontset failed: %s" err) @@ -359,14 +216,12 @@ EVENT is a `preedit-text-event'." (define-key special-event-map [preedit-text] 'pgtk-preedit-text) -(add-hook 'after-init-hook - (function - (lambda () - (when (eq window-system 'pgtk) - (pgtk-use-im-context pgtk-use-im-context-on-new-connection))))) - +(defun pgtk-use-im-context-handler () + "Set up input context usage after Emacs initialization." + (when (eq window-system 'pgtk) + (pgtk-use-im-context pgtk-use-im-context-on-new-connection))) -;;; +(add-hook 'after-init-hook #'pgtk-use-im-context-handler) (defcustom x-gtk-stock-map (mapcar (lambda (arg) diff --git a/src/pgtkfns.c b/src/pgtkfns.c index 38e6085843..b028296720 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -38,13 +38,6 @@ along with GNU Emacs. If not, see . */ #include "xsettings.h" #include "atimer.h" - -#ifdef HAVE_PGTK - -/* Static variables to handle applescript execution. */ -static Lisp_Object as_script, *as_result; -static int as_status; - static ptrdiff_t image_cache_refcount; static int x_decode_color (struct frame *f, Lisp_Object color_name, @@ -4007,10 +4000,6 @@ be used as the image of the icon representing the frame. */); defsubr (&Sx_file_dialog); defsubr (&Sx_select_font); - as_status = 0; - as_script = Qnil; - as_result = 0; - monitor_scale_factor_alist = Qnil; staticpro (&monitor_scale_factor_alist); @@ -4055,5 +4044,3 @@ be used as the image of the icon representing the frame. */); DEFSYM (Qreverse_portrait, "reverse-portrait"); DEFSYM (Qreverse_landscape, "reverse-landscape"); } - -#endif diff --git a/src/pgtkselect.c b/src/pgtkselect.c index 2660ea3ed3..2f4a872a05 100644 --- a/src/pgtkselect.c +++ b/src/pgtkselect.c @@ -17,13 +17,15 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ -/* -Originally by Carl Edman -Updated by Christian Limpach (chris@nice.ch) -OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com) -macOS/Aqua port by Christophe de Dinechin (descubes@earthlink.net) -GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu) -*/ +/* FIXME: this file needs a major rewrite to replace the use of GTK's + own high-level GtkClipboard API with the GDK selection API: + + https://developer-old.gnome.org/gdk3/stable/gdk3-Selections.html + + That way, most of the code can be shared with X, and non-text + targets along with drag-and-drop can be supported. GDK implements + selections according to the ICCCM, as on X, but its selection API + will work on any supported window system. */ /* This should be the first include, as it may set up #defines affecting interpretation of even the system includes. */ @@ -151,10 +153,8 @@ selection_type_to_quarks (GdkAtom type, GQuark * quark_data, *quark_size = quark_clipboard_size; } else - { - /* fixme: Is it safe to use 'error' here? */ - error ("Unknown selection type."); - } + /* FIXME: Is it safe to use 'error' here? */ + error ("Unknown selection type."); } static void diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 9458738142..b2816aa04a 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -136,12 +136,10 @@ pgtk_toolkit_position (struct frame *f, int x, int y, } } -/* - * This is not a flip context in the same sense as gpu rendering - * scences, it only occurs when a new context was required due to a - * resize or other fundamental change. This is called when that - * context's surface has completed drawing - */ +/* This is not a flip context in the same sense as gpu rendering + scenes, it only occurs when a new context was required due to a + resize or other fundamental change. This is called when that + context's surface has completed drawing. */ static void flip_cr_context (struct frame *f) @@ -221,14 +219,8 @@ mark_pgtkterm (void) char * get_keysym_name (int keysym) -/* -------------------------------------------------------------------------- - Called by keyboard.c. Not sure if the return val is important, except - that it be unique. - -------------------------------------------------------------------------- */ { - static char value[16]; - sprintf (value, "%d", keysym); - return value; + return gdk_keyval_name (keysym); } void @@ -531,31 +523,8 @@ pgtk_set_window_size (struct frame *f, bool change_gravity, gtk_widget_get_size_request (FRAME_GTK_WIDGET (f), &pixelwidth, &pixelheight); -#if 0 - if (pixelwise) - { - pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width); - pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height); - } - else - { - pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width); - pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height); - } -#else pixelwidth = width; pixelheight = height; -#endif - -#if 0 - frame_size_history_add - (f, Qx_set_window_size_1, width, height, - list5 (Fcons (make_fixnum (pixelwidth), make_fixnum (pixelheight)), - Fcons (make_fixnum (pixelwidth), make_fixnum (pixelheight)), - make_fixnum (f->border_width), - make_fixnum (FRAME_PGTK_TITLEBAR_HEIGHT (f)), - make_fixnum (FRAME_TOOLBAR_HEIGHT (f)))); -#endif for (GtkWidget * w = FRAME_GTK_WIDGET (f); w != NULL; w = gtk_widget_get_parent (w)) @@ -3921,28 +3890,21 @@ xg_scroll_callback (GtkRange * range, switch (scroll) { case GTK_SCROLL_JUMP: -#if 0 - /* Buttons 1 2 or 3 must be grabbed. */ - if (FRAME_DISPLAY_INFO (f)->grabbed != 0 - && FRAME_DISPLAY_INFO (f)->grabbed < (1 << 4)) -#endif - { - if (bar->horizontal) - { - part = scroll_bar_horizontal_handle; - whole = (int) (gtk_adjustment_get_upper (adj) - - gtk_adjustment_get_page_size (adj)); - portion = min ((int) value, whole); - bar->dragging = portion; - } - else - { - part = scroll_bar_handle; - whole = gtk_adjustment_get_upper (adj) - - gtk_adjustment_get_page_size (adj); - portion = min ((int) value, whole); - bar->dragging = portion; - } + if (bar->horizontal) + { + part = scroll_bar_horizontal_handle; + whole = (int) (gtk_adjustment_get_upper (adj) - + gtk_adjustment_get_page_size (adj)); + portion = min ((int) value, whole); + bar->dragging = portion; + } + else + { + part = scroll_bar_handle; + whole = gtk_adjustment_get_upper (adj) - + gtk_adjustment_get_page_size (adj); + portion = min ((int) value, whole); + bar->dragging = portion; } break; case GTK_SCROLL_STEP_BACKWARD: @@ -4505,8 +4467,6 @@ pgtk_delete_terminal (struct terminal *terminal) xg_display_close (dpyinfo->gdpy); - /* Do not close the connection here because it's already closed - by X(t)CloseDisplay (Bug#18403). */ dpyinfo->gdpy = NULL; } commit f0ff20be51980731364ef5ccf0505c35ea1b4e78 Author: Po Lu Date: Wed Apr 6 10:29:53 2022 +0800 * src/emacs.c (main): Improve accuracy of daemon warning message on PGTK. diff --git a/src/emacs.c b/src/emacs.c index 2a4dcc2c2c..acb409fcb7 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1734,12 +1734,25 @@ main (int argc, char **argv) sockfd = SD_LISTEN_FDS_START; #endif /* HAVE_LIBSYSTEMD */ -#ifdef USE_GTK + /* On X, the bug happens because we call abort to avoid GLib + crashes upon a longjmp in our X error handler. + + On PGTK, GTK calls exit in its own error handlers for either + X or Wayland. Display different messages depending on the + window system to avoid referring users to the wrong GTK bug + report. */ +#ifdef HAVE_PGTK + fputs ("Due to a limitation in GTK 3, Emacs built with PGTK will simply exit when a" + "display connection is closed." + "\nThere is no way to fix this problem, so if you want to use Emacs on Wayland" + "on multiple displays and have Emacs survive disconnects, you lose.", + stderr); +#elif defined USE_GTK fputs ("\nWarning: due to a long standing Gtk+ bug\nhttps://gitlab.gnome.org/GNOME/gtk/issues/221\n\ Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n", stderr); -#endif /* USE_GTK */ +#endif if (daemon_type == 2) { commit e2fb5ecaea67497224455fdbfe4850a5a74c9d00 Author: Po Lu Date: Wed Apr 6 09:09:13 2022 +0800 * src/xterm.c (x_dnd_send_unsupported_drop): Also handle TEXT target. diff --git a/src/xterm.c b/src/xterm.c index 926fb9b048..102447ad7e 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -2787,6 +2787,7 @@ x_dnd_send_unsupported_drop (struct x_display_info *dpyinfo, Window target_windo for (i = 0; i < x_dnd_n_targets; ++i) { if (x_dnd_targets[i] == XA_STRING + || x_dnd_targets[i] == dpyinfo->Xatom_TEXT || x_dnd_targets[i] == dpyinfo->Xatom_COMPOUND_TEXT || x_dnd_targets[i] == dpyinfo->Xatom_UTF8_STRING) break; commit bda8f5deec7dcbe35530f4a0b9f00cdec3805449 Author: Po Lu Date: Wed Apr 6 08:55:30 2022 +0800 Preserve contents of PRIMARY when sending unsupported drop * src/xterm.c (x_dnd_send_unsupported_drop): Set local value of PRIMARY to the preexisting selection value, if any. diff --git a/src/xterm.c b/src/xterm.c index 37bbd5d7e1..926fb9b048 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -2824,7 +2824,10 @@ x_dnd_send_unsupported_drop (struct x_display_info *dpyinfo, Window target_windo root_y = dest_y; } - x_own_selection (QPRIMARY, Qnil, frame); + x_own_selection (QPRIMARY, + assq_no_quit (QPRIMARY, + dpyinfo->terminal->Vselection_alist), + frame); event.xbutton.window = child; event.xbutton.x = dest_x; commit 8ef37913d3be5ff518018acb6b0144d6e559b5ba Author: Paul Eggert Date: Tue Apr 5 17:48:05 2022 -0700 Port Org encode-time usage back to Emacs 25 * lisp/org/ol.el (org-store-link): * lisp/org/org-clock.el (org-clock-sum) (org-clock-update-time-maybe): * lisp/org/org-colview.el (org-colview-construct-allowed-dates): * lisp/org/org-macro.el (org-macro--vc-modified-time): * lisp/org/org-macs.el (org-2ft, org-matcher-time): * lisp/org/org-table.el (org-table-eval-formula): * lisp/org/org.el (org-read-date, org-display-custom-time) (org-time-string-to-time, org-timestamp-change): Don’t assume Emacs 27 encode-time, since standalone Org still works with Emacs 25 and it’s easier if we minimize differences from standalone Org. Problem reported by Max Nikulin (Bug#54731). This reverts much of 2021-12-16T17:40:21Z!eggert@cs.ucla.edu. diff --git a/lisp/org/ol.el b/lisp/org/ol.el index 905e491f4a..a03d85f618 100644 --- a/lisp/org/ol.el +++ b/lisp/org/ol.el @@ -1575,7 +1575,7 @@ non-nil." (setq link (format-time-string (car org-time-stamp-formats) - (encode-time + (apply 'encode-time (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd) nil nil nil)))) (org-link-store-props :type "calendar" :date cd))) diff --git a/lisp/org/org-clock.el b/lisp/org/org-clock.el index dce5d9d4c0..7395669109 100644 --- a/lisp/org/org-clock.el +++ b/lisp/org/org-clock.el @@ -1904,11 +1904,11 @@ PROPNAME lets you set a custom text property instead of :org-clock-minutes." ((match-end 2) ;; Two time stamps. (let* ((ts (float-time - (encode-time + (apply #'encode-time (save-match-data (org-parse-time-string (match-string 2)))))) (te (float-time - (encode-time + (apply #'encode-time (org-parse-time-string (match-string 3))))) (dt (- (if tend (min te tend) te) (if tstart (max ts tstart) ts)))) @@ -3042,9 +3042,9 @@ Otherwise, return nil." (setq ts (match-string 1) te (match-string 3)) (setq s (- (float-time - (encode-time (org-parse-time-string te))) + (apply #'encode-time (org-parse-time-string te))) (float-time - (encode-time (org-parse-time-string ts)))) + (apply #'encode-time (org-parse-time-string ts)))) neg (< s 0) s (abs s) h (floor (/ s 3600)) diff --git a/lisp/org/org-colview.el b/lisp/org/org-colview.el index 371889432d..829fcbbe3f 100644 --- a/lisp/org/org-colview.el +++ b/lisp/org/org-colview.el @@ -782,7 +782,7 @@ around it." (setq time-after (copy-sequence time)) (setf (nth 3 time-before) (1- (nth 3 time))) (setf (nth 3 time-after) (1+ (nth 3 time))) - (mapcar (lambda (x) (format-time-string fmt (encode-time x))) + (mapcar (lambda (x) (format-time-string fmt (apply #'encode-time x))) (list time-before time time-after))))) (defun org-columns-open-link (&optional arg) diff --git a/lisp/org/org-macro.el b/lisp/org/org-macro.el index bb8a95065b..0921f3aa27 100644 --- a/lisp/org/org-macro.el +++ b/lisp/org/org-macro.el @@ -378,7 +378,7 @@ Return value as a string." (buffer-substring (point) (line-end-position))))) (when (cl-some #'identity time) - (setq date (encode-time time)))))))) + (setq date (apply #'encode-time time)))))))) (let ((proc (get-buffer-process buf))) (while (and proc (accept-process-output proc .5 nil t))))) (kill-buffer buf)) diff --git a/lisp/org/org-macs.el b/lisp/org/org-macs.el index 6f038f026b..b10725bd52 100644 --- a/lisp/org/org-macs.el +++ b/lisp/org/org-macs.el @@ -1185,7 +1185,7 @@ nil, just return 0." ((numberp s) s) ((stringp s) (condition-case nil - (float-time (encode-time (org-parse-time-string s))) + (float-time (apply #'encode-time (org-parse-time-string s))) (error 0))) (t 0))) @@ -1252,7 +1252,7 @@ following special strings: \"\", \"\", \"\", and \"\". Return 0. if S is not recognized as a valid value." - (let ((today (float-time (encode-time + (let ((today (float-time (apply #'encode-time (append '(0 0 0) (nthcdr 3 (decode-time))))))) (save-match-data (cond diff --git a/lisp/org/org-table.el b/lisp/org/org-table.el index 58707eae44..c4daed1665 100644 --- a/lisp/org/org-table.el +++ b/lisp/org/org-table.el @@ -2606,7 +2606,7 @@ location of point." (format-time-string (org-time-stamp-format (string-match-p "[0-9]\\{1,2\\}:[0-9]\\{2\\}" ts)) - (encode-time + (apply #'encode-time (save-match-data (org-parse-time-string ts)))))) form t t)) diff --git a/lisp/org/org.el b/lisp/org/org.el index 67c8f1cedf..d656a51591 100644 --- a/lisp/org/org.el +++ b/lisp/org/org.el @@ -13986,7 +13986,7 @@ user." (when (< (nth 2 org-defdecode) org-extend-today-until) (setf (nth 2 org-defdecode) -1) (setf (nth 1 org-defdecode) 59) - (setq org-def (encode-time org-defdecode)) + (setq org-def (apply #'encode-time org-defdecode)) (setq org-defdecode (decode-time org-def))) (let* ((timestr (format-time-string (if org-with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") @@ -14470,7 +14470,7 @@ The command returns the inserted time stamp." time (org-fix-decoded-time t1) str (org-add-props (format-time-string - (substring tf 1 -1) (encode-time time)) + (substring tf 1 -1) (apply 'encode-time time)) nil 'mouse-face 'highlight)) (put-text-property beg end 'display str))) @@ -14725,7 +14725,7 @@ days in order to avoid rounding problems." (defun org-time-string-to-time (s) "Convert timestamp string S into internal time." - (encode-time (org-parse-time-string s))) + (apply #'encode-time (org-parse-time-string s))) (defun org-time-string-to-seconds (s) "Convert a timestamp string S into a number of seconds." @@ -15155,7 +15155,7 @@ When SUPPRESS-TMP-DELAY is non-nil, suppress delays like (setcar time0 (or (car time0) 0)) (setcar (nthcdr 1 time0) (or (nth 1 time0) 0)) (setcar (nthcdr 2 time0) (or (nth 2 time0) 0)) - (setq time (encode-time time0)))) + (setq time (apply 'encode-time time0)))) ;; Insert the new time-stamp, and ensure point stays in the same ;; category as before (i.e. not after the last position in that ;; category). commit 2aa588f016239e8fef3aeec97df7285f81b7f80b Author: Po Lu Date: Wed Apr 6 08:48:41 2022 +0800 * src/xterm.c (handle_one_xevent): Assert that hold_quit is present instead. diff --git a/src/xterm.c b/src/xterm.c index 42ab90df75..37bbd5d7e1 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -13826,8 +13826,9 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (x_dnd_in_progress || x_dnd_waiting_for_finish) { - if (hold_quit) - *hold_quit = inev.ie; + eassert (hold_quit); + + *hold_quit = inev.ie; EVENT_INIT (inev.ie); } commit 743a95f8139fb30705352d721f17ff3217e460b6 Author: Paul Eggert Date: Tue Apr 5 17:20:34 2022 -0700 Pacify gcc -Wanalyzer-null-dereference * src/xterm.c (handle_one_xevent): Don’t dereference HOLD_QUIT if it’s null. Potential problem found with gcc 11.2.1 20220127 (Red Hat 11.2.1-9), when configured with --enable-gcc-warnings. diff --git a/src/xterm.c b/src/xterm.c index b9a5355b41..42ab90df75 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -13826,7 +13826,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (x_dnd_in_progress || x_dnd_waiting_for_finish) { - *hold_quit = inev.ie; + if (hold_quit) + *hold_quit = inev.ie; EVENT_INIT (inev.ie); }