/** * Get the frame buffer sizes. * @param root The window (Unused). * @param num The number of sizes. * @return The sizes. * * Get the list of possible frame buffer sizes (at the normal * orientation supported by the screen associated to @p window (passed * to ecore_x_randr_get_screen_info_prefetch()). Each size indicates * both the linear physical size of the screen and the pixel size. * * To use this function, you must call before, and in order, * ecore_x_randr_get_screen_info_prefetch(), which sends the GetScreenInfo request, * then ecore_x_randr_get_screen_info_fetch(), which gets the reply. * @ingroup Ecore_X_RandR_Group */ EAPI Ecore_X_Screen_Size * ecore_x_randr_screen_sizes_get(Ecore_X_Window root __UNUSED__, int *num) { #ifdef ECORE_XCB_RANDR xcb_randr_get_screen_info_reply_t *reply; xcb_randr_screen_size_t *sizes; Ecore_X_Screen_Size *ret; int n; int i; if (num) *num = 0; reply = _ecore_xcb_reply_get(); if (!reply) return NULL; n = xcb_randr_get_screen_info_sizes_length(reply); ret = calloc(n, sizeof(Ecore_X_Screen_Size)); if (!ret) return NULL; if (num) *num = n; sizes = xcb_randr_get_screen_info_sizes(reply); for (i = 0; i < n; i++) { ret[i].width = sizes[i].width; ret[i].height = sizes[i].height; } return ret; #else if (num) *num = 0; return NULL; #endif /* ECORE_XCB_RANDR */ }
VideoMode VideoModeImpl::getDesktopMode() { VideoMode desktopMode; // Open a connection with the X server xcb_connection_t* connection = OpenConnection(); // Retrieve the default screen xcb_screen_t* screen = XCBDefaultScreen(connection); ScopedXcbPtr<xcb_generic_error_t> error(NULL); // Check if the RandR extension is present const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id); if (!randrExt || !randrExt->present) { // Randr extension is not supported: we cannot get the video modes err() << "Failed to use the RandR extension while trying to get the desktop video mode" << std::endl; // Close the connection with the X server CloseConnection(connection); return desktopMode; } // Load RandR and check its version ScopedXcbPtr<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply( connection, xcb_randr_query_version( connection, 1, 1 ), &error )); if (error) { err() << "Failed to load the RandR extension while trying to get the desktop video mode" << std::endl; // Close the connection with the X server CloseConnection(connection); return desktopMode; } // Get the current configuration ScopedXcbPtr<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply( connection, xcb_randr_get_screen_info( connection, screen->root ), &error )); if (error) { // Failed to get the screen configuration err() << "Failed to retrieve the screen configuration while trying to get the desktop video mode" << std::endl; // Close the connection with the X server CloseConnection(connection); return desktopMode; } // Get the current video mode xcb_randr_mode_t currentMode = config->sizeID; // Get the available screen sizes int nbSizes = xcb_randr_get_screen_info_sizes_length(config.get()); xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get()); if (sizes && (nbSizes > 0)) { desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, screen->root_depth); if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 || config->rotation == XCB_RANDR_ROTATION_ROTATE_270) std::swap(desktopMode.width, desktopMode.height); } else { err() << "Failed to retrieve any screen sizes while trying to get the desktop video mode" << std::endl; } // Close the connection with the X server CloseConnection(connection); return desktopMode; }