[Xfce4-commits] r29521 - in xfce4-settings/trunk: dialogs/appearance-settings xfsettingsd
Stephan Arts
stephan at xfce.org
Fri Feb 20 19:04:04 CET 2009
Author: stephan
Date: 2009-02-20 18:04:04 +0000 (Fri, 20 Feb 2009)
New Revision: 29521
Modified:
xfce4-settings/trunk/dialogs/appearance-settings/appearance-dialog.glade
xfce4-settings/trunk/dialogs/appearance-settings/main.c
xfce4-settings/trunk/xfsettingsd/registry.c
xfce4-settings/trunk/xfsettingsd/xsettings.xml
Log:
A last-minute fix of the DPI issues (patch by Jannis Pohlmann)
Modified: xfce4-settings/trunk/dialogs/appearance-settings/appearance-dialog.glade
===================================================================
--- xfce4-settings/trunk/dialogs/appearance-settings/appearance-dialog.glade 2009-02-20 17:15:49 UTC (rev 29520)
+++ xfce4-settings/trunk/dialogs/appearance-settings/appearance-dialog.glade 2009-02-20 18:04:04 UTC (rev 29521)
@@ -256,6 +256,7 @@
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
+ <property name="active">False</property>
</widget>
<packing>
<property name="expand">False</property>
@@ -265,10 +266,11 @@
<widget class="GtkSpinButton" id="xft_custom_dpi_spin_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="adjustment">96 48 160 1 10 0</property>
+ <property name="adjustment">96 48 1000 1 10 0</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="update_policy">GTK_UPDATE_IF_VALID</property>
+ <property name="sensitive">False</property>
</widget>
<packing>
<property name="expand">False</property>
Modified: xfce4-settings/trunk/dialogs/appearance-settings/main.c
===================================================================
--- xfce4-settings/trunk/dialogs/appearance-settings/main.c 2009-02-20 17:15:49 UTC (rev 29520)
+++ xfce4-settings/trunk/dialogs/appearance-settings/main.c 2009-02-20 18:04:04 UTC (rev 29521)
@@ -40,13 +40,15 @@
#include "appearance-dialog_glade.h"
#include "images.h"
+#define INCH_MM 25.4
+
+/* Use a fallback DPI of 96 which should be ok-ish on most systems
+ * and is only applied on rare occasions */
+#define FALLBACK_DPI 96
+
/* Increase this number if new gtk settings have been added */
#define INITIALIZE_UINT (1)
-#define DPI_DEFAULT 96
-#define DPI_MIN 50
-#define DPI_MAX 500
-
enum
{
COLUMN_THEME_NAME,
@@ -91,6 +93,30 @@
/* Global xfconf channel */
static XfconfChannel *xsettings_channel;
+static int
+compute_xsettings_dpi (GtkWidget *widget)
+{
+ Screen *xscreen;
+ int width_mm, height_mm;
+ int width, height;
+ int dpi;
+
+ xscreen = GDK_SCREEN_XSCREEN (gtk_widget_get_screen (widget));
+ width_mm = WidthMMOfScreen (xscreen);
+ height_mm = HeightMMOfScreen (xscreen);
+ dpi = FALLBACK_DPI;
+
+ if (width_mm > 0 && height_mm > 0)
+ {
+ width = WidthOfScreen (xscreen);
+ height = HeightOfScreen (xscreen);
+ dpi = MIN (INCH_MM * width / width_mm,
+ INCH_MM * height / height_mm);
+ }
+
+ return dpi;
+}
+
static void
cb_theme_tree_selection_changed (GtkTreeSelection *selection,
const gchar *property)
@@ -181,34 +207,55 @@
}
static void
-cb_custom_dpi_spin_value_changed (GtkSpinButton *custom_dpi_spin,
- GtkToggleButton *custom_dpi_toggle)
+cb_custom_dpi_check_button_toggled (GtkToggleButton *custom_dpi_toggle,
+ GtkSpinButton *custom_dpi_spin)
{
gint dpi;
if (gtk_toggle_button_get_active (custom_dpi_toggle))
{
- dpi = gtk_spin_button_get_value (custom_dpi_spin);
+ /* Custom DPI is activated, so restore the last custom DPI we know about */
+ dpi = xfconf_channel_get_int (xsettings_channel, "/Xfce/LastCustomDPI", -1);
+
+ /* Unfortunately, we don't have a valid custom DPI value to use, so compute it */
+ if (dpi <= 0)
+ dpi = compute_xsettings_dpi (GTK_WIDGET (custom_dpi_toggle));
+
+ /* Apply the computed custom DPI value */
xfconf_channel_set_int (xsettings_channel, "/Xft/DPI", dpi);
- }
-}
-static void
-cb_custom_dpi_check_button_toggled (GtkToggleButton *custom_dpi_toggle,
- GtkSpinButton *custom_dpi_spin)
-{
- if (gtk_toggle_button_get_active (custom_dpi_toggle))
- {
gtk_widget_set_sensitive (GTK_WIDGET (custom_dpi_spin), TRUE);
- cb_custom_dpi_spin_value_changed (custom_dpi_spin, custom_dpi_toggle);
}
else
{
+ /* Custom DPI is deactivated, so remember the current value as the last custom DPI */
+ dpi = gtk_spin_button_get_value_as_int (custom_dpi_spin);
+ xfconf_channel_set_int (xsettings_channel, "/Xfce/LastCustomDPI", dpi);
+
+ /* Tell xfsettingsd to compute the value itself */
+ xfconf_channel_set_int (xsettings_channel, "/Xft/DPI", -1);
+
+ /* Make the spin button insensitive */
gtk_widget_set_sensitive (GTK_WIDGET (custom_dpi_spin), FALSE);
- xfconf_channel_set_int (xsettings_channel, "/Xft/DPI", -1);
}
}
+static void
+cb_custom_dpi_spin_button_changed (GtkSpinButton *custom_dpi_spin,
+ GtkToggleButton *custom_dpi_toggle)
+{
+ gint dpi = gtk_spin_button_get_value_as_int (custom_dpi_spin);
+
+ if (GTK_WIDGET_IS_SENSITIVE (custom_dpi_spin) && gtk_toggle_button_get_active (custom_dpi_toggle))
+ {
+ /* Custom DPI is turned on and the spin button has changed, so remember the value */
+ xfconf_channel_set_int (xsettings_channel, "/Xfce/LastCustomDPI", dpi);
+ }
+
+ /* Tell xfsettingsd to apply the custom DPI value */
+ xfconf_channel_set_int (xsettings_channel, "/Xft/DPI", dpi);
+}
+
#ifdef ENABLE_SOUND_SETTINGS
static void
cb_enable_event_sounds_check_button_toggled (GtkToggleButton *toggle, GtkWidget *button)
@@ -451,36 +498,6 @@
}
}
-static gdouble
-appearance_settings_get_dpi_from_x (void)
-{
- GdkScreen *screen;
- gdouble height_dpi = 0, width_dpi = 0;
- gint height_mm, width_mm;
-
- screen = gdk_screen_get_default ();
- if (G_LIKELY (screen != NULL))
- {
- width_mm = gdk_screen_get_width_mm (screen);
- if (width_mm >= 1)
- width_dpi = gdk_screen_get_width (screen) / (width_mm / 25.4);
- else
- width_dpi = 0;
-
- height_mm = gdk_screen_get_height_mm (screen);
- if (height_mm >= 1)
- height_dpi = gdk_screen_get_height (screen) / (height_mm / 25.4);
- else
- height_dpi = 0;
- }
-
- if (width_dpi < DPI_MIN || width_dpi > DPI_MAX
- || height_dpi < DPI_MIN || height_dpi > DPI_MAX)
- return DPI_DEFAULT;
-
- return (width_dpi + height_dpi) / 2.00;
-}
-
static void
appearance_settings_dialog_channel_property_changed (XfconfChannel *channel,
const gchar *property_name,
@@ -558,21 +575,29 @@
}
else if (strcmp (property_name, "/Xft/DPI") == 0)
{
+ /* The DPI has changed, so get its value and the last known custom value */
+ gint dpi = xfconf_channel_get_int (xsettings_channel, property_name, FALLBACK_DPI);
+ gint custom_dpi = xfconf_channel_get_int (xsettings_channel, "/Xfce/LastCustomDPI", -1);
+
+ /* Activate the check button if we're using a custom DPI */
widget = glade_xml_get_widget (gxml, "xft_custom_dpi_check_button");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), dpi >= 0);
+
+ /* If we're not using a custom DPI, compute the future custom DPI automatically */
+ if (custom_dpi == -1)
+ custom_dpi = compute_xsettings_dpi (widget);
+
spin = glade_xml_get_widget (gxml, "xft_custom_dpi_spin_button");
- dpi = xfconf_channel_get_int (xsettings_channel, property_name, -1);
-
- if (dpi == -1)
+
+ if (dpi > 0)
{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
- gtk_widget_set_sensitive (spin, FALSE);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), appearance_settings_get_dpi_from_x ());
+ /* We're using a custom DPI, so use the current DPI setting for the spin value */
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), dpi);
}
else
{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
- gtk_widget_set_sensitive (spin, TRUE);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), (gdouble) dpi);
+ /* Set the spin button value to the last custom DPI */
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), custom_dpi);
}
}
else if (strcmp (property_name, "/Net/ThemeName") == 0)
@@ -745,8 +770,8 @@
GtkWidget *custom_dpi_check = glade_xml_get_widget (gxml, "xft_custom_dpi_check_button");
GtkWidget *custom_dpi_spin = glade_xml_get_widget (gxml, "xft_custom_dpi_spin_button");
appearance_settings_dialog_channel_property_changed (xsettings_channel, "/Xft/DPI", NULL, gxml);
- g_signal_connect (G_OBJECT (custom_dpi_check), "toggled", G_CALLBACK (cb_custom_dpi_check_button_toggled), custom_dpi_spin);
- g_signal_connect (G_OBJECT (custom_dpi_spin), "value-changed", G_CALLBACK (cb_custom_dpi_spin_value_changed), custom_dpi_check);
+ g_signal_connect (custom_dpi_check, "toggled", G_CALLBACK (cb_custom_dpi_check_button_toggled), custom_dpi_spin);
+ g_signal_connect (custom_dpi_spin, "value-changed", G_CALLBACK (cb_custom_dpi_spin_button_changed), custom_dpi_check);
#ifdef ENABLE_SOUND_SETTINGS
/* Sounds */
Modified: xfce4-settings/trunk/xfsettingsd/registry.c
===================================================================
--- xfce4-settings/trunk/xfsettingsd/registry.c 2009-02-20 17:15:49 UTC (rev 29520)
+++ xfce4-settings/trunk/xfsettingsd/registry.c 2009-02-20 18:04:04 UTC (rev 29521)
@@ -74,6 +74,16 @@
| G_PARAM_STATIC_NICK \
| G_PARAM_STATIC_BLURB)
+#define INCH_MM 25.4
+
+/* Use a fallback DPI of 96 which should be ok-ish on most systems
+ * and is only applied on rare occasions */
+#define FALLBACK_DPI 96
+
+/* Use the same min/max DPI as in the appearance settings dialog */
+#define MIN_DPI 48
+#define MAX_DPI 1000
+
G_DEFINE_TYPE(XSettingsRegistry, xsettings_registry, G_TYPE_OBJECT);
enum
@@ -169,6 +179,8 @@
cb_xsettings_registry_channel_property_changed(XfconfChannel *channel, const gchar *property_name, const GValue *value, XSettingsRegistry *registry);
static Bool
timestamp_predicate (Display *display, XEvent *xevent, XPointer arg);
+static int
+compute_xsettings_dpi (XSettingsRegistry *registry);
gboolean
xsettings_registry_process_event (XSettingsRegistry *registry, XEvent *xevent)
@@ -286,6 +298,7 @@
break;
}
}
+
xsettings_registry_notify(registry);
if (!strncmp(name, "/Xft", 4) || !strncmp(name, "/Gtk/CursorTheme", 16))
xsettings_registry_store_xrdb(registry);
@@ -319,7 +332,7 @@
g_string_append_printf (string, "Xft.hintstyle: %s\n", g_value_get_string (&properties[XSETTING_ENTRY_XFT_HINTSTYLE].value));
else
string = g_string_append (string, "Xft.hintstyle: hintnone\n");
-
+
if (g_value_get_int (&properties[XSETTING_ENTRY_XFT_DPI].value) > 0)
g_string_append_printf (string, "Xft.dpi: %d\n", g_value_get_int (&properties[XSETTING_ENTRY_XFT_DPI].value));
@@ -402,6 +415,31 @@
g_error_free (error);
}
+static int
+compute_xsettings_dpi (XSettingsRegistry *registry)
+{
+ Screen *xscreen;
+ int width_mm, height_mm;
+ int width, height;
+ int dpi;
+
+ xscreen = ScreenOfDisplay (registry->priv->display,
+ registry->priv->screen);
+ width_mm = WidthMMOfScreen (xscreen);
+ height_mm = HeightMMOfScreen (xscreen);
+ dpi = FALLBACK_DPI;
+
+ if (width_mm > 0 && height_mm > 0)
+ {
+ width = WidthOfScreen (xscreen);
+ height = HeightOfScreen (xscreen);
+ dpi = MIN (INCH_MM * width / width_mm,
+ INCH_MM * height / height_mm);
+ }
+
+ return dpi;
+}
+
void
xsettings_registry_notify(XSettingsRegistry *registry)
{
@@ -544,8 +582,23 @@
* font sizes with -1 DPI and a forced setting equal to the X
* server's calculated DPI don't match. Need to look into
* this a bit more. */
- if (strcmp (entry->name, "Xft/DPI") == 0 && g_value_get_int(&entry->value) != -1)
- *(CARD32 *)pos = g_value_get_int(&entry->value) * 1024;
+ if (strcmp (entry->name, "Xft/DPI") == 0)
+ {
+ gint dpi = g_value_get_int (&entry->value);
+
+ if (dpi < 0)
+ {
+ /* Compute the DPI based on X */
+ dpi = compute_xsettings_dpi (registry);
+ }
+
+ /* Make sure to use the fallback DPI if the user-defined or computed
+ * value is out of range */
+ dpi = dpi < MIN_DPI ? FALLBACK_DPI : (dpi > MAX_DPI ? FALLBACK_DPI : dpi);
+
+ /* Apply the new value */
+ *(CARD32 *)pos = 1024 * dpi;
+ }
else
*(CARD32 *)pos = g_value_get_int(&entry->value);
pos += 4;
Modified: xfce4-settings/trunk/xfsettingsd/xsettings.xml
===================================================================
--- xfce4-settings/trunk/xfsettingsd/xsettings.xml 2009-02-20 17:15:49 UTC (rev 29520)
+++ xfce4-settings/trunk/xfsettingsd/xsettings.xml 2009-02-20 18:04:04 UTC (rev 29521)
@@ -5,4 +5,7 @@
<property name="ThemeName" type="string" value="Xfce"/>
<property name="IconThemeName" type="string" value="Rodent"/>
</property>
+ <property name="Xft" type="empty">
+ <property name="DPI" type="int" value="-1"/>
+ </property>
</channel>
More information about the Xfce4-commits
mailing list