You are not logged in.

#1 2013-11-02 15:25:32

yabasta
Member
Registered: 2010-05-01
Posts: 167

awesome wm keybindings and luakit

hi guys,
i've recently installed awesome wm, and am having some bother with the keybindings working with luakit.

for some reason when i'm on a site and i want to turn scripts on using

,ts

i just cannot make the letter t appear. same goes with trying to press t for the tabopen shortcut.

there seem to be other letters that i cant make appear on the command line in luakit for some reason.

been looking for a tutorial or something to get me under way, but i cant find anything. do you need to be a coder tu understand and use awesome wm?

thanks for your time

Offline

#2 2013-11-02 15:41:38

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: awesome wm keybindings and luakit

Is this specific to awesomewm?  Have you used luakit in other WMs?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2013-11-02 16:00:18

yabasta
Member
Registered: 2010-05-01
Posts: 167

Re: awesome wm keybindings and luakit

yes it's specific to awesome. on my other machine which i use openbox on there are no issues with luakit. maybe theres a way to turn off the awesome keybindings off while using luakit for instance.

as another example of oddities, i can only type in this box if i press the windows key. otherwise all the awesome keybindings kick in. pressing p without pressing the windows key will bring up a run menu, as will pressing r. though i can type by pressing the windows key, i can only backspace if i dont press the windows key.

i just cant seem to find an explanation for this, and can only find key-bindings in the awesome config file, even then i'm a bit unsure of what some do.

using a workaround here of putting caps lock on, and using shift when i need to use 'r' or 't' for shortcuts in luakit.

Last edited by yabasta (2013-11-02 16:07:32)

Offline

#4 2013-11-05 05:51:01

anonymous_user
Member
Registered: 2009-08-28
Posts: 3,059

Re: awesome wm keybindings and luakit

You said you have Openbox on another machine, but have you tried using Openbox (or any other WM) on the machine with the problem?

Also do you have another keyboard to try with?

Offline

#5 2013-11-05 20:06:46

yabasta
Member
Registered: 2010-05-01
Posts: 167

Re: awesome wm keybindings and luakit

yes, i use openbox on the machine with the problem, and there's no problem with luakit on that. and i use the same unedited luakit configurations on both machines.

i don't know if there's a conflict with the keybindings on a standard unedited luakit and awesome wm setup. search results are throwing up nada on the subject.

i should also add, that i can't use any of the keyboard number keys using luakit in awesome. curiouser and curiouser

Offline

#6 2013-11-05 21:33:39

anonymous_user
Member
Registered: 2009-08-28
Posts: 3,059

Re: awesome wm keybindings and luakit

You said your luakit config is unedited, but have you also tried with a stock awesome rc.lua?

Offline

#7 2013-11-06 11:32:54

yabasta
Member
Registered: 2010-05-01
Posts: 167

Re: awesome wm keybindings and luakit

I use the stock rc.lua for awesome too. here it is:

-- Standard awesome library
local gears = require("gears")
local awful = require("awful")
awful.rules = require("awful.rules")
require("awful.autofocus")
-- Widget and layout library
local wibox = require("wibox")
-- Theme handling library
local beautiful = require("beautiful")
-- Notification library
local naughty = require("naughty")
local menubar = require("menubar")

-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
if awesome.startup_errors then
    naughty.notify({ preset = naughty.config.presets.critical,
                     title = "Oops, there were errors during startup!",
                     text = awesome.startup_errors })
end

-- Handle runtime errors after startup
do
    local in_error = false
    awesome.connect_signal("debug::error", function (err)
        -- Make sure we don't go into an endless error loop
        if in_error then return end
        in_error = true

        naughty.notify({ preset = naughty.config.presets.critical,
                         title = "Oops, an error happened!",
                         text = err })
        in_error = false
    end)
end
-- }}}

-- {{{ Variable definitions
-- Themes define colours, icons, and wallpapers
beautiful.init("/usr/share/awesome/themes/default/theme.lua")

-- This is used later as the default terminal and editor to run.
terminal = "urxvt"
editor = os.getenv("EDITOR") or "nano"
editor_cmd = terminal .. " -e " .. editor

-- Default modkey.
-- Usually, Mod4 is the key with a logo between Control and Alt.
-- If you do not like this or do not have such a key,
-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
-- However, you can use another modifier like Mod1, but it may interact with others.
modkey = "mod4"

-- Table of layouts to cover with awful.layout.inc, order matters.
local layouts =
{
    awful.layout.suit.floating,
    awful.layout.suit.tile,
    awful.layout.suit.tile.left,
    awful.layout.suit.tile.bottom,
    awful.layout.suit.tile.top,
    awful.layout.suit.fair,
    awful.layout.suit.fair.horizontal,
    awful.layout.suit.spiral,
    awful.layout.suit.spiral.dwindle,
    awful.layout.suit.max,
    awful.layout.suit.max.fullscreen,
    awful.layout.suit.magnifier
}
-- }}}

-- {{{ Wallpaper
if beautiful.wallpaper then
    for s = 1, screen.count() do
        gears.wallpaper.maximized(beautiful.wallpaper, s, true)
    end
end
-- }}}

