Skip to content

Return a table instead of using module() #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 50 additions & 24 deletions hints.lua
Original file line number Diff line number Diff line change
@@ -1,60 +1,86 @@
-- hints.lua --- window picker and hints for awesome
--
-- Source: https://github.com/zackpete/hints
-- License: GPLv2
--
-- Usage:
-- hints = require('hints')
--
-- -- Set the prefered order of accelerators if you don't like the default.
-- hints.charoder = 'jkluiopyhnmfdsatgvcewqzx1234567890'
--
-- -- Initialize the module (must come after beautiful.init()).
-- hints.init()
--
-- -- Add a keybinding to globalkeys.
-- awful.key({ modkey }, "j", function () hints.focus() end),

local awful = require("awful")
local client = client
local keygrabber= keygrabber
local naughty = require("naughty")
local pairs = pairs
local beautiful = require("beautiful")
local wibox = require("wibox")
local client = client
local keygrabber= keygrabber

module("hints")

charorder = "jkluiopyhnmfdsatgvcewqzx1234567890"
hintbox = {} -- Table of letter wiboxes with characters as the keys
local hints = {
charorder = "jkluiopyhnmfdsatgvcewqzx1234567890",
hintbox = {} -- Table of letter wiboxes with characters as the keys
}

function debuginfo( message )
local debuginfo = function (message)
nid = naughty.notify({ text = message, timeout = 10 })
end

-- Create the wiboxes, but don't show them
function init()
function hints.init()
hintsize = 60
local fontcolor = beautiful.fg_normal
local letterbox = {}
for i = 1, #charorder do
local char = charorder:sub(i,i)
hintbox[char] = wibox({fg=beautiful.fg_normal, bg=beautiful.bg_focus, border_color=beautiful.border_focus, border_width=beautiful.border_width})
hintbox[char].ontop = true
hintbox[char].width = hintsize
hintbox[char].height = hintsize

for i = 1, #hints.charorder do
local char = hints.charorder:sub(i,i)
hints.hintbox[char] = wibox({fg=beautiful.fg_normal, bg=beautiful.bg_focus, border_color=beautiful.border_focus, border_width=beautiful.border_width})
hints.hintbox[char].ontop = true
hints.hintbox[char].width = hintsize
hints.hintbox[char].height = hintsize

letterbox[char] = wibox.widget.textbox()
letterbox[char]:set_markup("<span color=\"" .. beautiful.fg_normal .. "\"" .. ">" .. char.upper(char) .. "</span>")
letterbox[char]:set_font("dejavu sans mono 40")
letterbox[char]:set_align("center")
hintbox[char]:set_widget(letterbox[char])

hints.hintbox[char]:set_widget(letterbox[char])
end
end

function focus()
function hints.focus()
local hintindex = {} -- Table of visible clients with the hint letter as the keys
local clientlist = awful.client.visible()
for i,thisclient in pairs(clientlist) do -- Move wiboxes to center of visible windows and populate hintindex
local char = charorder:sub(i,i)

-- Move wiboxes to center of visible windows and populate hintindex
for i, thisclient in pairs(clientlist) do
local char = hints.charorder:sub(i,i)
hintindex[char] = thisclient
local geom = thisclient.geometry(thisclient)
hintbox[char].visible = true
hintbox[char].x = geom.x + geom.width/2 - hintsize/2
hintbox[char].y = geom.y + geom.height/2 - hintsize/2
hintbox[char].screen = thisclient.screen
hints.hintbox[char].visible = true
hints.hintbox[char].x = geom.x + geom.width/2 - hintsize/2
hints.hintbox[char].y = geom.y + geom.height/2 - hintsize/2
hints.hintbox[char].screen = thisclient.screen
end

keygrabber.run( function(mod,key,event)
if event == "release" then return true end
keygrabber.stop()

if hintindex[key] then
client.focus = hintindex[key]
hintindex[key]:raise()
end

for i,j in pairs(hintindex) do
hintbox[i].visible = false
hints.hintbox[i].visible = false
end
end)
end

return hints