19
19
* You should have received a copy of the GNU Library General Public
20
20
* License along with the Gnome Library; see the file COPYING.LIB. If not,
21
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22
* Boston, MA 02111-1307, USA.
21
* write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
* Boston, MA 02110-1301, USA.
24
24
* Author: Soren Sandmann <sandmann@redhat.com>
44
48
#define CONFIG_INTENDED_BASENAME "monitors.xml"
45
49
#define CONFIG_BACKUP_BASENAME "monitors.xml.backup"
51
/* Look for DPI_FALLBACK in:
52
* http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/xsettings/gsd-xsettings-manager.c
53
* for the reasoning */
54
#define DPI_FALLBACK 96.0
47
56
/* In version 0 of the config file format, we had several <configuration>
48
57
* toplevel elements and no explicit version number. So, the filed looked
1170
output_info_is_laptop (GnomeRROutputInfo *info)
1172
if (info->priv->name
1173
&& (strstr (info->priv->name, "lvds") || /* Most drivers use an "LVDS" prefix... */
1174
strstr (info->priv->name, "LVDS") ||
1175
strstr (info->priv->name, "Lvds") ||
1176
strstr (info->priv->name, "LCD"))) /* ... but fglrx uses "LCD" in some versions. Shoot me now, kthxbye. */
1183
1174
gnome_rr_config_ensure_primary (GnomeRRConfig *configuration)
1818
1809
g_list_free (active_crtcs);
1813
unity_running (void)
1815
const gchar *desktop_environment = g_getenv ("DESKTOP_SESSION");
1817
return !g_strcmp0 (desktop_environment, "ubuntu");
1820
static gint _max_texture_size_cache = -1;
1823
get_max_texture_size (GnomeRRScreen *screen)
1825
if (_max_texture_size_cache != -1)
1827
return _max_texture_size_cache;
1830
* Spawn a second process to check the GL texture limits
1831
* We do this across a process boundary to ensure that crashes
1832
* in the GL driver (which are unfortunately common) don't take
1838
char * const canary_argv[] = { LIBEXECDIR "/check_gl_texture_size", NULL };
1839
char *canary_env[2];
1840
char display_env[80];
1842
snprintf (display_env, sizeof (display_env), "DISPLAY=%s", DisplayString (screen->priv->xdisplay));
1843
canary_env[0] = display_env;
1844
canary_env[1] = NULL;
1847
if (pipe (pipe_fd) == -1)
1849
_max_texture_size_cache = 0;
1852
canary_pid = fork ();
1853
if (canary_pid == -1)
1855
_max_texture_size_cache = 0;
1859
if (canary_pid == 0)
1862
dup2 (pipe_fd[1], 1);
1865
execve (canary_argv[0], canary_argv, canary_env);
1868
gint max_texture_size;
1871
struct timespec fifty_msec = {0, 50000000};
1876
/* Empirical testing suggests this check takes < 150msec on my
1877
* crappy Atom netbook with slow rotating HDD. A 500msec timeout
1878
* should be generous while not being *too* long if it triggers.
1880
* Do a sleep/poll dance because we're a library and there's no
1881
* guarantee that waiting on SIGCHLD won't stomp over a client's
1884
while (waitpid (canary_pid, &child_status, WNOHANG) == 0 && wait_count < 10) {
1885
g_debug ("Waiting for GL_MAX_TEXTURE_SIZE helper...");
1886
nanosleep (&fifty_msec, NULL);
1890
if (WIFEXITED (child_status) && WEXITSTATUS (child_status) == EXIT_SUCCESS)
1892
if ((num_char = read (pipe_fd[0], buffer, sizeof(buffer) - 1)) <= 0)
1894
g_warning ("Failed to read GL_MAX_TEXTURE_SIZE from helper.");
1895
max_texture_size = 0;
1897
buffer[num_char] = '\0';
1898
sscanf (buffer, "%u", &max_texture_size);
1900
* Sanity check the numbers. No hardware I know of has a
1901
* GL_MAX_TEXTURE_SIZE smaller than 1024.
1903
if (max_texture_size < 1024)
1904
max_texture_size = 0;
1907
if (wait_count == 10) {
1908
g_warning ("Timed out waiting for GL_MAX_TEXTURE_SIZE helper");
1910
/* Ensure we don't leave processes sitting around. Who knows what they're doing? */
1911
kill (canary_pid, SIGTERM);
1912
waitpid (canary_pid, &child_status, 0);
1914
g_warning ("GL_MAX_TEXTURE_SIZE helper quit unexpectedly");
1916
max_texture_size = 0;
1920
g_debug ("Found GL_MAX_TEXTURE_SIZE of %u", max_texture_size);
1921
_max_texture_size_cache = max_texture_size;
1922
return _max_texture_size_cache;
1821
1927
static CrtcAssignment *
1822
1928
crtc_assignment_new (GnomeRRScreen *screen, GnomeRROutputInfo **outputs, GError **error)
1831
1937
int width, height;
1832
1938
int min_width, max_width, min_height, max_height;
1833
int required_pixels, min_pixels, max_pixels;
1939
int max_texture_size;
1835
1941
get_required_virtual_size (assignment, &width, &height);
1837
1943
gnome_rr_screen_get_ranges (
1838
1944
screen, &min_width, &max_width, &min_height, &max_height);
1840
required_pixels = width * height;
1841
min_pixels = min_width * min_height;
1842
max_pixels = max_width * max_height;
1844
if (required_pixels < min_pixels || required_pixels > max_pixels)
1946
if (width < min_width || width > max_width ||
1947
height < min_height || height > max_height)
1846
1949
g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_BOUNDS_ERROR,
1847
1950
/* Translators: the "requested", "minimum", and
1962
* This should either be solved by
1963
* (a) Allowing the compositor to veto RandR changes
1964
* (b) Fixing the compositor
1966
* Nethier of these are feasible at this point, so just fix Unity.
1969
if (unity_running ())
1971
max_texture_size = get_max_texture_size (screen);
1972
if (max_texture_size > 0 && (width > max_texture_size || height > max_texture_size))
1974
g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_BOUNDS_ERROR,
1975
_("Requested size (%d, %d) exceeds 3D hardware limit (%d, %d).\n"
1976
"You must either rearrange the displays so that they fit within a (%d, %d) square."),
1977
width, height, max_texture_size, max_texture_size,
1978
max_texture_size, max_texture_size);
1858
1984
assignment->screen = screen;
1860
1986
return assignment;