-- {{{ Tags
-- Define a tag table which hold all screen tags.
tags = {}
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])
end
-- }}}

-- {{{ Menu
-- Create a laucher widget and a main menu
myawesomemenu = {
   { "manual", terminal .. " -e man awesome" },
   { "edit config", editor_cmd .. " " .. awesome.conffile },
   { "restart", awesome.restart },
   { "quit", awesome.quit }
}

mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
                                    { "open terminal", terminal }
                                  }
                        })

mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
                                     menu = mymainmenu })

-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
-- }}}

-- {{{ Wibox
-- Create a textclock widget
mytextclock = awful.widget.textclock()

-- Create a wibox for each screen and add it
mywibox = {}
mypromptbox = {}
mylayoutbox = {}
mytaglist = {}
mytaglist.buttons = awful.util.table.join(
                    awful.button({ }, 1, awful.tag.viewonly),
                    awful.button({ modkey }, 1, awful.client.movetotag),
                    awful.button({ }, 3, awful.tag.viewtoggle),
                    awful.button({ modkey }, 3, awful.client.toggletag),
                    awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
                    awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
                    )
mytasklist = {}
mytasklist.buttons = awful.util.table.join(
                     awful.button({ }, 1, function (c)
                                              if c == client.focus then
                                                  c.minimized = true
                                              else
                                                  -- Without this, the following
                                                  -- :isvisible() makes no sense
                                                  c.minimized = false
                                                  if not c:isvisible() then
                                                      awful.tag.viewonly(c:tags()[1])
                                                  end
                                                  -- This will also un-minimize
                                                  -- the client, if needed
                                                  client.focus = c
                                                  c:raise()
                                              end
                                          end),
                     awful.button({ }, 3, function ()
                                              if instance then
                                                  instance:hide()
                                                  instance = nil
                                              else
                                                  instance = awful.menu.clients({ width=250 })
                                              end
                                          end),
                     awful.button({ }, 4, function ()
                                              awful.client.focus.byidx(1)
                                              if client.focus then client.focus:raise() end
                                          end),
                     awful.button({ }, 5, function ()
                                              awful.client.focus.byidx(-1)
                                              if client.focus then client.focus:raise() end
                                          end))

for s = 1, screen.count() do
    -- Create a promptbox for each screen
    mypromptbox[s] = awful.widget.prompt()
    -- Create an imagebox widget which will contains an icon indicating which layout we're using.
    -- We need one layoutbox per screen.
    mylayoutbox[s] = awful.widget.layoutbox(s)
    mylayoutbox[s]:buttons(awful.util.table.join(
                           awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
                           awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
                           awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
                           awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
    -- Create a taglist widget
    mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)

    -- Create a tasklist widget
    mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)

    -- Create the wibox
    mywibox[s] = awful.wibox({ position = "top", screen = s })

    -- Widgets that are aligned to the left
    local left_layout = wibox.layout.fixed.horizontal()
    left_layout:add(mylauncher)
    left_layout:add(mytaglist[s])
    left_layout:add(mypromptbox[s])

    -- Widgets that are aligned to the right
    local right_layout = wibox.layout.fixed.horizontal()
    if s == 1 then right_layout:add(wibox.widget.systray()) end
    right_layout:add(mytextclock)
    right_layout:add(mylayoutbox[s])

    -- Now bring it all together (with the tasklist in the middle)
    local layout = wibox.layout.align.horizontal()
    layout:set_left(left_layout)
    layout:set_middle(mytasklist[s])
    layout:set_right(right_layout)

    mywibox[s]:set_widget(layout)
end
-- }}}

-- {{{ Mouse bindings
root.buttons(awful.util.table.join(
    awful.button({ }, 3, function () mymainmenu:toggle() end),
    awful.button({ }, 4, awful.tag.viewnext),
    awful.button({ }, 5, awful.tag.viewprev)
))
-- }}}

-- {{{ Key bindings
globalkeys = awful.util.table.join(
    awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
    awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
    awful.key({ modkey,           }, "Escape", awful.tag.history.restore),

    awful.key({ modkey,           }, "j",
        function ()
            awful.client.focus.byidx( 1)
            if client.focus then client.focus:raise() end
        end),
    awful.key({ modkey,           }, "k",
        function ()
            awful.client.focus.byidx(-1)
            if client.focus then client.focus:raise() end
        end),
    awful.key({ modkey,           }, "w", function () mymainmenu:show() 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,           }, "Tab",
        function ()
            awful.client.focus.history.previous()
            if client.focus then
                client.focus:raise()
            end
        end),

    -- Standard program
    awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
    awful.key({ modkey, "Control" }, "r", awesome.restart),
    awful.key({ modkey, "Shift"   }, "q", awesome.quit),

    awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
    awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
    awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
    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,           }, "space", function () awful.layout.inc(layouts,  1) end),
    awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),

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

    -- Prompt
    awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),

    awful.key({ modkey }, "x",
              function ()
                  awful.prompt.run({ prompt = "Run Lua code: " },
                  mypromptbox[mouse.screen].widget,
                  awful.util.eval, nil,
                  awful.util.getdir("cache") .. "/history_eval")
              end),
    -- Menubar
    awful.key({ modkey }, "p", function() menubar.show() end)
)

clientkeys = awful.util.table.join(
    awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
    awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
    awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
    awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
    awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
    awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            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)
)

-- Bind all key numbers to tags.
-- Be careful: we use keycodes to make it works on any keyboard layout.
-- This should map on the top row of your keyboard, usually 1 to 9.
for i = 1, 9 do
    globalkeys = awful.util.table.join(globalkeys,
        awful.key({ modkey }, "#" .. i + 9,
                  function ()
                        local screen = mouse.screen
                        local tag = awful.tag.gettags(screen)[i]
                        if tag then
                           awful.tag.viewonly(tag)
                        end
                  end),
        awful.key({ modkey, "Control" }, "#" .. i + 9,
                  function ()
                      local screen = mouse.screen
                      local tag = awful.tag.gettags(screen)[i]
                      if tag then
                         awful.tag.viewtoggle(tag)
                      end
                  end),
        awful.key({ modkey, "Shift" }, "#" .. i + 9,
                  function ()
                      if client.focus then
                          local tag = awful.tag.gettags(client.focus.screen)[i]
                          if tag then
                              awful.client.movetotag(tag)
                          end
                     end
                  end),
        awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
                  function ()
                      if client.focus then
                          local tag = awful.tag.gettags(client.focus.screen)[i]
                          if tag then
                              awful.client.toggletag(tag)
                          end
                      end
                  end))
end

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 }, 3, awful.mouse.client.resize))

-- Set keys
root.keys(globalkeys)
-- }}}

-- {{{ Rules
awful.rules.rules = {
    -- All clients will match this rule.
    { rule = { },
      properties = { border_width = beautiful.border_width,
                     border_color = beautiful.border_normal,
                     focus = awful.client.focus.filter,
                     keys = clientkeys,
                     buttons = clientbuttons } },
    { rule = { class = "MPlayer" },
      properties = { floating = true } },
    { rule = { class = "pinentry" },
      properties = { floating = true } },
    { rule = { class = "gimp" },
      properties = { floating = true } },
    -- Set Firefox to always map on tags number 2 of screen 1.
    -- { rule = { class = "Firefox" },
    --   properties = { tag = tags[1][2] } },
}
-- }}}

-- {{{ Signals
-- Signal function to execute when a new client appears.
client.connect_signal("manage", function (c, startup)
    -- Enable sloppy focus
    c:connect_signal("mouse::enter", function(c)
        if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
            and awful.client.focus.filter(c) then
            client.focus = c
        end
    end)

    if not startup then
        -- Set the windows at the slave,
        -- i.e. put it at the end of others instead of setting it master.
        -- awful.client.setslave(c)

        -- Put windows in a smart way, only if they does not set an initial position.
        if not c.size_hints.user_position and not c.size_hints.program_position then
            awful.placement.no_overlap(c)
            awful.placement.no_offscreen(c)
        end
    end

    local titlebars_enabled = false
    if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
        -- buttons for the titlebar
        local buttons = awful.util.table.join(
                awful.button({ }, 1, function()
                    client.focus = c
                    c:raise()
                    awful.mouse.client.move(c)
                end),
                awful.button({ }, 3, function()
                    client.focus = c
                    c:raise()
                    awful.mouse.client.resize(c)
                end)
                )

        -- Widgets that are aligned to the left
        local left_layout = wibox.layout.fixed.horizontal()
        left_layout:add(awful.titlebar.widget.iconwidget(c))
        left_layout:buttons(buttons)

        -- Widgets that are aligned to the right
        local right_layout = wibox.layout.fixed.horizontal()
        right_layout:add(awful.titlebar.widget.floatingbutton(c))
        right_layout:add(awful.titlebar.widget.maximizedbutton(c))
        right_layout:add(awful.titlebar.widget.stickybutton(c))
        right_layout:add(awful.titlebar.widget.ontopbutton(c))
        right_layout:add(awful.titlebar.widget.closebutton(c))

        -- The title goes in the middle
        local middle_layout = wibox.layout.flex.horizontal()
        local title = awful.titlebar.widget.titlewidget(c)
        title:set_align("center")
        middle_layout:add(title)
        middle_layout:buttons(buttons)

        -- Now bring it all together
        local layout = wibox.layout.align.horizontal()
        layout:set_left(left_layout)
        layout:set_right(right_layout)
        layout:set_middle(middle_layout)

        awful.titlebar(c):set_widget(layout)
    end
end)

client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
-- }}}

and here"s the rc.lua for luakit:

-----------------------------------------------------------------------
-- luakit configuration file, more information at http://luakit.org/ --
-----------------------------------------------------------------------

require "lfs"

if unique then
    unique.new("org.luakit")
    -- Check for a running luakit instance
    if unique.is_running() then
        if uris[1] then
            for _, uri in ipairs(uris) do
                if lfs.attributes(uri) then uri = os.abspath(uri) end
                unique.send_message("tabopen " .. uri)
            end
        else
            unique.send_message("winopen")
        end
        luakit.quit()
    end
end

-- Load library of useful functions for luakit
require "lousy"

