---
 src/gpm-prefs-core.c |   73 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 29 deletions(-)

--- a/src/gpm-prefs-core.c
+++ b/src/gpm-prefs-core.c
@@ -270,6 +270,12 @@
 	return g_strdup_printf ("%.0f%%", value);
 }
 
+static gint
+gpm_prefs_get_never_time (GtkWidget *widget)
+{
+	return (gint) gtk_range_get_adjustment (GTK_RANGE (widget))->upper;
+}
+
 /**
  * gpm_prefs_format_time_cb:
  * @scale: The GtkScale object
@@ -282,7 +288,8 @@
 			  GpmPrefs *prefs)
 {
 	gchar *str;
-	if ((gint) value == NEVER_TIME_ON_SLIDER) {
+	gint never_time = gpm_prefs_get_never_time (GTK_WIDGET (scale));
+	if ((gint) value >= never_time) {
 		str = g_strdup (_("Never"));
 	} else {
 		str = gpm_get_timestring (value * 60);
@@ -302,10 +309,11 @@
 	int value;
 	int gs_idle_time;
 	char *gpm_pref_key;
+	gint never_time = gpm_prefs_get_never_time (GTK_WIDGET (range));
 
 	value = (int) gtk_range_get_value (range);
 
-	if (value == NEVER_TIME_ON_SLIDER) {
+	if (value >= never_time) {
 		/* power manager interprets 0 as Never */
 		value = 0;
 	} else {
@@ -314,6 +322,8 @@
 		 * declares the session idle */
 		gs_idle_time = gpm_idle_get_delay (prefs->priv->idle);
 		value -= gs_idle_time;
+		if (value < 0)
+			value = 0;
 
 		/* policy is in seconds, slider is in minutes */
 		value *= 60;
@@ -324,6 +334,11 @@
 	gpm_conf_set_int (prefs->priv->conf, gpm_pref_key, value);
 }
 
+static void set_idle_hscale_stops (GpmPrefs    *prefs,
+				   const gchar *widget_name,
+				   gint         gs_idle_time,
+				   gint         oldval);
+
 /**
  * gpm_prefs_setup_sleep_slider:
  * @prefs: This prefs class instance
@@ -349,15 +364,17 @@
 
 	gtk_widget_set_sensitive (widget, is_writable);
 
-	if (value == 0) {
-		value = NEVER_TIME_ON_SLIDER;
-	} else {
+	gs_idle_time = gpm_idle_get_delay (prefs->priv->idle);
+
+	if (value > 0) {
 		/* policy is in seconds, slider is in minutes */
 		value /= 60;
-		gs_idle_time = gpm_idle_get_delay (prefs->priv->idle);
 		value += gs_idle_time;
 	}
+	set_idle_hscale_stops (prefs, widget_name, gs_idle_time, value);
 
+	if (!value)
+		value = gpm_prefs_get_never_time (widget);
 	gtk_range_set_value (GTK_RANGE (widget), value);
 
 	g_object_set_data (G_OBJECT (widget), "conf_key", (gpointer) gpm_pref_key);
