Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/awesome/osk.lua
987 views
1
----------------------------------------------------
2
-- On Screen Keyboard for the awesome window manager
3
----------------------------------------------------
4
-- Coded by: farhaven <[email protected]>
5
-- Hacked by: Adrian C. <[email protected]>
6
-- Licensed under the WTFPL version 2
7
-- * http://sam.zoy.org/wtfpl/COPYING
8
----------------------------------------------------
9
-- To use this module add:
10
-- require("osk")
11
-- to your rc.lua, and call it from a keybinding:
12
-- osk(position, screen)
13
--
14
-- Parameters:
15
-- position - optional, "bottom" by default
16
-- screen - optional, screen.count() by default
17
----------------------------------------------------
18
19
-- Grab environment
20
local util = require("awful.util")
21
local wibox = require("awful.wibox")
22
local button = require("awful.button")
23
local layout = require("awful.widget.layout")
24
local table = table
25
local ipairs = ipairs
26
local tostring = tostring
27
local setmetatable = setmetatable
28
local capi = {
29
widget = widget,
30
screen = screen,
31
fake_input = root.fake_input
32
}
33
34
-- OSK: On Screen Keyboard for the awesome window manager
35
module("osk")
36
37
-- Variable definitions
38
local kbd = {}
39
kbd.codes = {
40
q=24, w=25, e=26, r=27, t=28, z=52, u=30, i=31, o=32, p=33, ["."]=60,
41
a=38, s=39, d=40, f=41, g=42, h=43, j=44, k=45, l=46,
42
Caps=66, y=29, x=53, c=54, v=55, b=56, n=57, m=58, Spc=65, Ret=36, Del=22,
43
}
44
45
-- Create a chain of key widgets for an OSK row
46
local function create_button_row(...)
47
local widgets = { layout = layout.horizontal.flex }
48
49
for _, i in ipairs(arg) do
50
local w = capi.widget({ type = "textbox" })
51
w:margin({ top = 10, left = 10, right = 10, bottom = 10 })
52
w.border_width = 1
53
w.text_align = "center"
54
w.border_color = "#1E2320"
55
w.text = util.escape(tostring(i))
56
w:buttons(util.table.join(
57
button({ }, 1, nil, function ()
58
capi.fake_input("key_press", kbd.codes[i])
59
capi.fake_input("key_release", kbd.codes[i])
60
end)
61
))
62
63
table.insert(widgets, w)
64
end
65
66
return widgets
67
end
68
69
-- Create a wibox holding OSK rows and toggle its visibility
70
setmetatable(_M, { __call = function (_, pos, scr)
71
if not kbd.init then
72
kbd.box = wibox({
73
height = 100,
74
position = pos or "bottom",
75
screen = scr or capi.screen.count(),
76
fg = "#F0DFAF",
77
bg = "#4F4F4F",
78
widgets = {
79
{ create_button_row("q", "w", "e", "r", "t", "z", "u", "i", "o", "p", ".") },
80
{ create_button_row("a", "s", "d", "f", "g", "h", "j", "k", "l") },
81
{ create_button_row("Caps", "y", "x", "c", "v", "b", "n", "m", "Spc", "Ret", "Del") },
82
layout = layout.vertical.flex
83
}
84
})
85
kbd.init = true
86
kbd.box.visible = false
87
end
88
89
kbd.box.visible = not kbd.box.visible
90
end })
91
92