mirror of
https://gitlab.freedesktop.org/wayland/weston
synced 2024-09-06 09:56:14 +00:00
compositor: use smoother range for backlight control
now it goes from 0 to 255. Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
This commit is contained in:
parent
1b079abe0e
commit
5ab91ad845
|
@ -927,7 +927,7 @@ sprite_handle_pending_buffer_destroy(struct wl_listener *listener,
|
||||||
sprite->pending_surface = NULL;
|
sprite->pending_surface = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns a value between 1-10 range, where higher is brighter */
|
/* returns a value between 0-255 range, where higher is brighter */
|
||||||
static uint32_t
|
static uint32_t
|
||||||
drm_get_backlight(struct drm_output *output)
|
drm_get_backlight(struct drm_output *output)
|
||||||
{
|
{
|
||||||
|
@ -936,13 +936,13 @@ drm_get_backlight(struct drm_output *output)
|
||||||
brightness = backlight_get_brightness(output->backlight);
|
brightness = backlight_get_brightness(output->backlight);
|
||||||
max_brightness = backlight_get_max_brightness(output->backlight);
|
max_brightness = backlight_get_max_brightness(output->backlight);
|
||||||
|
|
||||||
/* convert it on a scale of 1 to 10 */
|
/* convert it on a scale of 0 to 255 */
|
||||||
norm = 1 + ((brightness) * 9)/(max_brightness);
|
norm = (brightness * 255)/(max_brightness);
|
||||||
|
|
||||||
return (uint32_t) norm;
|
return (uint32_t) norm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* values accepted are between 1-10 range */
|
/* values accepted are between 0-255 range */
|
||||||
static void
|
static void
|
||||||
drm_set_backlight(struct weston_output *output_base, uint32_t value)
|
drm_set_backlight(struct weston_output *output_base, uint32_t value)
|
||||||
{
|
{
|
||||||
|
@ -952,13 +952,13 @@ drm_set_backlight(struct weston_output *output_base, uint32_t value)
|
||||||
if (!output->backlight)
|
if (!output->backlight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (value < 1 || value > 10)
|
if (value < 0 || value > 255)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
max_brightness = backlight_get_max_brightness(output->backlight);
|
max_brightness = backlight_get_max_brightness(output->backlight);
|
||||||
|
|
||||||
/* get denormalized value */
|
/* get denormalized value */
|
||||||
new_brightness = ((value - 1) * (max_brightness)) / 9;
|
new_brightness = (value * max_brightness) / 255;
|
||||||
|
|
||||||
backlight_set_brightness(output->backlight, new_brightness);
|
backlight_set_brightness(output->backlight, new_brightness);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ struct weston_output {
|
||||||
void (*destroy)(struct weston_output *output);
|
void (*destroy)(struct weston_output *output);
|
||||||
void (*assign_planes)(struct weston_output *output);
|
void (*assign_planes)(struct weston_output *output);
|
||||||
|
|
||||||
/* backlight values are on 1-10 range, where higher is brighter */
|
/* backlight values are on 0-255 range, where higher is brighter */
|
||||||
uint32_t backlight_current;
|
uint32_t backlight_current;
|
||||||
void (*set_backlight)(struct weston_output *output, uint32_t value);
|
void (*set_backlight)(struct weston_output *output, uint32_t value);
|
||||||
void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
|
void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
|
||||||
|
|
17
src/shell.c
17
src/shell.c
|
@ -1927,6 +1927,7 @@ backlight_binding(struct wl_input_device *device, uint32_t time,
|
||||||
{
|
{
|
||||||
struct weston_compositor *compositor = data;
|
struct weston_compositor *compositor = data;
|
||||||
struct weston_output *output;
|
struct weston_output *output;
|
||||||
|
long backlight_new = 0;
|
||||||
|
|
||||||
/* TODO: we're limiting to simple use cases, where we assume just
|
/* TODO: we're limiting to simple use cases, where we assume just
|
||||||
* control on the primary display. We'd have to extend later if we
|
* control on the primary display. We'd have to extend later if we
|
||||||
|
@ -1939,13 +1940,17 @@ backlight_binding(struct wl_input_device *device, uint32_t time,
|
||||||
if (!output->set_backlight)
|
if (!output->set_backlight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) &&
|
if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
|
||||||
output->backlight_current > 1)
|
backlight_new = output->backlight_current - 25;
|
||||||
output->backlight_current--;
|
else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
|
||||||
else if ((key == KEY_F10 || key == KEY_BRIGHTNESSUP) &&
|
backlight_new = output->backlight_current + 25;
|
||||||
output->backlight_current < 10)
|
|
||||||
output->backlight_current++;
|
|
||||||
|
|
||||||
|
if (backlight_new < 5)
|
||||||
|
backlight_new = 5;
|
||||||
|
if (backlight_new > 255)
|
||||||
|
backlight_new = 255;
|
||||||
|
|
||||||
|
output->backlight_current = backlight_new;
|
||||||
output->set_backlight(output, output->backlight_current);
|
output->set_backlight(output, output->backlight_current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue