-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 FLAG_FULLSCREEN_DESKTOP #3382
Conversation
I think this feature is useful. |
@ubkp You were working on this feature, please could you take a look? |
@raysan5 Sure thing. Tested (62d3066), some considerations:
Environment: tested for |
@ubkp thank you very much for taking a look and the fast response!
|
@raysan5 No problem. 👍 1 - Yes, but is expected for an actual fullscreen, not for a "desktop fullscreen". This was one of the main problems that 2 - I mean, if I compile 62d3066 and use it on an example that just doesn't use 4 - Personal opinion: IMHO that's a lot of change for something that can be done with 2 calls on the user side. |
e47bb70 replaces |
Sorry, but:
|
Actually, these two calls do not work as expected: SetWindowSize(GetMonitorWidth(0), GetMonitorHeight(0));
ToggleFullscreen(); The reason is because The wrong video mode problem when entering fullscreen mode can be solved by doing: if (IsKeyPressed(KEY_F)) {
SetWindowSize(GetMonitorWidth(0), GetMonitorHeight(0));
fullscreen_toggled = true;
}
BeginDrawing();
EndDrawing();
if (fullscreen_toggled) {
ToggleFullscreen();
fullscreen_toggled = false;
} However, this still causes a video mode change, which involves the annoying screen blackout for about a second. When running the code example 1 below, we see "800x600" on the screen instead of the actual monitor size even in fullscreen. Code example 1#include <raylib.h>
#include <stdio.h>
int main()
{
int win_width;
int win_height;
char str[64];
InitWindow(800, 600, "Test");
while (!WindowShouldClose()) {
win_width = GetScreenWidth();
win_height = GetScreenHeight();
sprintf(str, "Screen size: %dx%d", win_width, win_height);
if (IsKeyPressed(KEY_F)) {
SetWindowSize(GetMonitorWidth(0), GetMonitorHeight(0));
ToggleFullscreen();
}
BeginDrawing();
ClearBackground(GRAY);
DrawText(str, 0, 64, 32, BLACK);
EndDrawing();
}
CloseWindow();
return 0;
} Code example 2#include <raylib.h>
#include <stdio.h>
#include <stdbool.h>
int main()
{
int win_width;
int win_height;
bool fullscreen_toggled = false;
char str[64];
InitWindow(800, 600, "Test");
while (!WindowShouldClose()) {
win_width = GetScreenWidth();
win_height = GetScreenHeight();
sprintf(str, "Screen size: %dx%d", win_width, win_height);
if (IsKeyPressed(KEY_F)) {
SetWindowSize(GetMonitorWidth(0), GetMonitorHeight(0));
fullscreen_toggled = true;
}
BeginDrawing();
ClearBackground(GRAY);
DrawText(str, 0, 64, 32, BLACK);
EndDrawing();
if (fullscreen_toggled) {
ToggleFullscreen();
fullscreen_toggled = false;
}
}
CloseWindow();
return 0;
} |
Then |
For some reason, the mode change still happens in my system when using If everyone agrees, we can implement the first approach suggested in #3378, in which the screen size is checked and, if it is the same as the monitor, the refresh rate is passed to |
Also note that the code example 2 in #3382 (comment) does not automatically restore the window size when leaving fullscreen mode. In this case, the responsibility of storing and then restoring the window size is left to the programmer, not done automatically by raylib. |
The only thing that should be fixed at this point is |
Any fullscreen call will cause the window to be minimized if alt-tabbing. |
This and also the undesirable video mode change when the screen (or window) size is set to the same as the monitor. Update: This is what issue #3390 is about.
If the user does not want this behavior, using |
I have done some tests with the first approach suggested in #3378, but found a considerable increase in complexity for the program's code due to it needing to manage the window restore size (which would not be managed by raylib) and also that a mode change happened when toggling between fullscreen and windowed mode multiple times too quickly. It looks like the third approach, as implemented in this PR, allows the program's code to be simpler while adding just a few more lines of code to raylib. Here is an example of the increased code complexity: #include <raylib.h>
#include <stdio.h>
#include <stdbool.h>
int main()
{
int restore_width = 0;
int restore_height = 0;
bool fullscreen_toggled = false;
bool leave_fullscreen = false;
char str[32];
InitWindow(800, 600, "Test: fullscreen without video mode change");
while (!WindowShouldClose()) {
if (IsKeyPressed(KEY_F)) {
fullscreen_toggled = true;
if (!IsWindowFullscreen()) {
//Change to fullscreen
restore_width = GetScreenWidth();
restore_height = GetScreenHeight();
SetWindowSize(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor()));
} else {
leave_fullscreen = true;
}
}
sprintf(str, "Screen size: %dx%d %c", GetScreenWidth(), GetScreenHeight(), IsWindowFullscreen() ? 'F' : 'W');
BeginDrawing();
ClearBackground(GRAY);
DrawText(str, 0, 64, 32, BLACK);
EndDrawing();
if (fullscreen_toggled) {
fullscreen_toggled = false;
ToggleFullscreen();
if (leave_fullscreen) {
SetWindowSize(restore_width, restore_height);
leave_fullscreen = false;
}
}
}
CloseWindow();
return 0;
} This would be simpler, but did not work as expected (probably related to #include <raylib.h>
#include <stdio.h>
#include <stdbool.h>
int main()
{
int restore_width = 0;
int restore_height = 0;
bool fullscreen_toggled = false;
char str[32];
InitWindow(800, 600, "Test: fullscreen without video mode change");
while (!WindowShouldClose()) {
if (IsKeyPressed(KEY_F)) {
fullscreen_toggled = true;
if (!IsWindowFullscreen()) {
//Change to fullscreen
restore_width = GetScreenWidth();
restore_height = GetScreenHeight();
SetWindowSize(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor()));
} else {
SetWindowSize(restore_width, restore_height);
}
}
sprintf(str, "Screen size: %dx%d %c", GetScreenWidth(), GetScreenHeight(), IsWindowFullscreen() ? 'F' : 'W');
BeginDrawing();
ClearBackground(GRAY);
DrawText(str, 0, 64, 32, BLACK);
EndDrawing();
if (fullscreen_toggled) {
fullscreen_toggled = false;
ToggleFullscreen();
}
}
CloseWindow();
return 0;
} |
e47bb70
to
aa11065
Compare
Marking it as ready for review, as it seems to work fine on two monitors. |
This still does not work as expected: SetConfigFlags(FLAG_FULLSCREEN_DESKTOP | FLAG_FULLSCREEN_MODE); Should raylib handle this case or can we just instruct the programmer to create the window initially without Also, if the program starts in fullscreen mode, there will be no size to restore the window to when changing to windowed mode. A possible solution is to change |
Repeating myself: the only thing that should be fixed is @raysan5 I'm sorry, but I'm no longer wasting time reviewing or testing this. |
#3391 proposes a fix to |
aa11065
to
1234a5f
Compare
Turns out that the refresh rate on my system was not set to the highest available. By changing to the highest available refresh rate, a mode change did not happen with |
@M374LX I'm not implementing this change |
This PR implements the third approach suggested in #3378.
Update: not ready to be merged because it has the same problems as #3391 (comment).
Code example