From 15b025ff915e41c718d6d37c220ffbe3bee23589 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 2 Jul 2017 10:55:21 -0400 Subject: [PATCH 1/2] tests: Add the theme path ENV variable That way theme assets can be used by the documentation images --- tests/examples/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/examples/CMakeLists.txt b/tests/examples/CMakeLists.txt index ae0a72ce..bf2eda33 100644 --- a/tests/examples/CMakeLists.txt +++ b/tests/examples/CMakeLists.txt @@ -63,6 +63,11 @@ ${LUA_PATH_}") set(LUA_COV_RUNNER env -u LUA_PATH_5_1 -u LUA_PATH_5_2 -u LUA_PATH_5_3 "LUA_PATH=${LUA_PATH_}" ${LUA_COV_RUNNER}) +# Done in 3 variables to avoid CMake from implicitly converting into a list. +set(ENV{LUA_PATH} "${LUA_PATH3_}${LUA_PATH2_}${LUA_PATH_}") + +set(ENV{AWESOME_THEMES_PATH} "${TOP_SOURCE_DIR}/themes/") + # The documentation images directory. set(IMAGE_DIR "${CMAKE_BINARY_DIR}/doc/images") file(MAKE_DIRECTORY "${IMAGE_DIR}") From 8e87bd7c648b19dca9aaa5c0dc74d38b315d295b Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 15 May 2017 02:24:52 -0400 Subject: [PATCH 2/2] tests: Add some methods to the shims --- tests/examples/shims/_common_template.lua | 3 +- tests/examples/shims/awesome.lua | 26 ++++++++++ tests/examples/shims/beautiful.lua | 63 +++++++++++++++++++++++ tests/examples/shims/client.lua | 24 +++++++++ tests/examples/shims/dbus.lua | 13 +++++ tests/examples/shims/drawin.lua | 38 ++++++++++++-- tests/examples/shims/screen.lua | 23 ++++++++- 7 files changed, 184 insertions(+), 6 deletions(-) create mode 100644 tests/examples/shims/dbus.lua diff --git a/tests/examples/shims/_common_template.lua b/tests/examples/shims/_common_template.lua index c1cfd1ce..80d271c7 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 + -- luacheck: globals mousegrabber keygrabber dbus awesome = require( "awesome" ) root = require( "root" ) tag = require( "tag" ) @@ -18,6 +18,7 @@ return function(_, _) button = require( "button" ) keygrabber = require( "keygrabber" ) mousegrabber = require( "mousegrabber" ) + dbus = require( "dbus" ) -- 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/awesome.lua b/tests/examples/shims/awesome.lua index a0e2becc..8db8133c 100644 --- a/tests/examples/shims/awesome.lua +++ b/tests/examples/shims/awesome.lua @@ -1,3 +1,6 @@ +local lgi = require("lgi") +local GdkPixbuf = lgi.GdkPixbuf +local Gdk = lgi.Gdk local gears_obj = require("gears.object") -- Emulate the C API classes. They differ from C API objects as connect_signal @@ -45,6 +48,29 @@ awesome.startup = true function awesome.register_xproperty() end +local init, surfaces = false, {} + +function awesome.load_image(file) + if not init then + Gdk.init{} + init = true + end + + local _, width, height = GdkPixbuf.Pixbuf.get_file_info(file) + + local pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, width, height) + + if not pixbuf then + return nil, "Could not load "..file + end + + local s = Gdk.cairo_surface_create_from_pixbuf( pixbuf, 1, nil ) + + table.insert(surfaces, s) + + return s._native, not s and "Could not load surface from "..file or nil, s +end + -- Always show deprecated messages awesome.version = "v9999" diff --git a/tests/examples/shims/beautiful.lua b/tests/examples/shims/beautiful.lua index d9f96fff..7a145d23 100644 --- a/tests/examples/shims/beautiful.lua +++ b/tests/examples/shims/beautiful.lua @@ -51,6 +51,69 @@ function module.get_font() return f end +function module.get_font_height() + return 9 +end + +------------------------------------------------------------------ +-- Import the titlebar and layout assets from the default theme -- +------------------------------------------------------------------ + +-- It's fine as long as gears doesn't depend on CAPI and $AWESOME_THEMES_PATH is set. +local themes_path = require("gears.filesystem").get_themes_dir() + +-- Define the image to load +module.titlebar_close_button_normal = themes_path.."default/titlebar/close_normal.png" +module.titlebar_close_button_focus = themes_path.."default/titlebar/close_focus.png" + +module.titlebar_minimize_button_normal = themes_path.."default/titlebar/minimize_normal.png" +module.titlebar_minimize_button_focus = themes_path.."default/titlebar/minimize_focus.png" + +module.titlebar_ontop_button_normal_inactive = themes_path.."default/titlebar/ontop_normal_inactive.png" +module.titlebar_ontop_button_focus_inactive = themes_path.."default/titlebar/ontop_focus_inactive.png" +module.titlebar_ontop_button_normal_active = themes_path.."default/titlebar/ontop_normal_active.png" +module.titlebar_ontop_button_focus_active = themes_path.."default/titlebar/ontop_focus_active.png" + +module.titlebar_sticky_button_normal_inactive = themes_path.."default/titlebar/sticky_normal_inactive.png" +module.titlebar_sticky_button_focus_inactive = themes_path.."default/titlebar/sticky_focus_inactive.png" +module.titlebar_sticky_button_normal_active = themes_path.."default/titlebar/sticky_normal_active.png" +module.titlebar_sticky_button_focus_active = themes_path.."default/titlebar/sticky_focus_active.png" + +module.titlebar_floating_button_normal_inactive = themes_path.."default/titlebar/floating_normal_inactive.png" +module.titlebar_floating_button_focus_inactive = themes_path.."default/titlebar/floating_focus_inactive.png" +module.titlebar_floating_button_normal_active = themes_path.."default/titlebar/floating_normal_active.png" +module.titlebar_floating_button_focus_active = themes_path.."default/titlebar/floating_focus_active.png" + +module.titlebar_maximized_button_normal_inactive = themes_path.."default/titlebar/maximized_normal_inactive.png" +module.titlebar_maximized_button_focus_inactive = themes_path.."default/titlebar/maximized_focus_inactive.png" +module.titlebar_maximized_button_normal_active = themes_path.."default/titlebar/maximized_normal_active.png" +module.titlebar_maximized_button_focus_active = themes_path.."default/titlebar/maximized_focus_active.png" + +module.wallpaper = themes_path.."default/background.png" + +-- You can use your own layout icons like this: +module.layout_fairh = themes_path.."default/layouts/fairhw.png" +module.layout_fairv = themes_path.."default/layouts/fairvw.png" +module.layout_floating = themes_path.."default/layouts/floatingw.png" +module.layout_magnifier = themes_path.."default/layouts/magnifierw.png" +module.layout_max = themes_path.."default/layouts/maxw.png" +module.layout_fullscreen = themes_path.."default/layouts/fullscreenw.png" +module.layout_tilebottom = themes_path.."default/layouts/tilebottomw.png" +module.layout_tileleft = themes_path.."default/layouts/tileleftw.png" +module.layout_tile = themes_path.."default/layouts/tilew.png" +module.layout_tiletop = themes_path.."default/layouts/tiletopw.png" +module.layout_spiral = themes_path.."default/layouts/spiralw.png" +module.layout_dwindle = themes_path.."default/layouts/dwindlew.png" +module.layout_cornernw = themes_path.."default/layouts/cornernww.png" +module.layout_cornerne = themes_path.."default/layouts/cornernew.png" +module.layout_cornersw = themes_path.."default/layouts/cornersww.png" +module.layout_cornerse = themes_path.."default/layouts/cornersew.png" + +-- Taglist +module.taglist_bg_focus = module.bg_highlight +module.taglist_bg_used = module.bg_normal + + function module.get() return module end diff --git a/tests/examples/shims/client.lua b/tests/examples/shims/client.lua index f5b61fad..78790005 100644 --- a/tests/examples/shims/client.lua +++ b/tests/examples/shims/client.lua @@ -14,6 +14,14 @@ end -- CURRENTLY UNUSED -- end +local function titlebar_meta(c) + for _, position in ipairs {"top", "bottom", "left", "right" } do + c["titlebar_"..position] = function(size) --luacheck: no unused + return drawin{} + end + end +end + -- Create fake clients to move around function client.gen_fake(args) local ret = gears_obj() @@ -22,6 +30,7 @@ function client.gen_fake(args) ret.valid = true ret.size_hints = {} ret.border_width = 1 + ret.icon_sizes = {{16,16}} -- Apply all properties for k,v in pairs(args or {}) do @@ -71,6 +80,20 @@ function client.gen_fake(args) return nil end + function ret:get_icon(_) + return require("beautiful").awesome_icon + end + + function ret:raise() + --TODO + end + + function ret:lower() + --TODO + end + + titlebar_meta(ret) + function ret:tags(new) --FIXME if new then ret._tags = new @@ -92,6 +115,7 @@ function client.gen_fake(args) -- Record the geometry ret._old_geo = {} push_geometry(ret) + ret._old_geo[1]._hide = args.hide_first -- Set the attributes ret.screen = args.screen or screen[1] diff --git a/tests/examples/shims/dbus.lua b/tests/examples/shims/dbus.lua new file mode 100644 index 00000000..f0e301e5 --- /dev/null +++ b/tests/examples/shims/dbus.lua @@ -0,0 +1,13 @@ +local dbus = awesome._shim_fake_class() + +function dbus.notify_send(...) + dbus.emit_signal("org.freedesktop.Notifications", ...) +end + +function dbus.request_name() + -- Ignore +end + +return dbus + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/shims/drawin.lua b/tests/examples/shims/drawin.lua index 689aba32..121a7a8d 100644 --- a/tests/examples/shims/drawin.lua +++ b/tests/examples/shims/drawin.lua @@ -1,19 +1,51 @@ local gears_obj = require("gears.object") local drawin, meta = awesome._shim_fake_class() +local drawins = setmetatable({}, {__mode="v"}) local function new_drawin(_, args) local ret = gears_obj() ret.data = {drawable = gears_obj()} - for k, v in pairs(args) do - rawset(ret, k, v) + ret.x=0 + ret.y=0 + ret.width=1 + ret.height=1 + + ret.geometry = function(_, new) + new = new or {} + ret.x = new.x or ret.x + ret.y = new.y or ret.y + ret.width = new.width or ret.width + ret.height = new.height or ret.height + return { + x = ret.x, + y = ret.y, + width = ret.width, + height = ret.height + } end - return setmetatable(ret, { + for _, k in pairs{ "buttons", "struts", "get_xproperty", "set_xproperty" } do + ret[k] = function() end + end + + local md = setmetatable(ret, { __index = function(...) return meta.__index(...) end, __newindex = function(...) return meta.__newindex(...) end }) + + for k, v in pairs(args) do + ret[k] = v + end + + table.insert(drawins, md) + + return md +end + +function drawin.get() + return drawins end return setmetatable(drawin, { diff --git a/tests/examples/shims/screen.lua b/tests/examples/shims/screen.lua index fef1af19..6e5d59dd 100644 --- a/tests/examples/shims/screen.lua +++ b/tests/examples/shims/screen.lua @@ -7,6 +7,7 @@ screen.count = 1 local function create_screen(args) local s = gears_obj() s.data = {} + s.valid = true -- Copy the geo in case the args are mutated local geo = { @@ -53,7 +54,10 @@ local screens = {} function screen._add_screen(args) local s = create_screen(args) table.insert(screens, s) - s.index = #screens + + -- Skip the metatable or it will have side effects + rawset(s, "index", #screens) + screen[#screen+1] = s screen[s] = s end @@ -94,8 +98,23 @@ function screen._setup_grid(w, h, rows, args) end end +local function iter_scr(_, _, s) + if not s then + assert(screen[1]) + return screen[1], 1 + end + + local i = s.index + + if i + 1 < #screen then + return screen[i+1], i+1 + end +end + screen._add_screen {width=320, height=240} -return screen +return setmetatable(screen, { + __call = iter_scr +}) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80