Difference between revisions of "Activating numlock on bootup"

From ArchWiki
Jump to navigation Jump to search
(→‎GDM: Change /etc/gdm/Init to xprofile.)
 
(27 intermediate revisions by 14 users not shown)
Line 5: Line 5:
 
[[it:Activating Numlock on Bootup]]
 
[[it:Activating Numlock on Bootup]]
 
[[ja:起動時に Numlock を有効化]]
 
[[ja:起動時に Numlock を有効化]]
 +
[[pt:Activating numlock on bootup]]
 
[[ru:Activating Numlock on Bootup]]
 
[[ru:Activating Numlock on Bootup]]
[[tr:Açılışta numlock etkinleştirme]]
 
 
[[zh-hans:Activating Numlock on Bootup]]
 
[[zh-hans:Activating Numlock on Bootup]]
 
== Console ==
 
== Console ==
Line 16: Line 16:
 
First create a script to set the numlock on relevant TTYs:
 
First create a script to set the numlock on relevant TTYs:
  
{{hc|/usr/bin/numlock|<nowiki>
+
{{hc|/usr/local/bin/numlock|
 
#!/bin/bash
 
#!/bin/bash
  
Line 23: Line 23:
 
     /usr/bin/setleds -D +num < "$tty";
 
     /usr/bin/setleds -D +num < "$tty";
 
done
 
done
</nowiki>}}
+
}}
 +
 
 +
Once the script is created, you will need to make it [[executable]]. Otherwise the script cannot run.
  
 
Then create and [[enable]] a systemd service:
 
Then create and [[enable]] a systemd service:
  
{{hc|/etc/systemd/system/numlock.service|<nowiki>
+
{{hc|/etc/systemd/system/numlock.service|2=
 
[Unit]
 
[Unit]
 
Description=numlock
 
Description=numlock
  
 
[Service]
 
[Service]
ExecStart=/usr/bin/numlock
+
ExecStart=/usr/local/bin/numlock
 
StandardInput=tty
 
StandardInput=tty
 
RemainAfterExit=yes
 
RemainAfterExit=yes
  
 
[Install]
 
[Install]
WantedBy=multi-user.target</nowiki>}}
+
WantedBy=multi-user.target
 +
}}
  
 
=== Extending getty@.service ===
 
=== Extending getty@.service ===
  
This is simpler than using a separate service (especially since systemd-198) and does not hardcode the number of VTs in a script. Create a drop-in snippet for getty@.service which are applied on top of the original unit:
+
This is simpler than using a separate service and does not hardcode the number of VTs in a script. Create a [[drop-in snippet]] for {{ic|getty@.service}} which are applied on top of the original unit:
  
{{hc|# systemctl edit getty\@.service|<nowiki>
+
{{hc|/etc/systemd/system/getty@.service.d/activate-numlock.conf|2=
 
[Service]
 
[Service]
ExecStartPre=/bin/sh -c 'setleds +num < /dev/%I'
+
ExecStartPre=/bin/sh -c 'setleds -D +num < /dev/%I'
</nowiki>}}
+
}}
 +
 
 +
{{Note|If you experience any problems, try replacing {{ic|ExecStartPre}} with {{ic|ExecStartPost}}, and/or disabling the hint as described below.}}
  
To disable the num-lock activation hint displaying on the login screen, edit getty@tty1.service and add {{ic|--nohints}} to agetty options:
+
To disable the numlock activation hint displaying on the login screen, [[edit]] {{ic|getty@tty1.service}} and add {{ic|--nohints}} to ''agetty'' options:
  
{{hc|# systemctl edit getty@tty1.service|<nowiki>
+
[Service]
[Service]
+
ExecStart=
ExecStart=
+
ExecStart=-/sbin/agetty '-p -- \\u' --nohints --noclear %I $TERM
ExecStart=-/sbin/agetty --nohints --noclear %I $TERM
 
</nowiki>}}
 
  
 
=== Bash alternative ===
 
=== Bash alternative ===
Line 79: Line 82:
 
  exec window_manager
 
  exec window_manager
  
=== KDE Plasma Users ===
+
=== MATE ===
 +
By default, MATE saves the last state on logout and restores it during the next login. To enable Numlock on every login, you must change the following DCONF-Values:
  
Go to System Settings, under the Hardware/Input Devices/Keyboard item you will find an option to select the behavior of NumLock.
+
dconf write org.mate.peripherals-keyboard remember-numlock-state false
 +
dconf write org.mate.peripherals-keyboard numlock-state 'on'
 +
 
 +
=== KDE Plasma ===
 +
 
 +
Go to ''System Settings > Input Devices > Keyboard'', in the ''Hardware'' tab, in the ''NumLock on Plasma Startup'' section, choose the desired NumLock behavior.
  
 
=== GDM ===
 
=== GDM ===
Line 95: Line 104:
 
=== GNOME ===
 
=== GNOME ===
  
When not using the GDM login manager, numlockx can be added to GNOME's start-up applications.
+
Run the following command:
  
[[Install]] the {{Pkg|numlockx}} package. Then, add a start-up command to launch {{ic|numlockx}}.
+
  $ gsettings set org.gnome.desktop.peripherals.keyboard numlock-state true
$ gnome-session-properties
 
  
The above command opens the '''Startup Applications Preferences''' applet. Click '''''Add'''''  and enter the following:
+
In order to remember last state of numlock key (whether you disabled or enabled), use:
  
