X.org

These are the customizations I've done for my linux system to handle non-gnome configs. This means keyboard mappings that are done as part of the X setup process, rather than using the menu driven aspect in Ubuntu, which doesn't translate across window managers.

Some dependencies for programs below.

sudo apt-get install xautolock xmonad xmobar i3lock feh trayer dmenu

Keyboard

setxkbmap is used to do keyboard remapping. The snippet below removes the capslock functionality and makes it a separate control instead. On Ubuntu, this is provided by the package x11-xkb-utils.

setxkbmap -layout us -option ctrl:nocaps 2>/dev/null
# gnome way to do this:  gsettings set org.gnome.desktop.input-sources xkb-options "['caps:ctrl_modifier']"

xmodmap lets me change individual keys. This is useful when either the settings aren't available in my system setting dialogs or I have fine-grained needs.

keycode 100 = Super_R
keycode 102 = Super_L

XMonad

XMonad is a tiling window manager. It's configuration is in haskell (which I'm not too familiar with). It seems really good otherwise.

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO
import System.Posix.Env(putEnv)
import Graphics.X11.ExtraTypes.XF86

Some tools, like Gimp or video viewers should default to "float". To figure out this className variable, you should run xprop WM_CLASS and click on the window. It'll output something like WM_CLASS(STRING) = "emacs", "Emacs24". For this, "Emacs24" would be the className. More info can be found in this section of the xmonad FAQ.

myManageHook = composeAll
    [ className =? "Gimp"                --> doFloat
    , className =? "Vncviewer"           --> doFloat
    , className =? "Screenruler"         --> doFloat
    , className =? "Gtk-recordmydesktop" --> doFloat
    ]

-- I think I want: Tall, Mirror Tall, Full, and something that does resizable stacks.


main = do
    xmproc <- spawnPipe "xmobar /home/jabrahms/.xmobarrc"
    putEnv "BROWSER=google-chrome"
    xmonad $ defaultConfig
        { manageHook = manageDocks <+> myManageHook -- make sure to include myManageHook definition from above
                        <+> manageHook defaultConfig
        , layoutHook = avoidStruts $ layoutHook defaultConfig
        , logHook = dynamicLogWithPP xmobarPP
                        { ppOutput = hPutStrLn xmproc
                        , ppTitle = xmobarColor "green" "" . shorten 50
                        }
        , modMask = mod4Mask     -- Rebind Mod to the Windows key
        } `additionalKeys`

These are a bunch of keybindings I've setup. In here, I'm using i3lock, because xscreensaver had a propensity for crashing.

-- Key Bindings
[ ((mod4Mask .|. controlMask, xK_l), spawn "i3lock -c 669966 -d")
, ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
, ((0, xF86XK_AudioLowerVolume   ), spawn "amixer -D pulse set Master 10%-")
, ((0, xF86XK_AudioRaiseVolume   ), spawn "amixer -D pulse set Master 10%+")
, ((0, xF86XK_AudioMute          ), spawn "amixer -D pulse set Master toggle")
, ((controlMask, xK_F12          ), spawn "~/xrandr_config")
, ((0, xK_Print), spawn "scrot")
]

xmobar is a status bar for xmonad. In it, I'd like my desktops in use, a title for the current app, some system utilization outputs, current weather, wifi/internet setup, and the current date/time. This started from the help provided on the xmonad wiki.

Config { font = "-*-Fixed-Bold-R-Normal-*-13-*-*-*-*-*-*-*"
       , bgColor = "black"
       , fgColor = "grey"
       , position = TopW L 90
       , commands = [ Run Weather "KBOS" ["-t","<tempF>F","-L","64","-H","77","--normal","green","--high","red","--low","lightblue"] 36000
                    , Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 50
                    , Run Memory ["-t","Mem: <usedratio>%"] 50
                    , Run Date "%a %b %_d %l:%M" "date" 30
                    , Run Battery [ "-t", "<acstatus> (<left>%)"
                                  , "--"
                                  , "-O", "charging"
                                  , "-i", "charged"
                                  , "-o", "unplugged" ] 50
                    , Run StdinReader
                    ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%StdinReader% }{ %cpu% | %memory% | %battery%      <fc=#ee9a00>%date%</fc> | BOS: %KBOS%"
}

.xsession

.xsession is a file that's run on x startup. We'll use it to set up a bunch of useful utilities.

We start by setting up a screensaver daemon.

exec xautolock -time 15 -locker "i3lock -c 669966 -d" &

Next, we use feh to choose a background from a directory of wallpapers I've collected. We scale the background (preserving aspect ratio) so it fills the monitor, cropping if necessary.

# set background to random wallpaper. Scales (preserving aspect ratio) and crops.
feh --bg-fill `ls ~/Dropbox/wallpapers/*.(png|jpg) | shuf`

Then, we setup the system tray.

# system tray
trayer --edge top --align right --SetDockType true --SetPartialStrut true \
       --expand true --width 10 --transparent true --tint 0x000000 --alpha 0 --height 17 &

if [ -x `which nm-applet` ] ; then
    nm-applet --sm-disable &
fi

if [ -x `which dropbox` ] ; then
    dropbox start
fi

if [ -x `which dcssd` ] ; then
    dcssd 2>/tmp/dotcss.err 1>/tmp/dotcss.out &
fi

if [ -x `which djsd` ] ; then
    djsd 2>/tmp/dotjs.err 1>/tmp/dotjs.out &
fi

Default browsers

Setting a default browser in linux when you don't have a "proper" desktop environment like Gnome is a pain. This is what you need to do to make clicking links open in the expected browser.

Thanks to wink in #xmonad for linking me to this blog post which had the answer.

[Default Applications]
x-scheme-handler/http=chrome.desktop
x-scheme-handler/https=chrome.desktop
x-scheme-handler/ftp=chrome.desktop

[Added Associations]
x-scheme-handler/http=google-chrome.desktop;
x-scheme-handler/https=google-chrome.desktop;

Trackpad Disabling

Touching the trackpad mistakenly messes up my typing. This small script will turn on or off the trackpad.

[[ -z "${TRACE:-}" ]] || set -x
FLAG=${1:-}
main () {
    local enabled=0;
    # disable == yes?
    if [[ $FLAG == 'yes' ]]; then
        enabled=0
    elif [[ $FLAG == 'no' ]]; then
        enabled=1
    else
        echo "You must specify 'yes' or 'no'"
        exit 1
    fi
    local DEVICE_ID="`xinput list | grep -i "touchpad" | tr "id=" " " | cut -f 2 | tr -d '[[:space:]]'`"
    xinput set-prop $DEVICE_ID "Device Enabled" $enabled
    exit 0
}
main
© 2012 - 2023 · Home — Theme Simpleness