fix: move shiftmode and altmode to global

now shiftmode and altmode is recoreded in Keys module.  So all the UIs
are sharing these two mode instead of remembering their own. These fix
the bug in UI switchings.

For instance, you use combo 'Alt'+'b' to fire up some menu in pdfreader,
the altmode is set, but the alt key was released after the menu show
up. Then the key release event will only be captured by the menu. So
after you exit from the menu, the altmode is still set in pdfreader,
which is not what we want.
pull/2/merge
Qingping Hou 12 years ago
parent e42f4ae38e
commit 53d4016c64

@ -146,9 +146,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 ev.code == KEY_SHIFT then
Keys.shiftmode = true
elseif ev.code == KEY_ALT then
Keys.altmode = true
elseif ev.code == KEY_FW_UP then
prevItem()
elseif ev.code == KEY_FW_DOWN then
nextItem()
@ -214,6 +218,12 @@ function FileChooser:choose(ypos, height)
elseif ev.code == KEY_BACK then
return nil
end
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_SHIFT then
Keys.shiftmode = false
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_ALT then
Keys.altmode = false
end
end
end

@ -216,7 +216,11 @@ 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
if ev.code == KEY_SHIFT then
Keys.shiftmode = true
elseif ev.code == KEY_ALT then
Keys.altmode = true
elseif ev.code == KEY_FW_UP then
prevItem()
elseif ev.code == KEY_FW_DOWN then
nextItem()
@ -272,6 +276,12 @@ function FileSearcher:choose(ypos, height, keywords)
elseif ev.code == KEY_BACK then
return nil
end
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_SHIFT then
Keys.shiftmode = false
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_ALT then
Keys.altmode = false
end
end
end

@ -102,9 +102,9 @@ function InputBox:input(ypos, height, title, d_text)
ev.code = adjustFWKey(ev.code)
--local secs, usecs = util.gettime()
if ev.code == KEY_SHIFT then
self.shiftmode = true
Keys.shiftmode = true
elseif ev.code == KEY_ALT then
self.altmode = true
Keys.altmode = true
elseif ev.code == KEY_FW_UP then
elseif ev.code == KEY_FW_DOWN then
elseif ev.code == KEY_A then
@ -200,10 +200,10 @@ function InputBox:input(ypos, height, title, d_text)
--print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur)
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_SHIFT then
self.shiftmode = false
Keys.shiftmode = false
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_ALT then
self.altmode = false
Keys.altmode = false
end
end
end

@ -24,6 +24,11 @@
and was licensed under the GPLv2
]]--
Keys = {
altmode = false,
shiftmode = false,
}
KEY_1 = 2
KEY_2 = 3
KEY_3 = 4
@ -120,6 +125,17 @@ function set_emu_keycodes()
KEY_ENTER = 36
KEY_1 = 10
KEY_2 = 11
KEY_3 = 12
KEY_4 = 13
KEY_5 = 14
KEY_6 = 15
KEY_7 = 16
KEY_8 = 17
KEY_9 = 18
KEY_0 = 19
KEY_Q = 24
KEY_W = 25
KEY_E = 26
@ -163,17 +179,17 @@ function getRotationMode()
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

@ -356,27 +356,27 @@ function PDFReader:inputloop()
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
local secs, usecs = util.gettime()
if ev.code == KEY_SHIFT then
self.shiftmode = true
Keys.shiftmode = true
elseif ev.code == KEY_ALT then
self.altmode = true
Keys.altmode = true
elseif ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then
if self.shiftmode then
if Keys.shiftmode then
self:setglobalzoom(self.globalzoom*1.2)
elseif self.altmode then
elseif Keys.altmode then
self:setglobalzoom(self.globalzoom*1.1)
else
self:goto(self.pageno + 1)
end
elseif ev.code == KEY_PGBCK or ev.code == KEY_LPGBCK then
if self.shiftmode then
if Keys.shiftmode then
self:setglobalzoom(self.globalzoom*0.8)
elseif self.altmode then
elseif Keys.altmode then
self:setglobalzoom(self.globalzoom*0.9)
else
self:goto(self.pageno - 1)
end
elseif ev.code == KEY_BACK then
if self.altmode then
if Keys.altmode then
-- altmode, exit pdfreader
self:clearcache()
if self.doc ~= nil then
@ -399,19 +399,19 @@ function PDFReader:inputloop()
elseif ev.code == KEY_VMINUS then
self:modify_gamma( 0.8 )
elseif ev.code == KEY_A then
if self.shiftmode then
if Keys.shiftmode then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT)
else
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE)
end
elseif ev.code == KEY_S then
if self.shiftmode then
if Keys.shiftmode then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT_WIDTH)
else
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_WIDTH)
end
elseif ev.code == KEY_D then
if self.shiftmode then
if Keys.shiftmode then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT_HEIGHT)
else
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_HEIGHT)
@ -430,10 +430,10 @@ function PDFReader:inputloop()
local x
local y
if self.shiftmode then -- shift always moves in small steps
if Keys.shiftmode then -- shift always moves in small steps
x = self.shift_x / 2
y = self.shift_y / 2
elseif self.altmode then
elseif Keys.altmode then
x = self.shift_x / 5
y = self.shift_y / 5
elseif self.pan_by_page then
@ -469,7 +469,7 @@ function PDFReader:inputloop()
self.offset_y = self.min_offset_y
end
elseif ev.code == KEY_FW_PRESS then
if self.shiftmode then
if Keys.shiftmode then
self.offset_x = 0
self.offset_y = 0
else
@ -487,9 +487,9 @@ function PDFReader:inputloop()
print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur)
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE and ev.code == KEY_SHIFT then
print "shift haha"
self.shiftmode = false
Keys.shiftmode = false
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE and ev.code == KEY_ALT then
self.altmode = false
Keys.altmode = false
end
end
end

@ -169,7 +169,11 @@ function SelectMenu: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
if ev.code == KEY_SHIFT then
Keys.shiftmode = true
elseif ev.code == KEY_ALT then
Keys.altmode = true
elseif ev.code == KEY_FW_UP then
prevItem()
elseif ev.code == KEY_FW_DOWN then
nextItem()
@ -201,6 +205,12 @@ function SelectMenu:choose(ypos, height)
elseif ev.code == KEY_BACK then
return nil
end
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_SHIFT then
Keys.shiftmode = false
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_ALT then
Keys.altmode = false
end
end
end

Loading…
Cancel
Save