Attached is a patch to add horizontal mouse wheel support. It may
look like a big patch, but the only real change is inside
gui.c/normal.c/edit.c (and it is quite minor, I had to modify some
horizontal scrollbar code and that's about it). It applies to the
latest vim73 changeset as of today (i.e. the one titled "Added
":earlier 1f" and ":later 1f".").
Currently only GTK is supported but I can't test it since I don't
actually have access to GTK -- I have only tested the patch in MacVim
(but that code is not included in this patch). Please let me know if
there are any problems with GTK.
I only added GTK support since it was completely straightforward -- I
leave adding support for other GUIs to whoever is interested (it
should be very easy).
One comment regarding the code: since vertical movement uses <MouseUp>
and <MouseDown> I named the horizontal keys <MouseLeft> and
<MouseRight> but I realize that this can be kind of confusing since
e.g. <LeftMouse> is used for clicking the left mouse button. Should I
change the names? To what?
I'm not sure how common it is to have horizontal mouse wheels on PCs
-- but pretty much every Mac comes with some form of horizontal
scrolling (e.g. trackpads on MacBooks or the Apple Magic Mouse) so
this patch is at least useful for MacVim users. (I'd be happy if this
makes it into 7.3 -- in any case I will add it to MacVim 7.3 when I
release that)
Björn
...
One comment regarding the code: since vertical movement uses <MouseUp>
and <MouseDown> I named the horizontal keys <MouseLeft> and
<MouseRight> but I realize that this can be kind of confusing since
e.g. <LeftMouse> is used for clicking the left mouse button. Should I
change the names? To what?
...
I agree that <MouseUp> is also confusing but unfortunately that can't
be changed since it will break backward compatibility (it is possible
to bind to <MouseUp>). Using <MouseScrollLeft> but then <MouseUp>
seemed even weirder to me which is why I chose <MouseLeft> even though
I dislike it.
Björn
This thread seems to have petered out without any sort of resolution.
I would like to see horizontal mouse wheel support added to Vim.
For what my opinion is worth, I don't think we'll ever get away from
the <MouseUp>/<MouseDown> identifiers, but perhaps a decent compromise
is to continue supporting them as "legacy"/deprecated, then add:
<MouseScrollUp> (Same as <MouseUp>)
<MouseScrollDown> (Same as <MouseDown>)
<MouseScrollLeft>
<MouseScrollRight>
- Christian
--
Christian J. Robinson <hep...@gmail.com>
I think this is a good compromise -- unless there are any immediate
objections I'll go ahead and update the patch.
Please note that I still need volunteers to test the patch on GTK
since I do not have access to it. Independent confirmation that the
patch actually works might increase the chances of it being included.
(I have only tested it in MacVim.)
Thanks,
Björn
As long as you're adding MouseScroll{Left,Right,Up,Down}, would this be
a good time to reverse the naming? (The oddity that <MouseUp> indicates
pushing the scrollwheel toward the bottom of the mouse [i.e. down]?)
So, where 'wheel' indicates a standard scrollwheel or the
supermouse-like trackball:
<MouseScrollUp> (Same as <MouseDown>) (pressing up on 'wheel')
<MouseScrollDown> (Same as <MouseUp>) (pressing down on 'wheel')
<MouseScrollLeft> (pressing left on 'wheel')
<MouseScrollRight> (pressing right on 'wheel')
[probably too confusing, and too late, but just a thought]
And another idea:
I don't have a mouse that supports horizontal scrolling, so I tried (but
failed -- see other thread) to test this using mappings similar to many
graphics editors, where shift+vertical-scroll is translated to
horizontal scrolling. (IIRC, it's usually rotated 90-degrees CCW:
up=left, down=right)
e.g.:
map <S-MouseUp> <MouseLeft>
map <S-MouseDown> <MouseRight>
...err, never-mind. I was going to suggest that those be default
mappings, but I just discovered Shift+ is already used to mean 'a full
page' -- :help <S-MouseUp>.
Nonetheless, possibly useful for others who might want to test this.
--
Best,
Ben
I don't think this is a bad idea. Are there any objections?
I just checked and with the patch <MouseLeft> is generated when you
swipe your finger to the right on a trackpad (in line with the
inverted up/down movement). This feels weird...
> And another idea:
>
> I don't have a mouse that supports horizontal scrolling, so I tried (but
> failed -- see other thread) to test this using mappings similar to many
> graphics editors, where shift+vertical-scroll is translated to
> horizontal scrolling. (IIRC, it's usually rotated 90-degrees CCW:
> up=left, down=right)
>
> e.g.:
>
> map <S-MouseUp> <MouseLeft>
> map <S-MouseDown> <MouseRight>
>
> ...err, never-mind. I was going to suggest that those be default
> mappings, but I just discovered Shift+ is already used to mean 'a full
> page' -- :help <S-MouseUp>.
Actually, on the Mac the Shift key is not used since when a "scroll
wheel" event arrives you also get to know "how much" the wheel has
moved and I use this to decide how many lines to scroll.
Is this sort of behavior available on other platforms? If so, I think
it is preferable over having to hold down a key to control how much to
scroll. I could submit another patch which includes the relevant code
from MacVim.
Björn
I wouldn't be surprised if the Synaptics driver had something like that,
but here at work, my run-of-the-mill HP mouse with standard scroll wheel
only shows boolean values for button 4/5.
--
Best,
Ben
Ok, here is the updated patch. I've renamed the keys as follows:
<ScrollWheelUp>
<ScrollWheelDown>
<ScrollWheelLeft>
<ScrollWheelRight>
These all scroll the _window_ in the direction indicated. So if I
push UP on my scroll wheel, the window moves up but the lines are
actually scrolled down (this is the most intuitive way of thinking
about scrolling in my opinion). Similarly, dragging my finger to the
LEFT on a laptop's trackpad scrolls the window to the left but the
columns are actually scrolled right.
It is still possible to use <MouseUp> as a synonym for
<ScrollWheelDown>, and to use <MouseDown> as a synonym for
<ScrollWheelUp>. I've updated all the help docs to reflect these
changes.
Oh, and I realized that the GTK patch had the left/right mixed up due
to the previously weird behavior where up/down left/right were
inverted. It should be right now (still nobody with a working
horizontal wheel/trackpad that is willing to test this?).
Björn
Looks good to me. With the Ctrl+scrollwheel changes, I was able to test
this by mapping <C-ScrollWheel{Up|Down}> to <ScrollWheel{Left|Right}>
and it seems to work fine in both term and GTK2.
The only thing I might change would be the symmetry of using 3 for the
default increment. Maybe 5 or 10 would be better for horizontal
scrolling? (With the default, horizontal scrolling seems much slower
than vertical scrolling.)
> It is still possible to use <MouseUp> as a synonym for
> <ScrollWheelDown>, and to use <MouseDown> as a synonym for
> <ScrollWheelUp>. I've updated all the help docs to reflect these
> changes.
The new list of the default keys seems very cluttered with the tags
listed all on one line. The old layout also had the benefit of ':help
<S-MouseUp>', etc. jumping to exactly the right line.
> Oh, and I realized that the GTK patch had the left/right mixed up due
> to the previously weird behavior where up/down left/right were
> inverted. It should be right now (still nobody with a working
> horizontal wheel/trackpad that is willing to test this?).
I'll check to see whether either of my touchpads support horizontal
scrolling when I get home tonight.
--
Best,
Ben
I increased the default number of lines to scroll to 6 -- any higher
and it was difficult to just scroll "a little" (with my track pad).
The docs have also been updated to reflect this.
>> It is still possible to use <MouseUp> as a synonym for
>> <ScrollWheelDown>, and to use <MouseDown> as a synonym for
>> <ScrollWheelUp>. I've updated all the help docs to reflect these
>> changes.
>
> The new list of the default keys seems very cluttered with the tags
> listed all on one line. The old layout also had the benefit of ':help
> <S-MouseUp>', etc. jumping to exactly the right line.
Sure, I tried changing it back and it seems a bit more readable that way.
The attached patch contains these minor updates.
Bram: could you indicate if there is any chance this is making it for
7.3 (or at all)? It seems this feature would mostly be used by Mac
users (since "all" Macs have horizontal scrolling abilities) and a few
users have asked for this feature. If you'd rather hold off merging
this patch I'll merge it with the MacVim source code so that it gets
tested properly and then you can take a look at it later.
Björn
It looks fairly good. It's a bit big to include at the last moment,
but we still have some time for testing.
Can you change the argument for the direction to use an enum or #defined
value? Using 0, 1, -1 and -2 is a bit confusing.
For style, instead of:
if (val < 0) val = 0;
use:
if (val < 0)
val = 0;
gui_find_longest_lnum() is missing a prototype.
--
If cars evolved at the same rate as computers have, they'd cost five euro,
run for a year on a couple of liters of petrol, and explode once a day.
/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Agreed. I did this since I wasn't sure where to add the #define's.
They are at the end of vim.h now, hope that makes sense (it seemed
standard to use a shortened version of the function where the #define
is used as a prefix so I called them MSCR_*).
>
> For style, instead of:
>
> if (val < 0) val = 0;
>
> use:
>
> if (val < 0)
> val = 0;
>
> gui_find_longest_lnum() is missing a prototype.
Ok, I have addressed these two issues as well.
The attached patch should be applied after the other three. I sent it
as a separate patch instead of merging it with the others to make it
easier to see what changes I made this time around.
Björn
> Bram: could you indicate if there is any chance this is making it for
> 7.3 (or at all)? It seems this feature would mostly be used by Mac
> users (since "all" Macs have horizontal scrolling abilities) and a few
> users have asked for this feature. If you'd rather hold off merging
> this patch I'll merge it with the MacVim source code so that it gets
> tested properly and then you can take a look at it later.
Note that pretty much all Intel laptops w/ a Synaptics touchpad can do horizontal scrolling as well. Many newer mice do too. So I think it would be good to include it in mainline.
Tom