Any way to enable scroll lock in x11?

More specifically in urxvt. Scrolling with shift+page up/down is so cumbersome. Any way to turn on and off manual scrolling with the scroll lock key like in the console? Couldn't find anything on the subject. Thanks.
 
Kids these days.

I don't know what you mean by that. Scrolling with shift doesn't even seem to work in the FreeBSD console. In vt(4) using scroll lock to scroll is the default way. I also find it better because it makes the tty stop moving and it resumes auto scrolling when you turn it off.

As far as I know scrolling with shift is purely a Linux and x11 thing.
 
Code:
URxvt*scrollTtyOutput:                  false
URxvt*scrollWithBuffer:                 true
URxvt*scrollTtyKeypress:                true
URxvt.saveLines:                        300000
Maybe this will help you.

I already have that in my .Xresources, as a matter of fact. What I'm looking for is vt(4) like behavior:

1. You activate scroll lock.
2. The tty stops scrolling by itself. You can now scroll with PgUp/PgDn.
3. You deactivate scroll lock.
4. The tty goes back to the bottom. Auto-scrolling is resumed.

If this isn't possible in urxvt, is there any terminal emulator that supports this?
 
Try using ^s (ctrl-s) to lock and ^q (ctrl-q) to unlock, works for me in xterm.

EDIT: posted before seeing your last message, those sequences would only lock the output, not allowing for pgup/pgdown scrolling.
 
dieselriot It's an old man joke about kids complaining about having to do work.

Which reminds me of the time I was browsing in a bookstore next to a dad who was with his young son. The kid was looking through his section but couldn't reach the books higher up. He complained to his dad, "Why do they put those books up so high? Don't they know kids can't reach them? Life is such a struggle!"
 
  • Like
Reactions: a6h
drhowarddrfine I know that much. I just didn't quite get it because I'm under the impression that scroll lock is the most "old-fashioned" way to scroll, so it'd be easier to picture young people complaining about the opposite i.e. shift scrolling not working in the console. Either way I'm still in my early twenties, but I instantly fell in love with the way scrolling works in vt.

In that case at the library the kid had every right to complain though!
 
If you want a solution that affects no other X client except urxvt, the following allows you to use Page Up/Down without the need to hold the Shift key down:
Code:
URxvt.keysym.Prior: eval:scroll_up_pages 1
URxvt.keysym.Next: eval:scroll_down_pages 1
If you're using a program that interprets the control sequences generated by the Page Up/Down keys (e.g. tmux, mail clients, news readers, playlist queues in some music players), this will affect that functionality. There may be a way to use Perl to interface with urxvt's key handling to achieve your desired behavior, but my lack of Perl knowledge means I won't be the one to tell you how.

You can also use setxkbmap -option shift:both_shiftlock (or the equivalent in a file such as /usr/local/etc/X11/xorg.conf.d/10-keyboard.conf). That XKB option will enable Shift Lock when you press both Shift keys; pressing a single Shift key will turn off Shift Lock. This means you can scroll by pressing and releasing Shift_L+Shift_R followed by Page Up (Prior) and Page Down (Next) as much as you want in urxvt until you press a Shift key again. Scroll Lock behavior will still need to be activated separately as usual, just as if you were using Shift+Page Up/Down. I realize this isn't exactly what you wanted, but it is a noteworthy compromise. Of course, there are caveats to using that XKB option, such as the fact that it affects all X clients; switching from a terminal you were scrolling to a program that uses vi-like keybindings without disabling Shift Lock can easily cause trouble for example. There will obviously be an adjustment period, and if you come to depend on this behavior, working with vt(4) will take a moment.

Or you could just use tmux in all of your terminals. In DWM, I have Mod+space configured to execute xterm -e 'tmux', starting a new tmux session in a new xterm. Mod+Shift+space will similarly execute xterm -e 'tmux a' to attach to the last tmux session I was using in a new xterm. Scrolling is done by using the prefix key (Ctrl+B by default) followed by Page Up/Down (technically Page Up enters "copy mode" before scrolling, which can be exited using the 'q' key).

I personally had no success trying to simply remap the Scroll Lock key to the Shift_Lock keysym, whether I used xmodmap or xkbcomp, so your desired behavior may not be easy to achieve. Otherwise, I would recommend a remapping of the actual Scroll Lock key to an unused keysym like F35, x11/sxhkd for detecting F35, and x11/xdotool to synthesize Shift_Lock and Scroll_Lock. Of course, that would mean the Shift Lock behavior in all X clients would be toggled on/off by your Scroll Lock key, not just urxvt. I was not the only one who encountered difficulty in remapping Scroll Lock either. Someone else tried using sxhkd to map it:
Even when Num_Lock and Scroll_Lock were mapped in sxhkdrc, pressing them alongside a shortcut still switched their respective lock modes on/off, which means that using these keys in keyboard shortcuts may be a bad idea, as one would be switching them on and off uncontrollably, changing the behavior of other keys and programs in the process.
https://douglasrizzo.com.br/sxkhd-masterkeys-pro-m-abnt2/

Incidentally, xterm also does not use Scroll Lock the way vt(4) does. I'm not saying the behavior of vt(4) should change, but you might consider simply accepting the current behavior of your terminal emulator of choice.
 
Back
Top