@@ -736,16 +753,27 @@
 static void
 set_idle_hscale_stops (GpmPrefs    *prefs,
 		       const gchar *widget_name,
-		       gint         gs_idle_time)
+		       gint         gs_idle_time,
+		       gint         oldval)
 {
 	GtkWidget *widget;
+	GtkRange *range;
+	gint never_time, new_never_time;
+
 	widget = glade_xml_get_widget (prefs->priv->glade_xml, widget_name);
-	if (gs_idle_time + 1 > NEVER_TIME_ON_SLIDER) {
-		egg_warning ("gnome-screensaver timeout is really big. "
-			     "Not sure what to do");
-		return;
+	range = GTK_RANGE (widget);
+	never_time = gpm_prefs_get_never_time (widget);
+	/* reset the new NEVER time to fit with the current range */
+	new_never_time = gs_idle_time + 2;
+	if (oldval != never_time && new_never_time <= oldval)
+		new_never_time = oldval + 1;
+	if (new_never_time < NEVER_TIME_ON_SLIDER)
+		new_never_time = NEVER_TIME_ON_SLIDER;
+	gtk_range_set_range (range, gs_idle_time + 1, new_never_time);
+	if (oldval == never_time && never_time != new_never_time) {
+		/* if the previous value is NEVER, let's point to NEVER again */
+		gtk_range_set_value (range, new_never_time);
 	}
-	gtk_range_set_range (GTK_RANGE (widget), gs_idle_time + 1, NEVER_TIME_ON_SLIDER);
 }
 
 /**
@@ -757,10 +785,10 @@
 	      guint	     delay)
 {
 	/* update the start and stop points on the hscales */
-	set_idle_hscale_stops (prefs, "hscale_battery_computer", delay);
-	set_idle_hscale_stops (prefs, "hscale_battery_display", delay);
-	set_idle_hscale_stops (prefs, "hscale_ac_computer", delay);
-	set_idle_hscale_stops (prefs, "hscale_ac_display", delay);
+	set_idle_hscale_stops (prefs, "hscale_battery_computer", delay, 0);
+	set_idle_hscale_stops (prefs, "hscale_battery_display", delay, 0);
+	set_idle_hscale_stops (prefs, "hscale_ac_computer", delay, 0);
+	set_idle_hscale_stops (prefs, "hscale_ac_display", delay, 0);
 }
 
 /**
@@ -895,7 +923,6 @@
 prefs_setup_ac (GpmPrefs *prefs)
 {
 	GtkWidget *widget;
-	gint delay;
 	const gchar  *button_lid_actions[] =
 				{ACTION_NOTHING,
 				 ACTION_BLANK,
@@ -917,10 +944,6 @@
 	gpm_prefs_setup_checkbox (prefs, "checkbutton_ac_display_dim",
 				  GPM_CONF_BACKLIGHT_IDLE_DIM_AC);
 
-	delay = gpm_idle_get_delay (prefs->priv->idle);
-	set_idle_hscale_stops (prefs, "hscale_ac_computer", delay);
-	set_idle_hscale_stops (prefs, "hscale_ac_display", delay);
-
 	if (prefs->priv->has_button_lid == FALSE) {
 		widget = glade_xml_get_widget (prefs->priv->glade_xml, "hbox_ac_lid");
 		gtk_widget_hide_all (widget);
@@ -938,7 +961,6 @@
 {
 	GtkWidget *widget;
 	GtkWidget *notebook;
-	gint delay;
 	gint page;
 
 	const gchar  *button_lid_actions[] =
@@ -986,10 +1008,6 @@
 		gtk_widget_hide_all (widget);
 	}
 
-	delay = gpm_idle_get_delay (prefs->priv->idle);
-	set_idle_hscale_stops (prefs, "hscale_battery_computer", delay);
-	set_idle_hscale_stops (prefs, "hscale_battery_display", delay);
-
 	if (prefs->priv->has_button_lid == FALSE) {
 		widget = glade_xml_get_widget (prefs->priv->glade_xml, "hbox_battery_lid");
 		gtk_widget_hide_all (widget);
@@ -1037,7 +1055,6 @@
 {
 	GtkWidget *widget;
 	GtkWidget *notebook;
-	gint delay;
 	gint page;
 
 	const gchar  *ups_low_actions[] =
@@ -1062,8 +1079,6 @@
 				      ups_low_actions);
 	gpm_prefs_setup_sleep_slider (prefs, "hscale_ups_computer",
 				      GPM_CONF_TIMEOUT_SLEEP_COMPUTER_BATT);
-	delay = gpm_idle_get_delay (prefs->priv->idle);
-	set_idle_hscale_stops (prefs, "hscale_ups_computer", delay);
 }
 
 static void
