Menu

#2170 Indicator with "hover" style, flicker on Windows platform

Cosmetic
closed-fixed
nobody
5
2020-09-11
2020-04-16
rolchg
No

During movement mouse cursor along line with indicator "hover" style the cursor is flipping rapidly
between "Window::cursorHand" and "Window::cursorText".
Simple modification by removing the last part of "if" statement in ScintillaWin.cxx where message"WM_SETCURSOR" is handled solves the problem. That means:
}// else {
//DisplayCursor(Window::cursorText);
//}
The cursor is correctelly switched in "Editor.cxx": SCI_SETCURSOR:
so I have not notice any problem with proper cursor state, after this change .

Discussion

  • Neil Hodgson

    Neil Hodgson - 2020-04-16

    You appear to be refering to an old version of Scintilla since the mentioned code is not present in 4.3.2 with a change to DisplayCursor(ContextCursor());. Its likely the right thing to do is to add more cases to ContextCursor so it can be called whenever needed instead of relying on mouse button changes.

     
  • Uhf7

    Uhf7 - 2020-07-30

    The reason, why the flicker occurs, is the following: There are two Windows messages sent by Windows to Scintilla, when the mouse is moved: WM_MOUSEMOVE and WM_SETCURSOR.

    • WM_MOUSEMOVE informs Scintilla, that the mouse has been moved inside its window.
    • WM_SETCURSOR informs Scintilla, that the mouse cursor has been moved. Anywhere, not necessarily in its window.

    Scintilla calls the Windows function SetCursor (, which sets the mouse cursor shape, not the position), while processing both messages. Unfortunately, Scintilla uses different ways to calculate the desired cursor shape. So, whenever the mouse cursor is moved, two SetCursor calls are applied, sometimes with two different cursor shapes.

    • On WM_MOUSEMOVE, Scintilla calls ButtonMoveWithModifiers, which sets the correct cursor shape.
    • On WM_SETCURSOR, Scintilla calculates the cursor shape by a call to the function Window::Cursor ScintillaWin::ContextCursor(), which calculates a different cursor shape while hovering over indicators.

    The problem could be removed by modifying the ContextCursor() function as follows:

    if (inDragDrop == ddDragging) {
        return Window::cursorUp;
    } else {
        // Display regular (drag) cursor over selection
        POINT pt;
        if (0 != ::GetCursorPos(&pt)) {
            ::ScreenToClient(MainHWND(), &pt);
            if (PointInSelMargin(PointFromPOINT(pt))) {
                return GetMarginCursor(PointFromPOINT(pt));
            } else if (PointInSelection(PointFromPOINT(pt)) && !SelectionEmpty()) {
                return Window::cursorArrow;
            } else if (PointIsHotspot(PointFromPOINT(pt))) {
                return Window::cursorHand;
            } else if (hoverIndicatorPos != Sci::invalidPosition) {
                return  Window::cursorHand;
            }
        }
    }
    return Window::cursorText;
    

    }

    I have added the (hoverIndicatorPos != Sci::invalidPosition) comparison, which is until now only included in the ButtonMoveWithModifiers function.

    I feel it would be the easiest way if you could include the two lines into the code yourself, if you think they are correct, of course.

    Please let me know, if I can assist in any way to get this effect fixed, because some Notepad++ users are not very happy about the flickering, and I kind of introduced it in Notepad++ by suggesting to use standard indicators instead of style byte indicators. I did it, because ScintillaDoc.html says so, and now, I would like to get it work completely smooth.

     
  • Neil Hodgson

    Neil Hodgson - 2020-07-30
    • labels: --> scintilla, win32, cursor
    • status: open --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2020-07-30

    Committed as [cb319e].

    It is credited to 'uhf7'. If you want a different name used then please tell me.

    A subsequent commit [7b1106] simplified the code a little.

     

    Related

    Commit: [7b1106]
    Commit: [cb319e]

  • Uhf7

    Uhf7 - 2020-07-31

    Thank you for the incredibly fast reaction, I just tested it on my system, it worked. I'm going to carry the good news to the Notepad++ developers now.

     
  • Uhf7

    Uhf7 - 2020-07-31

    Ok, now I have a new effect introduced, which is much less annoying, but I want to remove it too. It goes like this:

    • The WM_SETCURSOR message occurs not on mouse moves only, but on mouse clicks too.
    • If there is a standard indicator at the end of file (no non-indicator character after it), and a mouse click is done to the area after the end of file, the cursor switches to the hand icon.
    • It switches back, as soon as the mouse is moved.

    I didn't see it in the first place, but I it can be removed easily. If I click to the area after the end of file, then the caret is set to the end of file. At this occasion, the hoverIndicatorPos is set to this position too. But the WM_SETCURSOR message for the mouse click occurs at another position, after the end of file. In this moment, the hoverIndicatorPos does not match the mouse position. I fixed with a validity check in the ContextCursor() function:

    if (inDragDrop == ddDragging) {
        return Window::cursorUp;
    } else {
        // Display regular (drag) cursor over selection
        if (PointInSelMargin(pt)) {
            return GetMarginCursor(pt);
        } else if (!SelectionEmpty() && PointInSelection(pt)) {
            return Window::cursorArrow;
        } else if (PointIsHotspot(pt)) {
            return Window::cursorHand;
        } else {
            Sci::Position pos = PositionFromLocation(pt, true, true);
            if ((pos != Sci::invalidPosition) && (hoverIndicatorPos != Sci::invalidPosition)) {
                return Window::cursorHand;
            }
        }
    }
    return Window::cursorText;
    

    }

    Can you please insert this check too? Then the flickering problem is hopefully solved.

    The Notepad++ developers want to wait for a Scintilla release 4.4.5. Before this, I want to insert two other new lines into the code, but I will open a new issue for this, it has nothing to do with the flickering problem.

     
  • Neil Hodgson

    Neil Hodgson - 2020-08-03

    Committed as [34147e] with small change to avoid calculating PositionFromLocation unless needed.

     

    Related

    Commit: [34147e]

  • Uhf7

    Uhf7 - 2020-08-03

    Thank you again, the mouse cursor flicker issue should be resolved now for Notepad++.

     
  • Neil Hodgson

    Neil Hodgson - 2020-09-11
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB