rect sdl_basic_services::desktop_rect(uint32_t aDisplayIndex) const { iDesktopWorkAreas.clear(); #ifdef WIN32 EnumDisplayMonitors(NULL, NULL, &enum_display_monitors_proc, reinterpret_cast<LPARAM>(this)); #else for (int i = 0; i < display_count(); ++i) { SDL_Rect rectDisplayBounds; SDL_GetDisplayBounds(i, &rectDisplayBounds); iDesktopWorkAreas.push_back(rect{ point{ rectDisplayBounds.x, rectDisplayBounds.y }, size{ rectDisplayBounds.w, rectDisplayBounds.h } }); } #endif if (aDisplayIndex >= iDesktopWorkAreas.size()) throw bad_display_index(); return iDesktopWorkAreas[aDisplayIndex]; }
rect surface_manager::desktop_rect(const i_surface& aSurface) const { #ifdef WIN32 HMONITOR monitor = MonitorFromWindow(reinterpret_cast<HWND>(aSurface.native_surface().native_handle()), MONITOR_DEFAULTTONEAREST); MONITORINFOEX mi; mi.cbSize = sizeof(mi); GetMonitorInfo(monitor, &mi); return basic_rect<LONG>{ basic_point<LONG>{ mi.rcWork.left, mi.rcWork.top }, basic_size<LONG>{ mi.rcWork.right - mi.rcWork.left, mi.rcWork.bottom - mi.rcWork.top } }; #else /* todo */ rect rectSurface{ aSurface.surface_position(), aSurface.surface_size() }; std::multimap<double, uint32_t> matches; for (uint32_t i = 0; i < display_count(); ++i) { rect rectDisplay = desktop_rect(i); rect rectIntersection = rectDisplay.intersection(rectSurface); if (!rectIntersection.empty()) matches[rectIntersection.width() * rectIntersection.height()] = i; } if (matches.empty()) return desktop_rect(0); return desktop_rect(matches.rbegin()->second); #endif }