From 980c47d775c808d7845c2dce266ee8b4bca472d9 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 22 Jul 2018 16:10:46 -0400 Subject: [PATCH 1/9] tests: Mock capi.keygrabger It will now run "static code" when the module is loaded, so need to exist. --- spec/awful/prompt_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/awful/prompt_spec.lua b/spec/awful/prompt_spec.lua index 41ddce83c..5c7d35274 100644 --- a/spec/awful/prompt_spec.lua +++ b/spec/awful/prompt_spec.lua @@ -46,6 +46,10 @@ insulate('main', function () _G.awesome = { connect_signal = function() end } + _G.keygrabber = { + run = function() end, + stop = function() end, + } -- luacheck: globals string function string.wlen(self) return #self From 3c79f1c8d551759933947647d832aa4391778134 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 21 Jul 2018 14:24:37 -0400 Subject: [PATCH 2/9] awful.key: Add more fields to the description There is currently no centralized way to manage active keybindings so the description data case be used to fill part of that role until an official API is added. --- lib/awful/key.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/awful/key.lua b/lib/awful/key.lua index e7bddf163..87d27ab3f 100644 --- a/lib/awful/key.lua +++ b/lib/awful/key.lua @@ -99,6 +99,8 @@ function key.new(mod, _key, press, release, data) data = data and gtable.clone(data) or {} data.mod = mod data.key = _key + data.press = press + data.release = release table.insert(key.hotkeys, data) data.execute = function(_) key.execute(mod, _key) end From f1245f083c3b93f17eb0a4bb748f5af2f41810ce Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 24 Jul 2018 17:07:11 -0400 Subject: [PATCH 3/9] tests: Add a basic `key` shim --- tests/examples/shims/_common_template.lua | 3 ++- tests/examples/shims/key.lua | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/examples/shims/key.lua diff --git a/tests/examples/shims/_common_template.lua b/tests/examples/shims/_common_template.lua index 80d271c7b..8c31f0283 100644 --- a/tests/examples/shims/_common_template.lua +++ b/tests/examples/shims/_common_template.lua @@ -7,7 +7,7 @@ return function(_, _) -- Set the global shims -- luacheck: globals awesome root tag screen client mouse drawin button - -- luacheck: globals mousegrabber keygrabber dbus + -- luacheck: globals mousegrabber keygrabber dbus key awesome = require( "awesome" ) root = require( "root" ) tag = require( "tag" ) @@ -19,6 +19,7 @@ return function(_, _) keygrabber = require( "keygrabber" ) mousegrabber = require( "mousegrabber" ) dbus = require( "dbus" ) + key = require( "key" ) -- Force luacheck to be silent about setting those as unused globals assert(awesome and root and tag and screen and client and mouse) diff --git a/tests/examples/shims/key.lua b/tests/examples/shims/key.lua new file mode 100644 index 000000000..2936189dc --- /dev/null +++ b/tests/examples/shims/key.lua @@ -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}) From bf6ab0ba4c35362337ea5228ac731e734bec49a1 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 24 Jul 2018 17:08:10 -0400 Subject: [PATCH 4/9] tests: Mock the keyboard layout API enough to stop getting errors. It IS NOT correct, the point is to be able to load the keyboard widget with errors. --- tests/examples/shims/awesome.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/examples/shims/awesome.lua b/tests/examples/shims/awesome.lua index 990a2a224..6af6f0e93 100644 --- a/tests/examples/shims/awesome.lua +++ b/tests/examples/shims/awesome.lua @@ -46,6 +46,14 @@ awesome.startup = true function awesome.register_xproperty() 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 function awesome.pixbuf_to_surface(_, path) From ff9f78ef7eb2840fa5c27c1f8eebe0cb04e6f9b1 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 24 Jul 2018 17:09:16 -0400 Subject: [PATCH 5/9] tests: Add the cursor and focus colors to the generated images theme. --- tests/examples/shims/beautiful.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/examples/shims/beautiful.lua b/tests/examples/shims/beautiful.lua index 7a145d239..b1caef436 100644 --- a/tests/examples/shims/beautiful.lua +++ b/tests/examples/shims/beautiful.lua @@ -29,10 +29,13 @@ end local module = { fg_normal = "#000000" , bg_normal = "#6181FF7D", + bg_focus = "#AA00FF7D", bg_highlight = "#AA00FF7D", border_color = "#6181FF" , border_width = 1.5 , + prompt_bg_cursor = "#00FF7D", + -- Fake resources handling xresources = require("beautiful.xresources"), From 1df44210c81ae5ed3c037adc1346882df95a416e Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 24 Jul 2018 17:09:59 -0400 Subject: [PATCH 6/9] tests: Add many missing client properties so the tilebar loads correctly --- tests/examples/shims/client.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/examples/shims/client.lua b/tests/examples/shims/client.lua index 78790005f..8b3cdda31 100644 --- a/tests/examples/shims/client.lua +++ b/tests/examples/shims/client.lua @@ -31,6 +31,7 @@ function client.gen_fake(args) ret.size_hints = {} ret.border_width = 1 ret.icon_sizes = {{16,16}} + ret.name = "Example Client" -- Apply all properties for k,v in pairs(args or {}) do @@ -120,6 +121,20 @@ function client.gen_fake(args) -- Set the attributes 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 table.insert(clients, ret) From 2c8c274193876f31c1d3725c81f5dbcacf9e044f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 24 Jul 2018 17:11:00 -0400 Subject: [PATCH 7/9] tests: Add the capi.object miss handle support to the capi.mouse shim --- tests/examples/shims/mouse.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/examples/shims/mouse.lua b/tests/examples/shims/mouse.lua index 01d7bb40d..c4766f3b1 100644 --- a/tests/examples/shims/mouse.lua +++ b/tests/examples/shims/mouse.lua @@ -3,7 +3,6 @@ local screen = require("screen") local coords = {x=100,y=100} local mouse = { - screen = screen[1], old_histories = {}, history = {}, } @@ -17,11 +16,35 @@ function mouse.coords(args) return coords 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() table.insert(mouse.old_histories, mouse.history) mouse.history = {} 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 From 3adad38c0a8f833aa6842697d8a6541ebb7ccd92 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 24 Jul 2018 17:12:04 -0400 Subject: [PATCH 8/9] tests: Make the capi.screen shim more robust Also add some private properties to be consumed by the template for a better rendered documentation example image. --- tests/examples/shims/screen.lua | 34 +++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/examples/shims/screen.lua b/tests/examples/shims/screen.lua index f015dab05..09df11089 100644 --- a/tests/examples/shims/screen.lua +++ b/tests/examples/shims/screen.lua @@ -1,10 +1,7 @@ local gears_obj = require("gears.object") local screen, meta = awesome._shim_fake_class() - -function screen.count() - return 1 -end +screen._count = 0 local function create_screen(args) local s = gears_obj() @@ -26,8 +23,18 @@ local function create_screen(args) geo.height = args2.height or geo.height end + s.outputs = { ["LVDS1"] = { + mm_width = 0, + mm_height = 0, + }} + 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) if key == "geometry" then return { @@ -62,6 +69,7 @@ function screen._add_screen(args) screen[#screen+1] = s screen[s] = s + screen._count = screen._count + 1 end function screen._get_extents() @@ -84,6 +92,12 @@ function screen._clear() screen[i] = nil end screens = {} + + if mouse then + mouse.screen = nil + end + + screen._count = 0 end function screen._setup_grid(w, h, rows, args) @@ -91,8 +105,8 @@ function screen._setup_grid(w, h, rows, args) screen._clear() for i, row in ipairs(rows) do for j=1, row do - args.x = (j-1)*w + (j-1)*10 - args.y = (i-1)*h + (i-1)*10 + args.x = (j-1)*w + (j-1)*screen._grid_horizontal_margin + args.y = (i-1)*h + (i-1)*screen._grid_vertical_margin args.width = w args.height = h screen._add_screen(args) @@ -115,6 +129,14 @@ end 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, { __call = iter_scr }) From 6240ec113feab8a5e24810274f4a34d560fecc2f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 24 Jul 2018 17:13:36 -0400 Subject: [PATCH 9/9] tests: Implement keybindings, keygrabber and fake_inputs --- tests/examples/shims/keygrabber.lua | 19 +++-- tests/examples/shims/root.lua | 114 ++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 5 deletions(-) diff --git a/tests/examples/shims/keygrabber.lua b/tests/examples/shims/keygrabber.lua index c778f4ee4..f19d69e5c 100644 --- a/tests/examples/shims/keygrabber.lua +++ b/tests/examples/shims/keygrabber.lua @@ -1,11 +1,20 @@ +-- Needed for root.fake_inputs +local keygrabber = {_current_grabber = nil} -local keygrabber = { - run = function() end, - stop = function() end, - is_running = function() return false end, +local function stop() + keygrabber._current_grabber = nil +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 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/shims/root.lua b/tests/examples/shims/root.lua index dbe8754f2..bc6141873 100644 --- a/tests/examples/shims/root.lua +++ b/tests/examples/shims/root.lua @@ -1,9 +1,123 @@ local root = {_tags={}} +local gtable = require("gears.table") + +local hotkeys = nil + function root:tags() return root._tags 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 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80