-- Small util functions to print output (info prints only when luakit.verbose is true)
function warn(...) io.stderr:write(string.format(...) .. "\n") end
function info(...) if luakit.verbose then io.stdout:write(string.format(...) .. "\n") end end

-- Load users global config
-- ("$XDG_CONFIG_HOME/luakit/globals.lua" or "/etc/xdg/luakit/globals.lua")
require "globals"

-- Load users theme
-- ("$XDG_CONFIG_HOME/luakit/theme.lua" or "/etc/xdg/luakit/theme.lua")
lousy.theme.init(lousy.util.find_config("theme.lua"))
theme = assert(lousy.theme.get(), "failed to load theme")

-- Load users window class
-- ("$XDG_CONFIG_HOME/luakit/window.lua" or "/etc/xdg/luakit/window.lua")
require "window"

-- Load users webview class
-- ("$XDG_CONFIG_HOME/luakit/webview.lua" or "/etc/xdg/luakit/webview.lua")
require "webview"

-- Load users mode configuration
-- ("$XDG_CONFIG_HOME/luakit/modes.lua" or "/etc/xdg/luakit/modes.lua")
require "modes"

-- Load users keybindings
-- ("$XDG_CONFIG_HOME/luakit/binds.lua" or "/etc/xdg/luakit/binds.lua")
require "binds"

require "noscript"
noscript.enable_scripts = false
noscript.enable_plugins = false
----------------------------------
-- Optional user script loading --
----------------------------------

require "webinspector"

-- Add sqlite3 cookiejar
require "cookies"

-- Cookie blocking by domain (extends cookies module)
-- Add domains to the whitelist at "$XDG_CONFIG_HOME/luakit/cookie.whitelist"
-- and blacklist at "$XDG_CONFIG_HOME/luakit/cookie.blacklist".
-- Each domain must be on it's own line and you may use "*" as a
-- wildcard character (I.e. "*google.com")
--require "cookie_blocking"

-- Block all cookies by default (unless whitelisted)
--cookies.default_allow = false

-- Add uzbl-like form filling
require "formfiller"

-- Add proxy support & manager
require "proxy"

-- Add quickmarks support & manager
require "quickmarks"

-- Add session saving/loading support
require "session"

-- Add command to list closed tabs & bind to open closed tabs
require "undoclose"

-- Add command to list tab history items
require "tabhistory"

-- Add greasemonkey-like javascript userscript support
require "userscripts"

-- Add bookmarks support
require "bookmarks"
require "bookmarks_chrome"

-- Add download support
require "downloads"
require "downloads_chrome"

-- Example using xdg-open for opening downloads / showing download folders
--downloads.add_signal("open-file", function (file, mime)
--    luakit.spawn(string.format("xdg-open %q", file))
--    return true
--end)

-- Add vimperator-like link hinting & following
require "follow"

-- Use a custom charater set for hint labels
--local s = follow.label_styles
--follow.label_maker = s.sort(s.reverse(s.charset("asdfqwerzxcv")))

-- Match only hint labels
--follow.pattern_maker = follow.pattern_styles.match_label

-- Add command history
require "cmdhist"

-- Add search mode & binds
require "search"

-- Add ordering of new tabs
require "taborder"

-- Save web history
require "history"
require "history_chrome"

require "introspector"

-- Add command completion
require "completion"

-- NoScript plugin, toggle scripts and or plugins on a per-domain basis.
-- `,ts` to toggle scripts, `,tp` to toggle plugins, `,tr` to reset.
-- Remove all "enable_scripts" & "enable_plugins" lines from your
-- domain_props table (in config/globals.lua) as this module will conflict.
--require "noscript"

require "follow_selected"
require "go_input"
require "go_next_prev"
require "go_up"

-----------------------------
-- End user script loading --
-----------------------------

-- Restore last saved session
local w = (session and session.restore())
if w then
    for i, uri in ipairs(uris) do
        w:new_tab(uri, i == 1)
    end
else
    -- Or open new window
    window.new(uris)
end

-------------------------------------------
-- Open URIs from other luakit instances --
-------------------------------------------

if unique then
    unique.add_signal("message", function (msg, screen)
        local cmd, arg = string.match(msg, "^(%S+)%s*(.*)")
        local w = lousy.util.table.values(window.bywidget)[1]
        if cmd == "tabopen" then
            w:new_tab(arg)
        elseif cmd == "winopen" then
            w = window.new((arg ~= "") and { arg } or {})
        end
        w.win.screen = screen
        w.win.urgency_hint = true
    end)
end

-- vim: et:sw=4:ts=8:sts=4:tw=80

and the binds.lua for luakit:

-----------------
-- Keybindings --
-----------------

-- Binding aliases
local key, buf, but = lousy.bind.key, lousy.bind.buf, lousy.bind.but
local cmd, any = lousy.bind.cmd, lousy.bind.any

-- Util aliases
local match, join = string.match, lousy.util.table.join
local strip, split = lousy.util.string.strip, lousy.util.string.split

-- Globals or defaults that are used in binds
local scroll_step = globals.scroll_step or 20
local zoom_step = globals.zoom_step or 0.1

