From 569eff8750dee75d0789a3864c619ef1a560a4f7 Mon Sep 17 00:00:00 2001 From: Sebastian Dransfeld Date: Tue, 16 Dec 2014 10:13:55 +0100 Subject: [PATCH] randr: Don't track active outputs Remove tracking of active outputs to reduce code complexity. --- src/bin/e_randr.c | 39 +++++++++++++++++++++++++++------------ src/bin/e_randr.h | 1 - 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/bin/e_randr.c b/src/bin/e_randr.c index 2df80f0ca..069739408 100644 --- a/src/bin/e_randr.c +++ b/src/bin/e_randr.c @@ -36,6 +36,7 @@ static Eina_Bool _e_randr_output_mode_valid(Ecore_X_Randr_Mode mode, Ecore_X_Ran static void _e_randr_output_active_set(E_Randr_Output *output, Eina_Bool connected); //static int _e_randr_config_output_cmp(const void *a, const void *b); static char *_e_randr_output_name_get(Ecore_X_Window root, Ecore_X_Randr_Output output); +static int _e_randr_active_get(void); /* local variables */ static Eina_List *_randr_event_handlers = NULL; @@ -622,10 +623,13 @@ _e_randr_apply(void) /* if the output does not fit, disable it */ if (((x + w) > maxw) || ((y + h) > maxh) || (mode == 0)) { + Eina_List *ln; + printf("RRR2: crtc does not fit - off\n"); - /* TODO: This is wrong, should remove output from crtc->outputs */ ecore_x_randr_crtc_settings_set(root, crtc->xid, NULL, 0, 0, 0, 0, ECORE_X_RANDR_ORIENTATION_ROT_0); + EINA_LIST_FOREACH_SAFE(crtc->outputs, ll, ln, output) + _e_randr_output_active_set(output, EINA_FALSE); continue; } @@ -791,7 +795,7 @@ _e_randr_event_cb_output_change(void *data EINA_UNUSED, int type EINA_UNUSED, vo /* forget out crtc */ output->crtc = NULL; } - if ((!output->active) && (output->cfg->connect)) + if (output->cfg && output->cfg->connect) { /* connect to crtc */ _e_randr_output_active_set(output, EINA_TRUE); @@ -822,11 +826,8 @@ _e_randr_event_cb_output_change(void *data EINA_UNUSED, int type EINA_UNUSED, vo else if (ev->connection == ECORE_X_RANDR_CONNECTION_STATUS_DISCONNECTED) { /* disconnected */ - if (output->active) - { - _e_randr_output_active_set(output, EINA_FALSE); - changed = EINA_TRUE; - } + _e_randr_output_active_set(output, EINA_FALSE); + changed = EINA_TRUE; } /* save the config if anything changed or we added a new one */ @@ -1249,12 +1250,12 @@ _e_randr_lid_update(void) { if (!output->is_lid) continue; /* only disable lid if we got more than 1 connected output */ - if ((_e_randr_lid_is_closed) && (output->active) && (e_randr->active > 1)) + if ((_e_randr_lid_is_closed) && (_e_randr_active_get() > 1)) { _e_randr_output_active_set(output, EINA_FALSE); changed = EINA_TRUE; } - else if (!output->active) + else { _e_randr_output_active_set(output, EINA_TRUE); changed = EINA_TRUE; @@ -1290,22 +1291,21 @@ _e_randr_output_active_set(E_Randr_Output *output, Eina_Bool active) { _e_randr_output_crtc_find(output); } + output->active = EINA_FALSE; if (output->crtc) { - output->active = active; printf("RR: ... found crtc %i\n", active); if (active) { output->crtc->outputs = eina_list_append(output->crtc->outputs, output); - e_randr->active++; printf("RR: ... add active output for crtc now\n"); + output->active = EINA_TRUE; } else { output->crtc->outputs = eina_list_remove(output->crtc->outputs, output); - e_randr->active--; output->crtc = NULL; printf("RR: ... remove output for crtc now\n"); } @@ -1338,3 +1338,18 @@ _e_randr_output_name_get(Ecore_X_Window root, Ecore_X_Randr_Output output) } return name; } + +static int +_e_randr_active_get(void) +{ + int active = 0; + E_Randr_Output *output; + Eina_List *l; + + EINA_LIST_FOREACH(e_randr->outputs, l, output) + { + if (output->active) + active++; + } + return active; +} diff --git a/src/bin/e_randr.h b/src/bin/e_randr.h index 30e355d44..9c508a425 100644 --- a/src/bin/e_randr.h +++ b/src/bin/e_randr.h @@ -70,7 +70,6 @@ struct _E_Randr_Crtc struct _E_Randr { - int active; // number of active outputs Eina_List *crtcs; // list of crtcs Eina_List *outputs; // list of outputs };