Skip to content

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

Merged
spytheman merged 7 commits into
vlang:masterfrom
islonely:master
Jan 2, 2025
Merged

gg: add linux support for fn screen_size() Size fix (#23146)#23326
spytheman merged 7 commits into
vlang:masterfrom
islonely:master

Conversation

@islonely

@islonely islonely commented Dec 31, 2024

Copy link
Copy Markdown
Contributor

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

Comment thread vlib/gg/gg.c.v
Comment thread vlib/gg/gg.c.v Outdated
@spytheman

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

islonely commented Jan 1, 2025

Copy link
Copy Markdown
Contributor Author

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

islonely commented Jan 1, 2025

Copy link
Copy Markdown
Contributor Author

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

Comment thread vlib/gg/gg.c.v Outdated

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

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
@Wajinn

Wajinn commented Jan 16, 2025

Copy link
Copy Markdown

Fantastic!

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

4 participants