Proper event handling for Linux. Xpra CSS

This commit is contained in:
Empathic Qubit 2021-04-28 23:18:26 -04:00
parent 5ea3c30457
commit 36e7e75213
5 changed files with 79 additions and 18 deletions

View file

@ -35,7 +35,7 @@ _M.Filename = _M.PoolDir .. _M.State[1]
_M.StartPowerup = 0
_M.NeatConfig = {
Threads = 4,
Threads = 8,
--Filename = "DP1.state",
SaveFile = _M.Filename .. ".pool",
Filename = _M.Filename,

View file

@ -17,7 +17,7 @@ local statusLine = nil
local statusColor = 0x0000ff00
local species = nil
local speciesId = nil
local speciesId = -1
local generationIndex = nil
local runner = Runner()
@ -99,13 +99,16 @@ local function waitLoop()
print('Received input from master process')
local inputFile = io.open(inputFilePath, 'r')
local ok, inputData = serpent.load(inputFile:read('*a'))
inputFile:close()
local inputData = nil
local ok = false
while not ok or inputData == nil or speciesId == inputData[1].id do
local inputFile = io.open(inputFilePath, 'r')
ok, inputData = serpent.load(inputFile:read('*a'))
inputFile:close()
if not ok then
print("Deserialization error")
return
if not ok then
print("Deserialization error")
end
end
species = inputData[1]

View file

@ -20,7 +20,6 @@ for i=1,#temps,1 do
end
local tmpFileName = tempDir.."/donk_runner_"..
string.hex(math.floor(random.integer(0, 0xffffffff)))..
string.hex(math.floor(random.integer(0, 0xffffffff)))
@ -96,10 +95,24 @@ return function()
-- FIXME Linux
end
local inputPrefix = tmpFileName..'_input_'
local outputPrefix = tmpFileName..'_output_'
-- Create the input files and output files
for i=1,#species,1 do
local inputFileName = inputPrefix..i
local inputFile = io.open(inputFileName, 'a')
inputFile:close()
local outputFileName = outputPrefix..i
local outputFile = io.open(outputFileName, 'a')
outputFile:close()
end
while #_M.poppets < #species do
local i = #_M.poppets+1
local outputFileName = tmpFileName..'_output_'..i
local inputFileName = tmpFileName.."_input_"..i
local outputFileName = outputPrefix..i
local inputFileName = inputPrefix..i
message(_M, hostProcess)
@ -118,12 +131,17 @@ return function()
util.closeCmd(waiter)
end
local outputFileName = tmpFileName..'_output_*'
local waiter = util.waitForChange(outputFileName, #species)
local waiters = {}
for i=1,#species,1 do
table.insert(waiters, outputPrefix..i)
end
local waiter = util.waitForChange(waiters, nil, tmpFileName.."output_*")
message(_M, 'Setting up child processes')
for i=1,#species,1 do
local inputFileName = tmpFileName.."_input_"..i
local inputFile = io.open(inputFileName, 'w')
inputFile:write(serpent.dump({species[i], generationIdx}))

View file

@ -72,20 +72,48 @@ function _M.closeCmd(handle)
end
end
function _M.waitForChange(filename, count)
function _M.waitForChange(filenames, count, wild)
if type(filenames) == 'string' then
if wild == nil then
wild = filenames
end
filenames = {filenames}
end
if count == nil then
count = 1
count = #filenames
end
if _M.isWin then
local sec, usec = utime()
print(string.format('Starting watching file at %d', sec * 1000000 + usec))
return _M.popenCmd([[powershell "$filename = ']]..filename..
return _M.popenCmd([[powershell "$filename = ']]..wild..
[[' ; $targetCount = ]]..count..[[ ; $count = 0 ; Register-ObjectEvent (New-Object IO.FileSystemWatcher (Split-Path $filename), (Split-Path -Leaf $filename) -Property @{ IncludeSubdirectories = $false ; NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}) -EventName Changed -SourceIdentifier RunnerDataChanged -Action { $count += 1 ; if ( $count -ge $targetCount ) { [Environment]::Exit(0) } } ; while($true) { Start-Sleep -Milliseconds 1 }"]])
else
error("Not implemented")
-- FIXME Linux
local watchCmd = ''
if count == 1 then
watchCmd = [[which inotifywait >/dev/null && { inotifywait -q -e close_write ']]..filenames[1]..[[' || exit 0 ; }]]
else
watchCmd = [[bash <<'EOF'
COUNT=]]..count..[[
FILENAMES=(']]..table.concat(filenames, "' '")..[[')
declare -A SEEN
((I = 0))
set -m
which inotifywait >/dev/null
( inotifywait -q -m -e close_write "${FILENAMES[@]}" | while read LINE ; do
SEEN["$LINE"]=1
TOTAL=${#SEEN[@]}
if ((TOTAL == COUNT)) ; then
kill -s TERM 0
fi
done ) &
wait
EOF]]
end
return _M.popenCmd(watchCmd)
end
end

12
xpra.css Normal file
View file

@ -0,0 +1,12 @@
.wmclass-Lsnes {
display: block;
position: relative;
top: 0 !important;
left: 0 !important;
}
#screen {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}