-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.lua
114 lines (93 loc) · 2.42 KB
/
window.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
local pty = require("lpty")
local time = require("time")
local window = {}
window.client = {}
window.server = {}
function window.server.new()
local server = {}
local windows = {}
local widgets = {}
local clients = {}
function server.start_client_local(...)
local client = {
type = "pty",
id = "pty_client:"time.realtime(),
render_queue = {},
}
local client_pty = pty.new({
no_local_echo = {}
})
local env = client_pty:getenviron()
env["IS_WINDOW_CLIENT"] = "y"
client_pty:start_proc(...)
function client:read()
if client_pty:readok() then
return client_pty:readline(false, 0)
end
end
function client:write(line)
if client_pty:sendok() then
client_pty:send(line .. "\n")
end
end
function client:close(kill)
client_pty:endproc(kill)
for i,client in ipairs(clients) do
if client == self then
table.remove(clients, i)
end
end
end
table.insert(clients, client)
end
function server.loop()
local function handle_line(client, line)
local command, data = line:match("^([%a%d%.:_-]+):(.*)$")
if command == "create_drawbuffer" then
local name,w,h = data:match("^(%a%d%.:_-):(%d+):(%d+)$")
if name and tonumber(w) and tonumber(h) then
local db = lfb.new_drawbuffer(w,h)
db:clear(0,0,0,255)
table.insert(client.render_queue, {
db = db,
name = name,
client = client,
x = 0,
y = 0,
w = w,
h = h,
visible = false,
title = "",
order = 1000+#client.render_queue,
flags = {
window = false,
-- should this drabuffer be decorated as a window?
widget = false,
-- should this drabuffer be a desktop widget?
}
})
client:write("create_drawbuffer:ok:" .. #render_queue)
else
client:write("create_drawbuffer:fail")
end
elseif command == "db_copy_vline" then
elseif command == "db_copy_hline" then
elseif command == "db_set_pixel" then
elseif command == "db_copy_rect" then
elseif command == "db_set_title" then
else
print("Unknown command: " .. tostring(command) .. "(from line " .. tostring(line) .. " by client " .. client.id .. ")")
client:close()
end
end
for i,client in ipairs(clients) do
local line = client:read()
if line then
handle_line(line)
end
end
-- read all server input devices
-- render all drawbuffers
end
return server
end