0

I have been trying to bind numpad numeric keys on i3 unsuccessfully. This seems like a simple enough thing to do but it doesn't work. And I can't figure out why.

Keyboard layout: English US Default

For example:

bindsym $mod+KP_1 workspace $ws1

Does not do anything.

bindcode $mod+$KP_1 workspace $ws1

Errors out saying that there is an error in my i3 config with the following errors:

ERROR: Could not parse "$mod+$KP_1" as an input code, ignoring this binding.

$mod and $KP_1 was set to 133 and 87 prior to running the bindcode.

There is comment in GitHub saying that numpad keys cannot be used. Is that true ?

Does no one have bindings like $mod + KP_2 or something ?

2
  • How about bindcode $mod+87, but leaving $mod set as Mod4? Or bindsym $mod+KP_End / KP_Down, etc. Also check output of xev with numlock off for keysyms.
    – user391836
    Feb 9, 2020 at 12:32
  • @thisaccounthasbeen Solved. Posted the answer.
    – ng.newbie
    Feb 9, 2020 at 14:05

3 Answers 3

7

Solved. They should really add this into the documentation. Thanks to the guys on the IRC channel for helping me with this.

Ok since KP_0 and KP_1 keys are on the numpad they will only work in the numeric fashion when numlock is turned on, otherwise they are KP_END, KP_HOME, etc. Now for a normal human being that's fine, but the reason this does not work on i3 is because i3 needs to be told numlock is on. It is not smart enough to figure that by itself.

So the keybindings need to be written accordingly. So the correct keybindings would be:

bindsym $mod+mod2+KP_1 workspace $ws1
bindsym $mod+mod2+KP_2 workspace $ws2
bindsym $mod+mod2+KP_3 workspace $ws3
bindsym $mod+mod2+KP_4 workspace $ws4
bindsym $mod+mod2+KP_5 workspace $ws5
bindsym $mod+mod2+KP_6 workspace $ws6
bindsym $mod+mod2+KP_7 workspace $ws7
bindsym $mod+mod2+KP_8 workspace $ws8

The obvious question is what is mod2 ? Well just run xmodmap and you will find out. Most of the time it will be NumLock.

Now looking at this configuration it may look like that I am adding another keypress to my bindings but that is not so. Since numlock will already be ON I can just press the first modifier and the numpad key. I don't have to press mod2, since its "already pressed", so to speak.

So I can just press: Super(mod) and KP_1 on my keyboard to switch the workspace to 1.

A recommendation is to use a program like numlockx to always turn on login.

1
  • Thank you! But in my setup this solution does not work 100%. Switching workspaces Does work the way, you describe, but moving a focused window to a workspace does not. What am I missing? bindsym $super+mod2+KP_1 workspace $ws1 => works bindsym $super+Shift+mod2+KP_1 move container to workspace $ws1 => does not work Sep 6, 2021 at 19:12
2

If you also want to move windows to the workspace by adding a shift modifier remember that numpad numbers translate into numpad commands (e.g. KP_1 -> KP_End). You can use xmodmap -pke | grep KP_ to find out which number corresponds to which command. Wierdly you still need to specify mumlock (mod2) and shift explicitly in i3. This works for me:

bindsym $mod+mod2+KP_1 workspace $ws1
bindsym $mod+mod2+Shift+KP_End move container to workspace $ws1

Edit: Just found this exact workaround in the mentioned Github issue. Too late, but oh well :D

0

Well.. it costed me around 6 hours to do it. So I'm going to make a simple resume how I did it:

I have two monitors so I did fallowing:

I created a file workspaces.conf and inside I did this:

# assign workspaces to screens
workspace 1  output $Monitor_left
workspace 2  output $Monitor_left
...
workspace 9  output $Monitor_left
workspace 10 output $Monitor_left

workspace 11 output $Monitor_right
workspace 12 output $Monitor_right
...
workspace 19 output $Monitor_right
workspace 20 output $Monitor_right

# Define names for default workspaces for which we configure key bindings later on.
# We use variables to avoid repeating the names in multiple places.
set $ws01 "1"
set $ws02 "2"
....
set $ws09 "9"
set $ws00 "10"

set $ws11 "11"
...
set $ws19 "19"
set $ws20 "20"

