Py3status: keyboard layout: switch between layouts

Created on 30 Nov 2017  路  15Comments  路  Source: ultrabug/py3status

It would be really useful to me, if modules/keyboard_layout.py could allow me to switch to a different keyboard layout.

The usage I envision is similar to modules/xrandr.py:

  • Left click toggles through all configured layouts
  • Right click switches to a new layout

Most helpful comment

Agree on this, except that I suggest to use a much simpler usage, like we have in group, volume_status or backlight: configurable parameters button_next and button_prev, and click on them immediately switches to the next / previous layout.

With xrandr it takes a lot of time to readjust the display, that's why there is this "scroll but don't apply yet" behavior. With keyboard layout the change is instantaneous.

As a bonus, by having this simpler approach one could map hotkeys using py3-cmd, e.g. I will definitely bind Alt+Shift to switch my keyboard layout using keyboard_layout module once this is implemented 馃憤

All 15 comments

Agree on this, except that I suggest to use a much simpler usage, like we have in group, volume_status or backlight: configurable parameters button_next and button_prev, and click on them immediately switches to the next / previous layout.

With xrandr it takes a lot of time to readjust the display, that's why there is this "scroll but don't apply yet" behavior. With keyboard layout the change is instantaneous.

As a bonus, by having this simpler approach one could map hotkeys using py3-cmd, e.g. I will definitely bind Alt+Shift to switch my keyboard layout using keyboard_layout module once this is implemented 馃憤

Seeing how keyboard_layout does not have on_click, you could try this... on_click 4 = 'exec setxkbmap us' and on_click 5 = 'exec setxkbmap fr' in the keyboard layout module config... then you can switch the layout via mouse 4, 5 (up, down).

That's a cool idea, although for my personal usage I'd much prefer a circular scrolling over a configured list of layouts, so that there is one button that I can map to the Alt+Shift hotkey.

You can try this module. https://github.com/ultrabug/py3status/pull/1183 馃憤

That's interesting, however the missing piece in the switch module is of course the querying, in other words if I change keyboard layout _not_ via py3status, the module will be displaying a wrong layout. I kind of think it is a critical feature for all the examples that you added, volume, xrandr, etc...

@lasers: There won't be any feedback from whatever it is that we're trying to control.

Indeed. That's one caveat. This is a nice script. Users can pollute this with their favorite scripts, eg i3lock, dpms, suspend, shutdown, etc... Also, xrandr is broken for me, but I can use this to emulate xrandr behavior and/or basic functionality correctly. This works really nice emulating your module xrandr_rotate too. :-)

My thinking is that there are many commands and/or scripts that could be fed to this module... and sometimes on_click 1, on_click 3 is not just cutting it for us... so with this, we could rotate and/or rotate+click.

Maybe it's enough for some users since they don't change anything via not py3status. Anyhow, it's a start... and I'm not sure what more I can add to this module... and we potentially could avoid some new modules by using this module instead. I dunno. 馃憤

@lasers, I think your switch module will be sufficient for me. Very nice.

I am able to successfully toggle between layouts in my status bar, but my keyboard layout does not actually get changed. I tried to read through the code, but I do not see where the command gets executed?

Here is the config I used:

switch keyboard_layout {
  button_action = 1
  loop = True
  list = [
      ('\?color=#268BD2 dv', 'setxkbmap -layout dvorak'),
      ('\?color=#F75252 us', 'setxkbmap -layout us')
  ]
}

Do you have the latest switch.py? Before I made a pull request, I removed several self.py3.log() including one self.py3.command(). I added it back later. Maybe you still have that one?... And the new one have Popen to deal with the applications too.

If you want xrandr behavior, then the above is fine (EDIT: including button_next and button_previous)... If you want live switching, then just use button_next and button_previous without button_action. Let me know. Thx. 馃憤

EDIT: Also, without button_next and button_previous, you only can click on it.

Good, I updated to the latest version of your PR.

Now I get an error

'Py3status' object has no attribute 'active'

I believe this is from line 296. self.active does not seem to be initialized? Should I specify it in the config?

@tjaartvdwalt Ah. Stupid typo. Also, if you're only using button_action, then loop is implied since we only can travel one way. Maybe I should add it to the docs too. Try again. :-)

Thanks now it works!

Look forward to getting your PR merged :)

As far as I am concerned, we can close this issue. Reopen it if you have more to add.

This seems to me like a half-baked solution yet, can we keep this issue open?

Suppose switch module is merged, we now have two modules for switching keyboard layout, switch can switch the value but cannot query the current value, keyboard_layout can query but lacks switching functionality... It would be cool to have just one module that can do both 馃檪

We could investigate if it makes sense to reimplement keyboard_layout (and other modules) in terms of switch module, so that functionality is not duplicated and yet the correct parameters are hardcoded in the keyboard_layout module itself and it provides both query and switch functionality.

OK, I will reopen the issue.

1192 is merged, this can be closed now (/cc @ultrabug).

Thanks guys!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

root360-AndreasUlm picture root360-AndreasUlm  路  5Comments

CuriousFu picture CuriousFu  路  4Comments

maximbaz picture maximbaz  路  8Comments

tobes picture tobes  路  4Comments

gmagno picture gmagno  路  6Comments