aboutsummaryrefslogtreecommitdiff
path: root/src/syslua/lx
diff options
context:
space:
mode:
Diffstat (limited to 'src/syslua/lx')
-rw-r--r--src/syslua/lx/gui.lua100
-rw-r--r--src/syslua/lx/kbdcode.lua77
-rw-r--r--src/syslua/lx/mainloop.lua3
3 files changed, 175 insertions, 5 deletions
diff --git a/src/syslua/lx/gui.lua b/src/syslua/lx/gui.lua
index beb382e..23e6cb6 100644
--- a/src/syslua/lx/gui.lua
+++ b/src/syslua/lx/gui.lua
@@ -3,6 +3,9 @@ local sysdef= require 'lx.sysdef'
local ioctl = require 'lx.ioctl'
local draw = require 'lx.draw'
+local kbd = require 'lx.kbd'
+local kbdcode = require 'lx.kbdcode'
+
local mainloop = require 'lx.mainloop'
local gui = {
@@ -14,6 +17,7 @@ local gui = {
mouse_lbtn = false,
mouse_rbtn = false,
mouse_midbtn = false,
+ cursor_visible = false,
}
function gui.open()
@@ -31,8 +35,8 @@ function gui.open_io()
gui.vesa_fd = sys.open("io:/display/vesa", sysdef.FM_IOCTL | sysdef.FM_READ | sysdef.FM_WRITE | sysdef.FM_MMAP)
assert(gui.vesa_fd ~= 0)
- gui.vesa_info = ioctl.fb_get_info(gui.vesa_fd)
- gui.surface = draw.surface_from_fd(gui.vesa_fd, gui.vesa_info)
+ gui.surface_geom = ioctl.fb_get_info(gui.vesa_fd)
+ gui.surface = draw.surface_from_fd(gui.vesa_fd, gui.surface_geom)
-- Open keyboard
gui.pckbd_fd = sys.open("io:/input/pckbd", sysdef.FM_READ)
@@ -47,6 +51,8 @@ function gui.open_io()
end
gui.pckbd_mainloop_fd:expect(4, pckbd_handler)
+ gui.kbdlib = kbd.init()
+
-- Open mouse
gui.pcmouse_fd = sys.open("io:/input/pcmouse", sysdef.FM_READ)
assert(gui.pcmouse_fd ~= 0)
@@ -65,12 +71,98 @@ function gui.open_gip()
-- TODO
end
+function gui.load_cursor(filename)
+ gui.hide_cursor()
+ gui.cursor = draw.load_image(filename)
+ gui.cursor_backup = draw.new_surface(gui.cursor:width(),gui.cursor:height(), gui.surface_geom.bpp, false)
+end
+
+function gui.hide_cursor()
+ if not gui.cursor_visible then return end
+
+ gui.surface:blit(gui.mouse_x, gui.mouse_y, gui.cursor_backup)
+ gui.cursor_visible = false
+end
+
+function gui.show_cursor()
+ if gui.cursor_visible then return end
+ if not gui.cursor then return end
+
+ gui.cursor_backup:blit(0, 0, gui.surface:sub(gui.mouse_x, gui.mouse_y, gui.cursor:width(), gui.cursor:height()))
+ gui.surface:blit(gui.mouse_x, gui.mouse_y, gui.cursor)
+ gui.cursor_visible = true
+end
+
function gui.on_keyboard(scancode, ty)
- -- TODO
+ if ty == kbdcode.event.KEYPRESS then
+ local key = gui.kbdlib:press(scancode)
+ gui.on_key_down(key)
+ if key.chr then
+ gui.on_text_input(string.char(key.chr))
+ end
+ elseif ty == kbdcode.event.KEYRELEASE then
+ local key = gui.kbdlib:release(scancode)
+ gui.on_key_up(key)
+ end
+end
+
+function gui.on_key_down(key)
+ -- Can be replaced :)
+end
+
+function gui.on_text_input(chr)
+ -- Can be replaced :)
+end
+
+function gui.on_key_up(key)
+ -- Can be replaced :)
end
+
function gui.on_mouse(dx, dy, dw, lb, rb, mb)
- -- TODO
+ if dx ~= 0 or dy ~= 0 then
+ local csr = gui.cursor_visible
+ if csr then gui.hide_cursor() end
+
+ gui.mouse_x = gui.mouse_x + dx
+ gui.mouse_y = gui.mouse_y - dy
+ if gui.mouse_x < 0 then gui.mouse_x = 0 end
+ if gui.mouse_y < 0 then gui.mouse_y = 0 end
+ if gui.mouse_x >= gui.surface:width() then gui.mouse_x = gui.surface:width() - 1 end
+ if gui.mouse_y >= gui.surface:height() then gui.mouse_y = gui.surface:height() - 1 end
+
+ if csr then gui.show_cursor() end
+
+ gui.on_mouse_move(gui.mouse_x, gui.mouse_y)
+ end
+
+ if lb == 1 and not gui.mouse_lbtn then
+ gui.mouse_lbtn = true
+ gui.on_mouse_down(true, false, false)
+ elseif lb == 0 and gui.mouse_lbtn then
+ gui.mouse_lbtn = false
+ gui.on_mouse_up(true, false, false)
+ end
+
+ if rb == 1 and not gui.mouse_rbtn then
+ gui.mouse_rbtn = true
+ gui.on_mouse_down(false, true, false)
+ elseif rb == 0 and gui.mouse_rbtn then
+ gui.mouse_rbtn = false
+ gui.on_mouse_up(false, true, false)
+ end
+end
+
+function gui.on_mouse_move(x, y)
+ -- Nothing, can be replaced :)
+end
+
+function gui.on_mouse_down(lb, rb, mb)
+ -- Nothing, can be replaced :)
+end
+
+function gui.on_mouse_up(lb, rb, mb)
+ -- Nothing, can be replaced :)
end
return gui
diff --git a/src/syslua/lx/kbdcode.lua b/src/syslua/lx/kbdcode.lua
new file mode 100644
index 0000000..75f3a91
--- /dev/null
+++ b/src/syslua/lx/kbdcode.lua
@@ -0,0 +1,77 @@
+local kbdcode = {}
+
+kbdcode.event = {
+ KEYRELEASE = 0,
+ KEYPRESS = 1,
+}
+
+kbdcode.code = {
+ ESC = 1,
+ RETURN = 28,
+ BKSP = 14,
+ UP = 200,
+ DOWN = 208,
+ LEFT = 203,
+ RIGHT = 205,
+ HOME = 199,
+ END = 207,
+ PGUP = 201,
+ PGDOWN = 209,
+
+ LSHIFT = 42,
+ RSHIFT = 54,
+ CAPSLOCK = 58,
+ LCTRL = 29,
+ RCTRL = 157,
+ LALT = 56,
+ RALT = 184,
+ LSUPER = 219,
+ RSUPER = 220,
+ MENU = 221,
+ TAB = 15,
+ INS = 210,
+ DEL = 211,
+
+ F1 = 59,
+ F2 = 60,
+ F3 = 61,
+ F4 = 62,
+ F5 = 63,
+ F6 = 64,
+ F7 = 65,
+ F8 = 66,
+ F9 = 67,
+ F10 = 68,
+ F11 = 87,
+ F12 = 88,
+
+ NUMLOCK = 69,
+ SCRLLOCK = 70,
+ PRTSCN = 183,
+ SYSREQ = 84,
+
+ KPHOME = 71,
+ KPUP = 72,
+ KPPGUP = 73,
+ KPLEFT = 75,
+ KP5 = 76,
+ KPRIGHT = 77,
+ KPEND = 79,
+ KPDOWN = 80,
+ KPPGDOWN = 81,
+ KPINS = 82,
+ KPDEL = 83,
+}
+
+kbdcode.flags = {
+ CHAR = 0x01,
+ ALT = 0x02,
+ CTRL = 0x04,
+ SUPER = 0x08,
+ SHIFT = 0x10,
+ CAPS = 0x20,
+ MOD = 0x40,
+}
+
+
+return kbdcode
diff --git a/src/syslua/lx/mainloop.lua b/src/syslua/lx/mainloop.lua
index c2ae88d..b1b3feb 100644
--- a/src/syslua/lx/mainloop.lua
+++ b/src/syslua/lx/mainloop.lua
@@ -21,6 +21,7 @@ function new_fd(fd, error_cb)
function fd:expect(len, cb)
table.insert(self.rd_expect, {len, "", cb})
end
+ return fd
end
function mainloop.add_fd(fd, error_cb)
@@ -55,7 +56,7 @@ function mainloop.run()
local res = sys.select(sel_fds, -1)
assert(res, "select() call failed")
- for i, fd = pairs(fds) do
+ for i, fd in pairs(fds) do
local flags = sel_fds[i][3]
if flags & sysdef.SEL_ERROR ~= 0 then
fd.error_cb(fd)