Skip to content

Commit

Permalink
Engine: get desktop size and modes of display window is on (if able)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Nov 2, 2024
1 parent 5746a9d commit 2559c65
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Engine/platform/base/sys_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,19 @@ void sys_set_background_mode(bool /*on*/) {
// ----------------------------------------------------------------------------
const int DEFAULT_DISPLAY_INDEX = 0; // TODO: is this always right?

// Gets the display index on which the window is currently positioned.
// Returns default display index in case window does not exist yet, or on any error.
int sys_get_window_display_index() {
int index = -1;
SDL_Window *window = sys_get_window();
if (window)
index = SDL_GetWindowDisplayIndex(window);
return index >= 0 ? index : DEFAULT_DISPLAY_INDEX;
}

int sys_get_desktop_resolution(int &width, int &height) {
SDL_Rect r;
if (SDL_GetDisplayBounds(DEFAULT_DISPLAY_INDEX, &r) != 0) {
if (SDL_GetDisplayBounds(sys_get_window_display_index(), &r) != 0) {
Debug::Printf(kDbgMsg_Error, "SDL_GetDisplayBounds failed: %s", SDL_GetError());
return -1;
}
Expand All @@ -86,7 +96,7 @@ int sys_get_desktop_resolution(int &width, int &height) {

void sys_get_desktop_modes(std::vector<AGS::Engine::DisplayMode> &dms, int color_depth) {
SDL_DisplayMode mode;
const int display_id = DEFAULT_DISPLAY_INDEX;
const int display_id = sys_get_window_display_index();
const int count = SDL_GetNumDisplayModes(display_id);
dms.clear();
for (int i = 0; i < count; ++i) {
Expand Down

0 comments on commit 2559c65

Please sign in to comment.