kbdd_layout 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. #
  3. # kbdd_layout is a script that parse layout with kbdd in real time
  4. # Copyright (C) 2016,2019 Anton Karmanov <bergentroll@insiberia.net>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or any
  9. # later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. # Matches first 3 letters of layout name.
  19. MATCH='\w{3}'
  20. # Matches short layout name.
  21. #MATCH='\w*'
  22. # Matches full layout name.
  23. #MATCH='\w*(\s\(.*\))?'
  24. # Restart kbdd to apply layout changes on block reload.
  25. killall kbdd 2>/dev/null
  26. kbdd >/dev/null || exit 1
  27. # Get initial state of layout
  28. N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
  29. /ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
  30. sed -un 's/^.*uint32 //p' )
  31. # In case dbus service wasn't available yet, poll until service is ready.
  32. while [[ -z "$N" ]]; do
  33. sleep .1
  34. N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
  35. /ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
  36. sed -un 's/^.*uint32 //p' )
  37. done
  38. dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
  39. /ru/gentoo/KbddService ru.gentoo.kbdd.getLayoutName uint32:"$N" |\
  40. grep -Po "${MATCH}" | head -n1
  41. # Parse dbus output.
  42. dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" |\
  43. grep -Po --line-buffered "(?<=string \")${MATCH}"
  44. # dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" | cut -d "\"" -f2
  45. # if [[ ${lang} == "Eng" ]]; then
  46. # echo "English"
  47. # # echo "🇺🇸"
  48. # # printf "%s" "🇺🇸"
  49. # elif [[ ${lang} == "Rus" ]]; then
  50. # echo "Russian"
  51. # # echo "🇷🇺"
  52. # # printf "%s" "🇷🇺"
  53. # fi