Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[feat, UX] SDL: add Gtk3 filechooser (#3827)
The specifics for other implementations are easy to change in the backend.
  • Loading branch information
Frenzie committed Apr 3, 2018
1 parent 7f4be45 commit 086ced0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion frontend/device/input.lua
Expand Up @@ -114,6 +114,7 @@ local Input = {
-- keyboard state:
modifiers = {
Alt = false,
Ctrl = false,
Shift = false,
},

Expand Down Expand Up @@ -301,9 +302,22 @@ function Input:handleKeyBoardEv(ev)
end
end
local FileChooser = self.file_chooser
if FileChooser and self:isEvKeyPress(ev)
and self.modifiers["Ctrl"] and keycode == "O" then
logger.dbg("Opening FileChooser:", FileChooser.type)
local file_path = FileChooser:open()
if file_path then
local ReaderUI = require("apps/reader/readerui")
ReaderUI:doShowReader(file_path)
end
return
end
-- quit on Alt + F4
-- this is also emitted by the close event in SDL
if self.modifiers["Alt"] and keycode == "F4" then
if self:isEvKeyPress(ev) and self.modifiers["Alt"] and keycode == "F4" then
local Device = require("frontend/device")
local UIManager = require("ui/uimanager")
Expand Down
5 changes: 5 additions & 0 deletions frontend/device/sdl/device.lua
Expand Up @@ -49,6 +49,7 @@ function Device:init()

-- SDL events can remain cdata but are almost completely transparent
local SDL_MOUSEWHEEL = 1027
local SDL_MULTIGESTURE = 2050
local SDL_DROPFILE = 4096
local SDL_WINDOWEVENT_RESIZED = 5

Expand Down Expand Up @@ -99,6 +100,9 @@ function Device:init()
UIManager:broadcastEvent(fake_pan_ev)
UIManager:broadcastEvent(fake_release_ev)
end
elseif ev.code == SDL_MULTIGESTURE then
-- no-op for now
do end -- luacheck: ignore 541
elseif ev.code == SDL_DROPFILE then
local dropped_file_path = ev.value
if dropped_file_path and dropped_file_path ~= "" then
Expand Down Expand Up @@ -132,6 +136,7 @@ function Device:init()
setClipboardText = function(text)
return input.setClipboardText(text)
end,
file_chooser = input.file_chooser,
}
else
self.screen = require("ffi/framebuffer_SDL1_2"):new{device = self, debug = logger.dbg}
Expand Down
3 changes: 3 additions & 0 deletions frontend/device/sdl/event_map_sdl2.lua
Expand Up @@ -32,4 +32,7 @@ return {
[81] = "Down", -- arrow down
[78] = "RPgFwd", -- normal PageDown
[76] = "Del", -- Delete
[101] = "ContextMenu", -- Context menu key
[224] = "Ctrl", -- Left Ctrl
[228] = "Ctrl", -- Right Ctrl
}

0 comments on commit 086ced0

Please sign in to comment.