Add dpi-scale config option (#198)

If dpi-scale is set in aminal.toml then this overrides aminal's own
DPI calculation. This is useful for working around unusual monitor
setups or users just who prefer a different DPI scale.
This commit is contained in:
Menno Finlay-Smits 2019-02-06 02:18:24 +13:00 committed by Liam Galvin
parent c2b1b95343
commit 150b0493de
3 changed files with 33 additions and 22 deletions

View File

@ -114,6 +114,7 @@ shell = "/bin/bash" # The shell to run for the terminal session. Default
search_url = "https://www.google.com/search?q=$QUERY" # The search engine to use for the "search selected text" action. Defaults to google. Set this to your own search url using $QUERY as the keywords to replace when searching. search_url = "https://www.google.com/search?q=$QUERY" # The search engine to use for the "search selected text" action. Defaults to google. Set this to your own search url using $QUERY as the keywords to replace when searching.
max_lines = 1000 # Maximum number of lines in the terminal buffer. max_lines = 1000 # Maximum number of lines in the terminal buffer.
copy_and_paste_with_mouse = true # Text selected with the mouse is copied to the clipboard on end selection, and is pasted on right mouse button click. copy_and_paste_with_mouse = true # Text selected with the mouse is copied to the clipboard on end selection, and is pasted on right mouse button click.
dpi-scale = 0.0 # Override DPI scale. Defaults to 0.0 (let Aminal determine the DPI scale itself).
[colours] [colours]
cursor = "#e8dfd6" cursor = "#e8dfd6"

View File

@ -7,14 +7,15 @@ import (
) )
type Config struct { type Config struct {
DebugMode bool `toml:"debug"` DebugMode bool `toml:"debug"`
Slomo bool `toml:"slomo"` Slomo bool `toml:"slomo"`
ColourScheme ColourScheme `toml:"colours"` ColourScheme ColourScheme `toml:"colours"`
Shell string `toml:"shell"` DPIScale float32 `toml:"dpi-scale"`
KeyMapping KeyMappingConfig `toml:"keys"` Shell string `toml:"shell"`
SearchURL string `toml:"search_url"` KeyMapping KeyMappingConfig `toml:"keys"`
MaxLines uint64 `toml:"max_lines"` SearchURL string `toml:"search_url"`
CopyAndPasteWithMouse bool `toml:"copy_and_paste_with_mouse"` MaxLines uint64 `toml:"max_lines"`
CopyAndPasteWithMouse bool `toml:"copy_and_paste_with_mouse"`
} }
type KeyMappingConfig map[string]string type KeyMappingConfig map[string]string

View File

@ -50,12 +50,12 @@ type GUI struct {
arrowCursor *glfw.Cursor arrowCursor *glfw.Cursor
defaultCell *buffer.Cell defaultCell *buffer.Cell
prevLeftClickX uint16 prevLeftClickX uint16
prevLeftClickY uint16 prevLeftClickY uint16
leftClickTime time.Time leftClickTime time.Time
leftClickCount int // number of clicks in a serie - single click, double click, or triple click leftClickCount int // number of clicks in a serie - single click, double click, or triple click
mouseMovedAfterSelectionStarted bool mouseMovedAfterSelectionStarted bool
internalResize bool internalResize bool
} }
func Min(x, y int) int { func Min(x, y int) int {
@ -113,23 +113,32 @@ func (g *GUI) GetMonitor() *glfw.Monitor {
return currentMonitor return currentMonitor
} }
// RecalculateDpiScale calculates dpi scale in comparison with "standard" monitor's dpi values // SetDPIScale sets the GUI DPI scale from user configuration (if set)
func (g *GUI) RecalculateDpiScale() { // or by calculating it from the monitor's configuration and size.
func (g *GUI) SetDPIScale() {
if g.config.DPIScale > 0 {
g.dpiScale = g.config.DPIScale
return
}
g.dpiScale = g.calculateDpiScale()
}
// calculateDpiScale determines the DPI scale in comparison with "standard" monitor's DPI values.
func (g *GUI) calculateDpiScale() float32 {
const standardDpi = 96 const standardDpi = 96
const mmPerInch = 25.4 const mmPerInch = 25.4
m := g.GetMonitor() m := g.GetMonitor()
widthMM, _ := m.GetPhysicalSize() widthMM, _ := m.GetPhysicalSize()
if widthMM == 0 { if widthMM == 0 {
g.dpiScale = 1.0 return 1.0
} else {
monitorDpi := float32(m.GetVideoMode().Width) / (float32(widthMM) / mmPerInch)
g.dpiScale = monitorDpi / standardDpi
} }
monitorDpi := float32(m.GetVideoMode().Width) / (float32(widthMM) / mmPerInch)
return monitorDpi / standardDpi
} }
func New(config *config.Config, terminal *terminal.Terminal, logger *zap.SugaredLogger) (*GUI, error) { func New(config *config.Config, terminal *terminal.Terminal, logger *zap.SugaredLogger) (*GUI, error) {
shortcuts, err := config.KeyMapping.GenerateActionMap() shortcuts, err := config.KeyMapping.GenerateActionMap()
if err != nil { if err != nil {
return nil, err return nil, err
@ -293,7 +302,7 @@ func (gui *GUI) Render() error {
gui.logger.Debugf("Creating window...") gui.logger.Debugf("Creating window...")
var err error var err error
gui.window, err = gui.createWindow() gui.window, err = gui.createWindow()
gui.RecalculateDpiScale() gui.SetDPIScale()
gui.window.SetSize(int(float32(gui.width)*gui.dpiScale), gui.window.SetSize(int(float32(gui.width)*gui.dpiScale),
int(float32(gui.height)*gui.dpiScale)) int(float32(gui.height)*gui.dpiScale))
if err != nil { if err != nil {