Sunday, August 25, 2013

MPD and NCMPC setup

I decided on mpd (Music Player Daemon) and ncmpc (NCurses Music Player Client) to play my music.  The following commands install the necessary packages then use insserv to remove mpd from being started automatically by root since I want to configure and run mpd as user.  The cat command output shows that mpd was part of the system startup before the innserv command. After the insserv command the lack of output from that same cat command demonstrates mpd was removed from the startup file. The ps command checks for any instances of mpd, and the final command stops it if needed.
ROOTPROMPT$ apt-get install mpd ncmpc
ROOTPROMPT$ cat /etc/init.d/.depend.start | grep mpd
TARGETS = motd killprocs rpcbind nfs-common rsyslog sudo mpd atd exim4 rsync cron ssh dbus acpid bootlogs single rmnologin rc.local
rmnologin: sudo atd rsyslog rpcbind nfs-common exim4 motd bootlogs rsync cron ssh dbus acpid mpd
rc.local: atd rsyslog rpcbind nfs-common exim4 motd bootlogs rsync cron sudo ssh dbus acpid mpd
ROOTPROMPT$ insserv -r mpd
ROOTPROMPT$ cat /etc/init.d/.depend.start | grep mpd
ROOTPROMPT$ ps aux | grep mpd
root      5029  0.0  0.0 322696  7456 ?        Ssl  23:39   0:00 mpd
root      5033  0.0  0.0   7828   872 pts/1    S+   23:39   0:00 grep mpd
ROOTPROMPT$ /etc/init.d/mpd stop
If your system does not use dependency based boot sequence you will have to configure the mpd service using the update-rc.d command.

update: With systemd I had to run the following to prevent mpd startup on boot
ROOTPROMPT$ systemctl disable mpd
ROOTPROMPT$ systemctl disable mpd.service
ROOTPROMPT$ systemctl disable mpd.socket 
Found help on crunchbang mpd how to

Copy the example mpdconf file to your home directory.
$> gunzip usr/share/doc/mpd/examples/mpd.conf.gz > ~/.mpdconf
Edit this file to change the music_directory, playlist_directory, db_file, log_file, error_file, pid_file, and state_file. Also uncomment the mixer_type line for software volume control.  Below are the relevant exerpts from my config file showing the previous entry (commented out), the comment with my name to remind me I changed it, and my new entry. For easy viewing I've cut the comments, but I recommend reading them as you edit.
#music_directory  "/var/lib/mpd/music"
#ibyrd
music_directory     "/home/byrdi01/music"
...
#playlist_directory  "/var/lib/mpd/playlists"
#ibyrd
playlist_directory  "/home/byrdi01/.mpd/playlists"
...
#db_file   "/var/lib/mpd/tag_cache"
#ibyrd
db_file             "/home/byrdi01/.mpd/database"
...
#log_file   "/var/log/mpd/mpd.log"
#ibyrd
log_file            "/home/byrdi01/.mpd/log"
...
#pid_file   "/var/run/mpd/pid"
#ibyrd
pid_file            "/home/byrdi01/.mpd/pid"
...
#state_file   "/var/lib/mpd/state"
#ibyrd
state_file   "/home/byrdi01/.mpd/state"
...
#ibyrd.  uncomment the next line to enable software control of volume.
mixer_type   "software"

My music is in the "/home/byrdi01/music" directory. Change this as appropriate to tell mpd where your music is located. Create the .mpd/ and .mpd/playlists directories.
$> mkdir -p /home/byrdi01/.mpd/playlists
Now whenever you want to play music you need to start mpd and ncmpc
$> mp
$> ncmpc
The ncmpc client will take up the entire xterm. Press 1 in ncmpc to get the list of commands. 'q' quits ncmpc, but mpd continues, so either stop playing music before exiting ncmpc or run
$> mpd --kill
to kill the daemon.
The mpd wiki has a good mpd configuration page, and I used some information from the mpd config on Arch and the mpd config on Ubuntu pages.

Low volume with snd_hda_intel module

