diff options
author | Victor Kareh <[email protected]> | 2018-03-15 14:53:50 -0400 |
---|---|---|
committer | lukefromdc <[email protected]> | 2018-03-16 13:55:05 -0400 |
commit | 48b4fc3407816ddcab6e2bd20b063b6de9746e25 (patch) | |
tree | 09bd8464301c05e3b239eb50140e3b7260377705 /capplets/appearance/appearance-font.c | |
parent | 9888c14a69484aecdb48bfea6bcd562b178e9ff1 (diff) | |
download | mate-control-center-48b4fc3407816ddcab6e2bd20b063b6de9746e25.tar.bz2 mate-control-center-48b4fc3407816ddcab6e2bd20b063b6de9746e25.tar.xz |
Add auto-detect toggle switch
Currently if a user changes the DPI, there is no way to reset it back to
the auto-detected value from Xserver (which we store as 0 in gsettings).
Adding this toggle solves that issue.
I also removed a deprecated
[GtkHandleBox](https://developer.gnome.org/gtk3/stable/GtkHandleBox.html)
and all its associated code.
Diffstat (limited to 'capplets/appearance/appearance-font.c')
-rw-r--r-- | capplets/appearance/appearance-font.c | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/capplets/appearance/appearance-font.c b/capplets/appearance/appearance-font.c index 998bfa28..f4dd0d4d 100644 --- a/capplets/appearance/appearance-font.c +++ b/capplets/appearance/appearance-font.c @@ -473,11 +473,22 @@ dpi_load (GSettings *settings, } static void -dpi_changed (GSettings *settings, - gchar *key, - gpointer user_data) +dpi_changed (GSettings *settings, + gchar *key, + AppearanceData *data) { - dpi_load (settings, user_data); + GtkWidget *spinner; + GtkWidget *toggle; + gdouble dpi; + + dpi = g_settings_get_double (data->font_settings, FONT_DPI_KEY); + spinner = appearance_capplet_get_widget (data, "dpi_spinner"); + toggle = appearance_capplet_get_widget (data, "dpi_reset_switch"); + + dpi_load (settings, GTK_SPIN_BUTTON (spinner)); + + gtk_switch_set_state (GTK_SWITCH (toggle), dpi == 0); + gtk_widget_set_sensitive (spinner, dpi != 0); } static void @@ -490,8 +501,8 @@ monitors_changed (GdkScreen *screen, } static void -dpi_value_changed (GtkSpinButton *spinner, - GSettings *settings) +dpi_value_changed (GtkSpinButton *spinner, + AppearanceData *data) { /* Like any time when using a spin button with GSettings, there is * a race condition here. When we change, we send the new @@ -503,6 +514,7 @@ dpi_value_changed (GtkSpinButton *spinner, */ if (!in_change) { GdkScreen *screen; + GtkWidget *toggle; gint scale; gdouble new_dpi; @@ -510,12 +522,34 @@ dpi_value_changed (GtkSpinButton *spinner, scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen)); new_dpi = gtk_spin_button_get_value (spinner) / (double)scale; - g_settings_set_double (settings, FONT_DPI_KEY, new_dpi); + g_settings_set_double (data->font_settings, FONT_DPI_KEY, new_dpi); - dpi_load (settings, spinner); + dpi_load (data->font_settings, spinner); + + toggle = appearance_capplet_get_widget (data, "dpi_reset_switch"); + gtk_switch_set_active (GTK_SWITCH (toggle), FALSE); } } +static gboolean +dpi_value_reset (GtkSwitch *toggle, + gboolean state, + AppearanceData *data) +{ + GtkWidget *spinner; + spinner = appearance_capplet_get_widget (data, "dpi_spinner"); + + if (state) + g_settings_set_double (data->font_settings, FONT_DPI_KEY, 0); + else + dpi_value_changed (GTK_SPIN_BUTTON (spinner), data); + + gtk_switch_set_state(toggle, state); + gtk_widget_set_sensitive (spinner, !state); + + return TRUE; +} + static void cb_details_response (GtkDialog *dialog, gint response_id) { @@ -532,27 +566,37 @@ cb_show_details (GtkWidget *button, { if (!data->font_details) { GtkAdjustment *adjustment; - GtkWidget *widget; + GtkWidget *spinner; + GtkWidget *toggle; EnumGroup *group; + gdouble dpi; data->font_details = appearance_capplet_get_widget (data, "render_details"); gtk_window_set_transient_for (GTK_WINDOW (data->font_details), GTK_WINDOW (appearance_capplet_get_widget (data, "appearance_window"))); - widget = appearance_capplet_get_widget (data, "dpi_spinner"); + spinner = appearance_capplet_get_widget (data, "dpi_spinner"); + toggle = appearance_capplet_get_widget (data, "dpi_reset_switch"); + + /* Set initial state for widgets */ + dpi = g_settings_get_double (data->font_settings, FONT_DPI_KEY); + gtk_switch_set_active (GTK_SWITCH (toggle), dpi == 0); + gtk_widget_set_sensitive (GTK_WIDGET (spinner), dpi != 0); /* pick a sensible maximum dpi */ - adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)); + adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spinner)); gtk_adjustment_set_lower (adjustment, DPI_LOW_REASONABLE_VALUE); gtk_adjustment_set_upper (adjustment, DPI_HIGH_REASONABLE_VALUE); gtk_adjustment_set_step_increment (adjustment, 1); - dpi_load (data->font_settings, GTK_SPIN_BUTTON (widget)); - g_signal_connect (widget, "value_changed", - G_CALLBACK (dpi_value_changed), data->font_settings); + dpi_load (data->font_settings, GTK_SPIN_BUTTON (spinner)); + g_signal_connect (spinner, "value-changed", + G_CALLBACK (dpi_value_changed), data); + g_signal_connect (toggle, "state-set", + G_CALLBACK (dpi_value_reset), data); - g_signal_connect (data->font_settings, "changed::" FONT_DPI_KEY, G_CALLBACK (dpi_changed), widget); + g_signal_connect (data->font_settings, "changed::" FONT_DPI_KEY, G_CALLBACK (dpi_changed), data); /* Update font DPI when window scaling factor is changed */ g_signal_connect (gdk_screen_get_default (), "monitors-changed", G_CALLBACK (monitors_changed), data); |