コード例 #1
0
/**
 * gpm_backlight_init:
 * @brightness: This brightness class instance
 *
 * initialises the brightness class. NOTE: We expect laptop_panel objects
 * to *NOT* be removed or added during the session.
 * We only control the first laptop_panel object if there are more than one.
 **/
static void
gpm_backlight_init (GpmBacklight *backlight)
{
	gboolean lid_is_present = TRUE;
	GpmPrefsServer *prefs_server;

	backlight->priv = GPM_BACKLIGHT_GET_PRIVATE (backlight);

	/* record our idle time */
	backlight->priv->idle_timer = g_timer_new ();

	/* watch for manual brightness changes (for the popup widget) */
	backlight->priv->brightness = gpm_brightness_new ();
	g_signal_connect (backlight->priv->brightness, "brightness-changed",
			  G_CALLBACK (brightness_changed_cb), backlight);

	/* we use up_client for the ac-adapter-changed signal */
	backlight->priv->client = up_client_new ();
	g_signal_connect (backlight->priv->client, "changed",
			  G_CALLBACK (gpm_backlight_client_changed_cb), backlight);

	/* gets caps */
	backlight->priv->can_dim = gpm_brightness_has_hw (backlight->priv->brightness);

	/* we use DeviceKit-power to see if we should show the lid UI */
	g_object_get (backlight->priv->client,
		      "lid-is-present", &lid_is_present,
		      NULL);

	/* expose ui in prefs program */
	prefs_server = gpm_prefs_server_new ();
	if (lid_is_present)
		gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_LID);
	if (backlight->priv->can_dim)
		gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_BACKLIGHT);
	g_object_unref (prefs_server);

	/* watch for dim value changes */
	backlight->priv->conf = gconf_client_get_default ();

	/* watch gnome-power-manager keys */
	gconf_client_add_dir (backlight->priv->conf, GPM_CONF_DIR, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
	gconf_client_notify_add (backlight->priv->conf, GPM_CONF_DIR,
				 (GConfClientNotifyFunc) gpm_conf_gconf_key_changed_cb,
				 backlight, NULL, NULL);

	/* set the main brightness, this is designed to be updated if the user changes the
	 * brightness so we can undim to the 'correct' value */
	backlight->priv->master_percentage = gconf_client_get_int (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC, NULL);

	/* watch for brightness up and down buttons and also check lid state */
	backlight->priv->button = gpm_button_new ();
	g_signal_connect (backlight->priv->button, "button-pressed",
			  G_CALLBACK (gpm_backlight_button_pressed_cb), backlight);

	/* watch for idle mode changes */
	backlight->priv->idle = gpm_idle_new ();
	g_signal_connect (backlight->priv->idle, "idle-changed",
			  G_CALLBACK (idle_changed_cb), backlight);

	/* assumption */
	backlight->priv->system_is_idle = FALSE;
	backlight->priv->idle_dim_timeout = gconf_client_get_int (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_DIM_TIME, NULL);
	gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout);

	/* use a visual widget */
	backlight->priv->popup = gsd_media_keys_window_new ();
	gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup),
						 "gpm-brightness-lcd",
						 TRUE);
        gtk_window_set_position (GTK_WINDOW (backlight->priv->popup), GTK_WIN_POS_NONE);

	/* DPMS mode poll class */
	backlight->priv->dpms = gpm_dpms_new ();

	/* we refresh DPMS on resume */
	backlight->priv->control = gpm_control_new ();
	g_signal_connect (backlight->priv->control, "resume",
			  G_CALLBACK (control_resume_cb), backlight);

	/* Don't do dimming on inactive console */
	backlight->priv->consolekit = egg_console_kit_new ();

	/* sync at startup */
	gpm_backlight_brightness_evaluate_and_set (backlight, FALSE);
}
コード例 #2
0
/**
 * gpm_backlight_init:
 * @brightness: This brightness class instance
 *
 * initialises the brightness class. NOTE: We expect laptop_panel objects
 * to *NOT* be removed or added during the session.
 * We only control the first laptop_panel object if there are more than one.
 **/
static void
gpm_backlight_init (GpmBacklight *backlight)
{
    backlight->priv = GPM_BACKLIGHT_GET_PRIVATE (backlight);

    /* record our idle time */
    backlight->priv->idle_timer = g_timer_new ();

    /* watch for manual brightness changes (for the popup widget) */
    backlight->priv->brightness = gpm_brightness_new ();
    g_signal_connect (backlight->priv->brightness, "brightness-changed",
                      G_CALLBACK (brightness_changed_cb), backlight);

    /* we use up_client for the ac-adapter-changed signal */
    backlight->priv->client = up_client_new ();
    g_signal_connect (backlight->priv->client, "changed",
                      G_CALLBACK (gpm_backlight_client_changed_cb), backlight);

    /* gets caps */
    backlight->priv->can_dim = gpm_brightness_has_hw (backlight->priv->brightness);

    /* watch for dim value changes */
    backlight->priv->settings = g_settings_new (GPM_SETTINGS_SCHEMA);
    g_signal_connect (backlight->priv->settings, "changed", G_CALLBACK (gpm_settings_key_changed_cb), backlight);

    /* set the main brightness, this is designed to be updated if the user changes the
     * brightness so we can undim to the 'correct' value */
    backlight->priv->master_percentage = g_settings_get_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_AC);

    /* watch for brightness up and down buttons and also check lid state */
    backlight->priv->button = gpm_button_new ();
    g_signal_connect (backlight->priv->button, "button-pressed",
                      G_CALLBACK (gpm_backlight_button_pressed_cb), backlight);

    /* watch for idle mode changes */
    backlight->priv->idle = gpm_idle_new ();
    g_signal_connect (backlight->priv->idle, "idle-changed",
                      G_CALLBACK (idle_changed_cb), backlight);

    /* assumption */
    backlight->priv->system_is_idle = FALSE;
    backlight->priv->idle_dim_timeout = g_settings_get_int (backlight->priv->settings, GPM_SETTINGS_IDLE_DIM_TIME);
    gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout);

    /* use a visual widget */
    backlight->priv->popup = gsd_media_keys_window_new ();
    gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup),
            "gpm-brightness-lcd",
            TRUE);
    gtk_window_set_position (GTK_WINDOW (backlight->priv->popup), GTK_WIN_POS_NONE);

    /* DPMS mode poll class */
    backlight->priv->dpms = gpm_dpms_new ();

    /* we refresh DPMS on resume */
    backlight->priv->control = gpm_control_new ();
    g_signal_connect (backlight->priv->control, "resume",
                      G_CALLBACK (control_resume_cb), backlight);

    /* Don't do dimming on inactive console */
    backlight->priv->consolekit = egg_console_kit_new ();

    /* sync at startup */
    gpm_backlight_brightness_evaluate_and_set (backlight, FALSE, TRUE);
}