libacfutils icon indicating copy to clipboard operation
libacfutils copied to clipboard

Fixing the get_first_monitor_bounds function

Open nico87 opened this issue 5 years ago • 0 comments

https://github.com/skiselkov/libacfutils/blob/9f4b74e92d0e853b04fe437db2f38989a7b8b044/src/widget.c#L140-L168

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);
}

nico87 avatar May 18 '20 15:05 nico87