mirror of
https://github.com/brl/mutter.git
synced 2024-12-24 12:02:04 +00:00
monitor-manager: Add NightLightSupported property to DisplayConfig
This checks whether it's possible to set a CRTC GAMMA_LUT, which is what is necessary to implement night light. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2310>
This commit is contained in:
parent
f64259ceae
commit
8fdb80a718
@ -297,6 +297,13 @@
|
||||
-->
|
||||
<property name="ApplyMonitorsConfigAllowed" type="b" access="read" />
|
||||
|
||||
<!--
|
||||
NightLightSupported:
|
||||
|
||||
Whether night light is supported by this system.
|
||||
-->
|
||||
<property name="NightLightSupported" type="b" access="read" />
|
||||
|
||||
<!--
|
||||
MonitorsChanged:
|
||||
|
||||
|
@ -1165,11 +1165,65 @@ update_has_builtin_panel (MetaMonitorManager *manager)
|
||||
obj_props[PROP_HAS_BUILTIN_PANEL]);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_monitor_manager_get_crtc_gamma (MetaMonitorManager *manager,
|
||||
MetaCrtc *crtc,
|
||||
size_t *size,
|
||||
unsigned short **red,
|
||||
unsigned short **green,
|
||||
unsigned short **blue)
|
||||
{
|
||||
MetaMonitorManagerClass *klass = META_MONITOR_MANAGER_GET_CLASS (manager);
|
||||
|
||||
if (klass->get_crtc_gamma)
|
||||
{
|
||||
klass->get_crtc_gamma (manager, crtc, size, red, green, blue);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (size)
|
||||
*size = 0;
|
||||
if (red)
|
||||
*red = NULL;
|
||||
if (green)
|
||||
*green = NULL;
|
||||
if (blue)
|
||||
*blue = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_night_light_supported (MetaMonitorManager *manager)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = meta_backend_get_gpus (manager->backend); l; l = l->next)
|
||||
{
|
||||
MetaGpu *gpu = l->data;
|
||||
GList *l_crtc;
|
||||
|
||||
for (l_crtc = meta_gpu_get_crtcs (gpu); l_crtc; l_crtc = l_crtc->next)
|
||||
{
|
||||
MetaCrtc *crtc = l_crtc->data;
|
||||
size_t gamma_lut_size;
|
||||
|
||||
meta_monitor_manager_get_crtc_gamma (manager, crtc,
|
||||
&gamma_lut_size,
|
||||
NULL, NULL, NULL);
|
||||
if (gamma_lut_size > 0)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
meta_monitor_manager_setup (MetaMonitorManager *manager)
|
||||
{
|
||||
MetaMonitorConfigStore *config_store;
|
||||
const MetaMonitorConfigPolicy *policy;
|
||||
gboolean night_light_supported;
|
||||
|
||||
manager->in_init = TRUE;
|
||||
|
||||
@ -1180,6 +1234,9 @@ meta_monitor_manager_setup (MetaMonitorManager *manager)
|
||||
meta_dbus_display_config_set_apply_monitors_config_allowed (manager->display_config,
|
||||
policy->enable_dbus);
|
||||
|
||||
night_light_supported = is_night_light_supported (manager);
|
||||
meta_dbus_display_config_set_night_light_supported (manager->display_config,
|
||||
night_light_supported);
|
||||
|
||||
meta_monitor_manager_read_current_state (manager);
|
||||
|
||||
@ -2811,7 +2868,6 @@ meta_monitor_manager_handle_get_crtc_gamma (MetaDBusDisplayConfig *skeleton,
|
||||
guint crtc_id,
|
||||
MetaMonitorManager *manager)
|
||||
{
|
||||
MetaMonitorManagerClass *klass;
|
||||
GList *combined_crtcs;
|
||||
MetaCrtc *crtc;
|
||||
gsize size;
|
||||
@ -2842,14 +2898,8 @@ meta_monitor_manager_handle_get_crtc_gamma (MetaDBusDisplayConfig *skeleton,
|
||||
crtc = g_list_nth_data (combined_crtcs, crtc_id);
|
||||
g_list_free (combined_crtcs);
|
||||
|
||||
klass = META_MONITOR_MANAGER_GET_CLASS (manager);
|
||||
if (klass->get_crtc_gamma)
|
||||
klass->get_crtc_gamma (manager, crtc, &size, &red, &green, &blue);
|
||||
else
|
||||
{
|
||||
size = 0;
|
||||
red = green = blue = NULL;
|
||||
}
|
||||
meta_monitor_manager_get_crtc_gamma (manager, crtc,
|
||||
&size, &red, &green, &blue);
|
||||
|
||||
red_bytes = g_bytes_new_take (red, size * sizeof (unsigned short));
|
||||
green_bytes = g_bytes_new_take (green, size * sizeof (unsigned short));
|
||||
|
@ -365,27 +365,46 @@ meta_monitor_manager_native_get_crtc_gamma (MetaMonitorManager *manager,
|
||||
MetaKmsCrtc *kms_crtc;
|
||||
const MetaKmsCrtcState *crtc_state;
|
||||
|
||||
g_return_if_fail (META_IS_CRTC_KMS (crtc));
|
||||
if (!META_IS_CRTC_KMS (crtc))
|
||||
{
|
||||
if (size)
|
||||
*size = 0;
|
||||
if (red)
|
||||
*red = NULL;
|
||||
if (green)
|
||||
*green = NULL;
|
||||
if (blue)
|
||||
*blue = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
crtc_gamma =
|
||||
meta_monitor_manager_native_get_cached_crtc_gamma (manager_native,
|
||||
crtc_kms);
|
||||
if (crtc_gamma)
|
||||
{
|
||||
*size = crtc_gamma->size;
|
||||
*red = g_memdup2 (crtc_gamma->red, *size * sizeof **red);
|
||||
*green = g_memdup2 (crtc_gamma->green, *size * sizeof **green);
|
||||
*blue = g_memdup2 (crtc_gamma->blue, *size * sizeof **blue);
|
||||
if (size)
|
||||
*size = crtc_gamma->size;
|
||||
if (red)
|
||||
*red = g_memdup2 (crtc_gamma->red, *size * sizeof **red);
|
||||
if (green)
|
||||
*green = g_memdup2 (crtc_gamma->green, *size * sizeof **green);
|
||||
if (blue)
|
||||
*blue = g_memdup2 (crtc_gamma->blue, *size * sizeof **blue);
|
||||
return;
|
||||
}
|
||||
|
||||
kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
|
||||
crtc_state = meta_kms_crtc_get_current_state (kms_crtc);
|
||||
|
||||
*size = crtc_state->gamma.size;
|
||||
*red = g_memdup2 (crtc_state->gamma.red, *size * sizeof **red);
|
||||
*green = g_memdup2 (crtc_state->gamma.green, *size * sizeof **green);
|
||||
*blue = g_memdup2 (crtc_state->gamma.blue, *size * sizeof **blue);
|
||||
if (size)
|
||||
*size = crtc_state->gamma.size;
|
||||
if (red)
|
||||
*red = g_memdup2 (crtc_state->gamma.red, *size * sizeof **red);
|
||||
if (green)
|
||||
*green = g_memdup2 (crtc_state->gamma.green, *size * sizeof **green);
|
||||
if (blue)
|
||||
*blue = g_memdup2 (crtc_state->gamma.blue, *size * sizeof **blue);
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -663,9 +663,12 @@ meta_monitor_manager_xrandr_get_crtc_gamma (MetaMonitorManager *manager,
|
||||
(XID) meta_crtc_get_id (crtc));
|
||||
|
||||
*size = gamma->size;
|
||||
*red = g_memdup2 (gamma->red, sizeof (unsigned short) * gamma->size);
|
||||
*green = g_memdup2 (gamma->green, sizeof (unsigned short) * gamma->size);
|
||||
*blue = g_memdup2 (gamma->blue, sizeof (unsigned short) * gamma->size);
|
||||
if (red)
|
||||
*red = g_memdup2 (gamma->red, sizeof (unsigned short) * gamma->size);
|
||||
if (green)
|
||||
*green = g_memdup2 (gamma->green, sizeof (unsigned short) * gamma->size);
|
||||
if (blue)
|
||||
*blue = g_memdup2 (gamma->blue, sizeof (unsigned short) * gamma->size);
|
||||
|
||||
XRRFreeGamma (gamma);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user