and if you have 2 or more monitors PLEASE name the WSs as ws01, ws02, ws03,... instead of ws1, ws2, ws3. (I'll tell you why later ;D ).

After doing it you can include this file inside of yours i3config

config

include $HOME/.config/i3/workspaces.conf

After that, make sure to add the super keys (just use the command xmodmap)

#Master key Super "Windows" and Alt Left "alt"
(soon you will understand why 2 mod keys)

    set $mod Mod4
    set $mod_alt Mod1

And now set your monitors inside of variables (you can use the command xrand and findout what is the output)

set $Monitor_left DP-0
set $Monitor_right HDMI-0

Now make the confs to switch to the workspaces, something like this:

# switch to workspace
# Monitor1
bindsym $mod+mod2+KP_1  workspace $ws01 ; move workspace to output $Monitor_left
bindsym $mod+mod2+KP_2  workspace $ws02 ; move workspace to output $Monitor_left
 ......
bindsym $mod+mod2+KP_9  workspace $ws09 ; move workspace to output $Monitor_left
bindsym $mod+mod2+KP_0  workspace $ws00 ; move workspace to output $Monitor_left

# Monitor2
bindsym $mod_alt+mod2+KP_1   workspace $ws11 ; move workspace to output $Monitor_right
bindsym $mod_alt+mod2+KP_2   workspace $ws12 ; move workspace to output $Monitor_right
.....
bindsym $mod_alt+mod2+KP_9   workspace $ws19 ; move workspace to output $Monitor_right
bindsym $mod_alt+mod2+KP_0   workspace $ws20 ; move workspace to output $Monitor_right

it's almost perfect :) From now on, you can use superkey+number (windows_key) / superkey+numpad_number to switch to ALL workspaces (1-10) on your left monitor and alt_left+numpad_number to switch to ALL workspaces (11-20) on your right monitor

Moving containers to other workspacies! To do it you can just copy this lines here OR use the command xmodmap -pke | grep KP_ to find the right keys

# move focused container to workspace 
# (monitor1 numpad)
bindsym $mod+Mod2+Shift+KP_End move container to workspace    $ws01 
bindsym $mod+Mod2+Shift+KP_Down move container to workspace   $ws02 
bindsym $mod+Mod2+Shift+KP_Next move container to workspace   $ws03 
bindsym $mod+Mod2+Shift+KP_Left move container to workspace   $ws04 
bindsym $mod+Mod2+Shift+KP_Begin move container to workspace  $ws05 
bindsym $mod+Mod2+Shift+KP_Right move container to workspace  $ws06 
bindsym $mod+Mod2+Shift+KP_Home move container to workspace   $ws07 
bindsym $mod+Mod2+Shift+KP_Up move container to workspace     $ws08 
bindsym $mod+Mod2+Shift+KP_Prior move container to workspace  $ws09
bindsym $mod+Mod2+Shift+KP_Insert move container to workspace $ws00

# (Monitor2 numpad)
bindsym $mod_alt+Mod2+Shift+KP_End move container to workspace    $ws11 
bindsym $mod_alt+Mod2+Shift+KP_Down move container to workspace   $ws12 
bindsym $mod_alt+Mod2+Shift+KP_Next move container to workspace   $ws13 
bindsym $mod_alt+Mod2+Shift+KP_Left move container to workspace   $ws14 
bindsym $mod_alt+Mod2+Shift+KP_Begin move container to workspace  $ws15 
bindsym $mod_alt+Mod2+Shift+KP_Right move container to workspace  $ws16 
bindsym $mod_alt+Mod2+Shift+KP_Home move container to workspace   $ws17 
bindsym $mod_alt+Mod2+Shift+KP_Up move container to workspace     $ws18 
bindsym $mod_alt+Mod2+Shift+KP_Prior move container to workspace  $ws19
bindsym $mod_alt+Mod2+Shift+KP_Insert move container to workspace $ws20

I have never used the i3bar and I don't know how to config it. BUT if you are using polybar then you NEED to config like this:

[module/i3] ...

ws-icon-0 = "00;X"
ws-icon-1 = "01;I"
ws-icon-2 = "02;II"
ws-icon-3 = "03;III"
ws-icon-4 = "04;IV"
ws-icon-5 = "05;V"
ws-icon-6 = "06;VI"
ws-icon-7 = "07;VII"
ws-icon-8 = "08;VIII"
ws-icon-9 = "09;IX"

notice that if you try to call the WSs like this: ws-icon-1 = "1;I" it will get in conflict with the ws number 11

BUG by system start

I noticed that everytime when I started my system my i3 started in the workflow1 ($mod+1) instead of workflow01($mod+mod2+KP_1). So I created a mini script in python that solves that problem

config_workflow.py

import pyautogui

p=pyautogui

p.hotkey('win', 'right')
p.hotkey('altleft', 'num1')
p.hotkey('win', 'left')
p.hotkey('win', 'num1')

and of course I start the script every time when my i3 starts (i3 autostart) I don't know if there is a better way to solve it, BUT this was the only way I found.

You must log in to answer this question.

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