[gentoo-user] A fix for irritations with GPM
From
Alan Mackenzie@21:1/5 to
All on Sun Dec 15 12:10:01 2024
Hello, Gentoo.
As a long time user of the Linux console, two things about the GPM mouse utility get on my nerves.
The first is that on pasting a selection, a carriage return is appended to
the line (or the last line). This means that, for example, on copying a
bash command from one tty to another, there is no opportunity to edit it
before it gets run.
The second is that while selecting, the highlighting on the screen is
done crudely to the end of each line in the selection, rather than to the
end of the text in that line.
I have a fix for these, now. The pertinent source file is drivers/tty/vt/selection.c in the kernel. The patch is in the attached
file 6.8.1-SELECTION.20241215.diff. To use this patch (but see below,
first), extract the patch to your home directory, cd to /usr/src/linux-6.6.62-gentoo (or later version of the kernel), then issue
the command:
$ patch --dry-run -p1 < ~/6.8.1-SELECTION.20241215.diff
.. This is just a dry run which checks the patch applies cleanly rather
than actually applying it. If everything is OK, apply it for real with:
$ patch -p1 < ~/6.8.1-SELECTION.20241215.diff
.. If, on the other hand, you get an error saying Hunk #7 failed, you've probably already applied my earlier patch to enable scrolling on the
console, which included a patch for problem 1 above. You will need to
undo that patch before applying the main one. Extract the attached patch 6.6.13-TRIPLE.20240123.diff, and apply it reversed as follows:
$ patch -p1 -R < ~/6.6.13-TRIPLE.20240123.diff
.. Then apply the main patch, as above.
Having done that, rebuild your kernel, and install it to the /boot
partition in the normal (for you) way. Reboot and enjoy!
The usual reservations apply, of course. There's nothing malicious in
the patches, but if it breaks for you, I'll be sorry and will handle bug reports. Nothing more.
--
Alan Mackenzie (Nuremberg, Germany).
diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index 8967c3a0d916..545ca051635a 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -42,21 +42,20 @@ static struct vc_selection {
char *buffer;
unsigned int buf_len;
volatile int start; /* cleared by clear_selection */
- int end;
+ int end; /* Note: this points to the last char, not to after it. */
+ bool mouse_at_e;
+ unsigned short prev_x;
} vc_sel = {
.lock = __MUTEX_INITIALIZER(vc_sel.lock),
.start = -1,
};
+static bool unicode;
+static unsigned int size_row;
+
/* clear_selection, highlight and highlight_pointer can be called
from interrupt (via scrollback/front) */
-/* set reverse video on characters s-e of console with selection. */
-static inline void highlight(const int s, const int e)
-{
- invert_screen(vc_sel.cons, s, e-s+2, true);
-}
-
/* use complementary color to show the pointer */
static inline void highlight_pointer(const int where)
{
@@ -64,7 +63,7 @@ static inline void highlight_pointer(const int where)
}
static u32
-sel_pos(int n, bool unicode)