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

Monitor Display Switching Functions #9003

Open
Mr-Unown opened this issue Jan 12, 2025 · 5 comments
Open

Monitor Display Switching Functions #9003

Mr-Unown opened this issue Jan 12, 2025 · 5 comments
Labels
feature request New feature (or a request for one)

Comments

@Mr-Unown
Copy link

Is your feature request related to a problem?

Currently the only way (without extensions) of querying for multiple displays is through window_get_visible_rects(). In addition, simple functions for simply switching which display your game window doesn't exist, which leads to a lot of hacky solutions.

Describe the solution you'd like

Ideally, I want a whole suite of functions related to messing with the window and its current display.

  • window_set_display() // places your window in the specified display
  • window_get_display_count() // functions much like the gamepad_get_device_count() function
  • window_get_display_description() // could get monitor information and etc.
  • window_center() // could perhaps accept an optional value that matches a display index

Describe alternatives you've considered

No response

Additional context

No response

@Mr-Unown Mr-Unown added the feature request New feature (or a request for one) label Jan 12, 2025
@stuckie stuckie moved this from Triage to Backlog in Team Workload Jan 13, 2025
@gnysek
Copy link
Contributor

gnysek commented Jan 14, 2025

window_get_display_count is already kinda possible, with little trick:

function window_get_display_count() {
  var _data = window_get_visible_rects(0, 0, 1, 1);
  return array_length(_data) / 8;
}

You can get dimensions of screens in similar manner in fact (as window_get_visible_rects is meant to get info about which positions on screen current window overlaps, even if it's partially on more than 1 screen, but it also returns those displays dimensions, so by calling this function with any args we're getting info we want on positions 4..7, and +8 for each next monitor.

@Grisgram
Copy link

Grisgram commented Jan 14, 2025

window_get_display_count is already kinda possible, with little trick:

function window_get_display_count() {
var _data = window_get_visible_rects(0, 0, 1, 1);
return array_length(_data) / 8;
}
You can get dimensions of screens in similar manner in fact (as window_get_visible_rects is meant to get info about which positions on screen current window overlaps, even if it's partially on more than 1 screen, but it also returns those displays dimensions, so by calling this function with any args we're getting info we want on positions 4..7, and +8 for each next monitor.

This almost begs for a little MIT library to cover these in user-friendly functions, just in case, this FR never sees light of day...

@Alphish
Copy link
Contributor

Alphish commented Jan 14, 2025

I was wondering about adding it to the Community Toolbox, but a single function call takes about 0.3-0.6ms on my beefy PC, so doing various calls referring to window_get_visible_rects under the hood (like, "get number of displays", "get x/y/width/height of display X", etc.) might significantly bump up the performance cost, if one's not careful. Caching may be an option, but it would make things too non-trivial for Community Toolbox functions.

What I usually end up doing is creating a constructor which stores the data from window_get_visible_rects and then exposes methods to get data about various displays and/or related operations. I might add it to some display-focused library of mine at some point, but it can be a while since I get working on this one.

Other than that, I do like the idea of built-in functions as described in the FR, so I upvoted it. ^^

@DragoniteSpam
Copy link

I had someone request that I do this in duck game a while ago and I mostly ignored it because GM doesn't give you an easy way to do this. Hmmm...

@Zyl9393
Copy link

Zyl9393 commented Mar 8, 2025

What brought me here was display_get_width() and display_get_height() tripping me up completely by changing the display they were returning width and height of whenever you went into fullscreen on a different display, but not when moving the window to a different display, while window_set_position() and window_set_rectangle() always use virtual screen coordinates. window_get_visible_rects() is very good. I think the use cases are many and difficult, which is why there isn't anything more provided. Functions which I need would be:

  • window_display_get_size(): Get width/height of display which the window is actually on.
  • window_resize(_w, _h): In-place resizing which tries to maintain center of window, but shifts the window closer to display center if it would clip over screen edges or below taskbar.

Here is some useful debug code I wrote to sniff out the behavior of the relevant functions; maybe it helps someone:

function window_debug() {
	var _fullscreen = window_get_fullscreen();
	var _borderless = window_get_borderless_fullscreen();
	var _showborder = window_get_showborder();
	var _win_x = window_get_x();
	var _win_y = window_get_y();
	var _win_w = window_get_width();
	var _win_h = window_get_height();
	var _display_w = display_get_width();
	var _display_h = display_get_height();
	var _rects = window_get_visible_rects(_win_x, _win_y, _win_x + _win_w, _win_y + _win_h);
	var _num_displays = array_length(_rects) / 8;
	show_debug_message("=== WINDOW DEBUG | Fullscreen: " + string(_fullscreen)
			+ " | Borderless: " + string(_borderless) + " | Show border: " + string(_showborder) + "  ===");
	show_debug_message("  Window: " + string(_win_w) + "x" + string(_win_h)
			+ " @ " + string(_win_x) + ", " + string(_win_h));
	show_debug_message("  Display: " + string(_display_w) + "x" + string(_display_h));
	show_debug_message("  " + string(_num_displays) + " Virtual Screen Areas:");
	for (var _i = 0; _i < _num_displays; _i++) {
		var _info_overlap = "";
		var _overlap_w = _rects[_i*8+2] - _rects[_i*8];
		var _overlap_h = _rects[_i*8+3] - _rects[_i*8+1];
		if _overlap_w != 0 && _overlap_h != 0 {
			_info_overlap = " overlapped by " + string(_overlap_w) + "x" + string(_overlap_h)
					+ " @ " + string(_rects[_i*8]) + ", " + string(_rects[_i*8+1]);
		}
		var _area_w = _rects[_i*8+6] - _rects[_i*8+4];
		var _area_h = _rects[_i*8+7] - _rects[_i*8+5];
		show_debug_message("    " + string(_i) + ": " + string(_area_w) + "x" + string(_area_h)
				+ " @ " + string(_rects[_i*8+4]) + ", " + string(_rects[_i*8+5]) + _info_overlap);
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature (or a request for one)
Projects
Status: Backlog
Development

No branches or pull requests

6 participants