feature: handle xrandr backlight using a single, accurate handler

there's an event from ecore-x which tells us when this property has changed, which means we no longer have to be constantly checking to see if other apps have changed it
This commit is contained in:
Mike Blumenkrantz 2014-01-21 16:48:09 -05:00
parent d2f9a2efbf
commit 215c0409e0
2 changed files with 19 additions and 89 deletions

View File

@ -17,20 +17,10 @@ static int sysmode = MODE_NONE;
static Ecore_Animator *bl_anim = NULL;
static Eina_List *bl_devs = NULL;
static Ecore_Event_Handler *_e_backlight_handler_config_mode = NULL;
static Ecore_Event_Handler *_e_backlight_handler_border_fullscreen = NULL;
static Ecore_Event_Handler *_e_backlight_handler_border_unfullscreen = NULL;
static Ecore_Event_Handler *_e_backlight_handler_border_remove = NULL;
static Ecore_Event_Handler *_e_backlight_handler_border_iconify = NULL;
static Ecore_Event_Handler *_e_backlight_handler_border_uniconify = NULL;
static Ecore_Event_Handler *_e_backlight_handler_border_desk_set = NULL;
static Ecore_Event_Handler *_e_backlight_handler_desk_show = NULL;
static void _e_backlight_update(E_Zone *zone);
static void _e_backlight_set(E_Zone *zone, double val);
static Eina_Bool _bl_anim(void *data, double pos);
static Eina_Bool bl_avail = EINA_TRUE;
static Eina_Bool _e_backlight_handler(void *d, int type, void *ev);
#ifndef WAYLAND_ONLY
static Eina_Bool xbl_avail = EINA_FALSE;
#endif
@ -57,30 +47,6 @@ e_backlight_init(void)
eeze_init();
#endif
_e_backlight_handler_config_mode = ecore_event_handler_add
(E_EVENT_CONFIG_MODE_CHANGED, _e_backlight_handler, NULL);
_e_backlight_handler_border_fullscreen = ecore_event_handler_add
(E_EVENT_CLIENT_FULLSCREEN, _e_backlight_handler, NULL);
_e_backlight_handler_border_unfullscreen = ecore_event_handler_add
(E_EVENT_CLIENT_UNFULLSCREEN, _e_backlight_handler, NULL);
_e_backlight_handler_border_remove = ecore_event_handler_add
(E_EVENT_CLIENT_REMOVE, _e_backlight_handler, NULL);
_e_backlight_handler_border_iconify = ecore_event_handler_add
(E_EVENT_CLIENT_ICONIFY, _e_backlight_handler, NULL);
_e_backlight_handler_border_uniconify = ecore_event_handler_add
(E_EVENT_CLIENT_UNICONIFY, _e_backlight_handler, NULL);
_e_backlight_handler_border_desk_set = ecore_event_handler_add
(E_EVENT_CLIENT_DESK_SET, _e_backlight_handler, NULL);
_e_backlight_handler_desk_show = ecore_event_handler_add
(E_EVENT_DESK_SHOW, _e_backlight_handler, NULL);
#ifndef WAYLAND_ONLY
if (e_comp_get(NULL)->man->root)
xbl_avail = ecore_x_randr_output_backlight_available();
@ -119,53 +85,7 @@ e_backlight_shutdown(void)
bl_sys_pending_set = EINA_FALSE;
eeze_shutdown();
#endif
if (_e_backlight_handler_config_mode)
{
ecore_event_handler_del(_e_backlight_handler_config_mode);
_e_backlight_handler_config_mode = NULL;
}
if (_e_backlight_handler_border_fullscreen)
{
ecore_event_handler_del(_e_backlight_handler_border_fullscreen);
_e_backlight_handler_border_fullscreen = NULL;
}
if (_e_backlight_handler_border_unfullscreen)
{
ecore_event_handler_del(_e_backlight_handler_border_unfullscreen);
_e_backlight_handler_border_unfullscreen = NULL;
}
if (_e_backlight_handler_border_remove)
{
ecore_event_handler_del(_e_backlight_handler_border_remove);
_e_backlight_handler_border_remove = NULL;
}
if (_e_backlight_handler_border_iconify)
{
ecore_event_handler_del(_e_backlight_handler_border_iconify);
_e_backlight_handler_border_iconify = NULL;
}
if (_e_backlight_handler_border_uniconify)
{
ecore_event_handler_del(_e_backlight_handler_border_uniconify);
_e_backlight_handler_border_uniconify = NULL;
}
if (_e_backlight_handler_border_desk_set)
{
ecore_event_handler_del(_e_backlight_handler_border_desk_set);
_e_backlight_handler_border_desk_set = NULL;
}
if (_e_backlight_handler_desk_show)
{
ecore_event_handler_del(_e_backlight_handler_desk_show);
_e_backlight_handler_desk_show = NULL;
}
return 1;
}
@ -273,14 +193,6 @@ e_backlight_devices_get(void)
/* local subsystem functions */
static Eina_Bool
_e_backlight_handler(void *d __UNUSED__, int type __UNUSED__, void *ev __UNUSED__)
{
if (!bl_anim)
e_backlight_update();
return ECORE_CALLBACK_PASS_ON;
}
static void
_e_backlight_update(E_Zone *zone)
{

View File

@ -1,6 +1,9 @@
#include "e.h"
#include <Ecore_X.h>
# define RANDR_VERSION_1_3 ((1 << 16) | 3)
# define RANDR_VERSION_1_4 ((1 << 16) | 4)
#define GRAV_SET(ec, grav) \
ecore_x_window_gravity_set(e_client_util_pwin_get(ec), grav); \
if (ec->comp_data->lock_win) ecore_x_window_gravity_set(ec->comp_data->lock_win, grav); \
@ -51,6 +54,7 @@ static int screen_size_index = -1;
static Ecore_Timer *screensaver_idle_timer = NULL;
static Eina_Bool screensaver_dimmed = EINA_FALSE;
static Ecore_X_Atom backlight_atom = 0;
static inline Ecore_X_Window
_e_comp_x_client_window_get(const E_Client *ec)
@ -4300,6 +4304,14 @@ _e_comp_x_screensaver_notify_cb(void *data __UNUSED__, int type __UNUSED__, Ecor
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_e_comp_x_backlight_notify_cb(void *data EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Randr_Output_Property_Notify *ev)
{
if (ev->property == backlight_atom)
e_backlight_update();
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_e_comp_x_cb_frame_extents_request(void *data EINA_UNUSED, int ev_type EINA_UNUSED, Ecore_X_Event_Frame_Extents_Request *ev)
{
@ -5087,7 +5099,13 @@ e_comp_x_init(void)
_e_comp_x_cb_frame_extents_request, NULL);
E_LIST_HANDLER_APPEND(handlers, ECORE_X_EVENT_PING,
_e_comp_x_cb_ping, NULL);
E_LIST_HANDLER_APPEND(handlers, ECORE_X_EVENT_SCREENSAVER_NOTIFY, _e_comp_x_screensaver_notify_cb, NULL);;
E_LIST_HANDLER_APPEND(handlers, ECORE_X_EVENT_SCREENSAVER_NOTIFY, _e_comp_x_screensaver_notify_cb, NULL);
E_LIST_HANDLER_APPEND(handlers, ECORE_X_EVENT_RANDR_OUTPUT_PROPERTY_NOTIFY, _e_comp_x_backlight_notify_cb, NULL);
if (ecore_x_randr_version_get() >= RANDR_VERSION_1_3)
backlight_atom = ecore_x_atom_get("Backlight");
if (!backlight_atom)
backlight_atom = ecore_x_atom_get("BACKLIGHT");
ecore_x_screensaver_custom_blanking_enable();