0

I've got a keyboard that lights up when Scroll Lock is turned on, but my Debian 10 virtual machine (via VirtualBox) won't acknowledge the SCROLL_LOCK status unless I run the following command:

xmodmap -e 'add mod3 = Scroll_Lock'

It has to be executed again every time I reboot in order for the SCROLL_LOCK key to do anything.

I've tried setting up an automatic script two different ways, as described in an answer to Debian: How to run a script on startup without having to write 30 lines of shell script? but it doesn't work. I would guess it doesn't work those ways because they run as root, and I get the following error when I try to manually run xmodmap as root:

xmodmap: unable to open display ''

It only works if I run it as a non-root user.

I just now figured out that if I put my xmodmap command in ~/.bashrc, SCROLL_LOCK is enabled automatically when I log into the terminal, which is nice, but it would be nicer if it could happen when I log into the desktop (which is Xfce), and nicest if it could happen by the time the desktop log-in prompt appears.

Additional Information:

My desktop manager is lightdm-xsession.

1 Answer 1

-1

The problem here is that all the cases you've mentioned are somewhat different.

"The desktop login prompt"—as you've called it—is presented by the so-called desktop manager (DM) whose task is to authenticate the user and when it succeeds, to spawn an instance of X.org and run that user's X session on it, and Xfce kicks in only at that phase.

Putting a call to xmodmap to ~/.bashrc is not a too wise idea simply because xmodmap assumes it's able to find the active X session (usually by looking for a variable named DISPLAY in its environment, which is inherits from its parent process (which it inherits from theirs, and all the way back to the process responsible for bringing up an X session which actually sets that variable and exports it). So should you run bash, say, on a plain virtual terminal—that textual console which you see when you hit Ctrl+Alt+F1 while in X,—that call to xmodmap will bark at you for it will have been unable to locate an X server running an X session.

So basically your system roughly has several "phases" (or "contexts") of execution when it boots:

  1. The bootloader;
  2. Early boot / initramfs;
  3. System (after mounting the real root FS); the DM is spawned at this phase;
  4. The user's X session or the user's settion on a non-graphical session on a VT.

Another thing to note is that a Linux-based system running on a PC always has its users interact with it via virtual terminals (VTs), and an X server also runs on a VT, and is bound to it (and that's why you usually are able to switch to another, non graphical, VT while in X).

So, we could try to attack the problem this way:

  1. See if setting scroll lock to "on" on all the available VTs works—that is, when a DM starts on a VT and then spawns an X server, they both inherit the scoll lock setting.
  2. If that won't work, we can see which configuration your particular DM has (you did not tell us which DM you're using). It might have an ability to run external commands or it might have direct keyboard settings.
  3. If all that fails, we at least can see how Xfce may be made run an external command when it brings a user's session up.

So, while I don't have offhand answer to your problem, I'd attack it at step 3:

  • This suggests using setleds to setting up LEDs at system startup.
  • This explains how to set up NumLock at bootup using setleds and thus is trivially adaptable to the case of ScrollLock.
1
  • Your suggestion for NumLock solved my NumLock issue that I also happened to be having, but I still can't get anything to automate Scroll Lock. I added my desktop manager info to my question. Commented Mar 11, 2020 at 0:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .