Skip to content

Conversation

@maiconpintoabreu
Copy link
Contributor

@maiconpintoabreu maiconpintoabreu commented Sep 29, 2025

Add an example to show how to get information about the monitor and move a window to another monitor.

Added for: #5209

image

@maiconpintoabreu
Copy link
Contributor Author

Based on the other PR, I will add more comments here as well.

@raysan5
Copy link
Owner

raysan5 commented Sep 29, 2025

@maiconpintoabreu Considering raylib offers some monitor checking functionality, it would be great to use it on the example:

void SetWindowMonitor(int monitor);                 // Set monitor for the current window
int GetMonitorCount(void);                          // Get number of connected monitors
int GetCurrentMonitor(void);                        // Get current monitor where window is placed
Vector2 GetMonitorPosition(int monitor);            // Get specified monitor position
int GetMonitorWidth(int monitor);                   // Get specified monitor width (current video mode used by monitor)
int GetMonitorHeight(int monitor);                  // Get specified monitor height (current video mode used by monitor)
int GetMonitorPhysicalWidth(int monitor);           // Get specified monitor physical width in millimetres
int GetMonitorPhysicalHeight(int monitor);          // Get specified monitor physical height in millimetres
int GetMonitorRefreshRate(int monitor);             // Get specified monitor refresh rate
Vector2 GetWindowPosition(void);                    // Get window position XY on monitor
const char *GetMonitorName(int monitor);            // Get the human-readable, UTF-8 encoded name of the specified monitor

For example, have some keys to move window to the available monitors, show available monitors, show monitor names, physical size...

@raysan5 raysan5 changed the title [examples] Add core monitor change example [examples] Add core_monitor_change Sep 30, 2025
@raysan5
Copy link
Owner

raysan5 commented Sep 30, 2025

@maiconpintoabreu As the monitor layouts can be now detected and also current window, I think it would be nice to visualize with a rectangle the current window and how it is moved between monitors in real time.

@maiconpintoabreu
Copy link
Contributor Author

maiconpintoabreu commented Sep 30, 2025

The monitor that the window is will be highlighted and it happens as well if the window is moved manually.

You can see it on the screenshot that the active one is in red.

@maiconpintoabreu
Copy link
Contributor Author

Monitor position drawing realtime now.

Screenshot_20250930_171840 Screenshot_20250930_171910

@raysan5
Copy link
Owner

raysan5 commented Sep 30, 2025

@maiconpintoabreu Example looks good, but why not show the information in the same way as the tool you are using, with the monitor name and resolution inside the rectangles. Seems more complete to me than just a number.

@maiconpintoabreu
Copy link
Contributor Author

Hi, just confirmed that on Windows the monitor name is right, added the windows position in monitor rectangles(scaled) and infos inside the monitor rectangle as well.

screenrec001

@maiconpintoabreu
Copy link
Contributor Author

I got this issue:

This closes the window when a monitor is removed while the example is trying to access the monitor information.

WARNING: GLFW: Error: 65544 Description: X11: Failed to query video mode
WARNING: GLFW: Failed to find video mode for selected monitor
WARNING: GLFW: Error: 65544 Description: X11: Failed to query video mode
WARNING: GLFW: Failed to find video mode for selected monitor
WARNING: GLFW: Error: 65544 Description: X11: Failed to query video mode
WARNING: GLFW: Failed to find video mode for selected monitor
WARNING: GLFW: Error: 65544 Description: X11: Failed to query video mode

@raysan5
Copy link
Owner

raysan5 commented Oct 1, 2025

@maiconpintoabreu Thanks for the new example and all the imrpovements implemented!

About the GLFW issue... it should be reviewed. Please, could you open a separate issue for it? Thanks!

@raysan5 raysan5 merged commit 452cac3 into raysan5:master Oct 1, 2025
17 checks passed
@maiconpintoabreu
Copy link
Contributor Author

Hi @raysan5, It was easier to send the fix PR for the monitor issue: #5235

psxdev pushed a commit to raylib4Consoles/raylib that referenced this pull request Oct 5, 2025
* Add core monitor change example

* Add monitor drawing and more information

* Update monitor information every frame

* Show info and window position inside the rectangle
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.

2 participants