Bug 417326 - The cursor is drawn one pixel off its expected Y-coordinate
Summary: The cursor is drawn one pixel off its expected Y-coordinate
Status: CONFIRMED
Alias: None
Product: konsole
Classification: Applications
Component: general (show other bugs)
Version: master
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-09 08:51 UTC by Arthur Kasimov
Modified: 2021-03-10 19:10 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Screenshot of gap 1 (80.64 KB, image/png)
2020-02-09 08:51 UTC, Arthur Kasimov
Details
Screenshot of gap 2 (33.40 KB, image/png)
2020-02-09 08:52 UTC, Arthur Kasimov
Details
Remove adjustment of the cursor rectangle to avoid unwanted gaps (552 bytes, patch)
2020-02-09 08:52 UTC, Arthur Kasimov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Arthur Kasimov 2020-02-09 08:51:31 UTC
Created attachment 125775 [details]
Screenshot of gap 1

When Konsole draws the cursor, it always shifts down cursor Y position by one pixel. Usually it is not noticeable but in some applications, e.g. Vim, it produces an annoying gap on highlighted background.

For example, when you search a text in Vim, it highlights all occurrences of that text in a file. When you place the cursor over the highlighted text, a small but noticeable gap appears. Another example is highlighting of matching parentheses which reveals the same gap. Please check the attached screenshots.

The adjustment of cursor position is located in TerminalDisplay::drawCursor:

// shift rectangle top down one pixel to leave some space
// between top and bottom
QRectF cursorRect = rect.adjusted(0, 1, 0, 0);

Not sure whether this adjustment is still useful for some purposes or not. 
Shouldn't we simply remove it?

Thanks!
Comment 1 Arthur Kasimov 2020-02-09 08:52:09 UTC
Created attachment 125776 [details]
Screenshot of gap 2
Comment 2 Arthur Kasimov 2020-02-09 08:52:38 UTC
Created attachment 125777 [details]
Remove adjustment of the cursor rectangle to avoid unwanted gaps
Comment 3 Christoph Feck 2020-02-09 09:56:14 UTC
The code you remove says it's intentional.
Comment 4 Arthur Kasimov 2020-02-10 21:57:46 UTC
Indeed, the comment to the code says it is intentional but the result looks buggy. In most other terminal emulators the cursor height is the same as line height without any gaps.

I checked further and seems like this code was added while fixing another bug https://bugs.kde.org/show_bug.cgi?id=343283

The last commenter also wonders why the cursor is shifted down by one pixel. Seems like it was just an arbitrary choice without a clear reason. I believe it would be better to remove the gap and draw the cursor just like other terminal emulators do.
Comment 5 Egmont Koblinger 2020-02-10 22:42:13 UTC
(In reply to Christoph Feck from comment #3)
> The code you remove says it's intentional.

git blame'ing that points to bug 343283 - it doesn't seem to me that this gap of 1 pixel was intentional at all.
Comment 6 Justin Zobel 2020-11-05 00:18:23 UTC
Thanks for the report and screenshots Arthur, however I can't seem to reproduce this on konsole from git master.

Can you please retest and confirm if this is still an issue, thanks.
Comment 7 Arthur Kasimov 2020-11-05 02:36:14 UTC
Hi Justin, I can still reproduce the issue using the latest git master. It is not very noticeable though. There is just 1-pixel gap after all, so I used to live with it :)

Looking at the code, character classes were recently moved to new terminalDisplay directory. Nevertheless, the cursor adjustment code that produces a gap is still there - in TerminalPainter::drawCursor.
Comment 8 Justin Zobel 2020-11-05 02:47:22 UTC
Confirmed.