dotfiles

Obligatory dotfiles repo
git clone git://git.danielmoch.com/dotfiles.git
Log | Files | Refs

commit b92fed3865413dedc7d4819d50f6f3b0b3d55cb5
parent cc31f50971eb5ff5eeba56eb728d2934942444f5
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sun, 21 Jan 2018 11:01:10 -0500

WM-independent re-write

Lots of changes to support working in multiple window managers
environments. The biggest is the introduction of the 'my' script, which
supports multiple utility functions which I'll then map to keys. The
keys are mapped using Xbindkeys to maintain consistency and avoid the
work of having to map them separately in each WM.

Diffstat:
A.config/autostart/xbindkeys.desktop | 6++++++
M.config/awesome/rc.lua | 36++++++++++--------------------------
M.config/awesome/theme.lua | 37+++++--------------------------------
D.config/awesome/xrandr.lua | 135-------------------------------------------------------------------------------
A.local/bin/my | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A.xbindkeysrc | 36++++++++++++++++++++++++++++++++++++
M.xsession | 61+++++++++++++++++++++++++++++++++++++------------------------
7 files changed, 228 insertions(+), 217 deletions(-)

diff --git a/.config/autostart/xbindkeys.desktop b/.config/autostart/xbindkeys.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +TryExec=xbindkeys +Exec=xbindkeys -n +Name=xbindkeys +Comment=a grabbing keys program for X +Type=Application diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua @@ -1,3 +1,7 @@ +-- +-- ~/.config/awesome/rc.lua +-- + -- Standard awesome library local gears = require("gears") local awful = require("awful") @@ -13,8 +17,6 @@ local hotkeys_popup = require("awful.hotkeys_popup").widget -- Enable hotkeys help widget for VIM and other apps -- when client with a matching name is opened: require("awful.hotkeys_popup.keys") --- Xrandr library -local xrandr = require("xrandr") -- {{{ Error handling -- Check if awesome encountered an error during startup and fell back to @@ -46,7 +48,7 @@ end beautiful.init(gears.filesystem.get_dir("config") .. "theme.lua") -- This is used later as the default terminal and editor to run. -terminal = "xterm" +terminal = "my term" editor = os.getenv("EDITOR") or "nano" editor_cmd = terminal .. " -e " .. editor @@ -91,14 +93,6 @@ local function client_menu_toggle_fn() end end end - -local function hybrid_sleep() - awful.spawn('systemctl hybrid-sleep') -end - -local function lock_screen() - awful.spawn('xlock-off') -end -- }}} -- {{{ Menu @@ -123,10 +117,10 @@ mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, menubar.utils.terminal = terminal -- Set the terminal for applications that require it -- }}} +-- {{{ Wibar -- Keyboard map indicator and switcher mykeyboardlayout = awful.widget.keyboardlayout() --- {{{ Wibar -- Create a textclock widget mytextclock = wibox.widget.textclock() @@ -246,9 +240,9 @@ end) -- {{{ Mouse bindings root.buttons(gears.table.join( - awful.button({ }, 3, function () mymainmenu:toggle() end), - awful.button({ }, 4, awful.tag.viewnext), - awful.button({ }, 5, awful.tag.viewprev) + awful.button({ }, 3, function () mymainmenu:toggle() end) + -- awful.button({ }, 4, awful.tag.viewnext), + -- awful.button({ }, 5, awful.tag.viewprev) )) -- }}} @@ -256,10 +250,6 @@ root.buttons(gears.table.join( globalkeys = gears.table.join( awful.key({ modkey, }, "s", hotkeys_popup.show_help, {description="show help", group="awesome"}), - awful.key({ modkey, "Mod1" }, "s", hybrid_sleep, - {description="machine standby", group="awesome"}), - awful.key({ modkey, }, "l", lock_screen, - {description="lock screen", group="awesome"}), awful.key({ modkey, }, "Left", awful.tag.viewprev, {description = "view previous", group = "tag"}), awful.key({ modkey, }, "Right", awful.tag.viewnext, @@ -291,8 +281,6 @@ globalkeys = gears.table.join( {description = "focus the next screen", group = "screen"}), awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end, {description = "focus the previous screen", group = "screen"}), - awful.key({ modkey, "Control" }, "Return", function () xrandr.xrandr() end, - {description = "Cycle monitor layouts", group = "screen"}), awful.key({ modkey, }, "u", awful.client.urgent.jumpto, {description = "jump to urgent client", group = "client"}), awful.key({ modkey, }, "Tab", @@ -305,12 +293,8 @@ globalkeys = gears.table.join( {description = "go back", group = "client"}), -- Standard program - awful.key({ modkey, }, "Return", function () awful.spawn(terminal) end, - {description = "open a terminal", group = "launcher"}), - awful.key({ modkey, "Control" }, "r", awesome.restart, + awful.key({ modkey, "Control" }, "r", awesome.restart, {description = "reload awesome", group = "awesome"}), - awful.key({ modkey, "Shift" }, "q", awesome.quit, - {description = "quit awesome", group = "awesome"}), awful.key({ modkey, "Mod1" }, "l", function () awful.tag.incmwfact( 0.05) end, {description = "increase master width factor", group = "layout"}), diff --git a/.config/awesome/theme.lua b/.config/awesome/theme.lua @@ -1,13 +1,12 @@ ---------------------------- --- Default awesome theme -- ---------------------------- - +-- +-- ~/.config/awesome/theme.lua +-- local theme_assets = require("beautiful.theme_assets") local xresources = require("beautiful.xresources") local dpi = xresources.apply_dpi local gfs = require("gears.filesystem") -local gwp = require("gears.wallpaper") +local awful = require("awful") local themes_path = gfs.get_themes_dir() local theme = {} @@ -35,19 +34,6 @@ theme.hotkeys_bg = "#262626" theme.hotkeys_fg = "#BCBCBC" theme.hotkeys_modifiers_fg = "#5F8787" --- There are other variable sets --- overriding the default one when --- defined, the sets are: --- taglist_[bg|fg]_[focus|urgent|occupied|empty|volatile] --- tasklist_[bg|fg]_[focus|urgent] --- titlebar_[bg|fg]_[normal|focus] --- tooltip_[font|opacity|fg_color|bg_color|border_width|border_color] --- mouse_finder_[color|timeout|animate_timeout|radius|factor] --- prompt_[fg|bg|fg_cursor|bg_cursor|font] --- hotkeys_[bg|fg|border_width|border_color|shape|opacity|modifiers_fg|label_bg|label_fg|group_margin|font|description_font] --- Example: ---theme.taglist_bg_focus = "#ff0000" - -- Generate taglist squares: local taglist_square_size = dpi(4) theme.taglist_squares_sel = theme_assets.taglist_squares_sel( @@ -57,24 +43,11 @@ theme.taglist_squares_unsel = theme_assets.taglist_squares_unsel( taglist_square_size, theme.fg_normal ) --- Variables set for theming notifications: --- notification_font --- notification_[bg|fg] --- notification_[width|height|margin] --- notification_[border_color|border_width|shape|opacity] - -- Variables set for theming the menu: --- menu_[bg|fg]_[normal|focus] --- menu_[border_color|border_width] theme.menu_submenu_icon = themes_path.."default/submenu.png" theme.menu_height = dpi(15) theme.menu_width = dpi(100) --- You can add as many variables as --- you wish and access them by using --- beautiful.variable in your rc.lua ---theme.bg_widget = "#cc0000" - -- Define the image to load theme.titlebar_close_button_normal = themes_path.."default/titlebar/close_normal.png" theme.titlebar_close_button_focus = themes_path.."default/titlebar/close_focus.png" @@ -102,7 +75,7 @@ theme.titlebar_maximized_button_focus_inactive = themes_path.."default/titlebar theme.titlebar_maximized_button_normal_active = themes_path.."default/titlebar/maximized_normal_active.png" theme.titlebar_maximized_button_focus_active = themes_path.."default/titlebar/maximized_focus_active.png" -theme.wallpaper = gwp.maximized(os.getenv("HOME").."/Photos/desktop.jpg") +theme.wallpaper = function () awful.spawn('my wallpaper') end -- You can use your own layout icons like this: theme.layout_fairh = themes_path.."default/layouts/fairhw.png" diff --git a/.config/awesome/xrandr.lua b/.config/awesome/xrandr.lua @@ -1,135 +0,0 @@ ---- Separating Multiple Monitor functions as a separeted module (taken from awesome wiki) - -local awful = require("awful") -local naughty = require("naughty") - --- A path to a fancy icon -local icon_path = "" - --- Get active outputs -local function outputs() - local outputs = {} - local xrandr = io.popen("xrandr -q --current") - - if xrandr then - for line in xrandr:lines() do - local output = line:match("^([%w-]+) connected ") - if output then - outputs[#outputs + 1] = output - end - end - xrandr:close() - end - - return outputs -end - -local function arrange(out) - -- We need to enumerate all permutations of horizontal outputs. - - local choices = {} - local previous = { {} } - for i = 1, #out do - -- Find all permutation of length `i`: we take the permutation - -- of length `i-1` and for each of them, we create new - -- permutations by adding each output at the end of it if it is - -- not already present. - local new = {} - for _, p in pairs(previous) do - for _, o in pairs(out) do - if not awful.util.table.hasitem(p, o) then - new[#new + 1] = awful.util.table.join(p, {o}) - end - end - end - choices = awful.util.table.join(choices, new) - previous = new - end - - return choices -end - --- Build available choices -local function menu() - local menu = {} - local out = outputs() - local choices = arrange(out) - - for _, choice in pairs(choices) do - local cmd = "xrandr" - -- Enabled outputs - for i, o in pairs(choice) do - cmd = cmd .. " --output " .. o .. " --auto" - if i > 1 then - cmd = cmd .. " --right-of " .. choice[i-1] - end - end - -- Disabled outputs - for _, o in pairs(out) do - if not awful.util.table.hasitem(choice, o) then - cmd = cmd .. " --output " .. o .. " --off" - end - end - - local label = "" - if #choice == 1 then - label = 'Only <span weight="bold">' .. choice[1] .. '</span>' - else - for i, o in pairs(choice) do - if i > 1 then label = label .. " + " end - label = label .. '<span weight="bold">' .. o .. '</span>' - end - end - - menu[#menu + 1] = { label, cmd } - end - - return menu -end - --- Display xrandr notifications from choices -local state = { cid = nil } - -local function naughty_destroy_callback(reason) - if reason == naughty.notificationClosedReason.expired or - reason == naughty.notificationClosedReason.dismissedByUser then - local action = state.index and state.menu[state.index - 1][2] - if action then - awful.util.spawn(action, false) - state.index = nil - end - end -end - -local function xrandr() - -- Build the list of choices - if not state.index then - state.menu = menu() - state.index = 1 - end - - -- Select one and display the appropriate notification - local label, action - local next = state.menu[state.index] - state.index = state.index + 1 - - if not next then - label = "Keep the current configuration" - state.index = nil - else - label, action = unpack(next) - end - state.cid = naughty.notify({ text = label, - icon = icon_path, - timeout = 4, - screen = mouse.screen, - replaces_id = state.cid, - destroy = naughty_destroy_callback}).id -end - -return { - outputs = outputs, - arrange = arrange, - menu = menu, - xrandr = xrandr -} diff --git a/.local/bin/my b/.local/bin/my @@ -0,0 +1,134 @@ +#!/bin/sh +# +# ~/.local/bin/my +# + +# Command and handlers for them are added as-needed. Some commands only +# have one handler, but exist to avoid re-writes across my dotfiles +# later on. + +[ $# -eq 0 ] && exit 1 + +log="$HOME/.local/var/log/my" +command=$1 +shift + +__mylog() +{ + echo "$1 (`date +'%m/%d/%Y %H:%M:%S'`): $2" >> $log +} + +case $command in + term) + : ${XDG_CURRENT_DESKTOP:=${XDG_SESSION_DESKTOP:-X-Generic}} + case $XDG_CURRENT_DESKTOP in + XFCE) + if type xfce4-terminal > /dev/null 2>&1 + then + term=xfce4-terminal + fi + ;; + X-Cinnamon) + if type gnome-terminal > /dev/null 2>&1 + then + term=gnome-terminal + fi + ;; + esac + # If we get here, then handle generically + if type xterm > /dev/null 2>&1 + then + term=xterm + elif type x-terminal-emulator > /dev/null 2>&1 + then + term=x-terminal-emulator + fi + + if [ -n "$term" ] + then + exec $term $@ + else + __mylog "my term" "No terminal emulator found" + fi + ;; + lock) + sleep 1 + + for locker in light-locker cinnamon-screensaver gnome-screensaver xscreensaver + do + if type $locker-command && ps -U $LOGNAME | grep $locker > /dev/null 2>&1 + then + locker_running=1 + break + fi + done + + if [ -z "$locker_running" ] + then + __mylog "my lock" "No screen locker running" + exit 1 + else + xset dpms force off + fi + ;; + wallpaper) + xsetroot -solid "#444444" + [ -x "$HOME/.fehbg" ] && "$HOME/.fehbg" >> $log 2>&1 + ;; + standby) + if type systemctl > /dev/null 2>&1 + then + systemctl hybrid-sleep + else + __mylog "my standby" "No handler found" + fi + ;; + perms) + exec my-perms + ;; + init) + exec my-init + ;; + open) + exec my-open + ;; + sound) + if type pactl > /dev/null 2>&1 + then + exec pactl $@ + else + __mylog "my sound" "No handler found" + fi + ;; + kbopts) + setxkbmap -option -option ctrl:nocaps -option terminate:ctrl_alt_bksp + ;; + screen) + xrandr_options=`xrandr -q | grep ^[[:alpha:]] | awk 'BEGIN{getline}{print $1}'` + numoptions=`echo $xrandr_options | wc -w` + if [ $numoptions -eq 1 ] + then + xrandr --output $xrandr_options --auto + else + # Prefer external monitors + # If more than one display is connected, then enable the + # first non-primary display, and turn off all the others. + primary=`xrandr -q | grep primary | awk '{print $1}'` + + for option in $xrandr_options + do + [ $option = $primary ] && primary_found=1 && continue + [ -n "$primary_found" ] && selection=$option && break + done + + __mylog "my screen" "Executing xrandr --output $selection --auto" + xrandr --output $selection --auto + + for option in $xrandr_options + do + [ $option != $selection ] && __mylog "my screen" "Executing xrandr --output $option --off" && xrandr --output $option --off + done + fi + exec my wallpaper + ;; +esac diff --git a/.xbindkeysrc b/.xbindkeysrc @@ -0,0 +1,36 @@ +# +# ~/.xbindkeysrc +# +# vim: sts=2 sw=2 +"xbindkeys_show" + control+shift + q + +"my term" + Mod4 + Return + +"my wallpaper" + Mod1 + Mod4 + w + +"my kbopts" + Mod1 + Mod4 + k + +"my standby" + Mod1 + Mod4 + s + +"my lock" + Mod4 + l + +"eject" + XF86Eject + +"my sound set-sink-volume 0 +10%" + XF86AudioRaiseVolume + +"my sound set-sink-volume 0 -10%" + XF86AudioLowerVolume + +"my sound set-sink-mute 0 toggle" + XF86AudioMute + +"my screen" + Mod1 + Mod4 + Return diff --git a/.xsession b/.xsession @@ -2,17 +2,44 @@ # # ~/.xsession # - [ -n "$DISPLAY" ] && echo "$DISPLAY" > "$HOME/.xdisplay" [ -f "$HOME/.xdisplay" ] && chmod 600 "$HOME/.xdisplay" +__autostart() +{ + : ${XDG_CURRENT_DESKTOP:=${XDG_SESSION_DESKTOP:-$1}} + if type dex > /dev/null 2>&1 + then + AUTOSTART_CMD="dex -ae $XDG_CURRENT_DESKTOP" + elif type fbautostart > /dev/null 2>&1 + then + AUTOSTART_CMD="fbautostart" + fi + + until ps -u $LOGNAME -U $LOGNAME | grep $1 > /dev/null 2>&1 + do + sleep 1 + done + + case $XDG_CURRENT_DESKTOP in + awesome|i3|twm) + if [ -n "$AUTOSTART_CMD" ] + then + $AUTOSTART_CMD + else + xbindkeys + fi + ;; + esac +} + xset dpms 0 0 300 [ -r "$HOME/.Xmouse" ] && xmodmap .Xmouse SHLVL=0; export SHLVL -xsetroot -solid "#444444" -[ -x "$HOME/.fehbg" ] && "$HOME/.fehbg" +my kbopts +my screen if [ -d /usr/share/fonts/noto/ ] then @@ -22,8 +49,9 @@ fi if [ $# -eq 0 ] then - for wm in awesome i3 startxfce4 cinnamon-session twm + for wm in awesome startxfce4 i3 twm cinnamon-session do + >&2 echo "No params provided. Setting window manager." if type $wm > /dev/null 2>&1 then set -- $wm @@ -33,28 +61,13 @@ then done fi -if type dex > /dev/null 2>&1 -then - AUTOSTART_CMD='dex -ae $XDG_CURRENT_DESKTOP' -elif type fbautostart > /dev/null 2>&1 +if [ "$1" = "twm" ] then - AUTOSTART_CMD="fbautostart" + set -- xterm + twm & fi -if [ -n "$AUTOSTART_CMD" ] -then - : ${XDG_CURRENT_DESKTOP:=${XDG_SESSION_DESKTOP:-$1}} - case $XDG_CURRENT_DESKTOP in - awesome|i3|twm) - $AUTOSTART_CMD - ;; - esac - - if [ "$XDG_CURRENT_DESKTOP" = "twm" ] - then - set -- xterm - twm & - fi -fi +__autostart $@ & +unset __autostart [ -n $EXEC ] && exec $@