NVAPI Display position resets after calling "NvAPI_DISP_TryCustomDisplay"

Hi, I’m working on an open-source, simplified NVIDIA Control Panel for gamers to set custom resolutions and colors with profiles. I’m using NVAPI for this, and I’ve encountered an issue with the NvAPI_DISP_TryCustomDisplay function. After calling this function, the display position resets to default on multi-monitor setup, and I don’t know how to avoid this behavior.

For reference, when changing the resolution to a custom one in the NVIDIA Control Panel, it doesn’t reset the display position. This is what I mean by the “display position”: Imgur: The magic of the Internet

My implementation:

int nvapi_try_custom_display(unsigned int displayId, CustomDisplaySettings settings)
{
    NV_CUSTOM_DISPLAY custDisp = {0};
    custDisp.version = NV_CUSTOM_DISPLAY_VER;
    custDisp.width = settings.width;
    custDisp.height = settings.height;
    custDisp.depth = 32;
    custDisp.srcPartition = {0, 0, 1.0, 1.0};
    custDisp.xRatio = 1;
    custDisp.yRatio = 1;

    NV_TIMING_INPUT timing = {0};
    timing.version = NV_TIMING_INPUT_VER;
    timing.width = settings.width;
    timing.height = settings.height;
    timing.rr = settings.refresh;

    NvU32 displayIds[1] = {static_cast<NvU32>(displayId)};

    // Get proper timing values from NVAPI
    NvAPI_Status ret = NvAPI_DISP_GetTiming(displayIds[0], &timing, &custDisp.timing);
    if (ret != NVAPI_OK)
    {
        return ret;
    }

    return NvAPI_DISP_TryCustomDisplay(displayIds, 1, &custDisp);
}

GitHub