Skip to content

Commit

Permalink
Redo X key bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
tpope committed Apr 24, 2016
1 parent 14b737f commit a7be021
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 79 deletions.
124 changes: 71 additions & 53 deletions .config/awesome/rc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,21 @@ end
-- }}}

-- {{{ Tags
-- Define a tag table which hold all screen tags.
tags = {}

local tags = {}
local mwfact = 1 - (802 + 4 * beautiful.border_width)/1920
for s = 1, screen.count() do
-- Each screen has its own tag table.
tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
awful.tag.setmwfact(mwfact, tags[s][1])
end

local function toggle_layout (l)
if awful.layout.get() == l then
awful.layout.set(awful.layout.suit.tile)
else
awful.layout.set(l)
end
end
awful.tag.setmwfact(0.5806)

-- }}}

Expand Down Expand Up @@ -874,15 +882,21 @@ awful.button({ }, 5, awful.tag.viewprev)

-- {{{ Key bindings

function executor (cmd)
return function () os.execute(cmd) end
function lua_eval ()
awful.prompt.run({ prompt = "Run Lua code: " },
mypromptbox[mouse.screen].widget,
function(code)
local result, err = loadstring("return " .. code)
naughty.notify({
title = code,
text = err or inspect(result())
})
end
, nil,
awful.util.getdir("cache") .. "/history_eval")
end

globalkeys = awful.util.table.join(
awful.key({modkey, "Mod1" }, "a", executor('import -window root $HOME/Pictures/root-`date +%Y-%m-%d_%H-%M-%S`.png')),
awful.key({modkey, "Shift" }, "a", executor('import $HOME/Pictures/selection-`date +%Y-%m-%d_%H-%M-%S`.png')),
-- awful.key({ modkey, }, "Left", awful.tag.viewprev ),
-- awful.key({ modkey, }, "Right", awful.tag.viewnext ),
local globalkeys = awful.util.table.join(
awful.key({ modkey, }, "Escape", awful.tag.history.restore),

awful.key({ modkey, }, "j",
Expand All @@ -895,15 +909,21 @@ globalkeys = awful.util.table.join(
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true, coords={x=0, y=0}}) end),
awful.key({ modkey, }, "a", function () mymainmenu:show({keygrabber=true, coords={x=0, y=0}}) end),

awful.key({ modkey, }, "w", function ()
local y = screen[mouse.screen].workarea.y
mymainmenu:show({keygrabber=true, coords={x=0, y=y > 0 and 0 or 9999}})
end),
awful.key({ modkey, "Shift" }, "f", function () toggle_layout(awful.layout.suit.floating) end),
awful.key({ modkey, "Mod1" }, "f", function () toggle_layout(awful.layout.suit.max) end),
awful.key({ modkey, }, "m", function () toggle_layout(awful.layout.suit.max) end),
awful.key({ modkey, "Control" }, "f", function () toggle_layout(awful.layout.suit.max.fullscreen) end),
-- Layout manipulation
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
awful.key({ modkey, }, "v", awful.client.urgent.jumpto),
awful.key({ modkey, }, "Tab",
function ()
awful.client.focus.history.previous()
Expand All @@ -922,40 +942,33 @@ globalkeys = awful.util.table.join(
awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
awful.key({ modkey, "Mod1" }, "h", function () awful.tag.setmwfact(0.5) end),
awful.key({ modkey, "Mod1" }, "l", function () awful.tag.setmwfact(mwfact) end),
awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
awful.key({ modkey, "Shift" }, "space", function () toggle_layout(awful.layout.suit.tile) end),

awful.key({ modkey, "Control" }, "n", awful.client.restore),

-- Prompt
awful.key({ modkey }, "r", function () if menubar then menubar.show() else mypromptbox[mouse.screen]:run() end end),
awful.key({ modkey }, "p", function () if menubar then menubar.show() else mypromptbox[mouse.screen]:run() end end),
awful.key({ modkey, "Mod1" }, "r", function () awful.prompt.run(
{ prompt = "Run in terminal: " },
mypromptbox[mouse.screen].widget,
function (cmd) shell_host('localhost ' .. cmd) end,
awful.completion.shell
) end),
awful.key({ modkey, "Mod1" }, "e", function () prompt_file(edit) end),
awful.key({ modkey, }, "e", function () prompt_file(edit) end),
awful.key({ modkey }, "semicolon", function () edit() end),
-- awful.key({ modkey }, "e", function () edit() end),
awful.key({ modkey }, "c", chat),
awful.key({ modkey }, "z", function () raise_host('localhost') end),
awful.key({ modkey, "Mod1" }, "z", function () mux_host('localhost') end),
awful.key({ modkey, "Control" }, "z", function () shell_host('localhost') end),
awful.key({ modkey }, "period", function () edit() end),
awful.key({ modkey, "Control" }, "d", chat),
awful.key({ modkey, "Shift" }, "x", function () local c = browser() if c then c:swap(awful.client.getmaster()) end end),
awful.key({ modkey, "Mod1" }, "s", function () pick_host(mux_host) end),
awful.key({ modkey, "Control" }, "s", function () pick_host(shell_host) end),
awful.key({ modkey }, "s", function () pick_host(raise_host) end),
awful.key({ modkey }, "x", function () local c = browser() if c then c:swap(awful.client.getmaster()) end end),

awful.key({ modkey }, "p",
function ()
awful.prompt.run({ prompt = "Run Lua code: " },
mypromptbox[mouse.screen].widget,
awful.util.eval, nil,
awful.util.getdir("cache") .. "/history_eval")
end)
)
awful.key({ modkey, "Shift" }, "r", lua_eval),
awful.key({ modkey, "Shift" }, "e", lua_eval)
)

clientkeys = awful.util.table.join(
awful.key({ modkey }, "Next", function () awful.client.moveresize( 20, 20, -40, -40) end),
Expand All @@ -964,37 +977,36 @@ clientkeys = awful.util.table.join(
awful.key({ modkey }, "Up", function () awful.client.moveresize( 0, -20, 0, 0) end),
awful.key({ modkey }, "Left", function () awful.client.moveresize(-20, 0, 0, 0) end),
awful.key({ modkey }, "Right", function () awful.client.moveresize( 20, 0, 0, 0) end),
awful.key({modkey, "Control" }, "a", function (c)
os.execute('import -window ' .. c.window .. ' $HOME/Pictures/' .. (c.title or "unnamed") .. ' -`date +%Y-%m-%d_%H-%M-%S`.png') end),
awful.key({ modkey, }, "c", function (c) client_menu_launcher(c, c:geometry()) end),
awful.key({ "Control", "Mod1" }, "Tab", function (c) client_menu_launcher(c) end),
awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
awful.key({ "Control", "Mod1" }, "Tab", function (c) client_menu_launcher(c) end),
awful.key({ modkey, }, "c", function (c) client_menu_launcher(c, c:geometry()) end),
awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
awful.key({ modkey, "Control" }, "space", function (c)
c.maximized_horizontal = false
c.maximized_vertical = false
awful.client.floating.toggle(c)
end),
awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
awful.key({ modkey, "Shift" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
awful.key({ modkey, }, "Return", function (c) c:swap(awful.client.getmaster()) end),
awful.key({ modkey, }, "o", awful.client.movetoscreen ),
awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
awful.key({ modkey, }, "a", function (c) client.focus = awful.client.getmaster() end),
awful.key({ modkey, "Shift" }, "a", function (c) c:swap(awful.client.getmaster()) end),
awful.key({ modkey, }, "e", awful.client.movetoscreen ),
awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
awful.key({ modkey, }, "i", function (c) awful.util.spawn("sh -c '(xwininfo -id " .. c.window .. "; xprop -id " .. c.window .. ")|tail -n +2|xmessage -title " .. c.window .. " -file -'") end),
awful.key({ modkey, "Mod1" }, "i", function (c) awful.util.spawn("sh -c 'xwininfo -id " .. c.window .. "|gxmessage -title xwininfo -file -'") end),
awful.key({ modkey, }, "n",
function (c)
-- The client currently has the input focus, so it cannot be
-- minimized, since minimized clients can't have the focus.
c.minimized = true
end),
awful.key({ modkey, }, "m",
function (c)
c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical
end)
awful.key({ modkey, "Shift" }, "t", function (c) c.ontop = not c.ontop end),
awful.key({ modkey, }, "n", function (c)
c.minimized = true
end),
awful.key({ modkey, "Shift" }, "m", function (c)
c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical
end)
)

-- Compute the maximum number of digit we need, limited to 9
keynumber = 0
for s = 1, screen.count() do
keynumber = math.min(9, math.max(#tags[s], keynumber));
keynumber = math.min(9, math.max(#tags[s], keynumber));
end

-- Bind all key numbers to tags.
Expand Down Expand Up @@ -1030,9 +1042,15 @@ for i = 1, keynumber do
end))
end

clientbuttons = awful.util.table.join(
local clientbuttons = awful.util.table.join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 2, function (c)
mousegrabber.run(function(m)
client_menu_launcher(c)
return false
end, "fleur")
end),
awful.button({ modkey }, 3, awful.mouse.client.resize))

-- Set keys
Expand Down
120 changes: 95 additions & 25 deletions .xbindkeysrc.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
;; vim:set lispwords+=xbind,xbindmod,xbindmods:

;; /usr/include/X11/keysymdef.h
;; /usr/include/X11/XF86keysym.h
;; /usr/share/doc/xbindkeys/examples/xbindkeysrc.scm.gz

(putenv "TMUX")
(putenv "TMUX_PANE")
(putenv "STY")
(putenv "WINDOWID")

(define mod
(string->symbol (or (getenv "XBINDKEYS_MOD") "mod4")))

Expand All @@ -9,53 +20,112 @@
(define (xbindmod keys command)
(xbind (cons mod keys) command))

(define (xbindmodmod1 keys command)
(xbind (list* 'control 'shift mod keys) command)
(unless (eq? mod 'mod1)
(xbind (list* 'mod1 mod keys) command)))
(define (xbindmods keys command)
(unless (cdr keys)
(xbind (cons* 'control 'shift mod keys) command))
(if (eq? mod 'mod1)
(xbind (cons* 'mod4 mod keys) command)
(xbind (cons* 'mod1 mod keys) command)))

(define active-window
"`xprop -root _NET_ACTIVE_WINDOW|sed -e 's/.* //'`")

(define (toggle . commands)
(let ((class (string-join commands "|")))
(string-append
"xdotool search --classname '" class "'|grep -q `xdotool getactivewindow` && "
"wmctrl -c :ACTIVE: || "
"xdotool search --classname '" class "' windowactivate || "
"exec " (string-join commands " || "))))

(define xmessage
(or (getenv "XMESSAGE")
(if (access? "/usr/bin/gxmessage" X_OK)
"gxmessage -wrap"
"xmessage")))

(xbindmods '(a) "sleep 1; xdg-screensaver lock || xset dpms force standby")

(define (toggle command)
(xbindmod '(control c)
(string-append
"xdotool search --classname " command "|grep -q `xdotool getactivewindow` && "
"wmctrl -c :ACTIVE: || "
"xdotool search --classname " command " windowactivate || "
"exec " command))
"xprop -id " active-window " -format _NET_WM_ICON '32o' ' = ...\n' |"
xmessage " -default okay -title " active-window " -file -"))

(xbindmod '(x) "exec tpope browser")
(xbindmod '(control x) "exec xdg-open \"$HOME\"")

(xbindmod '(control z) "exec tpope terminal -e tpope host shell localhost")
(xbindmod '(mod1 z) "xdotool search --classname '^mux@localhost$' windowactivate || exec tpope terminal -e tpope host mux localhost")
(xbindmod '(z) "xdotool search --desktop `xdotool get_desktop` --classname '@localhost$' windowactivate || xdotool search --classname '@localhost$' windowactivate")

(xbindmod '(shift p) "dmenu_run")

(xbindmod '(control a)
"if xdotool getmouselocation 2>/dev/null | grep 'y:0 ' >/dev/null; then
import -window root \"$HOME/Pictures/Screenshots/`date +%Y-%m-%d_%H-%M-%S`_Screenshot.png\"
else
import \"$HOME/Pictures/Screenshots/`date +%Y-%m-%d_%H-%M-%S`_`xdotool getactivewindow getwindowname | tr '[ /:~$]' '_'`.png\"
fi")
(xbindmod '(shift control a)
"import -window root \"$HOME/Pictures/Screenshots/`date +%Y-%m-%d_%H-%M-%S`_Screenshot.png\"")

;; ~/.local/bin/tpope-media

;; ~/bin/tpope-media
(xbindkey '(XF86AudioLowerVolume) "tpope media sink -5%")
(xbindkey '(XF86AudioRaiseVolume) "tpope media sink +5%")
(xbindkey '(XF86AudioMute) "tpope media sink toggle")
(xbindkey '(XF86AudioMicMute) "tpope media source toggle")
(xbindkey '(XF86AudioPrev) "tpope media prev")
(xbindkey '(XF86AudioNext) "tpope media next")
(xbindkey '(XF86AudioPlay) "tpope media toggle")
(xbindkey '(XF86AudioStop) "tpope media stop")

(xbindmod '(minus) "tpope media sink -5%")
(xbindmod '(shift minus) "tpope media sink -5% --current")
(xbindmod '(control minus) "tpope media sink prev")
(xbindmodmod1 '(minus) "tpope media sink prev --current")
(xbindmods '(minus) "tpope media sink prev --current")
(xbindmod '(equal) "tpope media sink +5%")
(xbindmod '(shift equal) "tpope media sink +5% --current")
(xbindmod '(control equal) "tpope media sink 100%")
(xbindmodmod1 '(equal) "tpope media sink 100% --current")
(xbindmods '(equal) "tpope media sink 100% --current")

(xbindmod '(backslash) "tpope media pause")
(xbindmod '(shift backslash) "tpope media toggle")
(xbindmod '(control backslash) "tpope media activate")
(xbindmodmod1 '(backslash) (toggle "pavucontrol"))
(unless (eq? mod 'mod1)
(xbindmod '(control mod1 backslash) (string-append "pkill pulseaudio\n" (toggle "pavucontrol"))))
(xbindkey '(XF86AudioPrev) "tpope media prev")
(xbindkey '(XF86AudioNext) "tpope media next")
(xbindkey '(XF86AudioPlay) "tpope media toggle")
(xbindkey '(XF86AudioStop) "tpope media stop")

(xbindmod '(bracketleft) "tpope media rate - || tpope media prev")
(xbindmod '(bracketright) "tpope media rate + || tpope media next")
(xbindmod '(shift bracketleft) "tpope media prev")
(xbindmod '(shift bracketright) "tpope media next")
(xbindmod '(control bracketleft) "tpope media seek -5")
(xbindmod '(control bracketright) "tpope media seek +5")
(xbindmodmod1 '(bracketleft) "tpope media prev")
(xbindmodmod1 '(bracketright) "tpope media next")
(xbindmods '(bracketleft) "tpope media prev")
(xbindmods '(bracketright) "tpope media next")

(xbindmod '(backslash) "tpope media toggle")
(xbindmod '(shift backslash) "tpope media pause")
(xbindmod '(control backslash) "tpope media activate")
(xbindmods '(backslash) (toggle "pavucontrol"))
(xbindmods '(control backslash) (string-append "pkill pulseaudio\n"
(toggle "pavucontrol")))

(define (clone resolution)
(string-append
"resolution=" resolution "
set --
for display in `xrandr -q | grep ' connected' | awk '{print $1}'`; do
d=`xrandr -q | sed -ne \"/^$display connected/,+1p\"|awk '/^ / {print $1}'`
set -- \"$@\" --output $display --pos 0x0 --panning $resolution
if [ \"${d%x*}\" -ge \"${resolution%x*}\" ]; then
set -- \"$@\" --mode $resolution --scale 1x1 --panning $resolution
else
set -- \"$@\" --mode $d --scale-from $resolution --panning $resolution
fi
done
exec xrandr \"$@\""))
(xbindmod '(o) (toggle "arandr" "lxrandr"))
(xbindmod '(shift o) "xrandr --auto")
(xbindmod '(control o)
(clone "`xrandr -q | grep '^ '|sort -rn|head -1|awk '{print $1}'`"))
(xbindmods '(o) (clone "1920x1080"))

(let ((local-file (string-append (or (getenv "HOME") ".") "/.xbindkeysrc.local.scm")))
(if (access? local-file R_OK)
(load local-file)))
(primitive-load local-file)))
1 change: 0 additions & 1 deletion .xmonad/xmonad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ main = xmonad $ withUrgencyHook BorderUrgencyHook {urgencyBorderColor = "yellow"
`removeKeys`
[ (modm .|. shiftMask, xK_slash)
, (modm, xK_question)
, (modm, xK_p)
, (modm .|. shiftMask, xK_p)
]
`additionalKeys`
Expand Down

0 comments on commit a7be021

Please sign in to comment.