{| class="wikitable"
+
   $ gsettings set org.gnome.desktop.peripherals.keyboard remember-numlock-state true
| Name:      ||  ''Numlockx''
 
|-
 
| Command:   ||  ''/usr/bin/numlockx on''
 
|-
 
| Comment:  ||  ''Turns on numlock.''
 
|}
 
  
{{note|This is not a system-wide change, repeat these steps for each user wishing to activate NumLock after logging in.}}
+
{{Note|The key {{ic|numlock-state}} was moved from {{ic|org.gnome.settings-daemon.peripherals.keyboard}} since GNOME 3.34[https://gitlab.gnome.org/GNOME/gnome-settings-daemon/merge_requests/107]}}
 +
 
 +
Alternatively, you can use add {{ic|numlockx on}} (from {{pkg|numlockx}} to a startup script, like {{ic|~/.bashrc}} (if using [[Bash]]) or {{ic|~/.profile}}.
  
 
=== Xfce ===
 
=== Xfce ===
Line 118: Line 122:
 
  <property name="Numlock" type="bool" value="true"/>
 
  <property name="Numlock" type="bool" value="true"/>
 
  <property name="RestoreNumlock" type="bool" value="true"/>
 
  <property name="RestoreNumlock" type="bool" value="true"/>
 +
 +
{{Note|If the file does not exist then open ''Settings > Keyboard'', then check and uncheck the ''Restore num lock state on startup''. This will create the {{ic|keyboards.xml}} file.}}
  
 
=== SDDM ===
 
=== SDDM ===
Line 154: Line 160:
 
Set the option in {{ic|~/.config/lxqt/session.conf}}:
 
Set the option in {{ic|~/.config/lxqt/session.conf}}:
  
 +
[Keyboard]
 
  numlock=true
 
  numlock=true

Latest revision as of 14:00, 14 November 2019

Console

Using a separate service

Tip: These steps can be automated by installing the systemd-numlockonttyAUR package and enabling the numLockOnTty service.

First create a script to set the numlock on relevant TTYs:

/usr/local/bin/numlock
#!/bin/bash

for tty in /dev/tty{1..6}
do
    /usr/bin/setleds -D +num < "$tty";
done

Once the script is created, you will need to make it executable. Otherwise the script cannot run.

Then create and enable a systemd service:

/etc/systemd/system/numlock.service
[Unit]
Description=numlock

[Service]
ExecStart=/usr/local/bin/numlock
StandardInput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Extending getty@.service

This is simpler than using a separate service and does not hardcode the number of VTs in a script. Create a drop-in snippet for getty@.service which are applied on top of the original unit:

/etc/systemd/system/getty@.service.d/activate-numlock.conf
[Service]
ExecStartPre=/bin/sh -c 'setleds -D +num < /dev/%I'
Note: If you experience any problems, try replacing ExecStartPre with ExecStartPost, and/or disabling the hint as described below.

To disable the numlock activation hint displaying on the login screen, edit getty@tty1.service and add --nohints to agetty options:

[Service]
ExecStart=
ExecStart=-/sbin/agetty '-p -- \\u' --nohints --noclear %I $TERM

Bash alternative

Add setleds -D +num to ~/.bash_profile. Note that, unlike the other methods, this will not take effect until after you log in.

X.org

Various methods are available.

startx

Install the numlockx package and add it to the ~/.xinitrc file before exec:

#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)
#

numlockx &

exec window_manager

MATE

By default, MATE saves the last state on logout and restores it during the next login. To enable Numlock on every login, you must change the following DCONF-Values:

dconf write org.mate.peripherals-keyboard remember-numlock-state false
dconf write org.mate.peripherals-keyboard numlock-state 'on'

KDE Plasma

Go to System Settings > Input Devices > Keyboard, in the Hardware tab, in the NumLock on Plasma Startup section, choose the desired NumLock behavior.

GDM

Note: GDM does not execute scripts in /etc/gdm/Init anymore.

Make sure that you have numlockx installed then add the following code to ~/.xprofile:

if [ -x /usr/bin/numlockx ]; then
      /usr/bin/numlockx on
fi

GNOME

Run the following command:

 $ gsettings set org.gnome.desktop.peripherals.keyboard numlock-state true

In order to remember last state of numlock key (whether you disabled or enabled), use:

 $ gsettings set org.gnome.desktop.peripherals.keyboard remember-numlock-state true
Note: The key numlock-state was moved from org.gnome.settings-daemon.peripherals.keyboard since GNOME 3.34[1]

Alternatively, you can use add numlockx on (from numlockx to a startup script, like ~/.bashrc (if using Bash) or ~/.profile.

Xfce

In the file ~/.config/xfce4/xfconf/xfce-perchannel-xml/keyboards.xml, make sure the following values are set to true:

<property name="Numlock" type="bool" value="true"/>
<property name="RestoreNumlock" type="bool" value="true"/>
Note: If the file does not exist then open Settings > Keyboard, then check and uncheck the Restore num lock state on startup. This will create the keyboards.xml file.

SDDM

In the file /etc/sddm.conf, under the [General] section, set Numlock value to on :

[General]
...
Numlock=on

SLiM

In the file /etc/slim.conf find the line and uncomment it (remove the #):

#numlock             on

OpenBox

In the file ~/.config/openbox/autostart add the line:

numlockx &

And then save the file.

LightDM

See LightDM#NumLock on by default.

LXDM

Set the option in /etc/lxdm/lxdm.conf:

numlock=1

LXQt

Set the option in ~/.config/lxqt/session.conf:

[Keyboard]
numlock=true