Wednesday 6 February 2013

DWM + Colemak + Conky

Toggle QWERTY and Colemak keyboard layouts with Super+F5 key combination while using DWM with conky notification in status bar in Debian GNU/Linux 6.
  1. configure DWM v6: config.h
    
    /* commands */
    static const char *setxkbmaptogglecmd[] = { "toggle-setxkbmap", NULL };
    
    * modifier key    function argument */
    { MODKEY,  XK_F5, spawn,   {.v = setxkbmaptogglecmd } },
    
  2. toggle-setxkbmap script: /usr/local/bin/toggle-setxkbmap
    
    #!/usr/bin/perl
    use warnings;
    use strict;
    
    my $var;
    
    $var=`setxkbmap -v 7`;
    if ( $var =~ /^variant:\s+colemak$/m ) {
     system("setxkbmap us");
    }
    else {
     system("setxkbmap us colemak");
    }
    
  3. configure conky: ~/.conkyrc
    
    out_to_console yes
    out_to_x no
    background no
    update_interval 1
    total_run_times 0
    use_spacer left
    pad_percents 3
    
    TEXT
    ${execi 10 setxkbmap -v 7 | perl -ne 'BEGIN{$var="qwerty"}$var="colemak" if /^variant:\s+colemak$/;END{print $var}'} ${cpu}% ${mem} ${time %a %b %d, %l:%M%P}
    
  4. configure ~/.xsession or ~/.xinitrc:
    
    conky | while true; read line;do xsetroot -name "$line"; done &
    exec dwm
    
  5. Reference:
    conky