Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyboardLayout show all layouts instead of current #373

Open
Jofsey opened this issue Feb 11, 2014 · 7 comments
Open

KeyboardLayout show all layouts instead of current #373

Jofsey opened this issue Feb 11, 2014 · 7 comments

Comments

@Jofsey
Copy link

Jofsey commented Feb 11, 2014

KeyboardLayout widget uses setxkbmap -query to get current layout, but in my case this command prints all layouts instead of current:

$ setxkbmap -query
rules:      evdev
model:      pc104
layout:     us,ru
options:    grp:caps_toggle,grp_led:scroll

This situation is also described here

@alexandr-kriptonov
Copy link
Contributor

Can use skb? http://plhk.ru/static/skb/skb-0.4.tar.gz
On python:

import subprocess

keyboard = subprocess.check_output(['skb', '-now']).strip()
print(unicode(keyboard))

@Jofsey
Copy link
Author

Jofsey commented Feb 12, 2014

As a variant, yes. This code is suitable. But I still hope to find solution which uses no external tools (only default X environment).

@tych0
Copy link
Member

tych0 commented Feb 12, 2014

Looking at the code for setxkbmap, it looks pretty dumb (i.e. it just takes whatever string the X server gives it and prints that). Are these in any particular order?

@Jofsey
Copy link
Author

Jofsey commented Feb 12, 2014

The order doesn't depend on current layout. Guess it is the same as in /etc/X11/xorg.conf.d/N-keyboard-layout.conf

This solution requeres no external tools, but works only for one or two layouts. Not ideal, but cover ~98% cases. I'll write the fix if noone will propose a better solution.

@alexandr-kriptonov
Copy link
Contributor

Another method. Using kbdd(https://github.com/qnikst/kbdd).

import dbus

languages = {
    '0': 'EN',
    '1': 'RU',
}

def main():
    remote_bus = dbus.SessionBus()

    # Check if kbdd is running.
    system_service_list = remote_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus').ListNames()

    kbdd_api_found = 0
    for service in system_service_list:
        if service == 'ru.gentoo.KbddService':
            kbdd_api_found = 1
            break
    if not kbdd_api_found:
        return -1

    # Get kbdd dbus api
    kbdd_service = remote_bus.get_object('ru.gentoo.KbddService', '/ru/gentoo/KbddService')

    # Connect to kdbb.
    answer = kbdd_service.getCurrentLayout()
    return answer

if __name__ == "__main__":
    result = main()
    print(languages[unicode(result)])

@alexandr-kriptonov
Copy link
Contributor

import subprocess
import re

languages = {
    'first': 'EN',
    'second': 'RU',
}

regular_strings = {
    'hexadecimal': {
        'first': """\w{4}e\w{3}""",
        'second': """\w{4}f\w{3}""",
    },
    'binary': {
        'first': """\w{4}0\w{3}""",
        'second': """\w{4}1\w{3}""",
    },
    "inetger": "\d{8}",
    "led_mask": """LED mask:\s\s\w{8}""",
}

data = subprocess.check_output(['xset', '-q'])
raw_list = []

for item in data.strip().splitlines():
    if re.search(regular_strings['led_mask'], item):
        raw_led_mask = re.search(regular_strings['led_mask'], item).group()
        raw_list = raw_led_mask.split(':')
        led_mask = raw_list[1].strip()
        break

print("led_mask", led_mask)

if not re.search(regular_strings['inetger'], led_mask):
    cur_regular_strings = regular_strings['hexadecimal']
else:
    cur_regular_strings = regular_strings['binary']

if re.search(cur_regular_strings['first'], led_mask):
    print languages['first']
elif re.search(cur_regular_strings['second'], led_mask):
    print languages['second']
else:
    print(None)

@dequis dequis added the bug label Jul 29, 2014
@ramnes ramnes added this to Needs triage in Bug triage Nov 15, 2018
@ramnes ramnes moved this from Needs triage to Low priority in Bug triage Nov 15, 2018
@zordsdavini
Copy link
Contributor

I did some tests for this case.

  • if layout is set from console like setxkbmap -layout us,lt,cn -option grp:alt_shift_toggle,compose:menu,grp_led:scroll the query output will have all 'us,lt,cn' layouts.
  • with good qtile config, ex. widget.KeyboardLayout(configured_keyboards=['us', 'lt', 'ru phonetic']) query gives current layout as expected
  • but if I run setxkbmap and reload Qtile - widget works a little bit strange

I suggest to close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Bug triage
  
Low priority
Development

No branches or pull requests

6 participants