diff options
Diffstat (limited to 'src/syslua/lx/tk.lua')
-rw-r--r-- | src/syslua/lx/tk.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/syslua/lx/tk.lua b/src/syslua/lx/tk.lua index e8686ba..f38efe2 100644 --- a/src/syslua/lx/tk.lua +++ b/src/syslua/lx/tk.lua @@ -1,5 +1,8 @@ local draw = require 'lx.draw' local sys = require 'lx.sys' +local gui = require 'lx.gui' +local gip = require 'lx.gip' +local kbdcode = require 'lx.kbdcode' local tk = {} @@ -225,6 +228,10 @@ function tk.widget(width, height, opts) self.left_click_valid = false end + function w:on_keyboard(scancode, ty) + -- Handler for raw keyboard event + end + function w:on_text_input(char) -- Handler for text input end @@ -266,6 +273,12 @@ function tk.init(gui, root_widget) root_widget:do_resize(gui.surface:width(), gui.surface:height()) + local prev_gui_on_keyboard = gui.on_keyboard + gui.on_keyboard = function(scancode, ty) + root_widget:on_keyboard(scancode, ty) + prev_gui_on_keyboard(scancode, ty) + end + gui.on_key_down = function(key) root_widget:on_key_down(key) end gui.on_key_up = function(key) root_widget:on_key_up(key) end gui.on_text_input = function(key) root_widget:on_text_input(char) end @@ -919,8 +932,51 @@ function tk.window_manager() end end + function wm:on_keyboard(scancode, ty) + wm.windows[#wm.windows].content:on_keyboard(scancode, ty) + end + return wm end +function tk.gipwidget(opts) + local w = tk.widget(nil, nil, opts) + + w.geom = { + bpp = gui.surface_geom.bpp, + memory_model = gui.surface_geom.memory_model, + width = opts.width, + height = opts.height, + pitch = opts.width * gui.surface_geom.bpp // 8 + } + w.shm_fd = sys.make_shm(w.geom.height * w.geom.pitch) + w.framebuffer = draw.surface_from_fd(w.shm_fd, w.geom) + + w.ch_srv, w.ch_cli = sys.make_channel(false) + w.gip_handler = gip.new_handler(w.ch_srv) + + function w.gip_handler:cb_reset(req_id, arg) + w.gip_handler:send_msg(gip.proto.GIPR_INITIATE, req_id, gip.proto.GIPF_DAMAGE_NOTIF) + w.gip_handler:send_msg(gip.proto.GIPN_BUFFER_INFO, 0, 0, { tok = sys.gen_token(w.shm_fd), geom = w.geom }) + end + + function w.gip_handler:cb_buffer_damage(req_id, arg, region) + w:redraw(region.x, region.y, region.w, region.h) + end + + function w:draw(x0, y0, buf) + if x0 < self.framebuffer:width() and y0 < self.framebuffer:height() then + buf:blit(0, 0, self.framebuffer:sub(x0, y0, self.framebuffer:width(), self.framebuffer:height())) + end + end + + function w:on_keyboard(scancode, ty) + sys.dbg_print("gipwidget:on_keyboard " .. tostring(scancode) .. "\n") + w.gip_handler:send_msg(ty == kbdcode.event.KEYPRESS and gip.proto.GIPN_KEY_DOWN or gip.proto.GIPN_KEY_UP, nil, scancode) + end + + return w +end + return tk |