From 0e5f759b511091c81a56d44bc672b48d481a9ac8 Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Wed, 22 Feb 2012 15:42:07 +0000 Subject: [PATCH] Do CRTC configuration/restoration in one step. SVN revision: 68276 --- src/bin/e_randr_12.c | 107 ++++++++++++++++++++++++----- src/bin/e_randr_12_crtc.c | 65 ------------------ src/bin/e_randr_12_serialization.c | 4 +- src/bin/e_randr_private.h | 1 - 4 files changed, 92 insertions(+), 85 deletions(-) diff --git a/src/bin/e_randr_12.c b/src/bin/e_randr_12.c index 07c653c79..c1b8afb6d 100644 --- a/src/bin/e_randr_12.c +++ b/src/bin/e_randr_12.c @@ -565,11 +565,13 @@ _output_property_change_event_cb(void *data __UNUSED__, int type, void *ev) _try_enable_output(E_Randr_Output_Info *output_info, Eina_Bool force) { Eina_List *iter, *outputs_list = NULL, *common_modes = NULL; - E_Randr_Crtc_Info *crtc_info, *usable_crtc = NULL; + E_Randr_Crtc_Info *crtc_info = NULL, *usable_crtc = NULL; + const E_Randr_Crtc_Info *crtc_rel = NULL; E_Randr_Output_Info *primary_output; Ecore_X_Randr_Output *outputs; Ecore_X_Randr_Mode_Info *mode_info; - Eina_Bool ret = EINA_FALSE; + int dx = Ecore_X_Randr_None, dy = Ecore_X_Randr_None; + Eina_Bool ret = EINA_TRUE; EINA_SAFETY_ON_NULL_RETURN_VAL(output_info, EINA_FALSE); EINA_SAFETY_ON_TRUE_RETURN_VAL((output_info->crtc && output_info->crtc->current_mode), EINA_FALSE); @@ -637,7 +639,7 @@ _try_enable_output(E_Randr_Output_Info *output_info, Eina_Bool force) outputs_list = eina_list_append(outputs_list, output_info); outputs = _outputs_to_array(outputs_list); primary_output->crtc->outputs = NULL; - ret = ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, primary_output->crtc->xid, outputs, eina_list_count(outputs_list), primary_output->crtc->current_mode->xid); + ret &= ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, primary_output->crtc->xid, outputs, eina_list_count(outputs_list), primary_output->crtc->current_mode->xid); free(outputs); eina_list_free(outputs_list); return ret; @@ -651,8 +653,9 @@ _try_enable_output(E_Randr_Output_Info *output_info, Eina_Bool force) /* * 2a. exact mode. */ - ret = ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, usable_crtc->xid, &output_info->xid, 1, primary_output->crtc->current_mode->xid); - return ret && ecore_x_randr_crtc_pos_relative_set(e_randr_screen_info.root, usable_crtc->xid, primary_output->crtc->xid, ECORE_X_RANDR_OUTPUT_POLICY_CLONE, e_randr_screen_info.rrvd_info.randr_info_12->alignment); + ret &= ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, usable_crtc->xid, &output_info->xid, 1, primary_output->crtc->current_mode->xid); + ret &= ecore_x_randr_crtc_pos_relative_set(e_randr_screen_info.root, usable_crtc->xid, primary_output->crtc->xid, ECORE_X_RANDR_OUTPUT_POLICY_CLONE, e_randr_screen_info.rrvd_info.randr_info_12->alignment); + return ret; } } else @@ -662,8 +665,9 @@ _try_enable_output(E_Randr_Output_Info *output_info, Eina_Bool force) */ if (primary_output->crtc && (mode_info = _mode_geo_identical_find(output_info->monitor->modes, primary_output->crtc->current_mode))) { - ret = ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, usable_crtc->xid, &output_info->xid, 1, mode_info->xid); - return ret && ecore_x_randr_crtc_pos_relative_set(e_randr_screen_info.root, usable_crtc->xid, primary_output->crtc->xid, ECORE_X_RANDR_OUTPUT_POLICY_CLONE, e_randr_screen_info.rrvd_info.randr_info_12->alignment); + ret &= ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, usable_crtc->xid, &output_info->xid, 1, mode_info->xid); + ret &= ecore_x_randr_crtc_pos_relative_set(e_randr_screen_info.root, usable_crtc->xid, primary_output->crtc->xid, ECORE_X_RANDR_OUTPUT_POLICY_CLONE, e_randr_screen_info.rrvd_info.randr_info_12->alignment); + return ret; } /* * 3. Find the highest resolution mode common to enable on primary output's CRTC and the new one. @@ -677,9 +681,9 @@ _try_enable_output(E_Randr_Output_Info *output_info, Eina_Bool force) { eina_list_free(common_modes); fprintf(stderr, "Will try to set mode: %dx%d for primary and clone.\n", mode_info->width, mode_info->height); - ret = ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, primary_output->crtc->xid, ((Ecore_X_Randr_Output *)Ecore_X_Randr_Unset), Ecore_X_Randr_Unset, mode_info->xid); - ret = (ret && ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, usable_crtc->xid, &output_info->xid, 1, mode_info->xid)); - ret = (ret && ecore_x_randr_crtc_pos_relative_set(e_randr_screen_info.root, usable_crtc->xid, primary_output->crtc->xid, ECORE_X_RANDR_OUTPUT_POLICY_CLONE, e_randr_screen_info.rrvd_info.randr_info_12->alignment)); + ret &= ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, primary_output->crtc->xid, ((Ecore_X_Randr_Output *)Ecore_X_Randr_Unset), Ecore_X_Randr_Unset, mode_info->xid); + ret &= ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, usable_crtc->xid, &output_info->xid, 1, mode_info->xid); + ret &= ecore_x_randr_crtc_pos_relative_set(e_randr_screen_info.root, usable_crtc->xid, primary_output->crtc->xid, ECORE_X_RANDR_OUTPUT_POLICY_CLONE, e_randr_screen_info.rrvd_info.randr_info_12->alignment); } } eina_list_free(outputs_list); @@ -701,20 +705,91 @@ _try_enable_output(E_Randr_Output_Info *output_info, Eina_Bool force) ret = EINA_FALSE; break; } - if ((ret = ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, usable_crtc->xid, &output_info->xid, 1, mode_info->xid))) + + //get the crtc we will place our's relative to. If it's NULL, this is the + //only output attached, work done. + if (!(crtc_rel = _crtc_according_to_policy_get(usable_crtc, output_info->policy))) + { + fprintf(stderr, "E_RANDR: CRTC %d enabled. No other CRTC had to be moved.\n", usable_crtc->xid); + ret &= ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, usable_crtc->xid, &output_info->xid, 1, mode_info->xid); + return ret; + } + + //Calculate new CRTC's position according to policy + switch (output_info->policy) + { + case ECORE_X_RANDR_OUTPUT_POLICY_ABOVE: + usable_crtc->geometry.x = crtc_rel->geometry.x; + usable_crtc->geometry.y = 0; + break; + case ECORE_X_RANDR_OUTPUT_POLICY_RIGHT: + usable_crtc->geometry.x = (crtc_rel->geometry.x + crtc_rel->geometry.w); + usable_crtc->geometry.y = crtc_rel->geometry.y; + break; + case ECORE_X_RANDR_OUTPUT_POLICY_BELOW: + usable_crtc->geometry.x = crtc_rel->geometry.x; + usable_crtc->geometry.y = (crtc_rel->geometry.y + crtc_rel->geometry.h); + break; + case ECORE_X_RANDR_OUTPUT_POLICY_LEFT: + usable_crtc->geometry.y = crtc_rel->geometry.y; + usable_crtc->geometry.x = 0; + break; + default: + usable_crtc->geometry.y = 0; + usable_crtc->geometry.x = 0; + } + + if ((ret &= ecore_x_randr_crtc_settings_set(e_randr_screen_info.root, usable_crtc->xid, &output_info->xid, 1, usable_crtc->geometry.x, usable_crtc->geometry.y, mode_info->xid, ECORE_X_RANDR_ORIENTATION_ROT_0))) { //WORKAROUND //Reason: the CRTC event, that'd bring the new info about the set //mode is arriving too late here. usable_crtc->current_mode = mode_info; - crtc_info->geometry.x = 0; - crtc_info->geometry.y = 0; - crtc_info->geometry.w = mode_info->width; - crtc_info->geometry.h = mode_info->height; + usable_crtc->geometry.w = mode_info->width; + usable_crtc->geometry.h = mode_info->height; //WORKAROUND END - ret &= _crtc_move_policy(usable_crtc, output_info->policy); + + fprintf(stderr, "E_RANDR: Moved CRTC %d has geometry (x,y,wxh): %d, %d, %dx%d.\n", usable_crtc->xid, usable_crtc->geometry.x, usable_crtc->geometry.y, usable_crtc->geometry.w, usable_crtc->geometry.h); + //following is policy dependend. + switch (output_info->policy) + { + case ECORE_X_RANDR_OUTPUT_POLICY_ABOVE: + dy = (crtc_rel->geometry.y - usable_crtc->geometry.h); + if (dy < 0) + { + //virtual move (move other CRTCs as nessesary) + dy = -dy; + ret &= ecore_x_randr_move_all_crtcs_but(e_randr_screen_info.root, + &usable_crtc->xid, + 1, + dx, + dy); + fprintf(stderr, "E_RANDR: Moving all CRTCs but %d, by %dx%d delta.\n", usable_crtc->xid, dx, dy); + } + break; + + case ECORE_X_RANDR_OUTPUT_POLICY_LEFT: + dx = (crtc_rel->geometry.x - usable_crtc->geometry.w); + if (dx < 0) + { + //virtual move (move other CRTCs as nessesary) + dx = -dx; + ret &= ecore_x_randr_move_all_crtcs_but(e_randr_screen_info.root, + &usable_crtc->xid, + 1, + dx, + dy); + fprintf(stderr, "E_RANDR: Moving all CRTCs but %d, by %dx%d delta.\n", usable_crtc->xid, dx, dy); + } + break; + + default: + break; + } + } } + if (ret) ecore_x_randr_screen_reset(e_randr_screen_info.root); diff --git a/src/bin/e_randr_12_crtc.c b/src/bin/e_randr_12_crtc.c index 17de0079a..2b74dade3 100644 --- a/src/bin/e_randr_12_crtc.c +++ b/src/bin/e_randr_12_crtc.c @@ -193,71 +193,6 @@ _crtc_outputs_mode_max_set(E_Randr_Crtc_Info *crtc_info) return ret; } -/* - * reconfigure screen setup according to policy. This is only required if all - * CRTCs' positions might be affected by the another screens' movement. This includes 'virtual' moves, - * which means that e.g. when a crtc should be placed at a position < 0, all - * other crtcs are accordingly moved instead, so the result is the same. - */ -Eina_Bool -_crtc_move_policy(E_Randr_Crtc_Info *new_crtc, Ecore_X_Randr_Output_Policy policy) -{ - const E_Randr_Crtc_Info *crtc_rel; - int dx = Ecore_X_Randr_None, dy = Ecore_X_Randr_None; - Eina_Bool ret = EINA_TRUE; - - EINA_SAFETY_ON_NULL_RETURN_VAL(new_crtc, EINA_FALSE); - - //get the crtc we will place our's relative to. If it's NULL, this is the - //only output attached, work done. - if (!(crtc_rel = _crtc_according_to_policy_get(new_crtc, policy))) - { - fprintf(stderr, "E_RANDR: Moving CRTC %d, there is no other CRTC to move this one relative to.\n", new_crtc->xid); - return EINA_TRUE; - } - - fprintf(stderr, "E_RANDR: Moved CRTC %d has geometry (x,y,wxh): %d, %d, %dx%d.\n", new_crtc->xid, new_crtc->geometry.x, new_crtc->geometry.y, new_crtc->geometry.w, new_crtc->geometry.h); - //following is policy dependend. - switch (policy) - { - case ECORE_X_RANDR_OUTPUT_POLICY_ABOVE: - dy = (crtc_rel->geometry.y - new_crtc->geometry.h); - if (dy < 0) - { - //virtual move (move other CRTCs as nessesary) - dy = -dy; - ret = ecore_x_randr_move_all_crtcs_but(e_randr_screen_info.root, - &new_crtc->xid, - 1, - dx, - dy); - fprintf(stderr, "E_RANDR: Moving all CRTCs but %d, by %dx%d delta.\n", new_crtc->xid, dx, dy); - } - break; - - case ECORE_X_RANDR_OUTPUT_POLICY_LEFT: - dx = (crtc_rel->geometry.x - new_crtc->geometry.w); - if (dx < 0) - { - //virtual move (move other CRTCs as nessesary) - dx = -dx; - ret = ecore_x_randr_move_all_crtcs_but(e_randr_screen_info.root, - &new_crtc->xid, - 1, - dx, - dy); - fprintf(stderr, "E_RANDR: Moving all CRTCs but %d, by %dx%d delta.\n", new_crtc->xid, dx, dy); - } - break; - - default: - break; - } - ret &= ecore_x_randr_crtc_pos_relative_set(e_randr_screen_info.root, new_crtc->xid, crtc_rel->xid, policy, e_randr_screen_info.rrvd_info.randr_info_12->alignment); - - return ret; -} - /* * this retrieves a CRTC depending on a policy. * Note that this is enlightenment specific! Enlightenment doesn't 'allow' zones diff --git a/src/bin/e_randr_12_serialization.c b/src/bin/e_randr_12_serialization.c index 7340fc003..f88ad1b1f 100644 --- a/src/bin/e_randr_12_serialization.c +++ b/src/bin/e_randr_12_serialization.c @@ -453,11 +453,9 @@ _12_try_restore_configuration(void) fprintf(stderr, ".\n"); // DEBUG END - ret &= ecore_x_randr_crtc_mode_set(e_randr_screen_info.root, ci->xid, outputs_array, eina_list_count(outputs_list), mode); + ret &= ecore_x_randr_crtc_settings_set(e_randr_screen_info.root, ci->xid, outputs_array, eina_list_count(outputs_list), sc->pos.x, sc->pos.y, mode, sc->orientation); eina_list_free(outputs_list); free(outputs_array); - ret &= ecore_x_randr_crtc_pos_set(e_randr_screen_info.root, ci->xid, sc->pos.x, sc->pos.y); - ret &= ecore_x_randr_crtc_orientation_set(e_randr_screen_info.root, ci->xid, sc->orientation); } return ret; } diff --git a/src/bin/e_randr_private.h b/src/bin/e_randr_private.h index 894e431ca..cada26aa2 100644 --- a/src/bin/e_randr_private.h +++ b/src/bin/e_randr_private.h @@ -61,7 +61,6 @@ E_Randr_Crtc_Info * _crtc_info_new(Ecore_X_Randr_Crtc crtc); void _crtc_info_free(E_Randr_Crtc_Info *crtc_info); void _crtc_refs_set(E_Randr_Crtc_Info *crtc_info); void _crtc_outputs_refs_set(E_Randr_Crtc_Info *crtc_info); -Eina_Bool _crtc_move_policy(E_Randr_Crtc_Info *new_crtc, Ecore_X_Randr_Output_Policy policy); const E_Randr_Crtc_Info *_crtc_according_to_policy_get(E_Randr_Crtc_Info *but, Ecore_X_Randr_Output_Policy policy); #endif