static void menu_on_item(GtkMenuItem *item, struct screen_info *screen_info)
{
    xcb_randr_rotation_t old_config, option, rotation, reflection;

    option = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(item), "rotation"));

    if (option & xcb_rotations_mask &&
            !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))) {
        /* let the activated item take care of the event */
        return;
    }

    old_config = normalize_rotation(screen_info->rotation);
    rotation = old_config & xcb_rotations_mask;
    reflection = old_config & xcb_reflections_mask;

    if (option & xcb_rotations_mask) {
            rotation = option;
    } else if (option & xcb_reflections_mask) {
            reflection ^= option;
    }

    xcb_randr_set_screen_config_unchecked(conn, screen_info->root,
            XCB_CURRENT_TIME, screen_info->config_timestamp,
            screen_info->sizeID,
            normalize_rotation(rotation | reflection),
            screen_info->rate);

    xcb_flush(conn);
}
/**
 * Set the screen refresh rate.
 * @param root The root window.
 * @param size The size.
 * @param rate The refresh rate.
 *
 * Set the size and the refresh rate of the screen associated to
 * @p root.
 *
 * Note that that function is blocking.
 * @ingroup Ecore_X_RandR_Group
 */
EAPI int
ecore_x_randr_screen_refresh_rate_set(Ecore_X_Window              root,
                                      Ecore_X_Screen_Size         size,
                                      Ecore_X_Screen_Refresh_Rate rate)
{
#ifdef ECORE_XCB_RANDR
   xcb_randr_set_screen_config_cookie_t cookie;
   xcb_randr_set_screen_config_reply_t *reply_config;
   xcb_randr_get_screen_info_reply_t   *reply;
   xcb_randr_screen_size_iterator_t     iter;
   int                                  size_index = -1;
   int                                  i;

   reply = _ecore_xcb_reply_get();
   if (!reply)
     return 0;

   iter = xcb_randr_get_screen_info_sizes_iterator(reply);
   for (i = 0; iter.rem; xcb_randr_screen_size_next(&iter), i++)
     {
        if ((iter.data->width = size.width) &&
            (iter.data->height = size.height) &&
            (iter.data->mwidth = size.width) &&
            (iter.data->mheight = size.height))
          {
            size_index = i;
            break;
          }
     }
   if (size_index == -1) return 0;

   cookie = xcb_randr_set_screen_config_unchecked(_ecore_xcb_conn, root,
                                                  XCB_CURRENT_TIME,
                                                  reply->config_timestamp,
                                                  size_index,
                                                  XCB_RANDR_ROTATION_ROTATE_0,
                                                  rate.rate);
   reply_config = xcb_randr_set_screen_config_reply(_ecore_xcb_conn, cookie, NULL);
   if (!reply_config)
     return 0;

   free(reply_config);

   return 1;
#else
   return 0;
#endif /* ECORE_XCB_RANDR */
}
/**
 * Set the screen rotation.
 * @param root The root window.
 * @param rot  The rotation.
 *
 * Set the rotation of the screen associated to @p root.
 *
 * Note that that function is blocking.
 * @ingroup Ecore_X_RandR_Group
 */
EAPI void
ecore_x_randr_screen_rotation_set(Ecore_X_Window         root,
                                  Ecore_X_Randr_Rotation rot)
{
#ifdef ECORE_XCB_RANDR
   xcb_randr_set_screen_config_cookie_t cookie;
   xcb_randr_set_screen_config_reply_t *reply_config;
   xcb_randr_get_screen_info_reply_t   *reply;

   reply = _ecore_xcb_reply_get();
   if (!reply)
     return;

   cookie = xcb_randr_set_screen_config_unchecked(_ecore_xcb_conn, root,
                                                  XCB_CURRENT_TIME,
                                                  reply->config_timestamp,
                                                  reply->sizeID,
                                                  rot,
                                                  0);
   reply_config = xcb_randr_set_screen_config_reply(_ecore_xcb_conn, cookie, NULL);
   if (reply_config)
     free(reply_config);
#endif /* ECORE_XCB_RANDR */
}