Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
KDE

Journal gameforge's Journal: X/KDE/ALSA Trick 6

Well, you asked about non-KDE tricks as well; this is partly a trick w/ KDE and partly a trick w/ X, and also w/ ALSA.

I've been using Linux and X-Windows for a fairly long time, as well as KDE (since 1.x). One thing that always bothered me was that I couldn't set up the Windows key exactly the way that it works in Windows. It keeps wanting to treat it as a meta key; KDE's 'Keyboard Shortcuts' control panel in the control center wouldn't let me set it up identical to Windows. It's certainly possible I did something wrong, but I sure played with it long enough...

Further, I have a Logitech Cordless MX Duo; it's a wireless keyboard & mouse. As most Logitech keyboards do, it has Internet buttons and multimedia buttons all over the place; there's also WWW back & forward thumb buttons on the mouse, which are quite convenient under Firefox/Windows.

So, after years of living without, I discovered the 'xmodmap', 'imwheel' and 'xev' commands. To get the mouse forward/backward buttons to work correctly, I execute a simple script called 'setup_mx700' when loading X:


#!/bin/sh
xmodmap -e "pointer = 1 2 3 6 7 4 5"
imwheel -f -k -p -b "67"

Then, in the imwheelrc file, I have this:

"(null)"
None, Up, Alt_L|Left
None, Down, Alt_L|Right

".*"
None, Up, Alt_L|Left
None, Down, Alt_L|Right

This tells X how many buttons are on the mouse, and in which order they are coded. Both imwheel and xmodmap have man pages; you can check them out if you have a different scenario, possibly if your mousewheel and/or middle buttons don't work, etc. Essentially, the back/forward buttons map out to 'Alt+Left' and 'Alt+Right', and the mouse wheel maps to 'up/down' (in case the program I'm using doesn't support mouse wheels). This will certainly vary from setup to setup, which is why I refer to the manpages.

Now for the keyboard issue. As I said, the Win key wouldn't work correctly (probably a messed up X setting somewhere), and none of the Logitech MM and WWW buttons would work. Using 'xev', I mapped out which keys correspond to which key codes. So, I have another script, called 'setup_iTouch' run when I start X, right after 'setup_mx700':

#!/bin/sh
xmodmap -e "keycode 115 = F13"
xmodmap -e "keycode 117 = F15"
xmodmap -e "keycode 160 = F14"
xmodmap -e "keycode 174 = F16"
xmodmap -e "keycode 176 = F17"
xmodmap -e "keycode 164 = F18"
xmodmap -e "keycode 162 = F19"
xmodmap -e "keycode 153 = F20"
xmodmap -e "keycode 144 = F21"

Once again, different setups will have different keycodes; use 'xev' to capture your own keyboard's proprietary codes.

Then you can go into KDE's shortcut and hotkey control panels, and when you try to assign these keys to an action, they pop up w/ no problems at all (as F13, F14, F15, etc.) I was able to assign the Win key to its proper shortcut, and it now behaves identically to Windows (pushing it twice makes it go away, etc.). The other multimedia/shortcut keys were pretty easy to bind and get them to do what I wanted.

However, I could not think of a program that I could use to simply 'mute' the master sound in ALSA, nor commands to simply increase/decrease the master volume in ALSA, which would retain previous settings & whatnot. So, I wrote yet another three scripts (all five of which I store in /usr/local/bin) that can be assigned to their respective keys in KDE's hotkey manager.

These three use an environment variable, $MVOL, to maintain ALSA's master sound level.

First, 'snd_mute':

#!/bin/bash
MVOL=`amixer sget Master | tail -n 1 | cut -c 18-20`
THIRD=`echo $MVOL | cut -c 3`
if [ "$THIRD" = "[" ]; then
      MVOL=`echo $MVOL | cut -c 1-2`
fi
if [ $MVOL = 0 ]; then
      if [ -a /tmp/mute_vol.tmp ]; then
            MVOL=`cat /tmp/mute_vol.tmp`
      else
            echo 0 > /tmp/mute_vol.tmp
      fi
      amixer sset Master $MVOL
