Proper event handling for Linux. Xpra CSS
This commit is contained in:
parent
5ea3c30457
commit
36e7e75213
5 changed files with 79 additions and 18 deletions
|
@ -35,7 +35,7 @@ _M.Filename = _M.PoolDir .. _M.State[1]
|
||||||
_M.StartPowerup = 0
|
_M.StartPowerup = 0
|
||||||
|
|
||||||
_M.NeatConfig = {
|
_M.NeatConfig = {
|
||||||
Threads = 4,
|
Threads = 8,
|
||||||
--Filename = "DP1.state",
|
--Filename = "DP1.state",
|
||||||
SaveFile = _M.Filename .. ".pool",
|
SaveFile = _M.Filename .. ".pool",
|
||||||
Filename = _M.Filename,
|
Filename = _M.Filename,
|
||||||
|
|
|
@ -17,7 +17,7 @@ local statusLine = nil
|
||||||
local statusColor = 0x0000ff00
|
local statusColor = 0x0000ff00
|
||||||
|
|
||||||
local species = nil
|
local species = nil
|
||||||
local speciesId = nil
|
local speciesId = -1
|
||||||
local generationIndex = nil
|
local generationIndex = nil
|
||||||
|
|
||||||
local runner = Runner()
|
local runner = Runner()
|
||||||
|
@ -99,13 +99,16 @@ local function waitLoop()
|
||||||
|
|
||||||
print('Received input from master process')
|
print('Received input from master process')
|
||||||
|
|
||||||
|
local inputData = nil
|
||||||
|
local ok = false
|
||||||
|
while not ok or inputData == nil or speciesId == inputData[1].id do
|
||||||
local inputFile = io.open(inputFilePath, 'r')
|
local inputFile = io.open(inputFilePath, 'r')
|
||||||
local ok, inputData = serpent.load(inputFile:read('*a'))
|
ok, inputData = serpent.load(inputFile:read('*a'))
|
||||||
inputFile:close()
|
inputFile:close()
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
print("Deserialization error")
|
print("Deserialization error")
|
||||||
return
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
species = inputData[1]
|
species = inputData[1]
|
||||||
|
|
|
@ -20,7 +20,6 @@ for i=1,#temps,1 do
|
||||||
end
|
end
|
||||||
|
|
||||||
local tmpFileName = tempDir.."/donk_runner_"..
|
local tmpFileName = tempDir.."/donk_runner_"..
|
||||||
|
|
||||||
string.hex(math.floor(random.integer(0, 0xffffffff)))..
|
string.hex(math.floor(random.integer(0, 0xffffffff)))..
|
||||||
string.hex(math.floor(random.integer(0, 0xffffffff)))
|
string.hex(math.floor(random.integer(0, 0xffffffff)))
|
||||||
|
|
||||||
|
@ -96,10 +95,24 @@ return function()
|
||||||
-- FIXME Linux
|
-- FIXME Linux
|
||||||
end
|
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
|
while #_M.poppets < #species do
|
||||||
local i = #_M.poppets+1
|
local i = #_M.poppets+1
|
||||||
local outputFileName = tmpFileName..'_output_'..i
|
local outputFileName = outputPrefix..i
|
||||||
local inputFileName = tmpFileName.."_input_"..i
|
local inputFileName = inputPrefix..i
|
||||||
|
|
||||||
message(_M, hostProcess)
|
message(_M, hostProcess)
|
||||||
|
|
||||||
|
@ -118,12 +131,17 @@ return function()
|
||||||
util.closeCmd(waiter)
|
util.closeCmd(waiter)
|
||||||
end
|
end
|
||||||
|
|
||||||
local outputFileName = tmpFileName..'_output_*'
|
local waiters = {}
|
||||||
local waiter = util.waitForChange(outputFileName, #species)
|
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')
|
message(_M, 'Setting up child processes')
|
||||||
|
|
||||||
for i=1,#species,1 do
|
for i=1,#species,1 do
|
||||||
|
|
||||||
local inputFileName = tmpFileName.."_input_"..i
|
local inputFileName = tmpFileName.."_input_"..i
|
||||||
local inputFile = io.open(inputFileName, 'w')
|
local inputFile = io.open(inputFileName, 'w')
|
||||||
inputFile:write(serpent.dump({species[i], generationIdx}))
|
inputFile:write(serpent.dump({species[i], generationIdx}))
|
||||||
|
|
38
util.lua
38
util.lua
|
@ -72,20 +72,48 @@ function _M.closeCmd(handle)
|
||||||
end
|
end
|
||||||
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
|
if count == nil then
|
||||||
count = 1
|
count = #filenames
|
||||||
end
|
end
|
||||||
|
|
||||||
if _M.isWin then
|
if _M.isWin then
|
||||||
local sec, usec = utime()
|
local sec, usec = utime()
|
||||||
print(string.format('Starting watching file at %d', sec * 1000000 + usec))
|
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 }"]])
|
[[' ; $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
|
else
|
||||||
error("Not implemented")
|
local watchCmd = ''
|
||||||
-- FIXME Linux
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
12
xpra.css
Normal file
12
xpra.css
Normal 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;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue