Skip to content

Commit

Permalink
Add more debugging logs and respect system dpi settings
Browse files Browse the repository at this point in the history
  • Loading branch information
hismailbulut committed Aug 18, 2021
1 parent 680513a commit 4e508e6
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/args.go
Expand Up @@ -153,9 +153,10 @@ func (options ParsedArgs) ProcessAfter() {
if options.singleinst {
server, err := CreateServer()
if err != nil {
logMessage(LOG_LEVEL_ERROR, LOG_TYPE_NEORAY, "Failed to create TCP listener:", err)
logMessage(LOG_LEVEL_ERROR, LOG_TYPE_NEORAY, "Failed to create tcp server:", err)
} else {
singleton.server = server
logMessage(LOG_LEVEL_TRACE, LOG_TYPE_NEORAY, "Tcp server created.")
}
}
if options.file != "" {
Expand Down
7 changes: 6 additions & 1 deletion src/font.go
Expand Up @@ -23,6 +23,9 @@ type Font struct {

func CreateDefaultFont() Font {
defer measure_execution_time()()

logDebug("Loading default font.")

font := Font{
size: DEFAULT_FONT_SIZE,
}
Expand Down Expand Up @@ -58,9 +61,11 @@ func CreateDefaultFont() Font {
func CreateFont(fontName string, size float32) (Font, bool) {
defer measure_execution_time()()

logDebug("Loading font", fontName, "with size", size)

if size < MINIMUM_FONT_SIZE {
logMessage(LOG_LEVEL_WARN, LOG_TYPE_NEORAY,
"Font size", size, "is small and set to default", DEFAULT_FONT_SIZE)
"Font size", size, "is small and automatically set to default", DEFAULT_FONT_SIZE)
size = DEFAULT_FONT_SIZE
}

Expand Down
21 changes: 1 addition & 20 deletions src/fontface.go
Expand Up @@ -17,10 +17,6 @@ const (
FONT_HINTING = font.HintingFull
)

var (
EnableExperimentalGlyphRendering bool
)

type FontFace struct {
handle font.Face
fontHandle *sfnt.Font
Expand Down Expand Up @@ -140,22 +136,7 @@ func (fontFace *FontFace) renderGlyph(char rune) *image.RGBA {
}
img := image.NewRGBA(image.Rect(0, 0, width, height))
draw.DrawMask(img, dr, image.White, image.Point{}, mask, maskp, draw.Over)

if !EnableExperimentalGlyphRendering {
return img
} else {
// Sandbox area for trying to improve glyph rendering quality and currently experimental.
// Could be enabled via F7 key only in debug build.
expImage := image.NewRGBA(img.Bounds())
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
mid := img.RGBAAt(x, y)
// Do something with pixels
expImage.SetRGBA(x, y, mid)
}
}
return expImage
}
return img
}
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions src/input.go
Expand Up @@ -226,20 +226,20 @@ func keyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action,
singleton.window.toggleFullscreen()
return
case "<ESC>":
// Hide popupmenu if esc pressed.
if singleton.options.popupMenuEnabled && !singleton.popupMenu.hidden {
singleton.popupMenu.Hide()
return
}
break
}

// For debugging
if isDebugBuild() {
switch keycode {
case "<F7>":
EnableExperimentalGlyphRendering = !EnableExperimentalGlyphRendering
singleton.renderer.clearAtlas()
return
case "<C-F2>":
panic("Control+F2 manual panic")
case "<C-F3>":
logMessage(LOG_LEVEL_FATAL, LOG_TYPE_NEORAY, "Control+F3 manual fatal")
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/logger.go
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"os"
"path/filepath"
"runtime/debug"
"runtime"
"time"

"github.com/sqweek/dialog"
Expand Down Expand Up @@ -74,11 +74,14 @@ func createCrashReport(msg string) {
crash_file, err := os.Create("neoray_crash.log")
if err == nil {
defer crash_file.Close()
crash_file.WriteString("NEORAY " + versionString() + " " + buildTypeString() + " Crash Report\n")
crash_file.WriteString(fmt.Sprintln("NEORAY", versionString(), buildTypeString(), "Crash Report", time.Now().UTC()))
crash_file.WriteString("Please open an issue in github with this file.\n")
crash_file.WriteString("The program is crashed because of the following reasons:\n")
crash_file.WriteString(msg)
crash_file.WriteString(fmt.Sprintln(string(debug.Stack())))
crash_file.WriteString("\ngoroutine dump:\n")
stackTrace := make([]byte, 1<<15)
stackLen := runtime.Stack(stackTrace, true)
crash_file.WriteString(string(stackTrace[:stackLen]))
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/nvimproc.go
Expand Up @@ -179,8 +179,7 @@ func (proc *NvimProcess) executeVimScript(format string, args ...interface{}) bo
logMessage(LOG_LEVEL_DEBUG, LOG_TYPE_NVIM, "Executing script: [", cmd, "]")
err := proc.handle.Command(cmd)
if err != nil {
logMessage(LOG_LEVEL_ERROR, LOG_TYPE_NVIM,
"Failed to execute vimscript: [", cmd, "] err:", err)
logMessage(LOG_LEVEL_ERROR, LOG_TYPE_NVIM, "Failed to execute vimscript: [", cmd, "] err:", err)
return false
}
return true
Expand Down
2 changes: 1 addition & 1 deletion src/renderer.go
Expand Up @@ -83,7 +83,7 @@ func (renderer *Renderer) setFontSize(size float32) {
renderer.clearAtlas()
renderer.fontSize = size
// TODO: Make all messages optional and can be disabled from init.vim.
singleton.nvim.echoMsg("Font Size: %.1f", size)
// singleton.nvim.echoMsg("Font Size: %.1f", size)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/renderergl.go
Expand Up @@ -43,6 +43,7 @@ var (
func rglInit() {
defer measure_execution_time()()

logDebug("Initializing opengl.")
// Initialize opengl
if err := gl.Init(); err != nil {
logMessage(LOG_LEVEL_FATAL, LOG_TYPE_RENDERER, "Failed to initialize opengl:", err)
Expand All @@ -55,7 +56,7 @@ func rglInit() {
rglCheckError("gl use program")

// Initialize vao
gl.CreateVertexArrays(1, &rgl_vao)
gl.GenVertexArrays(1, &rgl_vao)
gl.BindVertexArray(rgl_vao)

// Initialize vbo
Expand Down
3 changes: 2 additions & 1 deletion src/tcp.go
Expand Up @@ -135,6 +135,7 @@ func CreateServer() (*TCPServer, error) {
logMessage(LOG_LEVEL_WARN, LOG_TYPE_NEORAY, "Failed to read client data:", err)
break
}
logDebug("Signal Received:", data)
switch data {
case SIGNAL_CHECK_CONNECTION:
resp = SIGNAL_OK
Expand Down Expand Up @@ -192,9 +193,9 @@ func (server *TCPServer) update() {
break
}
}
singleton.window.raise()
server.data = nil
server.dataReceived.Set(false)
singleton.window.raise()
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/uioptions.go
Expand Up @@ -12,9 +12,9 @@ type UIOptions struct {
emoji bool
guifont string
guifontset string
guifontwide string
linespace int
pumblend int
guifontwide string // TODO
linespace int // TODO
pumblend int // TODO
showtabline int
termguicolors bool
// parsed options for forward usage
Expand Down
30 changes: 23 additions & 7 deletions src/window.go
Expand Up @@ -34,6 +34,8 @@ type Window struct {
func CreateWindow(width int, height int, title string) Window {
defer measure_execution_time()()

logDebug("Creating glfw window.")

videoMode := glfw.GetPrimaryMonitor().GetVideoMode()
rW := videoMode.Width
rH := videoMode.Height
Expand All @@ -45,6 +47,8 @@ func CreateWindow(width int, height int, title string) Window {
height = (rH / 4) * 3
}

logDebug("Window width:", width, "height:", height)

window := Window{
title: title,
width: width,
Expand All @@ -65,6 +69,7 @@ func CreateWindow(width int, height int, title string) Window {
logMessage(LOG_LEVEL_FATAL, LOG_TYPE_NEORAY, "Failed to create glfw window:", err)
}

logDebug("Glfw window created successfully.")
window.handle = windowHandle

window.handle.SetFramebufferSizeCallback(
Expand Down Expand Up @@ -204,14 +209,25 @@ func (window *Window) toggleFullscreen() {

func (window *Window) calculateDPI() {
monitor := glfw.GetPrimaryMonitor()

// Calculate physical diagonal size of the monitor in inches
pWidth, pHeight := monitor.GetPhysicalSize() // returns size in millimeters
pDiagonal := math.Sqrt(float64(pWidth*pWidth + pHeight*pHeight))
pDiagonalInch := pDiagonal * 0.0393700787
mWidth := monitor.GetVideoMode().Width
mHeight := monitor.GetVideoMode().Height
mDiagonal := math.Sqrt(float64(mWidth*mWidth + mHeight*mHeight))
window.dpi = mDiagonal / pDiagonalInch
logDebug("Monitor diagonal:", pDiagonalInch, "dpi:", window.dpi)
pDiagonal := math.Sqrt(float64(pWidth*pWidth+pHeight*pHeight)) * 0.0393700787

// Calculate logical diagonal size of the monitor in pixels
scaleX, scaleY := monitor.GetContentScale()
mWidth := float64(monitor.GetVideoMode().Width) * float64(scaleX)
mHeight := float64(monitor.GetVideoMode().Height) * float64(scaleY)
mDiagonal := math.Sqrt(mWidth*mWidth + mHeight*mHeight)

// Calculate dpi
window.dpi = mDiagonal / pDiagonal
if window.dpi < 72 {
// This could be actual dpi or we may failed to calculate dpi.
logMessage(LOG_LEVEL_WARN, LOG_TYPE_NEORAY, "Device dpi", window.dpi, "is very low and automatically set to 72.")
window.dpi = 72
}
logDebug("Monitor diagonal:", pDiagonal, "dpi:", window.dpi)
}

func (window *Window) Close() {
Expand Down

0 comments on commit 4e508e6

Please sign in to comment.