My new machine has six audio jacks on the back (shown in the figure) and two  on the front.  
I used alsamixer to unmute and set output to 0dB for the 'Headphone' (front green jack) and the 'Speaker' (rear green jack) channels, but the volume off the green jacks was barely audible at the maximum settings and with speakers set to maximum output.  Plugging the speakers into the the grey side speaker (#1) jack produced sound at reasonable volume. The following command gives the device [bus:slot.func] numbers, then the second command used this number to reveal which kernel modules were used by my card. (This snd_hda_intel howto was very helpful in sorting this out, despite the warning at the top that the information is outdated).
$> lspci | grep Audio
00:14.2 Audio device: Advanced Micro Devices [AMD] FCH Azalia Controller (rev 01)
$> lspci -v -s00:14.2
00:14.2 Audio device: Advanced Micro Devices [AMD] FCH Azalia Controller (rev 01)
        Subsystem: Hewlett-Packard Company Device 2ae0
        Flags: bus master, slow devsel, latency 32, IRQ 16
        Memory at feb40000 (64-bit, non-prefetchable) [size=16K]
        Capabilities: 
        Kernel driver in use: snd_hda_intel
A little Google and a lot of reading suggested the problem was with the snd_hda_intel module, and was fixed as follows (Note these instructions are only useful for cards relying on the snd_hda_intel module): First get the sound card model.
$> cat /proc/asound/card0/codec* | grep Codec
Codec: IDT 92HD73E1X5
My card model is 92HD73E1X5.  I checked HD Audio Models and found this entry was the closest match.
SSTAC92HD73*
 ===========
   ref           Reference board
   no-jd         BIOS setup but without jack-detection
   intel         Intel DG45* mobos
   dell-m6-amic  Dell desktops/laptops with analog mics
   dell-m6-dmic  Dell desktops/laptops with digital mics
   dell-m6       Dell desktops/laptops with both type of mics
   dell-eq       Dell desktops/laptops
   alienware     Alienware M17x
   auto          BIOS setup (default)
My computer is an HP Pavilion P7-1439 Desktop and HPs are not on this list.  I decided to try a few configurations, so as ROOT I added the following as the last line of my /etc/modprobe.d/alsa-base.conf file.
...
options snd-hda-intel model=[MODEL]
I iterated [MODEL] through the options available for the SSTAC92HD73 series. After each [MODEL] change I reloaded alsa
ROOT$> alsa force-reload
then opened alsamixer to unmute and increase volume to 0.0dB for all outputs.  I played music or ran the command
speaker-test -c 2 -t wav
while I moved the speaker plug to each jack, and tested headphone jack detection on the front jack by plugging/unplugging in headphones for each speaker plug location. I found that dell-m6 provided good volume levels from front green jack and rear black jack (with jack detection) for headphones and rear blue 'in' jack for speakers, but no volume from other jacks.  Not listing a model option in the config file produced speaker output from the 'side' (grey), 'rear' (black), and 'csub' (orange) jacks, but the volume from the front headphone jack was extremely low, although it did have jack detection.  Since I have a simple pair of old DELL PC speakers, using the dell-m6 model and plugging the speakers into the blue jack works for me.  However if you have surround sound you'll have to choose between that and audible headphone volume.

   A little investigating revealed this snd_hda_intel low volume bug, and posts 13-16 show a difference in the GPIO IO[0] data pin when the volume is correct and when it is not.  I did the following: Comment out the options snd-hda-intel model=dell-m6 in /etc/modprobe.d/alsa-base.conf so that the model loads as default, then
ROOT$> alsa force-reload
ROOT$> cat /proc/asound/card0/codec#3 > auto.txt 
Then uncomment that same line in /etc/modprobe.d/alsa-base.conf and
ROOT$> alsa force-reload
ROOT$> cat /proc/asound/card0/codec#3 > dellm6.txt 
So I could compare all differences. I've made the outputs for default, dell-eq, and dell-m6 available.  My GPIO IO[0] data=0 with models that produce low headphone jack volume and GPIO IO[0] data=1 for models that produced normal headphone jack volume.  the nodes are different for the headphone outputs as well, but I'm not sure that's important.  Because I don't have surround sound speakers, I didn't persist further with the hd-verb to manually change the data pin.

  Just to verify my card does produce surround sound, I commented out the options snd-hda-intel model=dell-m6 in /etc/modprobe.d/alsa-base.conf to load the default model then ran
speaker-test -D surround71 -c 6 -t wav
while moving the speaker plug to the 'side' (grey), 'rear' (black), and 'csub' (orange) jacks.  "Front Left" and "Front Right" played from the respective speakers when plugged into the grey jack, "Rear Left" and "Rear Right" played from the respective speakers when plugged into the black jack, and "Front Center" and Rear Center" played from the respective speakers when plugged into the orange jack, so my surround sound works on this card.

Monday, November 5, 2012

Automount USB devices with no desktop environment

I'm running a slim Debian install with Xmonad as my window manager, and need a lightweight automounter for USB devices.  I don't need to worry about icons popping up since I have no desktop environment.  usbmount meets those specs.  As of this writing it is an orphaned package, but is a relatively simple udev script, so I don't anticipate too many surprises.  Setup for generic USB devices is simple, just
ROOTPROMPT$> apt-get install usbmount
   At this point your system should automount ext[3,4] filesystems according to the particular device ownership.  VFAT filesystems don't have such properties so we have to tell usbmount how to handle them.  The instructions in the usbmount.conf file are thorough, so in brief we have to write the desired mount options for the filesystem type into the config file.  I want to mount vfat usb devices to the 'floppy' group with read and write privileges.  To do this open /etc/usbmount/usbmount.conf file as root and set the FS_MOUNTOPTIONS as follows:
FS_MOUNTOPTIONS="-fstype=vfat,gid=floppy,dmask=0007,fmask=0117"
Now the system should automount ext3, ext4 and vfat filesystems upon disk insertion.
   Other devices can be tricky.  I have an HP touchpad that does not have a partition table.  When plugged into the computer, the touchpad asks whether I want it to behave as as USB mass storage device.  After I select yes, is shows up as /dev/sd[b-h] depending on how many other devices I have plugged in.  The example below shows the device as /dev/sdb.
$> dmesg
/////skip a bunch//////
[ 3005.685270] sdb:
[ 3030.915649] usb 1-5: USB disconnect, address 8
[ 3035.340043] usb 1-5: new high speed USB device using ehci_hcd and address 9
[ 3035.474728] usb 1-5: New USB device found, idVendor=0830, idProduct=8074
[ 3035.474735] usb 1-5: New USB device strings: Mfr=2, Product=3, SerialNumber=4
[ 3035.474739] usb 1-5: Product: webOS-device
[ 3035.474743] usb 1-5: Manufacturer: HP
[ 3035.474746] usb 1-5: SerialNumber: 0123456789ABCDEF
[ 3035.474950] usb 1-5: configuration #1 chosen from 1 choice
[ 3035.482227] scsi7 : SCSI emulation for USB Mass Storage devices
[ 3035.486189] usb-storage: device found at 9
[ 3035.486194] usb-storage: waiting for device to settle before scanning
[ 3040.484486] usb-storage: device scan complete
[ 3040.489848] scsi 7:0:0:0: Direct-Access HP webOS-device 0327 PQ: 0 ANSI: 2
[ 3040.493881] sd 7:0:0:0: Attached scsi generic sg2 type 0
[ 3040.509961] sd 7:0:0:0: [sdb] Attached SCSI removable disk
[ 3152.892176] sd 7:0:0:0: [sdb] 57720832 512-byte logical blocks: (29.5 GB/27.5 GiB)
[ 3152.995534] sd 7:0:0:0: [sdb] Assuming drive cache: write through
fdisk shows no partition, just the entire block device.
ROOTPROMPT$> fdisk -l
/*skip other disc info*/
Disk /dev/sdb: 29.6 GB, 29553065984 bytes
64 heads, 32 sectors/track, 28184 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
I can mount it as root and see it is a vfat device.
ROOTPROMPT$> mount /dev/sdb /media/touchpad
ROOTPROMPT$> exit
$> df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sdb vfat 28853344 1854128 26999216 7% /media/touchpad
I tried adding a UUID based mount rule for the touchpad into the fstab,  but that didn't work until after I ran blkid on the device, which requires root access.
   I read up on writing udev rules at various websites.  The three I found useful are:
http://www.reactivated.net/writing_udev_rules.html - Good explanations, but udevinfo has been replaced by udevadm, so you have to adjust the examples.
http://workaround.org/mount-usb-memory-sticks - Good, but dated and uses udevinfo
http://wiki.debian.org/udev - debian specific udev page with udevadm examples.
   As root, create the rules file in the /etc/udev/rules.d directory.  I created /etc/udev/rules.d/10-touchpad-rules file.  Lower numbers at the beginning of the file increase precedence.  The following command gives a bunch of information, I've trimmed most of it out since I only needed a few pieces to write my rule.
ROOTPROMPT$> udevadm info -q all -n /dev/sdb
/* skip irrelevant details*/
E: UDEV_LOG=3
E: DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb1/1-6/1-6:1.0/host2/target2:0:0/2:0:0:0/block/sdb
E: MAJOR=8
E: MINOR=16
E: DEVNAME=/dev/sdb
E: DEVTYPE=disk
E: SUBSYSTEM=block
E: ID_VENDOR=HP
E: ID_VENDOR_ENC=HP\x20\x20\x20\x20\x20\x20
E: ID_VENDOR_ID=0830
E: ID_MODEL=webOS-device
E: ID_MODEL_ENC=webOS-device\x20\x20\x20\x20
   My rule is one line long and is the only entry in the /etc/udev/rules.d/10-touchpad-rules file:
KERNEL=="sd?", SUBSYSTEM=="block", ATTRS{model}=="webOS-device", SYMLINK+="touchpad"
The KERNEL identifies a block device (with no partition number), the SUBSYSTEM checks for a value of 'block', and the ATTRS{model} checks the ID_MODEL value given from the udevadm command.  If they match the device is symlinked to /dev/touchpad.  As is, my system cannot discriminate between HP touchpads, and if two were plugged in I think they would both symlink to /dev/touchpad.  I don't envision plugging multiple touchpads into my computer though.  The Udev rule creates the device identifier.  Add the following line to /etc/fstab to enable mounting by the user.  Don't forget the newline if at the end of the file.  Archwiki has a good write up on the fstab file to understand the options below.
/dev/touchpad /media/touchpad auto rw,user,noauto  0 0
Plug in the touchpad, and select the 'usbmount' option on that device, then mount it on the computer with
$> mount /media/touchpad
Before unplugging the disk run the following:
$> umount /media/touchpad
$> eject /dev/touchpad

Monday, October 8, 2012

MplabX with Xmonad

Download the mplabx install files from microchip.  From the same page, grab the install files for the compiler for the family of controllers you will work with.  I downloaded the mplabx-ide-v1.41-linux-installer.run for the IDE and the xc32-v1.11-linux-installer.run.tar for the PIC32 compiler.  Login as root, change the permissions, and install the IDE as follows.  These commands assume the current working directory contains the install files.
ROOTPROMPT$> chmod 770 mplabx-ide-v1.41-linux-installer.run
ROOTPROMPT$> ./mplabx-ide-v1.41-linux-installer.run
   I selected all the defaults through the install wizard.  After the IDE is installed, untar and  install the compiler(s).
ROOTPROMPT$> tar -xf xc32-v1.11-linux-installer.run.tar
ROOTPROMPT$> chmod 770 xc32-v1.11-linux-installer.run
ROOTPROMPT$> ./xc32-v1.11-linux-installer.run
   When prompted by the wizard, I selected to add the compiler location to the end of the PATH variable, and to use this setting for all users on this machine.  Otherwise I used the defaults.  For reference, everything for the compiler and IDE is installed to the /opt/microchip/ directory including the required java files, so no need to worry about installing the appropriate jdk with this version.  Exit root, and start the IDE from the terminal as follows.
$> mplab_ide
   You will probably get a floating splashscreen as if the program is starting, but then just a tiled  but empty grey window.  This is a java error with Xmonad as explained in section 4.12 of the FAQ linked.  Of the suggestions, Changing the AWT_TOOLKIT - as described in the link - worked for me.  To test it, run:
$> export AWT_TOOLKIT=MToolkit
$> mplab_ide
  And the IDE should launch correctly.  If this works, add the 'export AWT_TOOLKIT=MToolkit' line to your .bashrc file to have the export done automatically when the shell is started.  Otherwise you have to manually enter the export command to every new shell instance.


update 06DEC2012:
If building a project does nothing, and you see no compiler messages in the output window, make sure MAKE is installed on your machine.  The forums details a little of the  Linux MPLABX build does nothing problem, which is easily resolved.

Friday, October 5, 2012

Xscreensaver with Xmonad

Install xscreensaver from the repository, then add the highlighted line to your .xinitrc file.  Make sure it is before the final call to xmonad in the .xinitrc
if [ -f $HOME/.xresources ]; then
xrdb -merge $HOME/.xresources
fi
if [ -f $HOME/.xmodmap ]; then
/usr/bin/xmodmap $HOME/.xmodmap
fi
xscreensaver -no-splash &
xmonad

This will launch the xscreensaver daemon when X is started.  To configure the user options run
$> xscreensaver-demo

To lock the screen from the command line run
$> xscreensaver-command -lock

Tuesday, September 4, 2012

xmonad screenshot hotkeys

Install scrot.  Add the following to the key bindings portion of your /home/USER/.xmonad/xmonad.hs file.
   --take a screenshot of entire display
   , ((modm , xK_Print ), spawn "scrot screen_%Y-%m-%d-%H-%M-%S.png -d 1")

   --take a screenshot of focused window
   , ((modm .|. controlMask, xK_Print ), spawn "scrot window_%Y-%m-%d-%H-%M-%S.png -d 1-u")
then refresh xmonad with mod+q.  XK_Print is the Print Screen keysym name.  Now mod+PrtScr will take a screen shot of the entire display, and ctrl+mod+PrtScr will take a screen shot of the focused window.  The captured image is placed in the /home/USER/ directory.  The file name is prefixed either window or screen, and date+time stamped.  You can use the -e option of scrot to move the resulting file to a different directory.  For example:  scrot window_%Y-%m-%d-%H-%M-%S.png -d 1 -u -e 'mv $f /home/USER/image/'.  the $f is the scrot variable for the captured image path.
   Here is my current xmonad.hs file, which is this xmonad.hs example with some minor modifications.
-- xmonad example config file for xmonad-0.9
--
-- A template showing all available configuration hooks,
-- and how to override the defaults in your own xmonad.hs conf file.
--
-- Normally, you'd only override those defaults you care about.
--
-- NOTE: Those updating from earlier xmonad versions, who use
-- EwmhDesktops, safeSpawn, WindowGo, or the simple-status-bar
-- setup functions (dzen, xmobar) probably need to change
-- xmonad.hs, please see the notes below, or the following
-- link for more details:
--
-- http://www.haskell.org/haskellwiki/Xmonad/Notable_changes_since_0.8
--
 
import XMonad
import Data.Monoid
import System.Exit
 
import qualified XMonad.StackSet as W
import qualified Data.Map        as M
 
-- The preferred terminal program, which is used in a binding below and by
-- certain contrib modules.
--
myTerminal      = "xterm"
 
-- Whether focus follows the mouse pointer.
myFocusFollowsMouse :: Bool
myFocusFollowsMouse = True
 
-- Width of the window border in pixels.
--
myBorderWidth   = 1
 
-- modMask lets you specify which modkey you want to use. The default
-- is mod1Mask ("left alt").  You may also consider using mod3Mask
-- ("right alt"), which does not conflict with emacs keybindings. The
-- "windows key" is usually mod4Mask.
--
myModMask       = mod4Mask
 
-- NOTE: from 0.9.1 on numlock mask is set automatically. The numlockMask
-- setting should be removed from configs.
--
-- You can safely remove this even on earlier xmonad versions unless you
-- need to set it to something other than the default mod2Mask, (e.g. OSX).
--
-- The mask for the numlock key. Numlock status is "masked" from the
-- current modifier status, so the keybindings will work with numlock on or
-- off. You may need to change this on some systems.
--
-- You can find the numlock modifier by running "xmodmap" and looking for a
-- modifier with Num_Lock bound to it:
--
-- > $ xmodmap | grep Num
-- > mod2        Num_Lock (0x4d)
--
-- Set numlockMask = 0 if you don't have a numlock key, or want to treat
-- numlock status separately.
--
-- myNumlockMask   = mod2Mask -- deprecated in xmonad-0.9.1
------------------------------------------------------------
 
 
-- The default number of workspaces (virtual screens) and their names.
-- By default we use numeric strings, but any string may be used as a
-- workspace name. The number of workspaces is determined by the length
-- of this list.
--
-- A tagging example:
--
-- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
--
myWorkspaces    = ["1","2","3","4","5","6","7","8","9"]
 
-- Border colors for unfocused and focused windows, respectively.
--
myNormalBorderColor  = "#dddddd"
myFocusedBorderColor = "#ff0000"
 
------------------------------------------------------------------------
-- Key bindings. Add, modify or remove key bindings here.
--
myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
 
    -- launch a terminal
    [ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
 
    -- launch dmenu
    , ((modm,               xK_p     ), spawn "exe=`dmenu_path | dmenu` && eval \"exec $exe\"")
 
    -- launch gmrun
    , ((modm .|. shiftMask, xK_p     ), spawn "gmrun")

    --take a screenshot of entire display
    , ((modm ,              xK_Print ), spawn "scrot screen_%Y-%m-%d-%H-%M-%S.png -d 1")

    --take a screenshot of focused window
    , ((modm .|. controlMask, xK_Print ), spawn "scrot window_%Y-%m-%d-%H-%M-%S.png -d 1 -u")

    -- close focused window
    , ((modm .|. shiftMask, xK_c     ), kill)
 
     -- Rotate through the available layout algorithms
    , ((modm,               xK_space ), sendMessage NextLayout)
 
    --  Reset the layouts on the current workspace to default
    , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
 
    -- Resize viewed windows to the correct size
    , ((modm,               xK_n     ), refresh)
 
    -- Move focus to the next window
    , ((modm,               xK_Tab   ), windows W.focusDown)
 
    -- Move focus to the next window
    , ((modm,               xK_j     ), windows W.focusDown)
 
    -- Move focus to the previous window
    , ((modm,               xK_k     ), windows W.focusUp  )
 
    -- Move focus to the master window
    , ((modm,               xK_m     ), windows W.focusMaster  )
 
    -- Swap the focused window and the master window
    , ((modm,               xK_Return), windows W.swapMaster)
 
    -- Swap the focused window with the next window
    , ((modm .|. shiftMask, xK_j     ), windows W.swapDown  )
 
    -- Swap the focused window with the previous window
    , ((modm .|. shiftMask, xK_k     ), windows W.swapUp    )
 
    -- Shrink the master area
    , ((modm,               xK_h     ), sendMessage Shrink)
 
    -- Expand the master area
    , ((modm,               xK_l     ), sendMessage Expand)
 
    -- Push window back into tiling
    , ((modm,               xK_t     ), withFocused $ windows . W.sink)
 
    -- Increment the number of windows in the master area
    , ((modm              , xK_comma ), sendMessage (IncMasterN 1))
 
    -- Deincrement the number of windows in the master area
    , ((modm              , xK_period), sendMessage (IncMasterN (-1)))
 
    -- Toggle the status bar gap
    -- Use this binding with avoidStruts from Hooks.ManageDocks.
    -- See also the statusBar function from Hooks.DynamicLog.
    --
    -- , ((modm              , xK_b     ), sendMessage ToggleStruts)
 
    -- Quit xmonad
    , ((modm .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))
 
    -- Restart xmonad
    , ((modm              , xK_q     ), spawn "xmonad --recompile; xmonad --restart")
    ]
    ++
 
    --
    -- mod-[1..9], Switch to workspace N
    --
    -- mod-[1..9], Switch to workspace N
    -- mod-shift-[1..9], Move client to workspace N
    --
    [((m .|. modm, k), windows $ f i)
        | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
    ++
 
    --
    -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
    -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
    --
    [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
        | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
        , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
 
 
------------------------------------------------------------------------
-- Mouse bindings: default actions bound to mouse events
--
myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
 
    -- mod-button1, Set the window to floating mode and move by dragging
    [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
                                       >> windows W.shiftMaster))
 
    -- mod-button2, Raise the window to the top of the stack
    , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
 
    -- mod-button3, Set the window to floating mode and resize by dragging
    , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
                                       >> windows W.shiftMaster))
 
    -- you may also bind events to the mouse scroll wheel (button4 and button5)
    ]
 
