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

Conversation

islonely
Copy link
Contributor

@islonely islonely commented Dec 31, 2024

Fixes #23146 by adding support for Linux users using X11.

Huly®: V_0.6-21757

vlib/gg/gg.c.v Outdated Show resolved Hide resolved
@spytheman
Copy link
Member

This program:

#flag -lX11
#include <X11/Xlib.h>

@[typedef]
pub struct C.Display {}
fn C.XOpenDisplay(int) &C.Display
fn C.XCloseDisplay(display &C.Display) int
fn C.DefaultScreen(&C.Display) int
fn C.DisplayHeight(&C.Display, int) int
fn C.DisplayWidth(&C.Display, int) int

fn main() {
	println('start')
	display := C.XOpenDisplay(0)
	screen := C.DefaultScreen(display)
	dump( C.DisplayWidth(display, screen) )
	dump( C.DisplayHeight(display, screen) )
	C.XCloseDisplay(display)
	println('done')
}

locally produces:

start
[x.v:16] C.DisplayWidth(display, screen): 3840
[x.v:17] C.DisplayHeight(display, screen): 1080
done

I have 2 displays, both with a resolution of 1920x1080, according to xfce4-display-settings:
image

@spytheman
Copy link
Member

If I turn off the second monitor, I get:

start
[x.v:16] C.DisplayWidth(display, screen): 1920
[x.v:17] C.DisplayHeight(display, screen): 1080
done

@islonely
Copy link
Contributor Author

islonely commented Jan 1, 2025

If I turn off the second monitor, I get:

start
[x.v:16] C.DisplayWidth(display, screen): 1920
[x.v:17] C.DisplayHeight(display, screen): 1080
done

It seems there's not a good quick way to the size of a single screen. I'll be back with a solution soon.

@islonely
Copy link
Contributor Author

islonely commented Jan 1, 2025

libxrandr-dev is required on ubuntu based systems for this fix.

vlib/gg/gg.c.v Outdated Show resolved Hide resolved
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit c50d4ee into vlang:master Jan 2, 2025
69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update gg.c.v screen_size function for Linux and BSD-derivatives
3 participants