mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
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 <psychon@znc.in>
This commit is contained in:
parent
aab37dc629
commit
f8b735fa24
1 changed files with 33 additions and 8 deletions
|
@ -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))
|
||||
|
||||
|
|
Loading…
Reference in a new issue