forked from izaya/LuPPC
Basic Windows input, Fixed multiple issues
- Unicode iteration is some gpu functions was broken - Fixed native sleep - Fixed keyboard component registration for fb/win GPU - Fixed (workaround) tmp for windows
This commit is contained in:
parent
4a3242eb3e
commit
65ea917720
@ -8,10 +8,12 @@
|
|||||||
void logn(const char *message);
|
void logn(const char *message);
|
||||||
void logi(int message);
|
void logi(int message);
|
||||||
void logm(const char *message);
|
void logm(const char *message);
|
||||||
|
void logt(const char *message);
|
||||||
#else
|
#else
|
||||||
#define logn(m)
|
#define logn(m)
|
||||||
#define logi(m)
|
#define logi(m)
|
||||||
#define logm(m)
|
#define logm(m)
|
||||||
|
#define logt(m)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define pushstuple(state, name, value) lua_pushstring((state), (name)); lua_pushstring((state), (value)); lua_settable((state), -3)
|
#define pushstuple(state, name, value) lua_pushstring((state), (name)); lua_pushstring((state), (value)); lua_settable((state), -3)
|
||||||
|
@ -6,19 +6,68 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#define WIN32
|
#define WIN32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define LOCAL_SOCKETPAIR_AF AF_INET
|
||||||
|
#else
|
||||||
|
#define LOCAL_SOCKETPAIR_AF AF_UNIX
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <event2/event.h>
|
#include <event2/event.h>
|
||||||
#include <event2/event_struct.h>
|
#include <event2/event_struct.h>
|
||||||
|
|
||||||
struct event_base *base;
|
struct event_base *base;
|
||||||
struct event stdinEvent;
|
struct event stdinEvent;
|
||||||
|
|
||||||
int nevt = 0;
|
int nevt = 0;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
struct event winEvent;
|
||||||
|
evutil_socket_t pfd[2] = {0,0};
|
||||||
|
|
||||||
|
void pokeWinEvt(char ch) {
|
||||||
|
send(pfd[1], &ch, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handleWinevent(evutil_socket_t fd, short what, void *ptr) {
|
||||||
|
if(what != EV_READ) return;
|
||||||
|
|
||||||
|
char buf;
|
||||||
|
int r = recv(fd, &buf, 1, 0); /* TODO: Wide chars? */
|
||||||
|
if(r > 0) {
|
||||||
|
logi(buf);
|
||||||
|
logn(" < win char");
|
||||||
|
lua_State* L = getL();
|
||||||
|
|
||||||
|
lua_getglobal(L, "pushEvent");
|
||||||
|
lua_pushstring(L, "key_down");
|
||||||
|
lua_pushstring(L, "TODO:SetThisUuid");/* Also in textgpu.lua */
|
||||||
|
lua_pushnumber(L, buf);
|
||||||
|
lua_pushnumber(L, -1);
|
||||||
|
lua_pushstring(L, "root");
|
||||||
|
lua_call(L, 5, 0);
|
||||||
|
|
||||||
|
lua_getglobal(L, "pushEvent");
|
||||||
|
lua_pushstring(L, "key_up");
|
||||||
|
lua_pushstring(L, "TODO:SetThisUuid");
|
||||||
|
lua_pushnumber(L, buf);
|
||||||
|
lua_pushnumber(L, -1);
|
||||||
|
lua_pushstring(L, "root");
|
||||||
|
lua_call(L, 5, 0);
|
||||||
|
|
||||||
|
nevt += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void handleStdin(evutil_socket_t fd, short what, void *ptr) {
|
static void handleStdin(evutil_socket_t fd, short what, void *ptr) {
|
||||||
char buf;
|
char buf;
|
||||||
|
|
||||||
|
if(what != EV_READ) return;
|
||||||
|
|
||||||
int r = read(fd, &buf, 1); /* TODO: Wide chars? */
|
int r = read(fd, &buf, 1); /* TODO: Wide chars? */
|
||||||
if(r > 0) {
|
if(r > 0) {
|
||||||
lua_State* L = getL();
|
lua_State* L = getL();
|
||||||
@ -43,17 +92,30 @@ static void handleStdin(evutil_socket_t fd, short what, void *ptr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void event_prepare() {
|
void event_prepare() {
|
||||||
struct event_config* cfg = event_config_new();
|
struct event_config* cfg = event_config_new();
|
||||||
event_config_set_flag(cfg, EVENT_BASE_FLAG_NO_CACHE_TIME);
|
event_config_set_flag(cfg, EVENT_BASE_FLAG_NO_CACHE_TIME);
|
||||||
|
|
||||||
base = event_base_new_with_config(cfg);
|
base = event_base_new_with_config(cfg);
|
||||||
|
|
||||||
evutil_make_socket_nonblocking(STDIN_FILENO);
|
evutil_make_socket_nonblocking(STDIN_FILENO);
|
||||||
event_assign(&stdinEvent, base, STDIN_FILENO, EV_READ, handleStdin, NULL);
|
event_assign(&stdinEvent, base, STDIN_FILENO, EV_READ, handleStdin, NULL);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, pfd);
|
||||||
|
evutil_make_socket_nonblocking(pfd[0]);
|
||||||
|
event_assign(&winEvent, base, pfd[0], EV_READ, handleWinevent, NULL);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_events(struct timeval* timeout) {
|
static void add_events(struct timeval* timeout) {
|
||||||
|
#ifndef _WIN32
|
||||||
event_add(&stdinEvent, timeout);
|
event_add(&stdinEvent, timeout);
|
||||||
|
#endif
|
||||||
|
#ifdef _WIN32
|
||||||
|
event_add(&winEvent, timeout);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,13 +72,11 @@ static inline int win_draw_32(int x, int y, int bg, int fg, int chr, int cwd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pokeWinEvt(char ch);
|
||||||
|
|
||||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||||
logn("win: Msg");
|
|
||||||
switch(msg) {
|
switch(msg) {
|
||||||
case WM_PAINT: {
|
case WM_PAINT: {
|
||||||
logn("win: PAINT");
|
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
HDC hdc = BeginPaint(hwnd, &ps);
|
HDC hdc = BeginPaint(hwnd, &ps);
|
||||||
screenbmap = CreateBitmap(RES_X, RES_Y, 1, BYPP * 8, (void*) screenbb);
|
screenbmap = CreateBitmap(RES_X, RES_Y, 1, BYPP * 8, (void*) screenbb);
|
||||||
@ -90,12 +88,18 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||||||
EndPaint(hwnd, &ps);
|
EndPaint(hwnd, &ps);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case WM_CHAR:
|
||||||
|
//case WM_UNICHAR:
|
||||||
|
//case WM_KEYUP:
|
||||||
|
//case WM_KEYDOWN:
|
||||||
|
pokeWinEvt(wParam);
|
||||||
|
break;
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
logn("win: Create");
|
logn("win: Create");
|
||||||
screenbb = (uchar*) calloc(RES_X * RES_Y, BYPP);
|
screenbb = (uchar*) calloc(RES_X * RES_Y, BYPP);
|
||||||
|
|
||||||
colbuf = (char *)malloc(2 * CHARSW * CHARSH);
|
colbuf = (char*) malloc(2 * CHARSW * CHARSH);
|
||||||
chrbuf = (ushort *)malloc(2 * CHARSW * CHARSH);
|
chrbuf = (ushort*) malloc(2 * CHARSW * CHARSH);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#define KIOCSOUND 0x4B2F /* start sound generation (0 for off) */
|
#define KIOCSOUND 0x4B2F /* start sound generation (0 for off) */
|
||||||
|
|
||||||
|
long logStart = -1;
|
||||||
|
|
||||||
/* Enable in lupi.h */
|
/* Enable in lupi.h */
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
void logn(const char *message) {
|
void logn(const char *message) {
|
||||||
@ -69,6 +71,17 @@ void logm(const char *message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void logt(const char *message) {
|
||||||
|
struct timeval tp;
|
||||||
|
gettimeofday(&tp, NULL);
|
||||||
|
logm("[");
|
||||||
|
logi(tp.tv_sec - logStart);
|
||||||
|
logm("+");
|
||||||
|
logi(tp.tv_usec);
|
||||||
|
logm("]");
|
||||||
|
logm(message);
|
||||||
|
}
|
||||||
|
|
||||||
static int l_log (lua_State *L) {
|
static int l_log (lua_State *L) {
|
||||||
const char* t = lua_tostring(L, 1);
|
const char* t = lua_tostring(L, 1);
|
||||||
logn(t);
|
logn(t);
|
||||||
@ -79,6 +92,7 @@ static int l_log (lua_State *L) {
|
|||||||
#define logn(m)
|
#define logn(m)
|
||||||
#define logi(m)
|
#define logi(m)
|
||||||
#define logm(m)
|
#define logm(m)
|
||||||
|
#define logt(m)
|
||||||
static int l_log (lua_State *L) {
|
static int l_log (lua_State *L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -86,7 +100,8 @@ static int l_log (lua_State *L) {
|
|||||||
|
|
||||||
static int l_sleep (lua_State *L) {
|
static int l_sleep (lua_State *L) {
|
||||||
unsigned int t = lua_tonumber(L, 1);
|
unsigned int t = lua_tonumber(L, 1);
|
||||||
usleep(t);
|
struct timespec st = {.tv_sec = t / 1000000, .tv_nsec = (t % 1000000) * 1000};
|
||||||
|
nanosleep(&st, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,6 +465,10 @@ static int l_debug (lua_State *L) {
|
|||||||
|
|
||||||
void luanative_start(lua_State *L) {
|
void luanative_start(lua_State *L) {
|
||||||
|
|
||||||
|
struct timeval tp;
|
||||||
|
gettimeofday(&tp, NULL);
|
||||||
|
logStart = tp.tv_sec;
|
||||||
|
|
||||||
struct luaL_Reg nativelib[] = {
|
struct luaL_Reg nativelib[] = {
|
||||||
{"sleep", l_sleep},
|
{"sleep", l_sleep},
|
||||||
{"log", l_log},
|
{"log", l_log},
|
||||||
|
@ -46,6 +46,9 @@ function boot.boot()
|
|||||||
bsod(reason)
|
bsod(reason)
|
||||||
else
|
else
|
||||||
local crash = false
|
local crash = false
|
||||||
|
if native.debug then
|
||||||
|
native.sleep(500000)
|
||||||
|
end
|
||||||
xpcall(f, function(e)
|
xpcall(f, function(e)
|
||||||
local trace = {}
|
local trace = {}
|
||||||
|
|
||||||
|
@ -101,14 +101,14 @@ function computer.signalTransformers.key_down(s, a, ascii, key, user)
|
|||||||
if key ~= -1 then
|
if key ~= -1 then
|
||||||
return s, a, ascii, key, user
|
return s, a, ascii, key, user
|
||||||
end
|
end
|
||||||
return s, a, asciitr[ascii] or ascii, keymap[ascii] or key, user
|
return s, a, math.floor(asciitr[ascii] or ascii), keymap[ascii] or key, user
|
||||||
end
|
end
|
||||||
|
|
||||||
function computer.signalTransformers.key_up(s, a, ascii, key, user)
|
function computer.signalTransformers.key_up(s, a, ascii, key, user)
|
||||||
if key ~= -1 then
|
if key ~= -1 then
|
||||||
return s, a, ascii, key, user
|
return s, a, ascii, key, user
|
||||||
end
|
end
|
||||||
return s, a, asciitr[ascii] or ascii, keymap[ascii] or key, user
|
return s, a, math.floor(asciitr[ascii] or ascii), keymap[ascii] or key, user
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
@ -117,13 +117,13 @@ function fbgpu.start()
|
|||||||
y = math.floor(y)
|
y = math.floor(y)
|
||||||
if not vertical then
|
if not vertical then
|
||||||
local i = 0
|
local i = 0
|
||||||
value:gsub(".", function(c)
|
value:gsub("([%z\1-\127\194-\244][\128-\191]*)", function(c)
|
||||||
fb.put(x+i-1, y-1, background, foreground, utf8.codepoint(c))
|
fb.put(x+i-1, y-1, background, foreground, utf8.codepoint(c))
|
||||||
i = i+1
|
i = i+1
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
local i = 0
|
local i = 0
|
||||||
value:gsub(".", function(c)
|
value:gsub("([%z\1-\127\194-\244][\128-\191]*)", function(c)
|
||||||
fb.put(x-1, y+i-1, background, foreground, utf8.codepoint(c))
|
fb.put(x-1, y+i-1, background, foreground, utf8.codepoint(c))
|
||||||
i = i+1
|
i = i+1
|
||||||
end)
|
end)
|
||||||
@ -156,11 +156,17 @@ function fbgpu.start()
|
|||||||
gpu.setForeground(0xFFFFFF)
|
gpu.setForeground(0xFFFFFF)
|
||||||
gpu.setBackground(0x000000)
|
gpu.setBackground(0x000000)
|
||||||
|
|
||||||
|
local screenAddr
|
||||||
|
|
||||||
|
function gpu.getScreen()
|
||||||
|
return screenAddr
|
||||||
|
end
|
||||||
|
|
||||||
termutils.init()
|
termutils.init()
|
||||||
write("\x1b[?25l") --Disable cursor
|
write("\x1b[?25l") --Disable cursor
|
||||||
|
|
||||||
modules.component.api.register(nil, "gpu", gpu)
|
modules.component.api.register(nil, "gpu", gpu)
|
||||||
modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
|
screenAddr = modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
|
||||||
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
|
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
|
||||||
|
|
||||||
deadhooks[#deadhooks + 1] = function()
|
deadhooks[#deadhooks + 1] = function()
|
||||||
|
@ -107,7 +107,13 @@ function main()
|
|||||||
if native.debug and native.platform():match("unix") then
|
if native.debug and native.platform():match("unix") then
|
||||||
modules.filesystem.register("/", "11111111-1111-1111-1111-111111111111")
|
modules.filesystem.register("/", "11111111-1111-1111-1111-111111111111")
|
||||||
end
|
end
|
||||||
|
if native.platform():match("unix") then
|
||||||
modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid())
|
modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid())
|
||||||
|
else
|
||||||
|
native.fs_mkdir("tmp")
|
||||||
|
modules.computer.tmp = modules.filesystem.register("tmp/lupi-" .. modules.random.uuid())
|
||||||
|
--TODO: cleaning hook or something
|
||||||
|
end
|
||||||
|
|
||||||
modules.gpudetect.run()
|
modules.gpudetect.run()
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ function textgpu.start()
|
|||||||
else
|
else
|
||||||
--TODO: Buffers!
|
--TODO: Buffers!
|
||||||
write("\x1b[" .. y .. ";" .. x .. "H")
|
write("\x1b[" .. y .. ";" .. x .. "H")
|
||||||
value:gsub(".", function(c)
|
value:gsub("([%z\1-\127\194-\244][\128-\191]*)", function(c)
|
||||||
write(c .. "\x1b[D\x1b[B")
|
write(c .. "\x1b[D\x1b[B")
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -109,13 +109,13 @@ function wingpu.start()
|
|||||||
y = math.floor(y)
|
y = math.floor(y)
|
||||||
if not vertical then
|
if not vertical then
|
||||||
local i = 0
|
local i = 0
|
||||||
value:gsub(".", function(c)
|
value:gsub("([%z\1-\127\194-\244][\128-\191]*)", function(c)
|
||||||
win.put(x+i-1, y-1, background, foreground, utf8.codepoint(c))
|
win.put(x+i-1, y-1, background, foreground, utf8.codepoint(c))
|
||||||
i = i+1
|
i = i+1
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
local i = 0
|
local i = 0
|
||||||
value:gsub(".", function(c)
|
value:gsub("([%z\1-\127\194-\244][\128-\191]*)", function(c)
|
||||||
win.put(x-1, y+i-1, background, foreground, utf8.codepoint(c))
|
win.put(x-1, y+i-1, background, foreground, utf8.codepoint(c))
|
||||||
i = i+1
|
i = i+1
|
||||||
end)
|
end)
|
||||||
@ -147,6 +147,11 @@ function wingpu.start()
|
|||||||
gpu.setForeground(0xFFFFFF)
|
gpu.setForeground(0xFFFFFF)
|
||||||
gpu.setBackground(0x000000)
|
gpu.setBackground(0x000000)
|
||||||
|
|
||||||
|
local screenAddr
|
||||||
|
|
||||||
|
function gpu.getScreen()
|
||||||
|
return screenAddr
|
||||||
|
end
|
||||||
|
|
||||||
local s, reason = win.open()
|
local s, reason = win.open()
|
||||||
if not s then
|
if not s then
|
||||||
@ -154,7 +159,7 @@ function wingpu.start()
|
|||||||
end
|
end
|
||||||
|
|
||||||
modules.component.api.register(nil, "gpu", gpu)
|
modules.component.api.register(nil, "gpu", gpu)
|
||||||
modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
|
screenAddr = modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
|
||||||
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
|
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
Loading…
Reference in New Issue
Block a user