-- Add binds to a mode
function add_binds(mode, binds, before)
    assert(binds and type(binds) == "table", "invalid binds table type: " .. type(binds))
    mode = type(mode) ~= "table" and {mode} or mode
    for _, m in ipairs(mode) do
        local mdata = get_mode(m)
        if mdata and before then
            mdata.binds = join(binds, mdata.binds or {})
        elseif mdata then
            mdata.binds = mdata.binds or {}
            for _, b in ipairs(binds) do table.insert(mdata.binds, b) end
        else
            new_mode(m, { binds = binds })
        end
    end
end

-- Add commands to command mode
function add_cmds(cmds, before)
    add_binds("command", cmds, before)
end

-- Adds the default menu widget bindings to a mode
menu_binds = {
    -- Navigate items
    key({},          "j",       function (w) w.menu:move_down() end),
    key({},          "k",       function (w) w.menu:move_up()   end),
    key({},          "Down",    function (w) w.menu:move_down() end),
    key({},          "Up",      function (w) w.menu:move_up()   end),
    key({},          "Tab",     function (w) w.menu:move_down() end),
    key({"Shift"},   "Tab",     function (w) w.menu:move_up()   end),
}

-- Add binds to special mode "all" which adds its binds to all modes.
add_binds("all", {
    key({}, "Escape", "Return to `normal` mode.",
        function (w) w:set_mode() end),

    key({"Control"}, "[", "Return to `normal` mode.",
        function (w) w:set_mode() end),

    -- Mouse bindings
    but({}, 8, "Go back.",
        function (w) w:back() end),

    but({}, 9, "Go forward.",
        function (w) w:forward() end),

    -- Open link in new tab or navigate to selection
    but({}, 2, [[Open link under mouse cursor in new tab or navigate to the
        contents of `luakit.selection.primary`.]],
        function (w, m)
            -- Ignore button 2 clicks in form fields
            if not m.context.editable then
                -- Open hovered uri in new tab
                local uri = w.view.hovered_uri
                if uri then
                    w:new_tab(uri, false)
                else -- Open selection in current tab
                    uri = luakit.selection.primary
                    if uri then w:navigate(w:search_open(uri)) end
                end
            end
        end),

    -- Open link in new tab when Ctrl-clicked.
    but({"Control"}, 1, "Open link under mouse cursor in new tab.",
        function (w, m)
            local uri = w.view.hovered_uri
            if uri then
                w:new_tab(uri, false)
            end
        end),

    -- Zoom binds
    but({"Control"}, 4, "Increase text zoom level.",
        function (w, m) w:zoom_in() end),

    but({"Control"}, 5, "Reduce text zoom level.",
        function (w, m) w:zoom_out() end),

    -- Horizontal mouse scroll binds
    but({"Shift"}, 4, "Scroll left.",
        function (w, m) w:scroll{ xrel = -scroll_step } end),

    but({"Shift"}, 5, "Scroll right.",
        function (w, m) w:scroll{ xrel =  scroll_step } end),
})

