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

Module <layout> not showing changes #788

Closed
enrico223 opened this issue May 10, 2021 · 18 comments
Closed

Module <layout> not showing changes #788

enrico223 opened this issue May 10, 2021 · 18 comments
Assignees

Comments

@enrico223
Copy link

Bug Report

I'm Kubuntu 20.04 LTS, using i3wm. I set up the keybinding Super+space to change the keyboard layout.
The module does its work of changing the keyboard layout and showing the change if clicked on. When the layout is changed with the shortcut, then the layout changes, but the change is not shown in the module.

Description

Affected module: layout
Version used: latest git
Relevant i3 section:
# Start i3bar to display a workspace bar (plus the system information i3status finds out, if available)
bar { position top status_command /home/enrico/bumblebee-status/bumblebee-status -m datetime pomodoro battery layout memory \ pasink pasource -p time.format="%H:%M" -t iceberg-rainbow }

How to reproduce

Simply install the bumblebee status bar and set a keybinding in the system for changing keyboard layout.

@tobi-wan-kenobi
Copy link
Owner

Yes, unfortunately, the layout module doesn't pick up on that :(

Can you please give layout-xkbswitch and/or layout_xkb a go? If I remember correctly, one of them should have that capability,

@tobi-wan-kenobi tobi-wan-kenobi self-assigned this May 10, 2021
@enrico223
Copy link
Author

The layout_xkb doesn't work at all.
The layout-xkbswitch gives me this in the screenshot
image

@tobi-wan-kenobi
Copy link
Owner

layout-xkbswitch requires the tool xkb-switch to be installed, but then, it should work.

layout_xkb is pretty special and requires libX11.so.6 and the Python module xkbgroup, so it's hard to set up.

Hope this helps!

@enrico223
Copy link
Author

Installed xkb-switch, same problem as layout. Do you have any other suggestions?

@tobi-wan-kenobi
Copy link
Owner

No, I am very sorry, if the tool (e.g. xkb-switch) does not report the change, then I don't know what else to try.

The only thing I can think of is more of a workaround - using an explicit i3 binding that invokes xkb-switch for changing the layout - that should make layout-xkbswitch work (because then it's a single too that's being used).

@enrico223
Copy link
Author

I think I found the problem, but I don't know how to solve it. I'm now using xkb-switch and a bluetooth keyboard. When the input comes from the bluetooth keyboard, the module shows the change only after a few seconds, so this is one problem. The other is, of course, that the module still doesn't show the change when the input comes from my laptop's keyboard.
So I have two question, how can I set up the module so that it shows the changes right after I press the shortcut buttons? How can I make the input from the laptop's keyboard show up?

@tobi-wan-kenobi
Copy link
Owner

Regarding the update interval:

The only way bumblebee has to get the layout is to poll - by default, once prr second. And then, it shows the new layout only when the underlying tool -xkb-switch - shows it.

So unless you use a poll interval lower than the default 1s, Icdon't think there is a lot of possibility to speed that up.

If you are using multiple keyboards - is it possible that both of them have different layouts and bumblebee is showing only the layout of one of them? I.e. if the other changes layout, bumblebee does not update?

@enrico223
Copy link
Author

oh ok, got it! I think it is possible. But right now even the changes from the bluetooth keyboard don't show up.
If I manage to solve this problem, I'll let you know, thank you!

@tobi-wan-kenobi
Copy link
Owner

Sounds great, thanks for the update!

I have only recently figured out that different keyboards can have different layouts in X11, but have no clue how to query that in Python reliably.

If you find something, I can update the layout module.

Thanks!

@tobi-wan-kenobi
Copy link
Owner

One update to this: I found out that setxkbdmap supports a -device parameter for selecting the input device. Unfortunately, on my box, it seems this parameter is ignored when querying the current configuration :(

@tobi-wan-kenobi
Copy link
Owner

Note sure if this helps, but: I wrote a small C tool that seems to (finally) correctly determine the keyboard layout:

#include <stdio.h>
#include <stdlib.h>

#include <X11/XKBlib.h>

void err_if(int condition, const char* msg)
{
	if (condition) {
		fprintf(stderr, "fatal: %s\n", msg);
		exit(1);
	}
}

int main(int argc, char** argv)
{
	Display* display = XOpenDisplay(NULL);
	err_if(!display, "unable to open display");

	int kbd = argc == 1 ? XkbUseCoreKbd : atoi(argv[1]);

	XkbStateRec state;
	XkbGetState(display, kbd, &state);

	XkbDescPtr desc = XkbGetKeyboard(display, XkbAllComponentsMask, kbd);
	char *group = XGetAtomName(display, desc->names->groups[state.group]);
	printf("Group: %s\n", group);
	char* symbols = XGetAtomName(display, desc->names->symbols);
	printf("symbols: %s\n", symbols);

	XFree(group);
	XFree(symbols);
	XFree(desc);

	XCloseDisplay(display);

	return 0;
}

You need the X11 library headers (usually something like X11-devel or X11-dev) and compile it with:
gcc -g -o get-layout ./get-layout.c -Wall -Werror -lX11

./get-layout gives you the "core" layout then, and you can specify a device ID (from xinput -list|grep key) to get the layouts of a specific keyboard.

IF that works for you, that would be a first step towards a clean solution :)

@enrico223
Copy link
Author

Thank you! Where should I specify the device ID? And for which of the three modules?

@tobi-wan-kenobi
Copy link
Owner

Well, right now, that is not for any module, just to see whether this way retrieves the layout correctly.

You can get the ID of the keyboard by executing "xinput -list|grep key" - this gives you a list of your keyboard input devices along with their ID.

I am trying to call this directly in Python (by loading libX11), but ctypes is giving me a lot of grief :(

@enrico223
Copy link
Author

enrico223 commented May 16, 2021

It does retrieve the layout correctly. It works!

@tobi-wan-kenobi
Copy link
Owner

Great! Then I just need to call those functions with ctypes correctly, and bumblebee will finally have a working layout module :)

Thanks a lot for your patience!

@enrico223
Copy link
Author

It's you who doing the work, thank you!

tobi-wan-kenobi added a commit that referenced this issue May 16, 2021
Add a new module "layout" that will eventually evolve into the only
keyboard layout module.

Right now, it uses an external binary (get-kbd-layout) to determine the
layout of a keyboard device (because I did not manage to call libX11
with ctypes correctly).

see #788
see #790
@tobi-wan-kenobi
Copy link
Owner

@enrico223 There is now a new module "layout" that accepts a parameter "device" that should be the device ID - e.g. for me, bumblebee-status -m -m layout:kbd1 layout:kbd2 -p kbd1.device=9 kbd2.device=15 shows two different layouts.

It's very much alpha (i.e. no switching keyboard layouts via the module yet), but if it works fine for you, I will extend it to be "the" main module in the future.

@tobi-wan-kenobi
Copy link
Owner

Closing for now, further changes will be tracked in #790

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants