diff --git a/.github/workflows/gg_regressions_ci.yml b/.github/workflows/gg_regressions_ci.yml index 4ea21a06bc5ecf..64be6c48e6ef20 100644 --- a/.github/workflows/gg_regressions_ci.yml +++ b/.github/workflows/gg_regressions_ci.yml @@ -45,7 +45,7 @@ jobs: # libgl1-mesa-dri : For headless rendering / software DRI driver (LIBGL_ALWAYS_SOFTWARE=true) # freeglut3-dev : Fixes graphic apps compilation with tcc ./v retry -- sudo apt update - ./v retry -- sudo apt install imagemagick openimageio-tools libgl1-mesa-dri xvfb libxcursor-dev libxi-dev freeglut3-dev xsel xclip + ./v retry -- sudo apt install imagemagick openimageio-tools libgl1-mesa-dri xvfb libxcursor-dev libxi-dev libxrandr-dev freeglut3-dev xsel xclip ./v retry -- ./v download https://raw.githubusercontent.com/tremby/imgur.sh/c98345d/imgur.sh ./v retry -- git clone https://github.com/Larpon/gg-regression-images gg-regression-images chmod +x ./imgur.sh diff --git a/.github/workflows/other_ci.yml b/.github/workflows/other_ci.yml index 9b7c5da77a8676..d9f0cfc8c82d75 100644 --- a/.github/workflows/other_ci.yml +++ b/.github/workflows/other_ci.yml @@ -101,7 +101,7 @@ jobs: run: | ./v retry -- sudo apt update ./v retry -- sudo apt install --quiet -y libsodium-dev libssl-dev sqlite3 libsqlite3-dev postgresql libpq-dev valgrind - ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev xfonts-75dpi xfonts-base + ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev xfonts-75dpi xfonts-base ./v retry -- sudo apt install --quiet -y g++-9 g++-10 - name: g++-9 version diff --git a/.github/workflows/sanitized_ci.yml b/.github/workflows/sanitized_ci.yml index 8120f6e097ef87..7143e675c109b4 100644 --- a/.github/workflows/sanitized_ci.yml +++ b/.github/workflows/sanitized_ci.yml @@ -90,7 +90,7 @@ jobs: run: | ./v retry -- sudo apt update ./v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind - ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev + ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev ./v retry -- sudo apt install clang - name: Recompile V with -cstrict run: ./v -cg -cstrict -o v cmd/v @@ -116,7 +116,7 @@ jobs: run: | ./v retry -- sudo apt update ./v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind - ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev + ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev - name: Recompile V with -cstrict run: ./v -cg -cstrict -o v cmd/v - name: Self tests (-fsanitize=undefined) @@ -141,7 +141,7 @@ jobs: run: | ./v retry -- sudo apt update ./v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind - ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev + ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev ./v retry -- sudo apt install clang - name: Recompile V with -cstrict run: ./v -cg -cstrict -o v cmd/v @@ -194,7 +194,7 @@ jobs: run: | ./v retry -- sudo apt update ./v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind - ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev + ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev ./v retry -- sudo apt install clang - name: Recompile V with -cstrict run: ./v -cg -cstrict -o v cmd/v @@ -224,7 +224,7 @@ jobs: run: | ./v retry -- sudo apt update ./v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind - ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev + ./v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev ./v retry -- sudo apt install clang - name: Recompile V with clang and -cstrict run: ./v -cc clang -cg -cstrict -o v cmd/v diff --git a/.github/workflows/v_apps_and_modules_compile_ci.yml b/.github/workflows/v_apps_and_modules_compile_ci.yml index 1937e525067dd5..569deae304941c 100644 --- a/.github/workflows/v_apps_and_modules_compile_ci.yml +++ b/.github/workflows/v_apps_and_modules_compile_ci.yml @@ -40,7 +40,7 @@ jobs: if [ $RUNNER_OS == 'Linux' ]; then v retry -- sudo apt -qq update v retry -- sudo apt -qq install libgc-dev libsodium-dev libssl-dev sqlite3 libsqlite3-dev - v retry -- sudo apt -qq install libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev xfonts-75dpi xfonts-base + v retry -- sudo apt -qq install libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev xfonts-75dpi xfonts-base v retry -- sudo apt -qq install sassc libgit2-dev # needed by gitly else v retry brew install sassc libgit2 diff --git a/.github/workflows/vsl_and_vtl_compile_ci.yml b/.github/workflows/vsl_and_vtl_compile_ci.yml index d3d7a759cf3689..8000d4b7473a05 100644 --- a/.github/workflows/vsl_and_vtl_compile_ci.yml +++ b/.github/workflows/vsl_and_vtl_compile_ci.yml @@ -41,7 +41,7 @@ jobs: v retry -- sudo apt -qq update v retry -- sudo apt -qq install \ libgc-dev libgl1-mesa-dev mesa-common-dev liblapacke-dev libopenblas-dev libopenmpi-dev \ - opencl-headers libxcursor-dev libxi-dev libhdf5-cpp-103 libhdf5-dev libhdf5-mpi-dev hdf5-tools + opencl-headers libxcursor-dev libxi-dev libxrandr-dev libhdf5-cpp-103 libhdf5-dev libhdf5-mpi-dev hdf5-tools else v retry brew install coreutils hdf5 open-mpi openblas lapack opencl-headers fi diff --git a/README.md b/README.md index eee4eef374db35..0c7840b9d22023 100644 --- a/README.md +++ b/README.md @@ -266,16 +266,21 @@ v run news_fetcher.v v run tetris/tetris.v ``` + tetris screenshot -In order to build Tetris or 2048 (or anything else using `sokol` or `gg` graphics modules), -you will need additional development libraries for your system. +## Sokol and GG GUI apps/games: + +In order to build Tetris or 2048 (or anything else using the `sokol` or `gg` graphics modules), +you will need to install additional development libraries for your system. | System | Installation method | |---------------------|----------------------------------------------------------------------------------------------------| -| Debian/Ubuntu based | `sudo apt install libxi-dev libxcursor-dev libgl-dev libasound2-dev` | -| Fedora/RH/CentOS | `sudo dnf install libXcursor-devel libXi-devel libX11-devel libglvnd-devel` | -| NixOS | add `xorg.libX11.dev xorg.libXcursor.dev xorg.libXi.dev libGL.dev` to `environment.systemPackages` | +| Debian/Ubuntu based | Run `sudo apt install libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev` | +| Fedora/RH/CentOS | Run `sudo dnf install libXi-devel libXcursor-devel libX11-devel libXrandr-devel libglvnd-devel` | +| | | +| NixOS | Add `xorg.libX11.dev xorg.libXcursor.dev xorg.libXi.dev xorg.libXrandr.dev libGL.dev` to | +| | to `environment.systemPackages` | ## V net.http, net.websocket, `v install` diff --git a/ci/linux_ci.vsh b/ci/linux_ci.vsh index 1974b969bf0742..24ccd11a887d9f 100644 --- a/ci/linux_ci.vsh +++ b/ci/linux_ci.vsh @@ -58,7 +58,7 @@ fn build_v_with_prealloc() { fn install_dependencies_for_examples_and_tools_tcc() { exec('v retry -- sudo apt update') exec('v retry -- sudo apt install --quiet -y libssl-dev sqlite3 libsqlite3-dev valgrind') - exec('v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev') + exec('v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev') // The following is needed for examples/wkhtmltopdf.v exec('v retry -- wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb') exec('v retry -- sudo apt install --quiet -y xfonts-75dpi xfonts-base') @@ -171,7 +171,7 @@ fn all_code_is_formatted_gcc() { fn install_dependencies_for_examples_and_tools_gcc() { exec('v retry -- sudo apt update') exec('v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind') - exec('v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev') + exec('v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev') } fn recompile_v_with_cstrict_gcc() { @@ -287,7 +287,7 @@ fn all_code_is_formatted_clang() { fn install_dependencies_for_examples_and_tools_clang() { exec('v retry -- sudo apt update') exec('v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind') - exec('v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev') + exec('v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libxrandr-dev libasound2-dev') exec('v retry -- sudo apt install --quiet -y clang') } diff --git a/examples/tetris/README.md b/examples/tetris/README.md index 06fcba5e961845..e3192522873a7d 100644 --- a/examples/tetris/README.md +++ b/examples/tetris/README.md @@ -5,6 +5,7 @@ sudo apt install libx11-dev sudo apt install libxi-dev sudo apt install libxcursor-dev +sudo apt install libxrandr-dev sudo apt install libgl-dev ``` diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index 82bef109433e2f..1da6579312677b 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -10,6 +10,40 @@ import sokol.sapp import sokol.sgl import sokol.gfx +@[typedef] +struct C.XRRScreenResources { + noutput int + outputs &int +} + +@[typedef] +struct C.XRROutputInfo { + crtc u64 +} + +@[typedef] +struct C.XRRCrtcInfo { + width u32 + height u32 +} + +fn C.XOpenDisplay(int) voidptr +fn C.XCloseDisplay(voidptr) int +fn C.DefaultScreen(voidptr) int +fn C.DefaultRootWindow(voidptr) u64 +fn C.XRRGetScreenResources(voidptr, u64) &C.XRRScreenResources +fn C.XRRGetOutputPrimary(voidptr, u64) u64 +fn C.XRRFreeScreenResources(&C.XRRScreenResources) +fn C.XRRGetOutputInfo(voidptr, &C.XRRScreenResources, u64) &C.XRROutputInfo +fn C.XRRFreeOutputInfo(&C.XRROutputInfo) +fn C.XRRGetCrtcInfo(voidptr, &C.XRRScreenResources, u64) &C.XRRCrtcInfo +fn C.XRRFreeCrtcInfo(&C.XRRCrtcInfo) + +$if linux { + #flag -lXrandr + #include +} + $if windows { #flag -lgdi32 #include "windows.h" @@ -739,7 +773,41 @@ pub fn screen_size() Size { height: int(C.GetSystemMetrics(C.SM_CYSCREEN)) } } - // TODO: linux, etc + $if linux { + display := C.XOpenDisplay(0) + if display == unsafe { nil } { + return Size{} + } + defer { C.XCloseDisplay(display) } + root := C.DefaultRootWindow(display) + resources := C.XRRGetScreenResources(display, root) + if resources == unsafe { nil } { + return Size{} + } + defer { C.XRRFreeScreenResources(resources) } + primary_output := C.XRRGetOutputPrimary(display, root) + if primary_output == 0 { + return Size{} + } + for i := 0; i < resources.noutput; i++ { + if unsafe { u64(resources.outputs[i]) } == primary_output { + output_info := C.XRRGetOutputInfo(display, resources, unsafe { resources.outputs[i] }) + if output_info == unsafe { nil } { + return Size{} + } + defer { C.XRRFreeOutputInfo(output_info) } + crtc_info := C.XRRGetCrtcInfo(display, resources, output_info.crtc) + if crtc_info == unsafe { nil } { + return Size{} + } + defer { C.XRRFreeCrtcInfo(crtc_info) } + return Size{ + width: unsafe { int(crtc_info.width) } + height: unsafe { int(crtc_info.height) } + } + } + } + } return Size{} }