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 logi(int message);
|
||||
void logm(const char *message);
|
||||
void logt(const char *message);
|
||||
#else
|
||||
#define logn(m)
|
||||
#define logi(m)
|
||||
#define logm(m)
|
||||
#define logt(m)
|
||||
#endif
|
||||
|
||||
#define pushstuple(state, name, value) lua_pushstring((state), (name)); lua_pushstring((state), (value)); lua_settable((state), -3)
|
||||
|
@ -6,19 +6,68 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#define WIN32
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define LOCAL_SOCKETPAIR_AF AF_INET
|
||||
#else
|
||||
#define LOCAL_SOCKETPAIR_AF AF_UNIX
|
||||
#endif
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <event2/event_struct.h>
|
||||
|
||||
struct event_base *base;
|
||||
struct event stdinEvent;
|
||||
|
||||
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) {
|
||||
char buf;
|
||||
|
||||
if(what != EV_READ) return;
|
||||
|
||||
int r = read(fd, &buf, 1); /* TODO: Wide chars? */
|
||||
if(r > 0) {
|
||||
lua_State* L = getL();
|
||||
@ -43,17 +92,30 @@ static void handleStdin(evutil_socket_t fd, short what, void *ptr) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void event_prepare() {
|
||||
struct event_config* cfg = event_config_new();
|
||||
event_config_set_flag(cfg, EVENT_BASE_FLAG_NO_CACHE_TIME);
|
||||
|
||||
base = event_base_new_with_config(cfg);
|
||||
|
||||
evutil_make_socket_nonblocking(STDIN_FILENO);
|
||||
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) {
|
||||
#ifndef _WIN32
|
||||
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) {
|
||||
logn("win: Msg");
|
||||
switch(msg) {
|
||||
case WM_PAINT: {
|
||||
logn("win: PAINT");
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hwnd, &ps);
|
||||
screenbmap = CreateBitmap(RES_X, RES_Y, 1, BYPP * 8, (void*) screenbb);
|
||||
@ -90,6 +88,12 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
break;
|
||||
case WM_CHAR:
|
||||
//case WM_UNICHAR:
|
||||
//case WM_KEYUP:
|
||||
//case WM_KEYDOWN:
|
||||
pokeWinEvt(wParam);
|
||||
break;
|
||||
case WM_CREATE:
|
||||
logn("win: Create");
|
||||
screenbb = (uchar*) calloc(RES_X * RES_Y, BYPP);
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#define KIOCSOUND 0x4B2F /* start sound generation (0 for off) */
|
||||
|
||||
long logStart = -1;
|
||||
|
||||
/* Enable in lupi.h */
|
||||
#ifdef LOGGING
|
||||
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) {
|
||||
const char* t = lua_tostring(L, 1);
|
||||
logn(t);
|
||||
@ -79,6 +92,7 @@ static int l_log (lua_State *L) {
|
||||
#define logn(m)
|
||||
#define logi(m)
|
||||
#define logm(m)
|
||||
#define logt(m)
|
||||
static int l_log (lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
@ -86,7 +100,8 @@ static int l_log (lua_State *L) {
|
||||
|
||||
static int l_sleep (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -450,6 +465,10 @@ static int l_debug (lua_State *L) {
|
||||
|
||||
void luanative_start(lua_State *L) {
|
||||
|
||||
struct timeval tp;
|
||||
gettimeofday(&tp, NULL);
|
||||
logStart = tp.tv_sec;
|
||||
|
||||
struct luaL_Reg nativelib[] = {
|
||||
{"sleep", l_sleep},
|
||||
{"log", l_log},
|
||||
|
@ -46,6 +46,9 @@ function boot.boot()
|
||||
bsod(reason)
|
||||
else
|
||||
local crash = false
|
||||
if native.debug then
|
||||
native.sleep(500000)
|
||||
end
|
||||
xpcall(f, function(e)
|
||||
local trace = {}
|
||||
|
||||
|
@ -101,14 +101,14 @@ function computer.signalTransformers.key_down(s, a, ascii, key, user)
|
||||
if key ~= -1 then
|
||||
return s, a, ascii, key, user
|
||||
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
|
||||
|
||||
function computer.signalTransformers.key_up(s, a, ascii, key, user)
|
||||
if key ~= -1 then
|
||||
return s, a, ascii, key, user
|
||||
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
|
||||
|
||||
-----
|
||||
|
@ -117,13 +117,13 @@ function fbgpu.start()
|
||||
y = math.floor(y)
|
||||
if not vertical then
|
||||
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))
|
||||
i = i+1
|
||||
end)
|
||||
else
|
||||
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))
|
||||
i = i+1
|
||||
end)
|
||||
@ -156,11 +156,17 @@ function fbgpu.start()
|
||||
gpu.setForeground(0xFFFFFF)
|
||||
gpu.setBackground(0x000000)
|
||||
|
||||
local screenAddr
|
||||
|
||||
function gpu.getScreen()
|
||||
return screenAddr
|
||||
end
|
||||
|
||||
termutils.init()
|
||||
write("\x1b[?25l") --Disable cursor
|
||||
|
||||
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", {})
|
||||
|
||||
deadhooks[#deadhooks + 1] = function()
|
||||
|
@ -107,7 +107,13 @@ function main()
|
||||
if native.debug and native.platform():match("unix") then
|
||||
modules.filesystem.register("/", "11111111-1111-1111-1111-111111111111")
|
||||
end
|
||||
if native.platform():match("unix") then
|
||||
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()
|
||||
|
||||
|
@ -143,7 +143,7 @@ function textgpu.start()
|
||||
else
|
||||
--TODO: Buffers!
|
||||
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")
|
||||
end)
|
||||
end
|
||||
|
@ -109,13 +109,13 @@ function wingpu.start()
|
||||
y = math.floor(y)
|
||||
if not vertical then
|
||||
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))
|
||||
i = i+1
|
||||
end)
|
||||
else
|
||||
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))
|
||||
i = i+1
|
||||
end)
|
||||
@ -147,6 +147,11 @@ function wingpu.start()
|
||||
gpu.setForeground(0xFFFFFF)
|
||||
gpu.setBackground(0x000000)
|
||||
|
||||
local screenAddr
|
||||
|
||||
function gpu.getScreen()
|
||||
return screenAddr
|
||||
end
|
||||
|
||||
local s, reason = win.open()
|
||||
if not s then
|
||||
@ -154,7 +159,7 @@ function wingpu.start()
|
||||
end
|
||||
|
||||
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", {})
|
||||
|
||||
return s
|
||||
|
Loading…
Reference in New Issue
Block a user