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