all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: martin rudalics <rudalics@gmx.at>
Cc: emacs-devel@gnu.org
Subject: Re: make-pointer-invisible on Windows
Date: Thu, 25 Jun 2015 18:02:25 +0300	[thread overview]
Message-ID: <83a8vnesqm.fsf@gnu.org> (raw)
In-Reply-To: <558BA156.6090508@gmx.at>

> Date: Thu, 25 Jun 2015 08:36:06 +0200
> From: martin rudalics <rudalics@gmx.at>
> CC: emacs-devel@gnu.org
> 
>  > There are less radical ways of triggering more thorough redisplay,
>  > than redrawing the whole frame.  I will look into this when I have
>  > time, if no one beats me to it.
> 
> Please do that.

It turns out this has nothing to do with redisplay.  Inserting a
single character is enough to turn off the mouse pointer with your
original patch, after removing the call to SET_FRAME_GARBAGED.  The
problem is that sometimes the effect is far from immediate, you need
to wait for a second or so.

Looking into this, I concluded that calling SetCursor from the main
(a.k.a. "Lisp") thread has no effect whatsoever.  For some reason,
only the input thread can do that.  And it already does, whenever it
gets an appropriate message.  So all we have to do in the main thread
is send that message to the input thread.  This is what the first hunk
below, to be applied on top of your patch, does.

>  >>   > Also, what about the equivalent of the X code that makes the pointer
>  >>   > visible on focus-in events -- don't we need that on MS-Windows?
>  >>
>  >> I don't know.  It's certainly not necessary on XP here.  People would
>  >> have to try though.  In general, it seems that X and Windows differ
>  >> quite substantially in their respective behaviors.  For example, on X,
>  >> when a synchronous shell operation is active, the cursor becomes visible
>  >> as soon as the mouse is moved.  On Windows, the cursor remains invisible
>  >> until the shell operation terminates and the frame gets redrawn
>  >> (obviously, the frame doesn't look very decent in that period either, so
>  >> there are worse problems).
>  >
>  > I don't think this is related to the issue at hand.
> 
> I don't think so either.  My point was that X and Windows run into
> different problems when trying to make the pointer invisible.

Well, actually, it _is_ related, albeit to a different aspect of this.
The code that turns the mouse pointer back on when mouse moves also
runs in the main thread.  So whenever the main thread is busy with
some long calculation, or waits for some synchronous system call, we
cannot rely on this mechanism to timely turn the pointer back on.  But
the input thread can very well do that, so the second hunk of changes
below makes that happen.

So please install your changes, followed by mine (or tell me to do the
latter).  Thanks for working on this.

As for not redrawing the frame during these synchronous operations, I
will try to see why it happens (strangely, I only see it on XP, but
not on Windows 7).

--- src/w32term.c~0	2015-06-25 12:10:25 +0300
+++ src/w32term.c	2015-06-25 17:52:04 +0300
@@ -6613,14 +6613,10 @@ w32_toggle_invisible_pointer (struct fra
   if (f->pointer_invisible != invisible)
     {
       f->pointer_invisible = invisible;
-      SET_FRAME_GARBAGED (f);
+      w32_define_cursor (FRAME_W32_WINDOW (f),
+			 f->output_data.w32->current_cursor);
     }
 
-  if (invisible)
-    SetCursor (NULL);
-  else
-    SetCursor (f->output_data.w32->current_cursor);
-
   unblock_input ();
 }
 
--- src/w32fns.c~0	2015-06-25 12:29:41 +0300
+++ src/w32fns.c	2015-06-25 17:50:19 +0300
@@ -73,6 +73,7 @@ along with GNU Emacs.  If not, see <http
 
 #include <dlgs.h>
 #include <imm.h>
+#include <windowsx.h>
 
 #include "font.h"
 #include "w32font.h"
@@ -3492,13 +3493,31 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARA
       return (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONUP);
 
     case WM_MOUSEMOVE:
-      /* Ignore mouse movements as long as the menu is active.  These
-	 movements are processed by the window manager anyway, and
-	 it's wrong to handle them as if they happened on the
-	 underlying frame.  */
       f = x_window_to_frame (dpyinfo, hwnd);
-      if (f && f->output_data.w32->menubar_active)
-	return 0;
+      if (f)
+	{
+	  /* Ignore mouse movements as long as the menu is active.
+	     These movements are processed by the window manager
+	     anyway, and it's wrong to handle them as if they happened
+	     on the underlying frame.  */
+	  if (f->output_data.w32->menubar_active)
+	    return 0;
+
+	  /* If the mouse moved, and the mouse pointer is invisible,
+	     make it visible again.  We do this here so as to be able
+	     to show the mouse pointer even when the main
+	     (a.k.a. "Lisp") thread is busy doing something.  */
+	  static int last_x, last_y;
+	  int x = GET_X_LPARAM (lParam);
+	  int y = GET_Y_LPARAM (lParam);
+
+	  if (f->pointer_invisible
+	      && (x != last_x || y != last_y))
+	    f->pointer_invisible = false;
+
+	  last_x = x;
+	  last_y = y;
+	}
 
       /* If the mouse has just moved into the frame, start tracking
 	 it, so we will be notified when it leaves the frame.  Mouse



  reply	other threads:[~2015-06-25 15:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-24  9:17 make-pointer-invisible on Windows martin rudalics
2015-06-24 14:50 ` Eli Zaretskii
2015-06-24 17:40   ` martin rudalics
2015-06-24 19:21     ` Eli Zaretskii
2015-06-25  6:36       ` martin rudalics
2015-06-25 15:02         ` Eli Zaretskii [this message]
2015-06-26  6:55           ` martin rudalics
2015-06-26  8:43             ` Eli Zaretskii
2015-06-26  9:15               ` martin rudalics
2015-06-26  9:39                 ` Eli Zaretskii
2015-06-26 10:14                   ` martin rudalics
2015-06-26 10:24                     ` Eli Zaretskii
2015-06-28 14:52                       ` Eli Zaretskii
2015-06-29  9:46                         ` martin rudalics
2015-06-28 14:51                   ` Eli Zaretskii
2015-06-29  9:45                     ` martin rudalics
2015-06-29 14:43                       ` Eli Zaretskii
2015-06-29 17:16                         ` martin rudalics
2015-06-29 17:40                           ` Eli Zaretskii
2015-06-30  6:01                             ` martin rudalics
2015-06-30 15:09                               ` Eli Zaretskii
2015-07-02 13:21                                 ` martin rudalics

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=83a8vnesqm.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=rudalics@gmx.at \
    /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.