else
      echo $MVOL > /tmp/mute_vol.tmp
      amixer sset Master 0
fi

Then, snd_down:

#!/bin/bash
MVOL=`amixer sget Master | tail -n 1 | cut -c 18-20`
THIRD=`echo $MVOL | cut -c 3`
if [ "$THIRD" = "[" ]; then
      MVOL=`echo $MVOL | cut -c 1-2`
fi
if [ $MVOL -gt 0 ]; then
      MVOL=`expr $MVOL - 3`
      if [ $MVOL -lt 0 ]; then
            MVOL=0
      fi
      amixer sset Master $MVOL > /dev/null
fi

And finally, snd_up:

#!/bin/bash
MVOL=`amixer sget Master | tail -n 1 | cut -c 18-20`
THIRD=`echo $MVOL | cut -c 3`
if [ "$THIRD" = "[" ]; then
      MVOL=`echo $MVOL | cut -c 1-2`
fi
if [ $MVOL -lt 100 ]; then
      MVOL=`expr $MVOL + 3`
      if [ $MVOL -gt 100 ]; then
            MVOL=100
      fi
      amixer sset Master $MVOL > /dev/null
fi

To make it more precise, change

MVOL=`expr $MVOL + 3`

to + 1. To make it less precise, change it to + 5. Same for 'snd_down', but use - 1 and - 5.

It may work (with proper tweaking) with some other keyboards/GUI's, I don't know. Feel free to share modifications, questions, comments, etc. You could make it even more complete and get little overlay displays that tell you what's going on, and you could even make the volume control work for other sliders on the mixer; perhaps if the 'alt' key is pressed, it adjusts the 'Surround' volume, and with the 'ctrl' key pressed it adjusts the 'Bass' level, or something like that.

This discussion has been archived. No new comments can be posted.

X/KDE/ALSA Trick

Comments Filter:
  • i set mine as keycode 162 = XF86AudioPlay keycode 164 = XF86AudioStop keycode 160 = XF86AudioMute keycode 144 = XF86AudioPrev keycode 153 = XF86AudioNext keycode 176 = XF86AudioRaiseVolume keycode 174 = XF86AudioLowerVolume and the volume and mute worked without me having to do anything
    • Thanks for the reply.

      Was that as in xmodmap -e "keycode 174 = XF86AudioLowerVolume"? Which mixer does it change? It doesn't seem to work for me. I think I remember trying that a while back, and it worked on my laptop running SuSE but not on my desktop running Gentoo; and I think it changed the PCM level, rather than the master.

      With a custom amixer script, you can change the precision & extend the control to more than one mixer channel (i.e. my KB has a knob, so I could program it so that Alt+(rotate
      • sorry, slashdot borked my post. I have a .Xmodmap file in my home directory, I dont know what mixer it changed, I do know im using slackware 10.2 with kde 3.5. Each keycode command was supposed to be one a separate line.
        Im one of those people where, if it works, I am happy and I just leave it alone. I will check later to see what mixer it changes. But I'm rather sure it changes the master volume.
        • I haven't used Slackware since version 3.x, but doesn't it have some form of hardware auto-detection? I run Gentoo on the system w/ the Cordless Duo, and aside from some security and distro-specific patches, it installs a pretty vanilla x.org. I know most semi-functional distros go to great lengths to ensure that little stuff like that works, although when I had SuSE 9.2, I know that all of my utility/shortcut buttons & toys didn't work out of the box, and I tried tinkering with it then to no end...

          I
  • I've done the same trick with my one (generically and uselessly branded a "Logitech Cordless Keyboard" as the model). Did you have any issues where a key would appear as a left/right/middle click?
    • I have not; that sounds kind of bizarre. If you can figure out what model keyboard it is, you may be able to Google it & find another user with that issue? Are you sure the left mouse button isn't actually generating a key code, rather than the keyboard generating a mouse event? If you tweaked xmodmap and imwheel just right, I think that could be reversed...

Nothing happens.

Working...