emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 62eb57f438: Clean up more PGTK code


From: Po Lu
Subject: master 62eb57f438: Clean up more PGTK code
Date: Wed, 6 Apr 2022 00:31:10 -0400 (EDT)

branch: master
commit 62eb57f43871dacb6c7ac1f6e2cdaf7add1414e2
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    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.
---
 lisp/term/pgtk-win.el | 179 +++++---------------------------------------------
 src/pgtkfns.c         |  13 ----
 src/pgtkselect.c      |  22 +++----
 src/pgtkterm.c        |  80 ++++++----------------
 4 files changed, 48 insertions(+), 246 deletions(-)

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 <dreitter@inf.ed.ac.uk> ;
-;; 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 
<https://www.gnu.org/licenses/>.  */
 #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 <https://www.gnu.org/licenses/>.  */
 
-/*
-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;
     }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]