Use gtk to detect dpi.
This commit is contained in:
parent
e3cf7aa1d3
commit
4828870afd
@ -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")
|
||||
|
@ -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 \
|
||||
|
@ -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 <stdlib.h>
|
||||
#include <gdk/gdkx.h>
|
||||
#include <gdk/gdkscreen.h>
|
||||
#include <gtk/gtksettings.h>
|
||||
|
||||
#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;
|
||||
}
|
@ -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 <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gint sugar_get_screen_dpi (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __SUGAR_UTILS_H__ */
|
@ -88,7 +88,8 @@ else:
|
||||
width = 1200
|
||||
height = 900
|
||||
|
||||
_start_xephyr(width, height, min(_sugar.get_screen_dpi(), 96))
|
||||
_gtk_xft_dpi = float(gtk.settings_get_default().get_property('gtk-xft-dpi'))
|
||||
_start_xephyr(width, height, _gtk_xft_dpi / 1024)
|
||||
|
||||
os.environ['GTK2_RC_FILES'] = env.get_data_path('gtkrc')
|
||||
|
||||
|
@ -32,11 +32,6 @@ class Activity(Window, gtk.Container):
|
||||
def __init__(self, handle):
|
||||
Window.__init__(self)
|
||||
|
||||
# FIXME: This will work only for activities in python. We need a xsetting.
|
||||
display = gtk.gdk.display_manager_get().get_default_display()
|
||||
screen = display.get_default_screen()
|
||||
screen.set_resolution(_sugar.get_screen_dpi())
|
||||
|
||||
self.connect('destroy', self._destroy_cb)
|
||||
|
||||
self._shared = False
|
||||
|
@ -61,19 +61,18 @@ units to device units.
|
||||
|
||||
import gtk
|
||||
|
||||
import _sugar
|
||||
|
||||
_MAX_ZOOM_FACTOR = 2.0
|
||||
_ZOOM_CONSTANT = 650.0
|
||||
|
||||
def _compute_zoom_factor():
|
||||
screen_width = gtk.gdk.screen_width()
|
||||
if _sugar.get_screen_dpi() == 201.0 and screen_width == 1200:
|
||||
if _screen_dpi == 201.0 and screen_width == 1200:
|
||||
return 1.0
|
||||
else:
|
||||
return min(_MAX_ZOOM_FACTOR, screen_width / _ZOOM_CONSTANT)
|
||||
|
||||
_screen_dpi = float(_sugar.get_screen_dpi())
|
||||
_gtk_xft_dpi = gtk.settings_get_default().get_property('gtk-xft-dpi')
|
||||
_screen_dpi = float(_gtk_xft_dpi / 1024)
|
||||
_dpi_factor = _screen_dpi / 201.0
|
||||
_zoom_factor = _compute_zoom_factor()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user