static gboolean gpm_kbd_backlight_set (GpmKbdBacklight *backlight, guint percentage) { gint scale; guint goal; g_return_val_if_fail (GPM_IS_KBD_BACKLIGHT (backlight), FALSE); /* if we're setting the same we are, don't bother */ //g_return_val_if_fail (backlight->priv->brightness_percent != percentage, FALSE); goal = gpm_discrete_from_percent (percentage, backlight->priv->max_brightness); scale = percentage > backlight->priv->brightness_percent ? 1 : -1; /* step loop down by 1 for a dimming effect */ while (backlight->priv->brightness != goal) { backlight->priv->brightness += scale; backlight->priv->brightness_percent = gpm_discrete_to_percent (backlight->priv->brightness, backlight->priv->max_brightness); g_dbus_proxy_call (backlight->priv->upower_proxy, "SetBrightness", g_variant_new ("(i)", (gint) backlight->priv->brightness), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); } egg_debug("Set brightness to %i", backlight->priv->brightness); return TRUE; }
/** * gpm_kbd_backlight_get_brightness: * @backlight: * @brightness: * @error: * * Return value: */ gboolean gpm_kbd_backlight_get_brightness (GpmKbdBacklight *backlight, guint *brightness, GError **error) { g_return_val_if_fail (backlight != NULL, FALSE); g_return_val_if_fail (GPM_IS_KBD_BACKLIGHT (backlight), FALSE); g_return_val_if_fail (brightness != NULL, FALSE); if (backlight->priv->can_dim == FALSE) { g_set_error_literal (error, gpm_kbd_backlight_error_quark (), GPM_KBD_BACKLIGHT_ERROR_HARDWARE_NOT_PRESENT, "Dim capable hardware not present"); return FALSE; } *brightness = backlight->priv->brightness_percent; return TRUE; }