------------------------------------------------------------------------
-- Layouts:
 
-- You can specify and transform your layouts by modifying these values.
-- If you change layout bindings be sure to use 'mod-shift-space' after
-- restarting (with 'mod-q') to reset your layout state to the new
-- defaults, as xmonad preserves your old layout settings by default.
--
-- * NOTE: XMonad.Hooks.EwmhDesktops users must remove the obsolete
-- ewmhDesktopsLayout modifier from layoutHook. It no longer exists.
-- Instead use the 'ewmh' function from that module to modify your
-- defaultConfig as a whole. (See also logHook, handleEventHook, and
-- startupHook ewmh notes.)
--
-- The available layouts.  Note that each layout is separated by |||,
-- which denotes layout choice.
--
myLayout = tiled ||| Mirror tiled ||| Full
  where
    -- default tiling algorithm partitions the screen into two panes
    tiled   = Tall nmaster delta ratio
 
    -- The default number of windows in the master pane
    nmaster = 1
 
    -- Default proportion of screen occupied by master pane
    ratio   = 1/2
 
    -- Percent of screen to increment by when resizing panes
    delta   = 3/100
 
------------------------------------------------------------------------
-- Window rules:
 
-- Execute arbitrary actions and WindowSet manipulations when managing
-- a new window. You can use this to, for example, always float a
-- particular program, or have a client always appear on a particular
-- workspace.
--
-- To find the property name associated with a program, use
-- > xprop | grep WM_CLASS
-- and click on the client you're interested in.
--
-- To match on the WM_NAME, you can use 'title' in the same way that
-- 'className' and 'resource' are used below.
--
myManageHook = composeAll
    [ className =? "MPlayer"        --> doFloat
    , className =? "Gimp"           --> doFloat
    , resource  =? "desktop_window" --> doIgnore
    , resource  =? "kdesktop"       --> doIgnore ]
 
