aboutsummaryrefslogtreecommitdiff
path: root/src/sysapp/login/main.lua
blob: d099ec76fa3bacb88cabafbae8b616c1ce2ba876 (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
local sys = require 'lx.sys'
local sysdef = require 'lx.sysdef'

local mainloop = require 'lx.mainloop'
local gip = require 'lx.gip'
local draw = require 'lx.draw'


local io = gip.new(sysdef.STD_FD_GIP)

function io:damage(reg)
  if self.features & gipdef.GIPF_DAMAGE_NOTIF ~= 0 then
    self:send_buffer_damage(draw.region(0, 0, 256, 256))
  end
end

function io:on_initiate(arg)
  self.flags = arg

  self:async_enumerate_modes(function(modes)
    sys.dbg_print("Got mode list:\n")
    for i, v in pairs(modes) do
      sys.dbg_print(string.format("%d: %dx%d %d\n", i, v.width, v.height, v.bpp))
    end

    for i, v in pairs(modes) do
      if v.width == 800 and v.height == 600 and v.bpp == 24 then
        sys.dbg_print(string.format("Selecting mode %d\n", i))
        io:send_set_mode(i)
        return
      end
    end
  end)
end

function io:on_buffer_info(arg, tok, geom)
  self.surface = draw.surface_from_fd(sys.use_token(tok))
  self.geom = geom

  for x = 0, 255 do
    for y = 0, 255 do
      self.surface:put(x, y, draw.rgb(x, y, 128))
    end
  end

  self:damage(draw.region(0, 0, 256, 256))
end

function io:async_enumerate_modes(callback)
  local modelist = {}
  local function gotmode(cmd, arg)
    if arg == nil then
      callback(modelist)
    else
      modelist[#modelist + 1] = arg
      io.on_reply[io:send_query_mode(#modelist)] = gotmode
    end
  end
  io.on_reply[io:send_query_mode(#modelist)] = gotmode
end

mainloop.add(io)

io:send_reset()
mainloop.run()