i3 / i3lock

improved screen locker
https://i3wm.org/i3lock
BSD 3-Clause "New" or "Revised" License
920 stars 404 forks source link

Display the keyboard layout on the lock screen. #287

Closed Liorst4 closed 4 years ago

Liorst4 commented 4 years ago

I'm submitting a…

[ ] Bug
[x] Feature Request
[ ] Other (Please describe in detail)

Current Behavior

The input language is not displayed on the screen. If you don't remember what was the input language when you locked the machine, you need to switch the language and try until it works.

Expected Behavior

The input language should be displayed on the screen.

Reproduction Instructions

setxkbmap -option grp:alt_shift_toggle us,es
# Press alt+shift a random amount of times
i3lock
# You have only 50% chance of unlocking the computer if you enter the right password.

Environment

Output of i3lock --version:

i3lock version: 2.12
stapelberg commented 4 years ago

We display when you press caps lock, so the keyboard layout falls into the same category.

Unfortunately, things aren’t so easy with keyboard layouts: desktop environments may have the concept of a configured/enabled keyboard layout, but i3 (or other window managers used without desktop environments) don’t have that.

Without such a list, the only thing we could do is display the current keyboard layout all the time, which seems excessive to me. Most users only use one keyboard layout, so why would we annoy them with an unhelpful bit of information in a prominent place?

That said, if seeing the keyboard layout at the time of the screen lock on your lock screen, one option you have is to overlay this information on an image yourself in a wrapper script that starts i3lock.

stapelberg commented 4 years ago

I’ll tentatively close this as I don’t see a good way of making it happen.

orestisfl commented 4 years ago

@Liorst4 you can run [xkb-switch](https://github.com/grwlf/xkb-switch) -s us prior to locking to make sure that the correct layout is enabled.

@stapelberg Aren't layouts part of XKB? What do DEs have to do with them?

stapelberg commented 4 years ago

@stapelberg Aren't layouts part of XKB? What do DEs have to do with them?

Layouts are defined via XKB indeed.

What DEs can add is a dialog in which you select which keyboard layouts you actually want to use out of the ≈hundred that are available. This allows for chosing between, say, English and Russian (just 2 entries instead of 100s) in a drop-down (e.g. tray icon).

See the screenshots at http://linuxblog.darkduck.com/2013/10/how-to-configure-keyboard-layouts-in-unity-gnome3-kde.html if you’re unfamiliar.

Edit: what I’m trying to get at is that if i3lock could know that the user uses more than 1 layout, we could display which one is active. But we can’t know, and hence the UX of this feature would be poor.

Liorst4 commented 4 years ago
$ setxkbmap -query
...
layout:     us,es
options:    grp:alt_shift_toggle

setxkbmap can tell when there is more than one layout, can't i3lock do the same thing?

stapelberg commented 4 years ago

This only queries which layout you have selected when you configure 2 layouts at the same time on the XKB level.

This is not a common config—instead of configuring 2 layouts at the same time, many just switch between layouts altogether. Switching altogether becomes necessary when you use layouts that make use of all XKB layers, e.g. https://neo-layout.org/

rddunphy commented 4 years ago

Could this be added as a command line option? Something like i3lock --show-kbd-layout to show the layout alongside the CapsLock indicator, for example. This way the feature is available to those of us who toggle between keyboard layouts a lot, without affecting the UX of other users.

oditynet commented 1 year ago

Ok, i clone your git code and modify unlock_indicator.c `
if (unlock_state == STATE_KEY_ACTIVE) { / For normal keys, we use a lighter green. / cairo_set_source_rgb(ctx, 51.0 / 255, 219.0 / 255, 0); } else { / For backspace, we use red. / cairo_set_source_rgb(ctx, 219.0 / 255, 51.0 / 255, 0); }

...... //my code Display dpy = XOpenDisplay(NULL); if (dpy == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } XkbStateRec state; XkbGetState(dpy, XkbUseCoreKbd, &state); XkbDescPtr desc = XkbGetKeyboard(dpy, XkbAllComponentsMask, XkbUseCoreKbd); XGetAtomName(dpy, desc->names->groups[state.group]); XkbRF_VarDefsRec vd; XkbRF_GetNamesProp(dpy, NULL, &vd); char tok; tok = strtok(vd.layout, ","); for (int i = 0; i < state.group; i++) { tok = strtok(NULL, ","); } cairo_move_to(ctx,x+15,y+20); cairo_show_text(ctx, tok);

....//your code

        cairo_stroke(ctx);
        /* Draw two little separators for the highlighted part of the
         * unlock indicator. */

`

and it is work! i am not programmer and this code very quickly, but it is work and show current layer

compiler with ARGS=-I/usr/include -lX11 -lxkbfile or in file build/build.ninja add: LINK_ARGS = -Wl,-lX11,-lxkbfile,

i3lock need functional for show current a layer!

For example: show my photo https://ibb.co/xjSRXw8