add_binds("normal", {
    -- Autoparse the `[count]` before a binding and re-call the hit function
    -- with the count removed and added to the opts table.
    any([[Meta-binding to detect the `^[count]` syntax. The `[count]` is parsed
        and stripped from the internal buffer string and the value assigned to
        `state.count`. Then `lousy.bind.hit()` is re-called with the modified
        buffer string & original modifier state.

        #### Example binding

            lousy.bind.key({}, "%", function (w, state)
                w:scroll{ ypct = state.count }
            end, { count = 0 })

        This binding demonstrates several concepts. Firstly that you are able to
        specify per-binding default values of `count`. In this case if the user
        types `"%"` the document will be scrolled vertically to `0%` (the top).

        If the user types `"100%"` then the document will be scrolled to `100%`
        (the bottom). All without the need to use `lousy.bind.buf` bindings
        everywhere and or using a `^(%d*)` pattern prefix on every binding which
        would like to make use of the `[count]` syntax.]],
        function (w, m)
            local count, buf
            if m.buffer then
                count = string.match(m.buffer, "^(%d+)")
            end
            if count then
                buf = string.sub(m.buffer, #count + 1, (m.updated_buf and -2) or -1)
                local opts = join(m, {count = tonumber(count)})
                opts.buffer = (#buf > 0 and buf) or nil
                if lousy.bind.hit(w, m.binds, m.mods, m.key, opts) then
                    return true
                end
            end
            return false
        end),

    key({}, "i", "Enter `insert` mode.",
        function (w) w:set_mode("insert")  end),

    key({}, ":", "Enter `command` mode.",
        function (w) w:set_mode("command") end),

    -- Scrolling
    key({}, "j", "Scroll document down.",
        function (w) w:scroll{ yrel =  scroll_step } end),

    key({}, "k", "Scroll document up.",
        function (w) w:scroll{ yrel = -scroll_step } end),

    key({}, "h", "Scroll document left.",
        function (w) w:scroll{ xrel = -scroll_step } end),

    key({}, "l", "Scroll document right.",
        function (w) w:scroll{ xrel =  scroll_step } end),

    key({}, "Down", "Scroll document down.",
        function (w) w:scroll{ yrel =  scroll_step } end),

    key({}, "Up",   "Scroll document up.",
        function (w) w:scroll{ yrel = -scroll_step } end),

    key({}, "Left", "Scroll document left.",
        function (w) w:scroll{ xrel = -scroll_step } end),

    key({}, "Right", "Scroll document right.",
        function (w) w:scroll{ xrel =  scroll_step } end),

    key({}, "^", "Scroll to the absolute left of the document.",
        function (w) w:scroll{ x =  0 } end),

    key({}, "$", "Scroll to the absolute right of the document.",
        function (w) w:scroll{ x = -1 } end),

    key({}, "0", "Scroll to the absolute left of the document.",
        function (w, m)
            if not m.count then w:scroll{ y = 0 } else return false end
        end),

    key({"Control"}, "e", "Scroll document down.",
        function (w) w:scroll{ yrel =  scroll_step } end),

    key({"Control"}, "y", "Scroll document up.",
        function (w) w:scroll{ yrel = -scroll_step } end),

    key({"Control"}, "d", "Scroll half page down.",
        function (w) w:scroll{ ypagerel =  0.5 } end),

    key({"Control"}, "u", "Scroll half page up.",
        function (w) w:scroll{ ypagerel = -0.5 } end),

    key({"Control"}, "f", "Scroll page down.",
        function (w) w:scroll{ ypagerel =  1.0 } end),

    key({"Control"}, "b", "Scroll page up.",
        function (w) w:scroll{ ypagerel = -1.0 } end),

    key({}, "space", "Scroll page down.",
        function (w) w:scroll{ ypagerel =  1.0 } end),

    key({"Shift"}, "space", "Scroll page up.",
        function (w) w:scroll{ ypagerel = -1.0 } end),

    key({}, "BackSpace", "Scroll page up.",
        function (w) w:scroll{ ypagerel = -1.0 } end),

    key({}, "Page_Down", "Scroll page down.",
        function (w) w:scroll{ ypagerel =  1.0 } end),

    key({}, "Page_Up", "Scroll page up.",
        function (w) w:scroll{ ypagerel = -1.0 } end),

    key({}, "Home", "Go to the end of the document.",
        function (w) w:scroll{ y =  0 } end),

    key({}, "End", "Go to the top of the document.",
        function (w) w:scroll{ y = -1 } end),

    -- Specific scroll
    buf("^gg$", "Go to the top of the document.",
        function (w, b, m) w:scroll{ ypct = m.count } end, {count=0}),

    buf("^G$", "Go to the bottom of the document.",
        function (w, b, m) w:scroll{ ypct = m.count } end, {count=100}),

    buf("^%%$", "Go to `[count]` percent of the document.",
        function (w, b, m) w:scroll{ ypct = m.count } end),

    -- Zooming
    key({}, "+", "Enlarge text zoom of the current page.",
        function (w, m) w:zoom_in(zoom_step * m.count) end, {count=1}),

    key({}, "-", "Reduce text zom of the current page.",
        function (w, m) w:zoom_out(zoom_step * m.count) end, {count=1}),

    key({}, "=", "Reset zoom level.",
        function (w, m) w:zoom_set() end),

    buf("^z[iI]$", [[Enlarge text zoom of current page with `zi` or `zI` to
        reduce full zoom.]],
        function (w, b, m)
            w:zoom_in(zoom_step  * m.count, b == "zI")
        end, {count=1}),

    buf("^z[oO]$", [[Reduce text zoom of current page with `zo` or `zO` to
        reduce full zoom.]],
        function (w, b, m)
            w:zoom_out(zoom_step * m.count, b == "zO")
        end, {count=1}),

    -- Zoom reset or specific zoom ([count]zZ for full content zoom)
    buf("^z[zZ]$", [[Set current page zoom to `[count]` percent with
        `[count]zz`, use `[count]zZ` to set full zoom percent.]],
        function (w, b, m)
            w:zoom_set(m.count/100, b == "zZ")
        end, {count=100}),

    -- Fullscreen
    key({}, "F11", "Toggle fullscreen mode.",
        function (w) w.win.fullscreen = not w.win.fullscreen end),

    -- Clipboard
    key({}, "p", [[Open a URL based on the current primary selection contents
        in the current tab.]],
        function (w)
            local uri = luakit.selection.primary
            if not uri then w:notify("No primary selection...") return end
            w:navigate(w:search_open(uri))
        end),

    key({}, "P", [[Open a URL based on the current primary selection contents
        in `[count=1]` new tab(s).]],
        function (w, m)
            local uri = luakit.selection.primary
            if not uri then w:notify("No primary selection...") return end
            for i = 1, m.count do w:new_tab(w:search_open(uri)) end
        end, {count = 1}),

    -- Yanking
    key({}, "y", "Yank current URI to primary selection.",
        function (w)
            local uri = string.gsub(w.view.uri or "", " ", "%%20")
            luakit.selection.primary = uri
            w:notify("Yanked uri: " .. uri)
        end),

    -- Commands
    key({"Control"}, "a", "Increment last number in URL.",
        function (w) w:navigate(w:inc_uri(1)) end),

    key({"Control"}, "x", "Decrement last number in URL.",
        function (w) w:navigate(w:inc_uri(-1)) end),

    key({}, "o", "Open one or more URLs.",
        function (w) w:enter_cmd(":open ") end),

    key({}, "t", "Open one or more URLs in a new tab.",
        function (w) w:enter_cmd(":tabopen ") end),

    key({}, "w", "Open one or more URLs in a new window.",
        function (w) w:enter_cmd(":winopen ") end),

    key({}, "O", "Open one or more URLs based on current location.",
        function (w) w:enter_cmd(":open " .. (w.view.uri or "")) end),

    key({}, "T",
        "Open one or more URLs based on current location in a new tab.",
        function (w) w:enter_cmd(":tabopen " .. (w.view.uri or "")) end),

    key({}, "W",
        "Open one or more URLs based on current locaton in a new window.",
        function (w) w:enter_cmd(":winopen " .. (w.view.uri or "")) end),

    -- History
    key({}, "H", "Go back in the browser history `[count=1]` items.",
        function (w, m) w:back(m.count) end),

    key({}, "L", "Go forward in the browser history `[count=1]` times.",
        function (w, m) w:forward(m.count) end),

    key({}, "XF86Back", "Go back in the browser history.",
        function (w, m) w:back(m.count) end),

    key({}, "XF86Forward", "Go forward in the browser history.",
        function (w, m) w:forward(m.count) end),








    key({"Control"}, "o", "Go back in the browser history.",
        function (w, m) w:back(m.count) end),








    key({"Control"}, "i", "Go forward in the browser history.",
        function (w, m) w:forward(m.count) end),

    -- Tab
    key({"Control"}, "Page_Up", "Go to previous tab.",
        function (w) w:prev_tab() end),

    key({"Control"}, "Page_Down", "Go to next tab.",
        function (w) w:next_tab() end),

    key({"Control"}, "Tab", "Go to next tab.",
        function (w) w:next_tab() end),

    key({"Shift","Control"}, "Tab", "Go to previous tab.",
        function (w) w:prev_tab() end),

    buf("^gT$", "Go to previous tab.",
        function (w) w:prev_tab() end),

    buf("^gt$", "Go to next tab (or `[count]` nth tab).",
        function (w, b, m)
            if not w:goto_tab(m.count) then w:next_tab() end
        end, {count=0}),

    buf("^g0$", "Go to first tab.",
        function (w) w:goto_tab(1) end),

    buf("^g$$", "Go to last tab.",
        function (w) w:goto_tab(-1) end),

    key({"Control"}, "t", "Open a new tab.",
        function (w) w:new_tab(globals.homepage) end),

    key({"Control"}, "w", "Close current tab.",
        function (w) w:close_tab() end),

    key({}, "d", "Close current tab (or `[count]` tabs).",
        function (w, m) for i=1,m.count do w:close_tab() end end, {count=1}),

    key({}, "<", "Reorder tab left `[count=1]` positions.",
        function (w, m)
            w.tabs:reorder(w.view, w.tabs:current() - m.count)
        end, {count=1}),

    key({}, ">", "Reorder tab right `[count=1]` positions.",
        function (w, m)
            w.tabs:reorder(w.view,
                (w.tabs:current() + m.count) % w.tabs:count())
        end, {count=1}),

    buf("^gH$", "Open homepage in new tab.",
        function (w) w:new_tab(globals.homepage) end),

    buf("^gh$", "Open homepage.",
        function (w) w:navigate(globals.homepage) end),

    buf("^gy$", "Duplicate current tab.",
        function (w) w:new_tab(w.view.history or "") end),

    key({}, "r", "Reload current tab.",
        function (w) w:reload() end),

    key({}, "R", "Reload current tab (skipping cache).",
        function (w) w:reload(true) end),

    key({"Control"}, "c", "Stop loading the current tab.",
        function (w) w.view:stop() end),

    key({"Control", "Shift"}, "R", "Restart luakit (reloading configs).",
        function (w) w:restart() end),

    -- Window
    buf("^ZZ$", "Quit and save the session.",
        function (w) w:save_session() w:close_win() end),

    buf("^ZQ$", "Quit and don't save the session.",
        function (w) w:close_win() end),

    buf("^D$",  "Quit and don't save the session.",
        function (w) w:close_win() end),

    -- Enter passthrough mode
    key({"Control"}, "z",
        "Enter `passthrough` mode, ignores all luakit keybindings.",
        function (w) w:set_mode("passthrough") end),
})

add_binds("insert", {
    key({"Control"}, "z",
        "Enter `passthrough` mode, ignores all luakit keybindings.",
        function (w) w:set_mode("passthrough") end),
})

readline_bindings = {
    key({"Shift"}, "Insert",
        "Insert contents of primary selection at cursor position.",
        function (w) w:insert_cmd(luakit.selection.primary) end),

    key({"Control"}, "w", "Delete previous word.",
        function (w) w:del_word() end),

    key({"Control"}, "u", "Delete until beginning of current line.",
        function (w) w:del_line() end),

    key({"Control"}, "h", "Delete character to the left.",
        function (w) w:del_backward_char() end),

    key({"Control"}, "d", "Delete character to the right.",
        function (w) w:del_forward_char() end),

    key({"Control"}, "a", "Move cursor to beginning of current line.",
        function (w) w:beg_line() end),

    key({"Control"}, "e", "Move cursor to end of current line.",
        function (w) w:end_line() end),

    key({"Control"}, "f", "Move cursor forward one character.",
        function (w) w:forward_char() end),

    key({"Control"}, "b", "Move cursor backward one character.",
        function (w) w:backward_char() end),

    key({"Mod1"}, "f", "Move cursor forward one word.",
        function (w) w:forward_word() end),

    key({"Mod1"}, "b", "Move cursor backward one word.",
        function (w) w:backward_word() end),
}

add_binds({"command", "search"}, readline_bindings)

-- Switching tabs with Mod1+{1,2,3,...}
mod1binds = {}
for i=1,10 do
    table.insert(mod1binds,
        key({"Mod1"}, tostring(i % 10), "Jump to tab at index "..i..".",
            function (w) w.tabs:switch(i) end))
end
add_binds("normal", mod1binds)

-- Command bindings which are matched in the "command" mode from text
-- entered into the input bar.
add_cmds({
    buf("^%S+!",
        [[Detect bang syntax in `:command!` and recursively calls
        `lousy.bind.match_cmd(..)` removing the bang from the command string
        and setting `bang = true` in the bind opts table.]],
        function (w, cmd, opts)
            local cmd, args = string.match(cmd, "^(%S+)!+(.*)")
            if cmd then
                opts = join(opts, { bang = true })
                return lousy.bind.match_cmd(w, opts.binds, cmd .. args, opts)
            end
        end),

    cmd("c[lose]", "Close current tab.",
        function (w) w:close_tab() end),

    cmd("print", "Print current page.",
        function (w) w.view:eval_js("print()") end),

    cmd("stop", "Stop loading.",
        function (w) w.view:stop() end),

    cmd("reload", "Reload page",
        function (w) w:reload() end),

    cmd("restart", "Restart browser (reload config files).",
        function (w) w:restart() end),

    cmd("write", "Save current session.",
        function (w) w:save_session() end),

    cmd("noh[lsearch]", "Clear search highlighting.",
        function (w) w:clear_search() end),

    cmd("back", "Go back in the browser history `[count=1]` items.",
        function (w, a) w:back(tonumber(a) or 1) end),

    cmd("f[orward]", "Go forward in the browser history `[count=1]` items.",
        function (w, a) w:forward(tonumber(a) or 1) end),

    cmd("inc[rease]", "Increment last number in URL.",
        function (w, a) w:navigate(w:inc_uri(tonumber(a) or 1)) end),

    cmd("o[pen]", "Open one or more URLs.",
        function (w, a) w:navigate(w:search_open(a)) end),

    cmd("t[abopen]", "Open one or more URLs in a new tab.",
        function (w, a) w:new_tab(w:search_open(a)) end),

    cmd("w[inopen]", "Open one or more URLs in a new window.",
        function (w, a) window.new{w:search_open(a)} end),

    cmd({"javascript", "js"}, "Evaluate JavaScript snippet.",
        function (w, a) w.view:eval_js(a) end),

    -- Tab manipulation commands
    cmd("tab", "Execute command and open result in new tab.",
        function (w, a) w:new_tab() w:run_cmd(":" .. a) end),

    cmd("tabd[o]", "Execute command in each tab.",
        function (w, a) w:each_tab(function (v) w:run_cmd(":" .. a) end) end),

    cmd("tabdu[plicate]", "Duplicate current tab.",
        function (w) w:new_tab(w.view.history) end),

    cmd("tabfir[st]", "Switch to first tab.",
        function (w) w:goto_tab(1) end),

    cmd("tabl[ast]", "Switch to last tab.",
        function (w) w:goto_tab(-1) end),

    cmd("tabn[ext]", "Switch to the next tab.",
        function (w) w:next_tab() end),

    cmd("tabp[revious]", "Switch to the previous tab.",
        function (w) w:prev_tab() end),

    cmd("q[uit]", "Close the current window.",
        function (w, a, o) w:close_win(o.bang) end),

    cmd({"viewsource", "vs"}, "View the source code of the current document.",
        function (w, a, o) w:toggle_source(not o.bang and true or nil) end),

    cmd({"wqall", "wq"}, "Save the session and quit.",
        function (w, a, o) w:save_session() w:close_win(o.bang) end),

    cmd("lua", "Evaluate Lua snippet.", function (w, a)
        if a then
            local ret = assert(
                loadstring("return function(w) return "..a.." end"))()(w)
            if ret then print(ret) end
        else
            w:set_mode("lua")
        end
    end),

    cmd("dump", "Dump current tabs html to file.",
        function (w, a)
            local fname = string.gsub(w.win.title, '[^%w%.%-]', '_')..'.html' -- sanitize filename
            local file = a or luakit.save_file("Save file", w.win, xdg.download_dir or '.', fname)
            if file then
                local fd = assert(io.open(file, "w"), "failed to open: " .. file)
                local html = assert(w.view:eval_js("document.documentElement.outerHTML"), "Unable to get HTML")
                assert(fd:write(html), "unable to save html")
                io.close(fd)
                w:notify("Dumped HTML to: " .. file)
            end
        end),
})

-- vim: et:sw=4:ts=8:sts=4:tw=80

Offline

Board footer

Powered by FluxBB