diff --git a/src/xfpm-dpms-spins.c b/src/xfpm-dpms-spins.c index cd6a2a5d80e87da7fd3b410dafcd15b8d323fcf6..c41b698af8687c4eb3a5da776bcd9073c164f798 100644 --- a/src/xfpm-dpms-spins.c +++ b/src/xfpm-dpms-spins.c @@ -62,8 +62,13 @@ static void xfpm_dpms_spins_get_spin3_value_cb(GtkSpinButton *spin_3, struct XfpmDpmsSpinsPrivate { GtkWidget *spin_1; + gint spin_value_1; + GtkWidget *spin_2; + gint spin_value_2; + GtkWidget *spin_3; + gint spin_value_3; }; @@ -117,7 +122,7 @@ xfpm_dpms_spins_init(XfpmDpmsSpins *dpms_spins) label = gtk_label_new(_("Standby after")); gtk_widget_show(label); gtk_table_attach_defaults(GTK_TABLE(dpms_spins),label,0,1,0,1); - priv->spin_1 = xfpm_spin_button_new_with_range(1,238,1); + priv->spin_1 = xfpm_spin_button_new_with_range(0,298,1); xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_1),_(" min")); gtk_widget_show(priv->spin_1); gtk_table_attach(GTK_TABLE(dpms_spins),priv->spin_1,1,2,0,1,GTK_SHRINK,GTK_SHRINK,0,0); @@ -125,7 +130,7 @@ xfpm_dpms_spins_init(XfpmDpmsSpins *dpms_spins) label = gtk_label_new(_("Suspend after")); gtk_widget_show(label); gtk_table_attach_defaults(GTK_TABLE(dpms_spins),label,0,1,1,2); - priv->spin_2 = xfpm_spin_button_new_with_range(1,239,1); + priv->spin_2 = xfpm_spin_button_new_with_range(0,299,1); xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_2),_(" min")); gtk_widget_show(priv->spin_2); gtk_table_attach(GTK_TABLE(dpms_spins),priv->spin_2,1,2,1,2,GTK_SHRINK,GTK_SHRINK,0,0); @@ -133,7 +138,7 @@ xfpm_dpms_spins_init(XfpmDpmsSpins *dpms_spins) label = gtk_label_new(_("Turn off after")); gtk_widget_show(label); gtk_table_attach_defaults(GTK_TABLE(dpms_spins),label,0,1,2,3); - priv->spin_3 = xfpm_spin_button_new_with_range(1,300,1); + priv->spin_3 = xfpm_spin_button_new_with_range(0,300,1); xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_3),_(" min")); gtk_widget_show(priv->spin_3); gtk_table_attach(GTK_TABLE(dpms_spins),priv->spin_3,1,2,2,3,GTK_SHRINK,GTK_SHRINK,0,0); @@ -162,11 +167,24 @@ xfpm_dpms_spins_get_spin1_value_cb(GtkSpinButton *spin_1,XfpmDpmsSpins *spins) gint value1,value2,value3; value1 = gtk_spin_button_get_value(spin_1); - value2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_2)); - value3 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_3)); - + + if ( value1 == 0 ) + { + priv->spin_value_1 = 0; + xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_1),_(" disabled")); + g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0, + value1,value2,value3); + return; + } + if ( priv->spin_value_1 == 0 ) + { + xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_1),_(" min")); + if ( priv->spin_value_2 == 0 ) + gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_2),value1+1); + } + if ( value2 <= value1 ) { value2 = value1 + 1; @@ -203,6 +221,21 @@ xfpm_dpms_spins_get_spin2_value_cb(GtkSpinButton *spin_2,XfpmDpmsSpins *spins) value3 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_3)); + if ( value2 == 0 ) + { + priv->spin_value_2 = 0; + xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_2),_(" disabled")); + g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,value1,value2,value3); + + return; + } + if ( priv->spin_value_2 == 0 ) + { + xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_2),_(" min")); + if ( priv->spin_value_3 == 0 ) + gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),value2+1); + } + if ( value2 <= value1 ) { value2 = value1 + 1; @@ -236,6 +269,20 @@ xfpm_dpms_spins_get_spin3_value_cb(GtkSpinButton *spin_3,XfpmDpmsSpins *spins) value2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->spin_2)); + if ( value3 == 0 ) + { + priv->spin_value_3 = 0; + xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_3),_(" disabled")); + g_signal_emit(G_OBJECT(spins),signals[DPMS_VALUE_CHANGED],0,value1,value2,value3); + + return; + } + + if ( priv->spin_value_3 == 0 ) + { + xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(spin_3),_(" min")); + } + if ( value3 <= value2 ) { value3 = value2 + 1; @@ -261,9 +308,13 @@ void xfpm_dpms_spins_set_default_values(XfpmDpmsSpins *spins, { XfpmDpmsSpinsPrivate *priv; priv = XFPM_DPMS_SPINS_GET_PRIVATE(spins); - + if ( spin_1 == 0) xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_1),_(" disabled")); gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_1),spin_1); + + if ( spin_2 == 0) xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_2),_(" disabled")); gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_2),spin_2); + + if ( spin_3 == 0) xfpm_spin_button_set_suffix(XFPM_SPIN_BUTTON(priv->spin_3),_(" disabled")); gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_3),spin_3); } diff --git a/src/xfpm-dpms.c b/src/xfpm-dpms.c index 10f236056bd2ff4a681c77145274d3c18ec93044..bf013575ba3d19fa1067704ba48ba48c22f4f3ab 100644 --- a/src/xfpm-dpms.c +++ b/src/xfpm-dpms.c @@ -362,7 +362,7 @@ xfpm_dpms_notify_cb(GObject *object,GParamSpec *arg1,gpointer data) if ( dpms->dpms_enabled ) { - xfpm_dpms_set_timeouts(dpms); + xfpm_dpms_set_timeouts(dpms); } } diff --git a/src/xfpm-spin-button.c b/src/xfpm-spin-button.c index 023418bcdf6dd29fe5a23c3a717ce28d65506b4c..29b92b9cbf4495ee8d6654a9910d624efb904b75 100644 --- a/src/xfpm-spin-button.c +++ b/src/xfpm-spin-button.c @@ -132,7 +132,6 @@ xfpm_spin_button_editable_init(GtkEditableClass *iface) iface->delete_text = xfpm_spin_button_delete_text; } - static void _spin_button_update(XfpmSpinButton *spin) { @@ -144,8 +143,24 @@ _spin_button_update(XfpmSpinButton *spin) { gtk_widget_queue_resize_no_redraw(widget); } +} + + +static void +xfpm_spin_button_delete_all_text(GtkEditable *editable) +{ + GtkEditableClass *spin_iface = g_type_interface_peek (xfpm_spin_button_parent_class, + GTK_TYPE_EDITABLE); + GtkEditableClass *entry_iface = g_type_interface_peek_parent(spin_iface); + gint start,end; + const gchar *text = gtk_entry_get_text(GTK_ENTRY(editable)); + start = 0; + end = strlen(text); + + entry_iface->delete_text(editable,start,end); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(editable),gtk_spin_button_get_value(GTK_SPIN_BUTTON(editable))); } static void @@ -164,6 +179,7 @@ xfpm_spin_button_delete_text (GtkEditable *editable, gint text_length = strlen(text); gint length; + if ( spin->suffix ) { length = text_length - spin->suffix_length ; @@ -232,7 +248,7 @@ static void xfpm_spin_button_insert_text (GtkEditable *editable, } /* Constructor for the xfpm-spin button is the same as - * gtk_spin_button_new_with_range. + * gtk_spin_button_new_with_range but slightly modified * * GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald @@ -268,7 +284,7 @@ xfpm_spin_button_new_with_range(gdouble min,gdouble max,gdouble step) gtk_spin_button_configure (GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT (adj), step, digits); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON(spin), TRUE); - + return GTK_WIDGET(spin); } @@ -278,9 +294,18 @@ xfpm_spin_button_set_suffix (XfpmSpinButton *spin, { g_return_if_fail(XFPM_IS_SPIN_BUTTON(spin)); g_return_if_fail(suffix != NULL); - + + xfpm_spin_button_delete_all_text(GTK_EDITABLE(spin)); + + if ( spin->suffix ) g_free(spin->suffix); + spin->suffix = g_strdup(suffix); spin->suffix_length = strlen(spin->suffix); - - gtk_entry_append_text(GTK_ENTRY(spin),spin->suffix); + + gint spin_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)); + gint digits_num = 1 ; + if ( spin_value != 0 ) + digits_num = abs ((gint) floor (log10 (fabs (spin_value)))) + 1; + + xfpm_spin_button_insert_text(GTK_EDITABLE(spin),spin->suffix,spin->suffix_length,&(digits_num)); } diff --git a/src/xfpm-spin-button.h b/src/xfpm-spin-button.h index 0b7290e672bd8fcb7996dd6b51be76c74def4ad1..6c951446567d92cbfb553ffc13fc8eaf29790a05 100644 --- a/src/xfpm-spin-button.h +++ b/src/xfpm-spin-button.h @@ -40,6 +40,7 @@ typedef struct gchar *suffix; gint suffix_length; gint suffix_position; + gint digits_num; } XfpmSpinButton;