2011-11-05 23:41:39 -07:00
# include "e_int_config_randr.h"
# include "e_randr.h"
# include "e_widget_ilist.h"
# ifdef Ecore_X_Randr_Unset
# undef Ecore_X_Randr_Unset
2011-11-09 07:42:00 -08:00
# define Ecore_X_Randr_Unset -1
2011-11-05 23:41:39 -07:00
# else
2011-11-09 07:42:00 -08:00
# define Ecore_X_Randr_Unset -1
2011-11-05 23:41:39 -07:00
# endif
# ifdef Ecore_X_Randr_None
# undef Ecore_X_Randr_None
# endif
2011-11-09 07:42:00 -08:00
# define Ecore_X_Randr_None 0
2011-11-05 23:41:39 -07:00
2011-11-09 07:42:00 -08:00
# define ICON_WIDTH 10
# define ICON_HEIGHT 10
2011-11-05 23:41:39 -07:00
# define RESOLUTION_TXT_MAX_LENGTH 50
2011-11-09 07:39:26 -08:00
Evas_Object * dialog_subdialog_resolutions_basic_create_widgets ( Evas * canvas ) ;
2011-11-09 07:42:00 -08:00
Eina_Bool dialog_subdialog_resolutions_basic_apply_data ( E_Config_Dialog * cfd , E_Config_Dialog_Data * cfdata ) ;
Eina_Bool dialog_subdialog_resolutions_basic_check_changed ( E_Config_Dialog * cfd , E_Config_Dialog_Data * cfdata ) ;
void dialog_subdialog_resolutions_update_list ( Evas_Object * crtc ) ;
void dialog_subdialog_resolutions_keep_changes ( E_Config_Dialog_Data * cfdata ) ;
void dialog_subdialog_resolutions_discard_changes ( E_Config_Dialog_Data * cfdata ) ;
2011-11-05 23:41:39 -07:00
extern E_Config_Dialog_Data * e_config_runtime_info ;
2012-02-18 08:49:17 -08:00
static Ecore_X_Randr_Mode_Info disabled_mode = { . xid = Ecore_X_Randr_None } ;
2011-11-05 23:41:39 -07:00
2011-11-09 07:42:00 -08:00
Eina_Bool
2011-11-09 07:39:26 -08:00
dialog_subdialog_resolutions_create_data ( E_Config_Dialog_Data * cfdata )
2011-11-05 23:41:39 -07:00
{
E_Config_Randr_Dialog_Output_Dialog_Data * odd ;
Ecore_X_Randr_Mode_Info * mi ;
Eina_List * iter ;
if ( ! cfdata | | ! cfdata - > output_dialog_data_list ) return EINA_FALSE ;
2011-11-09 08:13:26 -08:00
EINA_LIST_FOREACH ( cfdata - > output_dialog_data_list , iter , odd )
2011-11-05 23:41:39 -07:00
{
if ( odd - > previous_mode | | odd - > preferred_mode )
{
//this means, that mode info is already filled
//(by the display arrangement code)
break ;
}
if ( odd - > crtc )
{
2011-11-09 07:42:00 -08:00
if ( ! ( mi = odd - > crtc - > current_mode ) )
mi = ( Ecore_X_Randr_Mode_Info * ) eina_list_data_get ( eina_list_last ( odd - > crtc - > outputs_common_modes ) ) ;
2011-11-05 23:41:39 -07:00
odd - > previous_mode = mi ;
}
2012-02-18 08:49:17 -08:00
else if ( odd - > output & & odd - > output - > monitor )
2011-11-05 23:41:39 -07:00
{
2011-12-14 09:37:17 -08:00
odd - > previous_mode = NULL ;
2012-02-18 08:49:17 -08:00
odd - > preferred_mode = ( Ecore_X_Randr_Mode_Info * ) eina_list_data_get ( eina_list_last ( odd - > output - > monitor - > preferred_modes ) ) ;
2011-11-05 23:41:39 -07:00
}
}
return EINA_TRUE ;
}
2011-11-09 07:42:00 -08:00
Evas_Object *
2011-11-09 07:39:26 -08:00
dialog_subdialog_resolutions_basic_create_widgets ( Evas * canvas )
2011-11-05 23:41:39 -07:00
{
Evas_Object * subdialog ;
if ( ! canvas | | ! e_config_runtime_info | | e_config_runtime_info - > gui . subdialogs . resolutions . dialog | | ! ( subdialog = e_widget_ilist_add ( canvas , ICON_WIDTH * e_scale , ICON_HEIGHT * e_scale , NULL ) ) ) return NULL ;
e_widget_ilist_multi_select_set ( subdialog , EINA_FALSE ) ;
e_widget_disabled_set ( subdialog , EINA_TRUE ) ;
evas_object_show ( subdialog ) ;
return subdialog ;
}
2011-11-09 07:42:00 -08:00
Eina_Bool
dialog_subdialog_resolutions_basic_apply_data ( E_Config_Dialog * cfd , E_Config_Dialog_Data * cfdata __UNUSED__ )
2011-11-05 23:41:39 -07:00
{
//Apply new mode
2011-11-09 07:42:00 -08:00
Ecore_X_Randr_Mode_Info * selected_mode ;
2012-02-18 08:49:17 -08:00
Ecore_X_Randr_Mode mode ;
2011-11-05 23:41:39 -07:00
E_Config_Randr_Dialog_Output_Dialog_Data * output_dialog_data ;
2012-02-18 08:49:17 -08:00
Ecore_X_Randr_Output * outputs = NULL ;
2011-11-05 23:41:39 -07:00
E_Randr_Crtc_Info * crtc_info = NULL , * crtc_iter ;
Eina_List * iter ;
int noutputs = Ecore_X_Randr_Unset ;
2011-12-20 17:23:16 -08:00
if ( ! e_config_runtime_info - > gui . selected_eo | | ! ( output_dialog_data = evas_object_data_get ( e_config_runtime_info - > gui . selected_eo , " rep_info " ) ) )
2011-11-05 23:41:39 -07:00
{
fprintf ( stderr , " CONF_RADNR: no crtc was selected or no output info could be retrieved for the selected crtc element (%p). \n " , e_config_runtime_info - > gui . selected_eo ) ;
return EINA_FALSE ;
}
if ( output_dialog_data - > crtc )
{
//CRTC is already asssigned, easy one!
crtc_info = output_dialog_data - > crtc ;
}
else if ( output_dialog_data - > output )
{
//CRTC not assigned yet. Let's try to find a non occupied one.
2012-02-18 08:49:17 -08:00
fprintf ( stderr , " CONF_RANDR: Trying to find a CRTC for output %d, %d crtcs are possible. \n " , output_dialog_data - > output - > xid , eina_list_count ( output_dialog_data - > output - > possible_crtcs ) ) ;
outputs = & output_dialog_data - > output - > xid ;
2011-11-05 23:41:39 -07:00
noutputs = 1 ;
2011-11-09 08:13:26 -08:00
EINA_LIST_FOREACH ( output_dialog_data - > output - > possible_crtcs , iter , crtc_iter )
2011-11-05 23:41:39 -07:00
{
if ( ! crtc_iter - > outputs )
{
//CRTC is not occupied yet
crtc_info = crtc_iter ;
break ;
}
}
}
if ( ! crtc_info )
{
fprintf ( stderr , " CONF_RANDR: Changing mode failed, no unoccupied CRTC found! \n " ) ;
return EINA_FALSE ;
}
//get selected mode
2011-11-09 07:42:00 -08:00
if ( ( selected_mode = ( Ecore_X_Randr_Mode_Info * ) e_widget_ilist_selected_data_get ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog ) ) )
2011-11-05 23:41:39 -07:00
{
2012-02-18 08:49:17 -08:00
mode = selected_mode - > xid ;
2011-11-05 23:41:39 -07:00
}
2012-02-18 08:49:17 -08:00
if ( selected_mode = = crtc_info - > current_mode )
2011-11-05 23:41:39 -07:00
{
2012-02-18 08:49:17 -08:00
if ( output_dialog_data - > output & & ( eina_list_data_find ( crtc_info - > outputs , output_dialog_data - > output ) ) )
{
fprintf ( stderr , " CONF_RANDR: Nothing to be done for output %s. \n " , output_dialog_data - > output - > name ) ;
return EINA_TRUE ;
}
fprintf ( stderr , " CONF_RANDR: Resolution remains unchanged for CRTC %d. \n " , crtc_info - > xid ) ;
return EINA_TRUE ;
2011-11-05 23:41:39 -07:00
}
2012-02-18 08:49:17 -08:00
fprintf ( stderr , " CONF_RANDR: Changing mode of crtc %d to %d. \n " , crtc_info - > xid , mode ) ;
2011-11-05 23:41:39 -07:00
2012-02-18 08:49:17 -08:00
if ( ecore_x_randr_crtc_mode_set ( cfd - > con - > manager - > root , crtc_info - > xid , outputs , noutputs , mode ) )
2011-11-05 23:41:39 -07:00
{
//update information
2012-02-18 08:49:17 -08:00
output_dialog_data - > crtc = crtc_info ;
2011-11-05 23:41:39 -07:00
output_dialog_data - > new_mode = selected_mode ;
return EINA_TRUE ;
}
return EINA_FALSE ;
}
2011-11-09 07:42:00 -08:00
Eina_Bool
2011-11-09 07:39:26 -08:00
dialog_subdialog_resolutions_basic_check_changed ( E_Config_Dialog * cfd __UNUSED__ , E_Config_Dialog_Data * cfdata __UNUSED__ )
2011-11-05 23:41:39 -07:00
{
2011-11-09 07:42:00 -08:00
Ecore_X_Randr_Mode_Info * selected_mode ;
2011-11-05 23:41:39 -07:00
E_Config_Randr_Dialog_Output_Dialog_Data * output_dialog_data ;
2011-12-20 17:23:16 -08:00
if ( ! e_config_runtime_info - > gui . selected_eo | | ! ( selected_mode = ( Ecore_X_Randr_Mode_Info * ) e_widget_ilist_selected_data_get ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog ) ) | | ! ( output_dialog_data = evas_object_data_get ( e_config_runtime_info - > gui . selected_eo , " rep_info " ) ) ) return EINA_FALSE ;
2011-11-05 23:41:39 -07:00
2011-11-09 07:42:00 -08:00
return selected_mode ! = output_dialog_data - > previous_mode ;
2011-11-05 23:41:39 -07:00
}
2011-11-09 07:42:00 -08:00
void
2012-02-18 08:49:17 -08:00
dialog_subdialog_resolutions_update_list ( Evas_Object * rep )
2011-11-05 23:41:39 -07:00
{
Eina_List * iter , * modelist = NULL ;
E_Config_Randr_Dialog_Output_Dialog_Data * output_dialog_data ;
Ecore_X_Randr_Mode_Info * mode_info , * current_mode ;
char resolution_text [ RESOLUTION_TXT_MAX_LENGTH ] ;
float rate ;
2012-02-18 08:49:17 -08:00
Eina_Bool enable = EINA_FALSE ;
2012-02-21 14:05:02 -08:00
int i = 0 ;
2011-11-05 23:41:39 -07:00
e_widget_ilist_freeze ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog ) ;
e_widget_ilist_clear ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog ) ;
2012-02-18 08:49:17 -08:00
if ( ! rep | | ! ( output_dialog_data = evas_object_data_get ( rep , " rep_info " ) ) )
goto _go_and_return ;
2011-11-05 23:41:39 -07:00
//select correct mode list
if ( output_dialog_data - > crtc )
{
current_mode = output_dialog_data - > crtc - > current_mode ;
modelist = output_dialog_data - > crtc - > outputs_common_modes ;
}
2012-02-18 08:49:17 -08:00
else if ( output_dialog_data - > output & & output_dialog_data - > output - > monitor )
2011-11-05 23:41:39 -07:00
{
current_mode = NULL ;
2012-02-18 08:49:17 -08:00
if ( output_dialog_data - > output - > monitor - > modes )
modelist = output_dialog_data - > output - > monitor - > modes ;
2011-11-05 23:41:39 -07:00
}
2012-02-18 08:49:17 -08:00
if ( ! modelist )
goto _go_and_return ;
2011-11-09 08:13:26 -08:00
EINA_LIST_FOREACH ( modelist , iter , mode_info )
2011-11-05 23:41:39 -07:00
{
//calculate refresh rate
if ( ! mode_info ) continue ;
if ( mode_info - > hTotal & & mode_info - > vTotal )
2011-11-09 07:42:00 -08:00
rate = ( ( float ) mode_info - > dotClock /
( ( float ) mode_info - > hTotal * ( float ) mode_info - > vTotal ) ) ;
2011-11-05 23:41:39 -07:00
else
rate = 0.0 ;
2012-02-21 14:05:02 -08:00
snprintf ( resolution_text , ( RESOLUTION_TXT_MAX_LENGTH - 1 ) , " %dx%d@%.1fHz " , mode_info - > width , mode_info - > height , rate ) ;
2011-11-05 23:41:39 -07:00
e_widget_ilist_append ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog , NULL , resolution_text , NULL , mode_info , NULL ) ;
//select currently enabled mode
if ( mode_info = = current_mode )
2011-11-09 07:42:00 -08:00
e_widget_ilist_selected_set ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog , i ) ;
2011-11-05 23:41:39 -07:00
i + + ;
}
//append 'disabled' mode
2012-02-18 08:49:17 -08:00
e_widget_ilist_append ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog , NULL , _ ( " Disabled " ) , NULL , & disabled_mode , NULL ) ;
2011-11-05 23:41:39 -07:00
//reenable widget
2012-02-18 08:49:17 -08:00
enable = EINA_TRUE ;
_go_and_return :
e_widget_disabled_set ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog , enable ) ;
2011-11-05 23:41:39 -07:00
e_widget_ilist_go ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog ) ;
e_widget_ilist_thaw ( e_config_runtime_info - > gui . subdialogs . resolutions . dialog ) ;
}
void
2011-11-09 07:39:26 -08:00
dialog_subdialog_resolutions_keep_changes ( E_Config_Dialog_Data * cfdata )
2011-11-05 23:41:39 -07:00
{
E_Config_Randr_Dialog_Output_Dialog_Data * odd ;
Eina_List * iter ;
if ( ! cfdata ) return ;
2011-11-09 08:13:26 -08:00
EINA_LIST_FOREACH ( cfdata - > output_dialog_data_list , iter , odd )
2011-11-05 23:41:39 -07:00
{
if ( odd & & odd - > new_mode & & ( odd - > new_mode ! = odd - > previous_mode ) )
{
odd - > previous_mode = odd - > new_mode ;
odd - > new_mode = NULL ;
}
}
}
2011-11-09 07:42:00 -08:00
void
2011-11-09 07:39:26 -08:00
dialog_subdialog_resolutions_discard_changes ( E_Config_Dialog_Data * cfdata )
2011-11-05 23:41:39 -07:00
{
E_Config_Randr_Dialog_Output_Dialog_Data * odd ;
Eina_List * iter ;
if ( ! cfdata ) return ;
2011-11-09 08:13:26 -08:00
EINA_LIST_FOREACH ( cfdata - > output_dialog_data_list , iter , odd )
2011-11-05 23:41:39 -07:00
{
//for now, there is no way to redisable an output during discartion
if ( ! odd - > crtc | | ! odd - > previous_mode ) continue ;
//use currently used outputs (noutputs == Ecore_X_Randr_Unset)
if ( ecore_x_randr_crtc_mode_set ( cfdata - > manager - > root , odd - > crtc - > xid , NULL , Ecore_X_Randr_Unset , odd - > previous_mode - > xid ) )
{
odd - > new_mode = odd - > previous_mode ;
odd - > previous_mode = NULL ;
ecore_x_randr_screen_reset ( cfdata - > manager - > root ) ;
}
}
}
2011-11-09 07:42:00 -08:00