LinHES Forums
http://forum.linhes.org/

Script to use different xmodmaps with different programs
http://forum.linhes.org/viewtopic.php?f=3&t=7024
Page 1 of 1

Author:  hbj [ Mon Nov 21, 2005 11:55 pm ]
Post subject:  Script to use different xmodmaps with different programs

After getting my RF ATI Remote Wonder to work with MythTV and configuring the keys with xmodmap, I found that I ran into key mapping problems when I tried to use mplayer, xine, or xmame from within MythTv. My solution was to write a small wrapper script to handle setting and resetting the key mappings.

To use this script, simply save it to someplace in your path - I saved it as
Code:
/usr/local/bin/keymap_wrapper


Next go into Utilities/Setup / Media Settings / Videos Settings / Player Settings, preceed the regular command with the name of this script.

For example, my video player command was originally:
Code:
mplayer -fs -zoom -quiet -vo xv -ao alsa:device=mixed-digital -ac hwac3, %s
which I replaced with
Code:
keymap_wrapper mplayer -fs -zoom -quiet -vo xv -ao alsa:device=mixed-digital -ac hwac3, %s


You can similarly change the DVD Settings / Play Settings and the Games Settings / General Settings.

When the wrapper script runs, it will search your home directory for a xmodmap file named according to the program you are running in the form
Code:
.Xmodmap_<player>
which for the example above using mplayer becomes
Code:
.Xmodmap_mplayer
If this xmodmap file is found, it dumps the current settings, whatever they are, to a file called
Code:
.Xmodmap_current
The player-specific key mappings are then loaded using xmodmap and the player program is called with all the arguments you passed to it. After the player exits, your original key mappings are restored.

The keymap_wrapper script is below. Any suggestions on how it might be improved will be appreciated.

Code:
#!/usr/bin/perl
# ***********************************************************************
#  Run this script to launch various applications from within MythTV by
#  preceeding the command to run with the path to this script.  This
#  script will look for a specific Xmodmap file for the player that you
#  want to run.  If found, it will run xmodmap to dump your current
#  settings.  Then it will load the settings specific to the player you
#  are launching.  The player will run with all the options you pass it
#  and afterwards, your original key bindings will be restored.
#
#  For example, if your DVD player command in mythtv was originally:
#
#    xine --audio-driver alsa -pfhq --auto-scan dvd
#
#  then you would replace it with:
#
#    keymap_wrapper xine --audio-driver alsa -pfhq --auto-scan dvd
#
#  This script will use the first argument, in this case 'xine' to look
#  for an xmodmap file called "$HOME/.Xmodmap_xine" which would hold
#  the key bindings you want to change for running xine.  After running
#  xine, your original key bindings will be restored.
# ***********************************************************************

# First argument should be the player we want - xine, mplayer, xmame, etc.
# and can be given with just the program name or the full path.
$app= $ARGV[0];
if ($app=~/\//) {
   @parts= split(/\//,$app);
   $app= $parts[-1];
}

# File and path settings
$xm_prefix=$ENV{HOME}."/.Xmodmap";
$xm_current="${xm_prefix}_current";
$xm_player="${xm_prefix}_$app";

print "xm_current= $xm_current\n";
print "xm_player = $xm_player\n";

# Set player-specific keymap
if ( -f $xm_player ) {

  # Store current xmodmap bindings
  `xmodmap -pke > $xm_current`;

  # Set the new xmodmap bindings
  `xmodmap $xm_player`;

}

# Run the player with all the options you passed it
$command= "";
foreach $a (@ARGV) {
   $a=~ s/\"/\\\"/g;
   $a=~ s/\`/\\\`/g;
   $a=~ s/\'/\\\'/g;
   if ($a=~ /\s/) {
      $a= "\"$a\"";
   }
   $command.= "$a ";
}
print `$command`;

# Restore original key bindings
if ( -f $xm_player ) {
  if ( -f $xm_current ) {
    `xmodmap $xm_current`;
  }
}

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/