-
Notifications
You must be signed in to change notification settings - Fork 17
Usecases
Tray indicator/switcher written in vala:
Create Perl script for Fvwm module ~/.fvwm/FvwmKbdd.pl
(and don't forget take a+x
permission!!):
#!/usr/bin/perl -w use lib `fvwm-perllib dir`; use FVWM::Module; use General::Parse; use Net::DBus; my $bus = Net::DBus->session(); my $service = $bus->get_service("ru.gentoo.KbddService"); my $object = $service->get_object("/ru/gentoo/KbddService"); my $module = new FVWM::Module( Name => "FvwmKbdd", Mask => M_STRING, Debug => 1, ); sub kbdd { my ($module, $event) = @_; my ($action, @args) = get_tokens($event->_text); if ($action eq "hello") { $module->send("Echo Hello from Kbdd..."); } elsif ($action eq "hel") { $module->send("Echo xxx..."); } elsif ($action eq "kbdd") { my $no = $args[0]; if ((0 <= $no) && ($no < 4)) { $object->set_layout(Net::DBus::dbus_uint32($no)); } else { $module->send("Echo Error: Kbdd no " . $no . "is not in 1..4 range"); } } elsif ($action eq "stop") { $module->send("Echo Kbdd exit..."); $module->terminate; } else { $module->send("Echo Kbdd unknown action: " . $action); } } $module->addHandler(M_STRING, \&kbdd); $module->send("Echo Kbdd loaded..."); $module->event_loop;
Update content of ~/.fvwm/config
startup script:
ModulePath $[FVWM_USERDIR]:+ Key 1 A 3 SendToModule FvwmKbdd.pl kbdd 0 Key 2 A 3 SendToModule FvwmKbdd.pl kbdd 1 Key 3 A 3 SendToModule FvwmKbdd.pl kbdd 2 AddToFunc StartFunction ++ I Module FvwmKbdd.pl
and setup langs in ~/.xinitrc
:
setxkbmap us,ru,ua
As you see it is very easy. I spend 8 hours to take this work (learn Fvwm debug technique, Perl, FvwmPerl module, Net::DBus lib).
In order to use kbdd as layout switcher one can use `xbindkeys` program for sending dbus events. So you can install `xbindkeys` and add next lines to `.xbindkeysrc` config file: "dbus-send --dest=ru.gentoo.KbddService /ru/gentoo/KbddService ru.gentoo.kbdd.set_layout uint32:0"
Mod1+Shift + 1
"dbus-send --dest=ru.gentoo.KbddService /ru/gentoo/KbddService ru.gentoo.kbdd.set_layout uint32:1"
Mod1+Shift + 2
Thus will bind switching to first group on Alt+Shift+1 keys and second group on Alt+Shift+2 keys. You can add up to 4 groups (limited by XKB).
If you use more than 3 layout groups you may be interested in using only 2 of them with current program.To perform such action you should call prev_layout
dbus method after switching layouts that you are interested in.
To do so you can use xbindkeys
or any other program. Just add next lines to .xbindkeysrc
file:
"dbus-send --dest=ru.gentoo.KbddService /ru/gentoo/KbddService ru.gentoo.kbdd.prev_layout"
Mod1+Shift + 5
and you can select last but one group used in current window.
Example Supposing you use 3 layout groups (1:en, 2:es, 3:de). Pressing Mod1+Shift+2 would switch to es, pressing Mod1+Shift+3 after that would switch to de, but es would be remembered as "previous layout". And you would be able to switch between es and de with Mod1+Shift+5.