all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Arthur Miller <arthur.miller@live.com>
To: emacs-devel@gnu.org
Subject: Sticky tooltips
Date: Mon, 05 Oct 2020 02:55:07 +0200	[thread overview]
Message-ID: <VI1PR06MB452697A1DAFBCB24D02BBA8B960C0@VI1PR06MB4526.eurprd06.prod.outlook.com> (raw)

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

I played a bit, and it does not look so bad actually. I have played both
with 'propertized' widget and one with 'plain' text; the latter takes
less space on the screen; but it is just to switch comments and test the
propertized version in the patch. 

Adding a checkbox wasn't difficult part and modifiying x-show-tip
accordingly wasn't the hard part. x-show-tip in xfns.c is almost
unchanged minus the part for creating a new buffer and inserting the
string. However, I don't know where to look for mouse motion callback to
turn off automatic hiding on mouse move. Anyway, with patch it is
possible to see how it looks like, even if callback itself does not work.

I added a customize option tooltip-enable-sticky (off by default) which
takes effect only if gtk tooltips are disabled:

(setq x-gtk-use-system-tooltips nil
      tooltip-enable-sticky t)

It is just an idea how it might look and work to see if it is interesting
to have.


[-- Attachment #2: tooltip.el.patch --]
[-- Type: text/x-patch, Size: 3690 bytes --]

--- tooltip.el	2020-08-21 15:12:24.108484748 +0200
+++ lisp/tooltip.el	2020-10-05 02:47:13.662826815 +0200
@@ -26,6 +26,7 @@
 ;;; Code:
 
 (require 'syntax)
+(require 'widget) ; for "sticky" tooltips
 
 (defvar comint-prompt-regexp)
 
@@ -164,6 +165,14 @@
   :group 'tooltip
   :version "27.1")
 
+(defcustom tooltip-enable-sticky nil
+  "Set this variable to true to enable `sticky' tooltip interface.
+This variable does not have effect when Gtk tooltips are enabled
+  (requires Emacs to be compiled with Gtk suppoart and
+  x-gtk-use-system-tootlip to be set to true)."
+  :type 'boolean
+  :group 'tooltip)
+
 \f
 ;;; Variables that are not customizable.
 
@@ -258,12 +267,61 @@
 	    (setf (alist-get 'border-color params) fg))
 	  (when (stringp bg)
 	    (setf (alist-get 'background-color params) bg))
-	  (x-show-tip (propertize text 'face 'tooltip)
-		      (selected-frame)
-		      params
-		      tooltip-hide-delay
-		      tooltip-x-offset
-		      tooltip-y-offset))
+          (if x-gtk-use-system-tooltips
+	      (x-show-tip (propertize text 'face 'tooltip)
+		          (selected-frame)
+		          params
+		          tooltip-hide-delay
+		          tooltip-x-offset
+		          tooltip-y-offset)
+
+            ;; we are not using gtk
+            (with-current-buffer (get-buffer-create " *tip*")
+              (let ((inhibit-read-only t))
+                (erase-buffer)
+                (remove-overlays)
+                (insert (propertize text 'face 'tooltip))
+
+                (when tooltip-enable-sticky
+                  (goto-char (point-min))
+                  (let ((cur-line 0)
+                        (lng-line 0))
+                    (while (not (eobp))
+                      (setq cur-line (- (line-end-position) (line-beginning-position)))
+                      (when (> cur-line lng-line)
+                        (setq lng-line cur-line))
+                      (forward-line))
+
+                    (newline)
+
+                    ;; (insert (propertize
+                    ;;               (make-string (- lng-line 6) ?─)
+                    ;;               'face 'tooltip))
+                    ;; (widget-insert (propertize " Sticky " 'face
+                    ;;                            'tooltip))
+                    (insert (make-string (- lng-line 6) ?─))
+                    (widget-insert " Sticky ")
+                    (widget-create 'checkbox
+                                   :notify (lambda (s &rest ignore)
+                                             (if (widget-value s)
+                                                 (progn ;; OBS nothing here yet
+                                                   ;; (when tooltip-timer
+                                                   ;;   (cancel-timer tooltip-timer)
+                                                   ;;   (setq tooltip-timer nil))
+                                                   )
+                                               ;; else
+                                               (tooltip-hide))))
+                  (use-local-map widget-keymap)
+                  (widget-setup)))
+
+                ;; this (propertize text ... ) here is unnecessary
+                ;; ... but this is just a fast hack
+                (x-show-tip (propertize text 'face 'tooltip)
+                            (selected-frame)
+		            params
+		            tooltip-hide-delay
+		            tooltip-x-offset
+		            tooltip-y-offset)))))
       (error
        (message "Error while displaying tooltip: %s" error)
        (sit-for 1)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: xfns.c.patch --]
[-- Type: text/x-patch, Size: 844 bytes --]

--- xfns.c	2020-09-27 12:07:36.298841349 +0200
+++ src/xfns.c	2020-10-05 02:15:01.690628616 +0200
@@ -7081,7 +7081,11 @@
      buffer.  */
   count_1 = SPECPDL_INDEX ();
   old_buffer = current_buffer;
+  /*
   set_buffer_internal_1 (XBUFFER (w->contents));
+  specbind (Qinhibit_read_only, Qt);
+  specbind (Qinhibit_modification_hooks, Qt);
+  specbind (Qinhibit_point_motion_hooks, Qt);
   bset_truncate_lines (current_buffer, Qnil);
   specbind (Qinhibit_read_only, Qt);
   specbind (Qinhibit_modification_hooks, Qt);
@@ -7092,6 +7096,7 @@
   clear_glyph_matrix (w->current_matrix);
   SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
   try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
+  */
   /* Calculate size of tooltip window.  */
   size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil,
 				  make_fixnum (w->pixel_height), Qnil);

             reply	other threads:[~2020-10-05  0:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05  0:55 Arthur Miller [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-10-22 16:17 Sticky tooltips Arthur Miller
2020-09-28 20:04 Arthur Miller
2020-09-28 22:11 ` Jean Louis
2020-09-29  3:39   ` Arthur Miller
2020-09-29  4:20     ` Jean Louis
2020-09-29  2:41 ` Eli Zaretskii
2020-09-29  3:36   ` Arthur Miller
2020-09-29 14:17     ` Eli Zaretskii
2020-09-29 21:30       ` Arthur Miller
2020-09-30 14:50         ` Eli Zaretskii
2020-09-30 15:17           ` Arthur Miller

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=VI1PR06MB452697A1DAFBCB24D02BBA8B960C0@VI1PR06MB4526.eurprd06.prod.outlook.com \
    --to=arthur.miller@live.com \
    --cc=emacs-devel@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.