Skip to content
This repository was archived by the owner on Oct 26, 2025. It is now read-only.
This repository was archived by the owner on Oct 26, 2025. It is now read-only.

Fixing the get_first_monitor_bounds function #7

@nico87

Description

@nico87

libacfutils/src/widget.c

Lines 140 to 168 in 9f4b74e

static monitor_t
get_first_monitor_bounds(void)
{
monitor_t mon;
memset(&mon, 0, sizeof (mon));
XPLMGetAllMonitorBoundsGlobal(find_first_monitor, &mon);
if (mon.left == 0 && mon.right == 0 && mon.top == 0 &&
mon.bottom == 0) {
XPLMGetScreenSize(&mon.right, &mon.top);
} else {
/*
* The modern coordinate system uses the top left corner
* as the origin, instead of the bottom left. So we need
* to flip the coordinates around.
*/
int glob_left, glob_top, glob_right, glob_bottom;
int glob_height;
XPLMGetScreenBoundsGlobal(&glob_left, &glob_top,
&glob_right, &glob_bottom);
glob_height = glob_top - glob_bottom;
mon.top = glob_height - mon.top;
mon.bottom = glob_height - mon.bottom;
}
return (mon);
}

Hi,

I'm nico87 from SimCoders.
I see that you're facing the same issue I faced few months ago while trying to improve the multi-monitor support in my plugin.

I was not actually able to figure out a reliable way to identify the main monitor and its bounds at once. So what I did is provide the user an option to set the proper monitor index that he wants to use as main for my plugin's windows.
Then, here's the simplified code I use to identify the proper coordinates. It worked reliably until now. I see that in your code you're doing more math but the solution is actually straightforward.
The code below is simplified because as I support more SDK versions, I have to use function pointers and figure out the proper SDK functions to use and it makes the code more difficult to read.

static monitor_t
get_first_monitor_bounds(void)
{

     monitor_t monitor;
     XPLMGetAllMonitorBoundsGlobal(find_first_monitor, &monitor);

     // Before XP11.30 there was a ugly bug :-/
     if (outXPlaneVersion < 11300) {
         // Just swap monitor.top and monitor.bottom
         int swap = monitor.top;
         monitor.top = monitor.bottom;
         monitor.bottom = swap;
     }
     return (monitor);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions