Merge pull request #2313 from Elv13/update_shims

Update the shims to be able to emulate the default rc.lua (look&feel) without errors.
This commit is contained in:
Emmanuel Lepage Vallée 2018-07-29 15:33:54 -04:00 committed by GitHub
commit 321eb30ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 221 additions and 14 deletions

View File

@ -99,6 +99,8 @@ function key.new(mod, _key, press, release, data)
data = data and gtable.clone(data) or {} data = data and gtable.clone(data) or {}
data.mod = mod data.mod = mod
data.key = _key data.key = _key
data.press = press
data.release = release
table.insert(key.hotkeys, data) table.insert(key.hotkeys, data)
data.execute = function(_) key.execute(mod, _key) end data.execute = function(_) key.execute(mod, _key) end

View File

@ -46,6 +46,10 @@ insulate('main', function ()
_G.awesome = { _G.awesome = {
connect_signal = function() end connect_signal = function() end
} }
_G.keygrabber = {
run = function() end,
stop = function() end,
}
-- luacheck: globals string -- luacheck: globals string
function string.wlen(self) function string.wlen(self)
return #self return #self

View File

@ -7,7 +7,7 @@ return function(_, _)
-- Set the global shims -- Set the global shims
-- luacheck: globals awesome root tag screen client mouse drawin button -- luacheck: globals awesome root tag screen client mouse drawin button
-- luacheck: globals mousegrabber keygrabber dbus -- luacheck: globals mousegrabber keygrabber dbus key
awesome = require( "awesome" ) awesome = require( "awesome" )
root = require( "root" ) root = require( "root" )
tag = require( "tag" ) tag = require( "tag" )
@ -19,6 +19,7 @@ return function(_, _)
keygrabber = require( "keygrabber" ) keygrabber = require( "keygrabber" )
mousegrabber = require( "mousegrabber" ) mousegrabber = require( "mousegrabber" )
dbus = require( "dbus" ) dbus = require( "dbus" )
key = require( "key" )
-- Force luacheck to be silent about setting those as unused globals -- Force luacheck to be silent about setting those as unused globals
assert(awesome and root and tag and screen and client and mouse) assert(awesome and root and tag and screen and client and mouse)

View File

@ -46,6 +46,14 @@ awesome.startup = true
function awesome.register_xproperty() function awesome.register_xproperty()
end end
function awesome.xkb_get_group_names()
return "pc+us+inet(evdev)"
end
function awesome.xkb_get_layout_group()
return 0
end
awesome.load_image = lgi.cairo.ImageSurface.create_from_png awesome.load_image = lgi.cairo.ImageSurface.create_from_png
function awesome.pixbuf_to_surface(_, path) function awesome.pixbuf_to_surface(_, path)

View File

@ -29,10 +29,13 @@ end
local module = { local module = {
fg_normal = "#000000" , fg_normal = "#000000" ,
bg_normal = "#6181FF7D", bg_normal = "#6181FF7D",
bg_focus = "#AA00FF7D",
bg_highlight = "#AA00FF7D", bg_highlight = "#AA00FF7D",
border_color = "#6181FF" , border_color = "#6181FF" ,
border_width = 1.5 , border_width = 1.5 ,
prompt_bg_cursor = "#00FF7D",
-- Fake resources handling -- Fake resources handling
xresources = require("beautiful.xresources"), xresources = require("beautiful.xresources"),

View File

@ -31,6 +31,7 @@ function client.gen_fake(args)
ret.size_hints = {} ret.size_hints = {}
ret.border_width = 1 ret.border_width = 1
ret.icon_sizes = {{16,16}} ret.icon_sizes = {{16,16}}
ret.name = "Example Client"
-- Apply all properties -- Apply all properties
for k,v in pairs(args or {}) do for k,v in pairs(args or {}) do
@ -120,6 +121,20 @@ function client.gen_fake(args)
-- Set the attributes -- Set the attributes
ret.screen = args.screen or screen[1] ret.screen = args.screen or screen[1]
-- Good enough for the geometry and border
ret.drawin = ret
ret.drawable = ret
-- Make sure the layer properties are not `nil`
ret.ontop = false
ret.below = false
ret.above = false
ret.sticky = false
ret.maximized = false
ret.fullscreen = false
ret.maximized_vertical = false
ret.maximized_horizontal = false
-- Add to the client list -- Add to the client list
table.insert(clients, ret) table.insert(clients, ret)

View File

@ -0,0 +1,6 @@
local gobject = require("gears.object")
local gtable = require("gears.table")
return setmetatable({}, {__call = function(_, args)
return gtable.crush(gobject(), args)
end})

View File

@ -1,11 +1,20 @@
-- Needed for root.fake_inputs
local keygrabber = {_current_grabber = nil}
local keygrabber = { local function stop()
run = function() end, keygrabber._current_grabber = nil
stop = function() end, end
is_running = function() return false end,
local function run(grabber)
keygrabber._current_grabber = grabber
end
keygrabber = {
run = run,
stop = stop,
isrunning = function() return keygrabber._current_grabber ~= nil end,
} }
return keygrabber return keygrabber
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -3,7 +3,6 @@ local screen = require("screen")
local coords = {x=100,y=100} local coords = {x=100,y=100}
local mouse = { local mouse = {
screen = screen[1],
old_histories = {}, old_histories = {},
history = {}, history = {},
} }
@ -17,11 +16,35 @@ function mouse.coords(args)
return coords return coords
end end
function mouse.set_newindex_miss_handler(h)
rawset(mouse, "_ni_handler", h)
end
function mouse.set_index_miss_handler(h)
rawset(mouse, "_i_handler", h)
end
function mouse.push_history() function mouse.push_history()
table.insert(mouse.old_histories, mouse.history) table.insert(mouse.old_histories, mouse.history)
mouse.history = {} mouse.history = {}
end end
return mouse return setmetatable(mouse, {
__index = function(self, key)
if key == "screen" then
return screen[1]
end
local h = rawget(mouse,"_i_handler")
if h then
return h(self, key)
end
end,
__newindex = function(...)
local h = rawget(mouse,"_ni_handler")
if h then
h(...)
end
end,
})
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,9 +1,123 @@
local root = {_tags={}} local root = {_tags={}}
local gtable = require("gears.table")
local hotkeys = nil
function root:tags() function root:tags()
return root._tags return root._tags
end end
function root:size() --TODO use the screens
return 0, 0
end
function root:size_mm()
return 0, 0
end
function root.cursor() end
-- GLOBAL KEYBINDINGS --
local keys = {}
function root.keys(k)
keys = k or keys
return keys
end
-- FAKE INPUTS --
-- Turn keysym into modkey names
local conversion = {
Super_L = "Mod4",
Control_L = "Control",
Shift_L = "Shift",
Alt_L = "Mod1",
Super_R = "Mod4",
Control_R = "Control",
Shift_R = "Shift",
Alt_R = "Mod1",
}
-- The currently pressed modkeys.
local mods = {}
local function get_mods()
local ret = {}
for mod in pairs(mods) do
table.insert(ret, mod)
end
return ret
end
local function add_modkey(key)
if not conversion[key] then return end
mods[conversion[key]] = true
end
local function remove_modkey(key)
if not conversion[key] then return end
mods[conversion[key]] = nil
end
local function match_modifiers(mods1, mods2)
if #mods1 ~= #mods2 then return false end
for _, mod1 in ipairs(mods1) do
if not gtable.hasitem(mods2, mod1) then
return false
end
end
return true
end
local function execute_keybinding(key, event)
-- It *could* be extracted from gears.object private API, but it's equally
-- ugly as using the list used by the hotkey widget.
if not hotkeys then
hotkeys = require("awful.key").hotkeys
end
for _, v in ipairs(hotkeys) do
if key == v.key and match_modifiers(v.mod, get_mods()) and v[event] then
v[event]()
return
end
end
end
local fake_input_handlers = {
key_press = function(key)
add_modkey(key)
if keygrabber._current_grabber then
keygrabber._current_grabber(get_mods(), key, "press")
else
execute_keybinding(key, "press")
end
end,
key_release = function(key)
remove_modkey(key)
if keygrabber._current_grabber then
keygrabber._current_grabber(get_mods(), key, "release")
else
execute_keybinding(key, "release")
end
end,
button_press = function() --[[TODO]] end,
button_release = function() --[[TODO]] end,
motion_notify = function() --[[TODO]] end,
}
function root.fake_inputs(event_type, detail, x, y)
assert(fake_input_handlers[event_type], "Unknown event_type")
fake_input_handlers[event_type](detail, x, y)
end
return root return root
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,10 +1,7 @@
local gears_obj = require("gears.object") local gears_obj = require("gears.object")
local screen, meta = awesome._shim_fake_class() local screen, meta = awesome._shim_fake_class()
screen._count = 0
function screen.count()
return 1
end
local function create_screen(args) local function create_screen(args)
local s = gears_obj() local s = gears_obj()
@ -26,8 +23,18 @@ local function create_screen(args)
geo.height = args2.height or geo.height geo.height = args2.height or geo.height
end end
s.outputs = { ["LVDS1"] = {
mm_width = 0,
mm_height = 0,
}}
local wa = args.workarea_sides or 10 local wa = args.workarea_sides or 10
-- This will happen if `clear()` is called
if mouse and not mouse.screen then
mouse.screen = s
end
return setmetatable(s,{ __index = function(_, key) return setmetatable(s,{ __index = function(_, key)
if key == "geometry" then if key == "geometry" then
return { return {
@ -62,6 +69,7 @@ function screen._add_screen(args)
screen[#screen+1] = s screen[#screen+1] = s
screen[s] = s screen[s] = s
screen._count = screen._count + 1
end end
function screen._get_extents() function screen._get_extents()
@ -84,6 +92,12 @@ function screen._clear()
screen[i] = nil screen[i] = nil
end end
screens = {} screens = {}
if mouse then
mouse.screen = nil
end
screen._count = 0
end end
function screen._setup_grid(w, h, rows, args) function screen._setup_grid(w, h, rows, args)
@ -91,8 +105,8 @@ function screen._setup_grid(w, h, rows, args)
screen._clear() screen._clear()
for i, row in ipairs(rows) do for i, row in ipairs(rows) do
for j=1, row do for j=1, row do
args.x = (j-1)*w + (j-1)*10 args.x = (j-1)*w + (j-1)*screen._grid_horizontal_margin
args.y = (i-1)*h + (i-1)*10 args.y = (i-1)*h + (i-1)*screen._grid_vertical_margin
args.width = w args.width = w
args.height = h args.height = h
screen._add_screen(args) screen._add_screen(args)
@ -115,6 +129,14 @@ end
screen._add_screen {width=320, height=240} screen._add_screen {width=320, height=240}
screen._grid_vertical_margin = 10
screen._grid_horizontal_margin = 10
function screen.count()
return screen._count
end
return setmetatable(screen, { return setmetatable(screen, {
__call = iter_scr __call = iter_scr
}) })