/
676767ap
/
AstroCatGame
Обзор
Документация
Войти
/
676767ap
/
AstroCatGame
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
resolution/linux_list.go
77 строк
2 KB
Anton Polikapov
Swithcing to 1920x1080 resolution
01 мар 2024, 16:27
01 мар 2024, 16:27
ad9a4d7
Код
Авторство
О чём код?
package resolution // #cgo LDFLAGS: -lX11 -lXrandr -lstdc++ // #include <X11/Xlib.h> // #include <X11/extensions/Xrandr.h> import "C" import ( "unsafe" ) var resPreset = []ScreenRes{ {3840, 2400}, {3840, 2160}, {3200, 1800}, {2880, 1800}, {2560, 1600}, {2736, 1824}, {2256, 1504}, {2560, 1440}, {1920, 1080}, {1680, 1050}, {1600, 900}, {1536, 864}, {1440, 900}, {1400, 1050}, {1366, 768}, {1280, 1024}, {1280, 800}, {1024, 768}, {800, 600}, } func ListResolutionsLinux() *ScreenResList { sl := &ScreenResList{ Resolutions: make(map[int]ScreenRes), } // Get the main display of X server. display := C.XOpenDisplay(nil) // Get the ID of the root window. window := C.XRootWindow(display, 0) // Get the information about the display. conf := C.XRRGetScreenInfo(display, window) // Get the rotation of the display. var originalRotation C.Rotation C.XRRConfigCurrentConfiguration(conf, &originalRotation) // Get the array of resolutions. var numSizes C.int resolutions := C.XRRSizes(display, 0, &numSizes) // Turn it into a Go slice. goResolutions := (*[1 << 30]C.XRRScreenSize)( unsafe.Pointer(resolutions))[:numSizes:numSizes] // Get all the frequency rates for each resolution. resRates := make([][]C.short, numSizes) for i := 0; i < int(numSizes); i++ { var numRates C.int rates := C.XRRRates(display, 0, C.int(i), &numRates) goRates := (*[1 << 30]C.short)( unsafe.Pointer(rates))[:numSizes:numSizes] // Add the array of rates to the table // of rates for resolutions. resRates[i] = goRates } for i := 0; i < int(numSizes); i++ { for j := 0; j < len(resPreset); j++ { if int(goResolutions[i].width) == resPreset[j].Width && int(goResolutions[i].height) == resPreset[j].Height { sl.Resolutions[i] = resPreset[j] } } } return sl }