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

💡 shell script / hook prior the swaylock #503

Open
1 task done
andrius opened this issue Apr 25, 2023 · 6 comments
Open
1 task done

💡 shell script / hook prior the swaylock #503

andrius opened this issue Apr 25, 2023 · 6 comments

Comments

@andrius
Copy link

andrius commented Apr 25, 2023

Summary

Background:

I use custom keyboard switcher through ~/.config/sway files, mainly because of the wayvnc; to get national languages working with the wayvnc, I had to add some workarounds.

This works fine however if swaylock get triggered while I do use Lithuanian or Russian layout, I can't enter the password.

So I want to call a shell script that switch keyboard to US English prior swaylock

Drawbacks

I do not see any drawbacks for the users: no script, no action

Implementation idea

Update swaylock script to call a shell file in some user directory (i.e. ~/.config/sway/scripts/before_swaylock.sh), if it exists

Will you be able to contribute a PR for this?

  • Yes I will be able to get that feature a lot quicker.
@boredland
Copy link
Member

This works fine however if swaylock get triggered while I do use Lithuanian or Russian layout, I can't enter the password.

So swaylock does have a different layout then the currently selected one? I am a bit confused as to what is going on.

@andrius
Copy link
Author

andrius commented Apr 26, 2023

yes it remains in the last selected layout. In case of Lithuanian - there is national letters at the place of digits, in case of Russian, there is cyrillic letters instead of the latin alphabet

@boredland
Copy link
Member

Do you have a discriminator key configured for switching the keyboard layout, like in our example? That isn't a fix, but could help you. I will take a look later at what is going on there.

@boredland
Copy link
Member

boredland commented Apr 27, 2023

Well, I can't reproduce right now:

I have three layouts configured: eu, us, de - eu is the default.

I switched to us using the discriminator key, locked my screen. The layout in swaylock is us.

@andrius
Copy link
Author

andrius commented Apr 28, 2023

The thing that I had to replace keyboard switching that you propose to the script based. Due to wayvnc, I wanted to get national languages working, for some reason the wayvnc does not allow to do the keyboard switch (there is issues about this topic in their repository).

After the switch I have the only single language in system.

What I want is to call a script 'set-us-layout' with before_sleep callback (or to make it usable, to add a option to call any script)

~/.config/sway/config.d/01-keyboard.conf

# # Bindings made for wayvnc
# $bindsym $mod+Alt+1 input "type:keyboard" xkb_layout "us(euro)"
# $bindsym $mod+Alt+2 input "type:keyboard" xkb_layout "ru(phonetic_mac)"
$bindsym Ctrl+space exec set-next-layout
$bindsym $mod+Ctrl+space exec set-next-layout

set-next-layout:

#!/bin/sh

FOCUSED_OUTPUT="$(swaymsg -t get_outputs --raw | jq -r '[.[] | select(.focused == true)][0] | .name')"
CURRENT_LAYOUT="$(swaymsg -t get_inputs --raw | jq -r '[.[] | select(.type == "keyboard")][0] | .xkb_active_layout_name' | awk '{print $1}')"
# KEYBOARD="$(swaymsg -t get_inputs --raw | jq '[.[] | select(.type == "keyboard")][0] | .identifier')"
KEYBOARD="*"

if [ "${FOCUSED_OUTPUT}" = "HEADLESS-1" ]; then
  if [ "${CURRENT_LAYOUT}" = "English" ]; then
    swaymsg input "${KEYBOARD}" xkb_layout "ru(phonetic_mac)"
  else
    swaymsg input "${KEYBOARD}" xkb_layout "us(euro)"
  fi
else
  swaymsg input "${KEYBOARD}" xkb_switch_layout next
fi

set-us-layout:

#!/bin/sh
KEYBOARD="*"
swaymsg input "${KEYBOARD}" xkb_layout "us(euro)"

(it is my own specific issue and setup: 2x laptops, iPad, VPS with manjaro-sway), I do working only on VPS

@boredland
Copy link
Member

Couln't you just do both: configure the layouts in sway and use your custom switcher-script? that way layout-switching in swaymsg should just work - on my machine I can switch locales through the discriminator key then.

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

No branches or pull requests

2 participants