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

1 Like

Hi, I managed to get around this issue by saving a snapshot of positions before setting the custom display and then using Winapi to reset display positions after saving the custom display using Nvapi. As using Nvapi to reset display positions also reverted the saved custom display.

I’m curious, did you ever manage to find a way to stop this from happening in the first place?

I never found solution using NvAPI_DISP_TryCustomDisplay. Insted I update resolution using NvAPI_DISP_SetDisplayConfig only changing:

            pathInfo[i].sourceModeInfo->resolution.width = settings.width;
            pathInfo[i].sourceModeInfo->resolution.height = settings.height;

It keeps display positions and surprisingly after using this method, NvAPI_DISP_RevertCustomDisplayTrial works normally as intended.