{"record":{"id":"33b3c1ec79378bd3","repo":"LGUG2Z/komorebi","slug":"could-not-find-device-id-for-hmonitor-hmonitor","errorCode":null,"errorMessage":"could not find device_id for hmonitor: {hmonitor}","messagePattern":"could not find device_id for hmonitor: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"komorebi/src/windows_api.rs","lineNumber":1142,"sourceCode":"                        display.serial_number_id = None;\n                    }\n                }\n\n                let monitor = monitor::new(\n                    hmonitor,\n                    display.size.into(),\n                    display.work_area_size.into(),\n                    name,\n                    device,\n                    device_id,\n                    display.serial_number_id,\n                );\n\n                return Ok(monitor);\n            }\n        }\n\n        bail!(\"could not find device_id for hmonitor: {hmonitor}\");\n    }\n\n    pub fn set_process_dpi_awareness_context() -> eyre::Result<()> {\n        unsafe { SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) }\n            .process()\n    }\n\n    #[allow(dead_code)]\n    pub fn system_parameters_info_w(\n        action: SYSTEM_PARAMETERS_INFO_ACTION,\n        ui_param: u32,\n        pv_param: *mut c_void,\n        update_flags: SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS,\n    ) -> eyre::Result<()> {\n        unsafe { SystemParametersInfoW(action, ui_param, Option::from(pv_param), update_flags) }\n            .process()\n    }\n","sourceCodeStart":1124,"sourceCodeEnd":1160,"githubUrl":"https://github.com/LGUG2Z/komorebi/blob/e0709f02bfae4e503bf4640f58ee75ecbbfdbb97/komorebi/src/windows_api.rs#L1124-L1160","documentation":"monitor resolves a monitor handle (HMONITOR) to its device id by iterating EnumDisplayDevices/monitor enumeration. If no device id matches the given hmonitor, komorebi bails with 'could not find device_id for hmonitor: {hmonitor}'. It means the handle does not correspond to any display device komorebi can enumerate.","triggerScenarios":"Calling WindowsApi::monitor(hmonitor) with an HMONITOR that is invalid, stale (monitor unplugged or topology changed), or one that display enumeration does not return (virtual/RDP display edge cases).","commonSituations":"Hot-plugging monitors or changing display topology while komorebi is running; RDP or virtual display adapters whose HMONITORs aren't matched by EnumDisplayDevices; passing a hardcoded/invalid monitor handle.","solutions":["Re-query the current monitor handles after any display topology change and retry","Verify the hmonitor value comes from a fresh EnumDisplayMonitors call","Restart komorebi after connecting/disconnecting monitors so it rebuilds its monitor list","Check display driver/RDP quirks; ensure the virtual display is a real enumerated device"],"exampleFix":"// before\nlet device_id = WindowsApi::monitor(old_hmonitor)?;\n// after\nlet device_id = WindowsApi::monitor(current_hmonitor)\n    .with_context(|| format!(\"stale hmonitor {old_hmonitor}; rescan displays\"))?;","handlingStrategy":"try-catch","validationCode":"// Confirm the hmonitor is currently enumerated\nfn hmonitor_is_current(hmonitor: isize, current: &[isize]) -> bool {\n    current.contains(&hmonitor)\n}","typeGuard":null,"tryCatchPattern":"match WindowsApi::monitor(hmonitor) {\n    Ok(device_id) => device_id,\n    Err(e) if e.to_string().contains(\"could not find device_id\") => {\n        log::warn!(\"stale hmonitor {hmonitor}; rescanning display topology\");\n        rescan_monitors()?;\n        WindowsApi::monitor(fresh_hmonitor)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Refresh monitor handles on WM_DISPLAYCHANGE / topology changes","Never cache HMONITOR values across display hotplug events","Verify RDP/virtual display adapters enumerate via EnumDisplayDevices","Rescan monitors at komorebi startup after logon"],"tags":["win32","monitor","display"],"backgroundTag":"resource-not-found","analyzedSha":"e0709f02bfae4e503bf4640f58ee75ecbbfdbb97","analyzedAt":"2026-09-06T07:08:05.107Z","contentChangedAt":"2026-09-06T07:08:05.107Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}