aboutsummaryrefslogtreecommitdiff
path: root/src/syslua/lx/gui.lua
blob: beb382edfc49d2a1d6d402dee520d12338cfd9f5 (plain) (blame)
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
local sys = require 'lx.sys'
local sysdef= require 'lx.sysdef'
local ioctl = require 'lx.ioctl'
local draw = require 'lx.draw'

local mainloop = require 'lx.mainloop'

local gui = {
	-- Keyboard info
	-- TODO
	-- Mouse info
	mouse_x = 0,
	mouse_y = 0,
	mouse_lbtn = false,
	mouse_rbtn = false,
	mouse_midbtn = false,
}

function gui.open()
	if sys.stat('io:/display/vesa') and sys.stat('io:/input/pckbd') and sys.stat('io:/input/pcmouse') then
		gui.open_io()
	elseif sys.stat_open(sysdef.STD_FD_GIP) then
		gui.open_gip()
	else
		error("Could not open GUI!")
	end
end

function gui.open_io()
	-- Open display
	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)

	-- Open keyboard
	gui.pckbd_fd = sys.open("io:/input/pckbd", sysdef.FM_READ)
	assert(gui.pckbd_fd ~= 0)

	gui.pckbd_mainloop_fd = mainloop.add_fd(gui.pckbd_fd, function() error('pckbd fd error') end)
	local function pckbd_handler(ev)
		local scancode, ty = string.unpack("HH", ev)
		gui.on_keyboard(scancode, ty)

		gui.pckbd_mainloop_fd:expect(4, pckbd_handler)
	end
	gui.pckbd_mainloop_fd:expect(4, pckbd_handler)

	-- Open mouse
	gui.pcmouse_fd = sys.open("io:/input/pcmouse", sysdef.FM_READ)
	assert(gui.pcmouse_fd ~= 0)

	gui.pcmouse_mainloop_fd = mainloop.add_fd(gui.pcmouse_fd, function() error("pcmouse fd error") end)
	local function pcmouse_handler(ev)
		local dx, dy, dw, lb, rb, mb = string.unpack("hhbBBB", ev)
		gui.on_mouse(dx, dy, dw, lb, rb, mb)

		gui.pcmouse_mainloop_fd:expect(8, pcmouse_handler)
	end
	gui.pcmouse_mainloop_fd:expect(8, pcmouse_handler)
end

function gui.open_gip()
	-- TODO
end

function gui.on_keyboard(scancode, ty)
	-- TODO
end

function gui.on_mouse(dx, dy, dw, lb, rb, mb)
	-- TODO
end

return gui