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.
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.
dpi-scale = 0.0 # Override DPI scale. Defaults to 0.0 (let Aminal determine the DPI scale itself).
[colours]
cursor = "#e8dfd6"

View File

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

View File

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