From fc692576601de6dba50a2d50b65a804801ff780b Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 11 Mar 2019 02:01:37 -0700 Subject: [PATCH] fix: auto dpi menu checkbox display (#4771) --- frontend/device/generic/device.lua | 2 ++ frontend/ui/elements/screen_dpi_menu_table.lua | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index b992ce188..6d6996a7d 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -13,6 +13,7 @@ local Device = { model = nil, powerd = nil, screen = nil, + screen_dpi_override = nil, input = nil, -- For Kobo, wait at least 15 seconds before calling suspend script. Otherwise, suspend might -- fail and the battery will be drained while we are in screensaver mode @@ -146,6 +147,7 @@ end function Device:setScreenDPI(dpi_override) self.screen:setDPI(dpi_override) self.input.gesture_detector:init() + self.screen_dpi_override = dpi_override end function Device:getPowerDevice() diff --git a/frontend/ui/elements/screen_dpi_menu_table.lua b/frontend/ui/elements/screen_dpi_menu_table.lua index cf30696e4..001a48233 100644 --- a/frontend/ui/elements/screen_dpi_menu_table.lua +++ b/frontend/ui/elements/screen_dpi_menu_table.lua @@ -1,7 +1,10 @@ local _ = require("gettext") -local Screen = require("device").screen +local Device = require("device") +local Screen = Device.screen local T = require("ffi/util").template +local function isAutoDPI() return Device.screen_dpi_override == nil end + local function dpi() return Screen:getDPI() end local function custom() return G_reader_settings:readSetting("custom_screen_dpi") end @@ -14,7 +17,7 @@ local function setDPI(_dpi) or _("DPI set to auto. This will take effect after restarting."), }) G_reader_settings:saveSetting("screen_dpi", _dpi) - Screen:setDPI(_dpi) + Device:setScreenDPI(_dpi) end local dpi_auto = Screen.device.screen_dpi @@ -31,14 +34,13 @@ return { { text = dpi_auto and T(_("Auto DPI (%1)"), dpi_auto) or _("Auto DPI"), help_text = _("The DPI of your screen is automatically detected so items can be drawn with the right amount of pixels. This will usually display at (roughly) the same size on different devices, while remaining sharp. Increasing the DPI setting will result in larger text and icons, while a lower DPI setting will look smaller on the screen."), - checked_func = function() - return dpi() == nil - end, + checked_func = isAutoDPI, callback = function() setDPI() end }, { text = T(_("Small (%1)"), dpi_small), checked_func = function() + if isAutoDPI() then return false end local _dpi, _custom = dpi(), custom() return _dpi and _dpi <= 140 and _dpi ~= _custom end, @@ -47,6 +49,7 @@ return { { text = T(_("Medium (%1)"), dpi_medium), checked_func = function() + if isAutoDPI() then return false end local _dpi, _custom = dpi(), custom() return _dpi and _dpi > 140 and _dpi <= 200 and _dpi ~= _custom end, @@ -55,6 +58,7 @@ return { { text = T(_("Large (%1)"), dpi_large), checked_func = function() + if isAutoDPI() then return false end local _dpi, _custom = dpi(), custom() return _dpi and _dpi > 200 and _dpi <= 280 and _dpi ~= _custom end, @@ -63,6 +67,7 @@ return { { text = T(_("Extra large (%1)"), dpi_xlarge), checked_func = function() + if isAutoDPI() then return false end local _dpi, _custom = dpi(), custom() return _dpi and _dpi > 280 and _dpi <= 400 and _dpi ~= _custom end, @@ -71,6 +76,7 @@ return { { text = T(_("Extra-Extra Large (%1)"), dpi_xxlarge), checked_func = function() + if isAutoDPI() then return false end local _dpi, _custom = dpi(), custom() return _dpi and _dpi > 400 and _dpi <= 560 and _dpi ~= _custom end, @@ -79,6 +85,7 @@ return { { text = T(_("Extra-Extra-Extra Large (%1)"), dpi_xxxlarge), checked_func = function() + if isAutoDPI() then return false end local _dpi, _custom = dpi(), custom() return _dpi and _dpi > 560 and _dpi ~= _custom end, @@ -89,6 +96,7 @@ return { return T(_("Custom DPI: %1 (hold to set)"), custom() or dpi_auto) end, checked_func = function() + if isAutoDPI() then return false end local _dpi, _custom = dpi(), custom() return _custom and _dpi == _custom end,