From 4828870afd08aef48fa96f7a82076e0fcf5fc2f5 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sat, 07 Apr 2007 01:42:51 +0000 Subject: Use gtk to detect dpi. --- (limited to 'lib') diff --git a/lib/python/_sugar.defs b/lib/python/_sugar.defs index b09d0eb..e59c985 100644 --- a/lib/python/_sugar.defs +++ b/lib/python/_sugar.defs @@ -199,11 +199,4 @@ ) ) -;; From sugar-utils.h - -(define-function get_screen_dpi - (c-name "sugar_get_screen_dpi") - (return-type "gint") -) - (include "gtkmozembed.defs") diff --git a/lib/src/Makefile.am b/lib/src/Makefile.am index 88e863a..504c211 100644 --- a/lib/src/Makefile.am +++ b/lib/src/Makefile.am @@ -37,9 +37,7 @@ libsugarprivate_la_SOURCES = \ sugar-download.h \ sugar-download.c \ sugar-download-manager.h \ - sugar-download-manager.c \ - sugar-utils.c \ - sugar-utils.h + sugar-download-manager.c BUILT_SOURCES = \ sugar-marshal.c \ diff --git a/lib/src/sugar-utils.c b/lib/src/sugar-utils.c deleted file mode 100644 index 6cc5946..0000000 --- a/lib/src/sugar-utils.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2006, Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include -#include -#include -#include - -#include "sugar-utils.h" - -/* Ported from mozilla nsDeviceContextGTK.cpp */ - -static gint -get_gtk_settings_dpi(void) -{ - GtkSettings *settings = gtk_settings_get_default(); - GParamSpec *spec; - gint dpi = 0; - - spec = g_object_class_find_property( - G_OBJECT_GET_CLASS(G_OBJECT(settings)), "gtk-xft-dpi"); - - if (spec) { - g_object_get(G_OBJECT(settings), - "gtk-xft-dpi", &dpi, - NULL); - } - - return (int)(dpi / 1024.0 + 0.5); -} - -static gint -get_xft_dpi(void) -{ - char *val = XGetDefault(GDK_DISPLAY(), "Xft", "dpi"); - if (val) { - char *e; - double d = strtod(val, &e); - - if (e != val) - return (int)(d + 0.5); - } - - return 0; -} - -static int -get_dpi_from_physical_resolution(void) -{ - float screen_width_in; - - screen_width_in = (float)(gdk_screen_width_mm()) / 25.4f; - - return (int)((float)(gdk_screen_width()) / screen_width_in + 0.5); -} - -gint -sugar_get_screen_dpi(void) -{ - int dpi; - - dpi = get_gtk_settings_dpi(); - - if (dpi == 0) { - dpi = get_xft_dpi(); - } - - if (dpi == 0) { - dpi = get_dpi_from_physical_resolution(); - } - - return dpi; -} diff --git a/lib/src/sugar-utils.h b/lib/src/sugar-utils.h deleted file mode 100644 index 1b45d25..0000000 --- a/lib/src/sugar-utils.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2006, Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __SUGAR_UTILS_H__ -#define __SUGAR_UTILS_H__ - -#include - -G_BEGIN_DECLS - -gint sugar_get_screen_dpi (void); - -G_END_DECLS - -#endif /* __SUGAR_UTILS_H__ */ -- cgit v0.9.1