diff --git a/filechooser.lua b/filechooser.lua index bd2fedbbc..afac047be 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -54,33 +54,6 @@ function FileChooser:setPath(newPath) return true end -function FileChooser:rotationMode() - --[[ - return code for four kinds of rotation mode: - - 0 for no rotation, - 1 for landscape with bottom on the right side of screen, etc. - - 2 - --------- - | | - | | - | | - 3 | | 1 - | | - | | - | | - --------- - 0 - --]] - if KEY_FW_DOWN == 116 then - return 0 - end - orie_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_orientation", "r")) - updown_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_upside_down", "r")) - mode = orie_fd:read() + (updown_fd:read() * 2) - return mode -end function FileChooser:choose(ypos, height) local perpage = math.floor(height / self.spacing) - 1 @@ -154,32 +127,13 @@ function FileChooser:choose(ypos, height) end local ev = input.waitForEvent() if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then - print("key code:"..ev.code) + --print("key code:"..ev.code) + ev.code = adjustFWKey(ev.code) if ev.code == KEY_FW_UP then - if self:rotationMode() == 0 then - prevItem() - elseif self:rotationMode() == 2 then - nextItem() - end + prevItem() elseif ev.code == KEY_FW_DOWN then - if self:rotationMode() == 0 then - nextItem() - elseif self:rotationMode() == 2 then - prevItem() - end - elseif ev.code == KEY_FW_LEFT then - if self:rotationMode() == 1 then - prevItem() - elseif self:rotationMode() == 3 then - nextItem() - end - elseif ev.code == KEY_FW_RIGHT then - if self:rotationMode() == 1 then - nextItem() - elseif self:rotationMode() == 3 then - prevItem() - end - elseif ev.code == KEY_F then + nextItem() + elseif ev.code == KEY_F then -- invoke fontchooser menu FontChooser:init() newfont = FontChooser:choose(0, height) if newfont ~= nil then @@ -187,8 +141,7 @@ function FileChooser:choose(ypos, height) clearglyphcache() end pagedirty = true - elseif ev.code == KEY_S then - -- invoke search input + elseif ev.code == KEY_S then -- invoke search input keywords = InputBox:input(height-100, 100, "Search:") if keywords then -- display search result according to keywords --[[ diff --git a/filesearcher.lua b/filesearcher.lua index d59e0cd49..5193a9056 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -188,6 +188,7 @@ function FileSearcher:choose(ypos, height, keywords) local ev = input.waitForEvent() if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then + ev.code = adjustFWKey(ev.code) if ev.code == KEY_FW_UP then prevItem() elseif ev.code == KEY_FW_DOWN then diff --git a/fontchooser.lua b/fontchooser.lua index a9d8c8c4d..9084368f1 100644 --- a/fontchooser.lua +++ b/fontchooser.lua @@ -31,8 +31,8 @@ FontChooser = { } function FontChooser:init() + clearglyphcache() self.items = #self.fonts - table.sort(self.fonts) end @@ -80,6 +80,7 @@ function FontChooser:choose(ypos, height) renderUtf8Text(fb.bb, x, y, self.tface, self.tfhash, "Fonts Menu", true) + -- draw font items fb.bb:paintRect(0, ypos + self.title_H + 10, fb.bb:getWidth(), height - self.title_H, 0) local c for c = 1, perpage do @@ -89,6 +90,7 @@ function FontChooser:choose(ypos, height) renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, self.fonts[i], true) end end + -- draw footer y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H x = (fb.bb:getWidth() / 2) - 50 @@ -122,6 +124,7 @@ function FontChooser:choose(ypos, height) local ev = input.waitForEvent() if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then + ev.code = adjustFWKey(ev.code) if ev.code == KEY_FW_UP then prevItem() elseif ev.code == KEY_FW_DOWN then diff --git a/inputbox.lua b/inputbox.lua index 2c50d6882..4ef3ee8d1 100644 --- a/inputbox.lua +++ b/inputbox.lua @@ -96,8 +96,8 @@ function InputBox:input(ypos, height, title, d_text) local ev = input.waitForEvent() if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then - print("key code:"..ev.code) - --ev.code = adjustFWKey(ev.code) + --print("key code:"..ev.code) + ev.code = adjustFWKey(ev.code) if ev.code == KEY_FW_UP then elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_A then diff --git a/keys.lua b/keys.lua index eb932176a..7e3f5aec7 100644 --- a/keys.lua +++ b/keys.lua @@ -154,3 +154,75 @@ function set_emu_keycodes() KEY_VPLUS = 95 -- F11 KEY_VMINUS = 96 -- F12 end + +function getRotationMode() + --[[ + return code for four kinds of rotation mode: + + 0 for no rotation, + 1 for landscape with bottom on the right side of screen, etc. + + 2 + ----------- + | ------- | + | | | | + | | | | + | | | | + 3 | | | | 1 + | | | | + | | | | + | ------- | + | | + ----------- + 0 + --]] + if KEY_FW_DOWN == 116 then -- in EMU mode always return 0 + return 0 + end + orie_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_orientation", "r")) + updown_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_upside_down", "r")) + mode = orie_fd:read() + (updown_fd:read() * 2) + return mode +end + +function adjustFWKey(code) + if getRotationMode() == 0 then + return code + elseif getRotationMode() == 1 then + if code == KEY_FW_UP then + return KEY_FW_RIGHT + elseif code == KEY_FW_RIGHT then + return KEY_FW_DOWN + elseif code == KEY_FW_DOWN then + return KEY_FW_LEFT + elseif code == KEY_FW_LEFT then + return KEY_FW_UP + else + return code + end + elseif getRotationMode() == 2 then + if code == KEY_FW_UP then + return KEY_FW_DOWN + elseif code == KEY_FW_RIGHT then + return KEY_FW_LEFT + elseif code == KEY_FW_DOWN then + return KEY_FW_UP + elseif code == KEY_FW_LEFT then + return KEY_FW_RIGHT + else + return code + end + elseif getRotationMode() == 3 then + if code == KEY_FW_UP then + return KEY_FW_LEFT + elseif code == KEY_FW_RIGHT then + return KEY_FW_UP + elseif code == KEY_FW_DOWN then + return KEY_FW_RIGHT + elseif code == KEY_FW_LEFT then + return KEY_FW_DOWN + else + return code + end + end +end