From f8b735fa24cdc0a5d8f653d84dbfa512ba2e552b Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 8 Jan 2017 15:14:08 +0100 Subject: [PATCH] test client: Add support for setting some size hints This adds a new argument to the test client spawning function that will make the test client window set a resize increment property. The API here is starting to a bit ugly, but since this is not any user facing API, that should not be a problem. Signed-off-by: Uli Schlachter --- tests/_client.lua | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/_client.lua b/tests/_client.lua index 18435527c..f6b839a80 100644 --- a/tests/_client.lua +++ b/tests/_client.lua @@ -5,30 +5,47 @@ local spawn = require("awful.spawn") local test_client_source = [[ local lgi = require 'lgi' +local Gdk = lgi.require('Gdk') local Gtk = lgi.require('Gtk') local Gio = lgi.require('Gio') Gtk.init() -local function open_window(class, title, snid) +local function open_window(class, title, options) local window = Gtk.Window { default_width = 100, default_height = 100, title = title } - if snid ~= "" then - window:set_startup_id(snid) + if options.snid and options.snid ~= "" then + window:set_startup_id(options.snid) + end + if options.resize_increment then + local geom = Gdk.Geometry { + width_inc = 200, + height_inc = 200, + } + window:set_geometry_hints(nil, geom, Gdk.WindowHints.RESIZE_INC) end window:set_wmclass(class, class) window:show_all() end +local function parse_options(options) + local result = {} + for word in string.gmatch(options, "([^,]+)") do + local key, value = string.match(word, "([^=]+)=?(.*)") + result[key] = value + end + return result +end + -- Start a coroutine for nicer input handling local coro = coroutine.wrap(function() while true do local class = coroutine.yield() local title = coroutine.yield() - local snid = coroutine.yield() - open_window(class, title, snid) + local options = coroutine.yield() + open_window(class, title, parse_options(options)) end end) coro() @@ -86,13 +103,21 @@ local function get_snid(sn_rules, callback) return snid end -return function(class, title, sn_rules, callback) +return function(class, title, sn_rules, callback, resize_increment) class = class or "test_app" title = title or "Awesome test client" init() - local snid = (sn_rules or callback) and get_snid(sn_rules, callback) or "" - local data = class .. "\n" .. title .. "\n" .. snid .. "\n" + local options = "" + local snid + if sn_rules or callback then + snid = get_snid(sn_rules, callback) + options = options .. "snid=" .. snid .. "," + end + if resize_increment then + options = options .. "resize_increment," + end + local data = class .. "\n" .. title .. "\n" .. options .. "\n" local success, msg = pipe:write_all(data) assert(success, tostring(msg))