GoLang, Pixel, Monitor

Like many, I am sure, I dove right in and created a window in pixel as my first interaction with the GoLang package. After creating a window I wanted to find out how I could resize the window or make the window fullscreen. So I have decided to explore the pixelgl monitor.go file. I want to find what properties and values I can get when detecting my monitor or monitors.

I have placed a snippet of code in below to show the data you can collect about your monitor or monitors. I am not creating a window yet, that will come in another code snippet, for now I am collecting data I may need in the future.

package main

import (
	"fmt"

	"github.com/faiface/pixel/pixelgl"
)

func run() {
	monitors := pixelgl.Monitors()

	for i, m := range monitors {

		fmt.Printf("monitor %v:\n", i)

		name := m.Name()
		fmt.Printf("-name: %v\n", name)

		bitDepthRed, bitDepthGreen, bitDepthBlue := m.BitDepth()
		fmt.Printf("-bitDepth: %v-bit red, %v-bit green, %v-bit blue\n",
			bitDepthRed, bitDepthGreen, bitDepthBlue)

		physicalSizeWidth, physicalSizeHeight := m.PhysicalSize()
		fmt.Printf("-physicalSize: %v mm, %v mm\n",
			physicalSizeWidth, physicalSizeHeight)

		positionX, positionY := m.Position()
		fmt.Printf("-position: %v, %v upper-left corner\n",
			positionX, positionY)

		refreshRate := m.RefreshRate()
		fmt.Printf("-refreshRate: %v Hz\n", refreshRate)

		sizeWidth, sizeHeight := m.Size()
		fmt.Printf("-size: %v px, %v px\n",
			sizeWidth, sizeHeight)

		videoModes := m.VideoModes()

		for j, vm := range videoModes {

			fmt.Printf("-video mode %v: -width: %v px, height: %v px, refresh rate:%v Hz\n",
				j, vm.Width, vm.Height, vm.RefreshRate)

		}
	}

	primaryMonitor := pixelgl.PrimaryMonitor()

	primaryMonitorName := primaryMonitor.Name()
	fmt.Printf("\nprimary monitor name: %v\n", primaryMonitorName)

}

func main() {
	pixelgl.Run(run)
}
monitor 0:
-name: eDP
-bitDepth: 8-bit red, 8-bit green, 8-bit blue
-physicalSize: 509 mm, 286 mm
-position: 0, 0 upper-left corner
-refreshRate: 59 Hz
-size: 1920 px, 1080 px
-video mode 0: -width: 640 px, height: 480 px, refresh rate:59 Hz
-video mode 1: -width: 720 px, height: 480 px, refresh rate:59 Hz
-video mode 2: -width: 848 px, height: 480 px, refresh rate:59 Hz
-video mode 3: -width: 800 px, height: 600 px, refresh rate:59 Hz
-video mode 4: -width: 1024 px, height: 768 px, refresh rate:59 Hz
-video mode 5: -width: 1152 px, height: 768 px, refresh rate:59 Hz
-video mode 6: -width: 1280 px, height: 720 px, refresh rate:59 Hz
-video mode 7: -width: 1280 px, height: 800 px, refresh rate:59 Hz
-video mode 8: -width: 1280 px, height: 854 px, refresh rate:59 Hz
-video mode 9: -width: 1280 px, height: 960 px, refresh rate:59 Hz
-video mode 10: -width: 1440 px, height: 900 px, refresh rate:59 Hz
-video mode 11: -width: 1280 px, height: 1024 px, refresh rate:59 Hz
-video mode 12: -width: 1400 px, height: 1050 px, refresh rate:59 Hz
-video mode 13: -width: 1680 px, height: 1050 px, refresh rate:59 Hz
-video mode 14: -width: 1920 px, height: 1080 px, refresh rate:59 Hz

monitor 1:
-name: HDMI-0
-bitDepth: 8-bit red, 8-bit green, 8-bit blue
-physicalSize: 477 mm, 268 mm
-position: 1920, 0 upper-left corner
-refreshRate: 60 Hz
-size: 1920 px, 1080 px
-video mode 0: -width: 720 px, height: 400 px, refresh rate:70 Hz
-video mode 1: -width: 640 px, height: 480 px, refresh rate:59 Hz
-video mode 2: -width: 640 px, height: 480 px, refresh rate:66 Hz
-video mode 3: -width: 640 px, height: 480 px, refresh rate:72 Hz
-video mode 4: -width: 640 px, height: 480 px, refresh rate:75 Hz
-video mode 5: -width: 800 px, height: 600 px, refresh rate:56 Hz
-video mode 6: -width: 800 px, height: 600 px, refresh rate:60 Hz
-video mode 7: -width: 800 px, height: 600 px, refresh rate:72 Hz
-video mode 8: -width: 800 px, height: 600 px, refresh rate:75 Hz
-video mode 9: -width: 832 px, height: 624 px, refresh rate:74 Hz
-video mode 10: -width: 1024 px, height: 768 px, refresh rate:60 Hz
-video mode 11: -width: 1024 px, height: 768 px, refresh rate:70 Hz
-video mode 12: -width: 1024 px, height: 768 px, refresh rate:75 Hz
-video mode 13: -width: 1152 px, height: 864 px, refresh rate:75 Hz
-video mode 14: -width: 1280 px, height: 800 px, refresh rate:59 Hz
-video mode 15: -width: 1280 px, height: 960 px, refresh rate:60 Hz
-video mode 16: -width: 1440 px, height: 900 px, refresh rate:59 Hz
-video mode 17: -width: 1280 px, height: 1024 px, refresh rate:60 Hz
-video mode 18: -width: 1280 px, height: 1024 px, refresh rate:75 Hz
-video mode 19: -width: 1600 px, height: 900 px, refresh rate:60 Hz
-video mode 20: -width: 1400 px, height: 1050 px, refresh rate:59 Hz
-video mode 21: -width: 1680 px, height: 1050 px, refresh rate:59 Hz
-video mode 22: -width: 1600 px, height: 1200 px, refresh rate:60 Hz
-video mode 23: -width: 1920 px, height: 1080 px, refresh rate:60 Hz

primary monitor name: eDP

Conclusion

As you can see from the output, there is some valuable information here that could be used in detecting your primary monitor or the video modes from your primary monitor or monitors. This gives me a little more knowledge about the window creation tutorial. The tutorial does not go into using the Monitor field, but I will tackle that in my next snippet.

Good luck with your own setup.

Be kind, Steve

comments powered by Disqus