Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gg: add linux support for fn screen_size() Size fix (#23146) #23326

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gg_regressions_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/other_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/sanitized_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/v_apps_and_modules_compile_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vsl_and_vtl_compile_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,21 @@ v run news_fetcher.v
v run tetris/tetris.v
```


<img src='https://raw.githubusercontent.com/vlang/v/master/examples/tetris/screenshot.png' width=300 alt='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`

Expand Down
6 changes: 3 additions & 3 deletions ci/linux_ci.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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')
}

Expand Down
1 change: 1 addition & 0 deletions examples/tetris/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
70 changes: 69 additions & 1 deletion vlib/gg/gg.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 <X11/extensions/Xrandr.h>
}

$if windows {
#flag -lgdi32
#include "windows.h"
Expand Down Expand Up @@ -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)
islonely marked this conversation as resolved.
Show resolved Hide resolved
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{}
}

Expand Down
Loading