------------------------------------------------------------------------
-- Event handling
 
-- Defines a custom handler function for X Events. The function should
-- return (All True) if the default handler is to be run afterwards. To
-- combine event hooks use mappend or mconcat from Data.Monoid.
--
-- * NOTE: EwmhDesktops users should use the 'ewmh' function from
-- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
-- It will add EWMH event handling to your custom event hooks by
-- combining them with ewmhDesktopsEventHook.
--
myEventHook = mempty
 
------------------------------------------------------------------------
-- Status bars and logging
 
-- Perform an arbitrary action on each internal state change or X event.
-- See the 'XMonad.Hooks.DynamicLog' extension for examples.
--
--
-- * NOTE: EwmhDesktops users should use the 'ewmh' function from
-- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
-- It will add EWMH logHook actions to your custom log hook by
-- combining it with ewmhDesktopsLogHook.
--
myLogHook = return ()
 
------------------------------------------------------------------------
-- Startup hook
 
-- Perform an arbitrary action each time xmonad starts or is restarted
-- with mod-q.  Used by, e.g., XMonad.Layout.PerWorkspace to initialize
-- per-workspace layout choices.
--
-- By default, do nothing.
--
-- * NOTE: EwmhDesktops users should use the 'ewmh' function from
-- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
-- It will add initialization of EWMH support to your custom startup
-- hook by combining it with ewmhDesktopsStartup.
--
myStartupHook = return ()
 
