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

Add mlx_new_fullscreen_window. #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

librity
Copy link

@librity librity commented Feb 18, 2022

I would like to add this functions that lets you create a fullscreen window.
I wanna add a fullscreen mode to my fract-ol project.

It's almost identical to mlx_new_window, except it gets the screen resolution from mlx_get_screen_size and sets the override_redirect WindowAttribute to true.
It's based on @jerem-ma 's implementation:

I don't know if there's a better way of doing this, and I'm open to suggestions.
I also separated the test main into different functions to facilitate debugging.

Thank you for your time.

@jerem-ma
Copy link

jerem-ma commented Feb 18, 2022

Hi !
This function you found on my repo is pretty ugly, for example it asks for a size even if it does not need one at all haha.
For the moment, this function is only used for test, let me fix that later, it will be prettier 👌

EDIT : Ah no, I do not have that in my function, you added that by your own, mb. It is still not pretty 👀

@Rush-iam
Copy link

I think it will be much better not to duplicate whole 50-lines function with differences in 2 lines, but make it much shorter with only 3 steps:

  1. mlx_get_screen_size()
  2. mlx_new_window() with screen size from step 1
  3. XChangeWindowAttributes() which will change override_redirect attribute of window from step 2

@librity
Copy link
Author

librity commented Feb 18, 2022

I think it will be much better not to duplicate whole 50-lines function with differences in 2 lines, but make it much shorter with only 3 steps:

  1. mlx_get_screen_size()
  2. mlx_new_window() with screen size from step 1
  3. XChangeWindowAttributes() which will change override_redirect attribute of window from step 2

Will do.

@librity
Copy link
Author

librity commented Feb 18, 2022

void	*mlx_new_fullscreen_window(t_xvar *xvar, int *size_x, int *size_y,
		char *title)
{
	t_win_list				*new_win;
	XSetWindowAttributes	x_set_wa;

	x_set_wa.override_redirect = 1;
	mlx_get_screen_size(xvar, size_x, size_y);
	new_win = mlx_new_window(xvar, *size_x, *size_y, title);
	if (new_win == NULL)
		return (NULL);
	XChangeWindowAttributes(xvar->display, new_win->window,
		CWOverrideRedirect,
		&x_set_wa
	);
	return (new_win);
}

@Rush-iam it's segfaulting when I call XChangeWindowAttributes, any insights why that might be?

@librity
Copy link
Author

librity commented Feb 19, 2022

@Rush-iam I ran XChangeWindowAttributes in the test main and it doesn't make the window go fullscreen, probably due to one of the many forced configs set in mlx_new_window.
I managed to re-use much of the logic with static functions.

Copy link

@vcwild vcwild left a comment

Choose a reason for hiding this comment

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

LGTM! 🔥 🔥

This is really useful if someone is using mlx with a tiling window manager

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.

None yet

4 participants