------------------------------------------------------------------------
-- Now run xmonad with all the defaults we set up.
 
-- Run xmonad with the settings you specify. No need to modify this.
--
main = xmonad defaults
 
-- A structure containing your configuration settings, overriding
-- fields in the default config. Any you don't override, will
-- use the defaults defined in xmonad/XMonad/Config.hs
--
-- No need to modify this.
--
defaults = defaultConfig {
      -- simple stuff
        terminal           = myTerminal,
        focusFollowsMouse  = myFocusFollowsMouse,
        borderWidth        = myBorderWidth,
        modMask            = myModMask,
        -- numlockMask deprecated in 0.9.1
        -- numlockMask        = myNumlockMask,
        workspaces         = myWorkspaces,
        normalBorderColor  = myNormalBorderColor,
        focusedBorderColor = myFocusedBorderColor,
 
      -- key bindings
        keys               = myKeys,
        mouseBindings      = myMouseBindings,
 
      -- hooks, layouts
        layoutHook         = myLayout,
        manageHook         = myManageHook,
        handleEventHook    = myEventHook,
        logHook            = myLogHook,
        startupHook        = myStartupHook
    }

Sunday, September 2, 2012

PTP camera with Xmonad

My camera supports the Picture Transfer Protocol (PTP) rather than the USB Mass Storage device Class (UMSC) protocol.  My bare bones debian install could not mount it.  This was easily resolved by installing gphotofs and fuse.
ROOTPROMPT$> apt-get install gphotofs 
Which will also install the fuse dependencies.  Then add the appropriate users to the fuse group.
ROOTPROMPT$> adduser USERNAME fuse
Reboot.  Plug the camera into the computer.  I haven't yet bothered to mount the camera to the /media directory.  I simply made a /home/USER/camera directory and mount to there when I need to move pictures.
$> mkdir /home/USER/camera
$> gphotofs /home/USER/camera
The camera is then mounted to the /home/USER/camera directory as a normal filesystem, and you can traverse it with common commands such as ls, cd, etc..
   The following command unmounts the camera.  This will not work if you have any terminals open to the camera directory.
$> fusermount -u camera