~fourdollars/ubuntu/trusty/gnome-desktop3/fix-lowest-brightness

« back to all changes in this revision

Viewing changes to libgnome-desktop/gnome-rr-config.c

  • Committer: Package Import Robot
  • Author(s): Tim Lunn
  • Date: 2013-05-28 09:10:46 UTC
  • mfrom: (1.6.1) (21.1.10 experimental)
  • Revision ID: package-import@ubuntu.com-20130528091046-b0oc28za9l97fgq1
Tags: 3.8.2-0ubuntu1
* New upstream release
* Sync with Debian (LP: #1184812) Remaining changes:
  - debian/patches:
    + 04_compute_average_color.patch: Compute the avergage color in
      gnome-desktop itself, not in unity to fix some races (LP #963140)
    + tweak_color_computation.patch, Patch from Gord, no patch header,
      no bug link.
    + git_revert_draw_background.patch
    + ubuntu_language.patch, Ported relevant bits from g-c-c 
      52_region_language.patch, as required for gnome 3.8 region panel
    + ubuntu_language_list_from_SUPPORTED.patch,
      adds api to get list of available languages from SUPPORTED file.
      To be used by gnome 3.8 region panel language installation.
  - debian/control.in:
    + Don't break gnome-shell << 3.7.90
    + Use source:Version for gnome-desktop3-data Depend
    + Add epoch to gnome-desktop3-data's Breaks/Replaces, as our old
      gnome-desktop source package introduced an epoch. This needs to be
      kept until after 14.04 LTS.
 - Install helper tools into a versioned directory (by overriding
   libexecdir). They could alternatively be installed in a separate package
* Dropped changes:
  - 02_refuse_to_break_GL_compositors.patch:
    + Doesn't appear to be needed any more
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * 
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.
23
23
 * 
24
24
 * Author: Soren Sandmann <sandmann@redhat.com>
25
25
 */
36
36
#include <X11/Xlib.h>
37
37
#include <gdk/gdkx.h>
38
38
 
 
39
#include <unistd.h>
 
40
#include <sys/wait.h>
 
41
#include <signal.h>
 
42
 
39
43
#include "gnome-rr-config.h"
40
44
 
41
45
#include "edid.h"
44
48
#define CONFIG_INTENDED_BASENAME "monitors.xml"
45
49
#define CONFIG_BACKUP_BASENAME "monitors.xml.backup"
46
50
 
 
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
 
55
 
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
49
58
 * like
516
525
 
517
526
        output->priv->name = g_strdup (gnome_rr_output_get_name (rr_output));
518
527
        output->priv->connected = gnome_rr_output_is_connected (rr_output);
 
528
        output->priv->display_name = g_strdup (gnome_rr_output_get_display_name (rr_output));
519
529
 
520
530
        if (!output->priv->connected)
521
531
        {
548
558
                output->priv->product = 0;
549
559
                output->priv->serial = 0;
550
560
            }
551
 
 
552
 
            if (gnome_rr_output_is_laptop (rr_output))
553
 
                output->priv->display_name = g_strdup (_("Laptop"));
554
 
            else
555
 
                output->priv->display_name = make_display_name (info);
556
 
                
557
561
            g_free (info);
558
562
                
559
563
            crtc = gnome_rr_output_get_crtc (rr_output);
1166
1170
    }
1167
1171
}
1168
1172
 
1169
 
static gboolean
1170
 
output_info_is_laptop (GnomeRROutputInfo *info)
1171
 
{
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. */
1177
 
                return TRUE;
1178
 
 
1179
 
        return FALSE;
1180
 
}
1181
 
 
1182
1173
gboolean
1183
1174
gnome_rr_config_ensure_primary (GnomeRRConfig *configuration)
1184
1175
{
1218
1209
                        top_left = info;
1219
1210
                }
1220
1211
                if (laptop == NULL
1221
 
                    && output_info_is_laptop (info)) {
 
1212
                    && _gnome_rr_output_name_is_laptop (info->priv->name)) {
1222
1213
                        /* shame we can't find the connector type
1223
1214
                           as with gnome_rr_output_is_laptop */
1224
1215
                        laptop = info;
1818
1809
    g_list_free (active_crtcs);
1819
1810
}
1820
1811
 
 
1812
static gboolean
 
1813
unity_running (void)
 
1814
{
 
1815
    const gchar *desktop_environment = g_getenv ("DESKTOP_SESSION");
 
1816
    
 
1817
    return !g_strcmp0 (desktop_environment, "ubuntu");
 
1818
}
 
1819
 
 
1820
static gint _max_texture_size_cache = -1;
 
1821
 
 
1822
static gint
 
1823
get_max_texture_size (GnomeRRScreen *screen)
 
1824
{
 
1825
    if (_max_texture_size_cache != -1)
 
1826
    {
 
1827
        return _max_texture_size_cache;
 
1828
    } else {
 
1829
        /* 
 
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
 
1833
         * down the app.
 
1834
         */
 
1835
        int pipe_fd[2];
 
1836
        pid_t canary_pid;
 
1837
 
 
1838
        char * const canary_argv[] = { LIBEXECDIR "/check_gl_texture_size", NULL };
 
1839
        char *canary_env[2];
 
1840
        char display_env[80];
 
1841
          
 
1842
        snprintf (display_env, sizeof (display_env), "DISPLAY=%s", DisplayString (screen->priv->xdisplay));
 
1843
        canary_env[0] = display_env;
 
1844
        canary_env[1] = NULL;
 
1845
 
 
1846
 
 
1847
        if (pipe (pipe_fd) == -1)
 
1848
        {
 
1849
            _max_texture_size_cache = 0;
 
1850
            return 0;
 
1851
        }
 
1852
        canary_pid = fork ();
 
1853
        if (canary_pid == -1)
 
1854
        {
 
1855
            _max_texture_size_cache = 0;
 
1856
            return 0;
 
1857
        }
 
1858
 
 
1859
        if (canary_pid == 0)
 
1860
        {
 
1861
          close (pipe_fd[0]);
 
1862
          dup2 (pipe_fd[1], 1);
 
1863
          close (pipe_fd[1]);
 
1864
         
 
1865
          execve (canary_argv[0], canary_argv, canary_env);
 
1866
        } else {
 
1867
            char buffer[10];
 
1868
            gint max_texture_size;
 
1869
            int child_status;
 
1870
            int num_char;
 
1871
            struct timespec fifty_msec = {0, 50000000};
 
1872
            int wait_count = 0;
 
1873
            
 
1874
            close (pipe_fd[1]);
 
1875
 
 
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.
 
1879
             *
 
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
 
1882
             * set up.
 
1883
             */
 
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);
 
1887
                wait_count++;
 
1888
            }
 
1889
 
 
1890
            if (WIFEXITED (child_status) && WEXITSTATUS (child_status) == EXIT_SUCCESS) 
 
1891
            {
 
1892
                if ((num_char = read (pipe_fd[0], buffer, sizeof(buffer) - 1)) <= 0) 
 
1893
                {
 
1894
                    g_warning ("Failed to read GL_MAX_TEXTURE_SIZE from helper.");
 
1895
                    max_texture_size = 0;
 
1896
                } else {
 
1897
                    buffer[num_char] = '\0';
 
1898
                    sscanf (buffer, "%u", &max_texture_size);
 
1899
                    /* 
 
1900
                     * Sanity check the numbers.  No hardware I know of has a
 
1901
                     * GL_MAX_TEXTURE_SIZE smaller than 1024.
 
1902
                     */
 
1903
                    if (max_texture_size < 1024)
 
1904
                        max_texture_size = 0;
 
1905
                }
 
1906
            } else {
 
1907
                if (wait_count == 10) {
 
1908
                    g_warning ("Timed out waiting for GL_MAX_TEXTURE_SIZE helper");
 
1909
 
 
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);
 
1913
                } else {
 
1914
                    g_warning ("GL_MAX_TEXTURE_SIZE helper quit unexpectedly");
 
1915
                }
 
1916
                max_texture_size = 0;
 
1917
            }
 
1918
 
 
1919
            close (pipe_fd[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;
 
1923
        }
 
1924
    }
 
1925
}
 
1926
 
1821
1927
static CrtcAssignment *
1822
1928
crtc_assignment_new (GnomeRRScreen *screen, GnomeRROutputInfo **outputs, GError **error)
1823
1929
{
1830
1936
    {
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;
1834
1940
 
1835
1941
        get_required_virtual_size (assignment, &width, &height);
1836
1942
 
1837
1943
        gnome_rr_screen_get_ranges (
1838
1944
            screen, &min_width, &max_width, &min_height, &max_height);
1839
 
 
1840
 
        required_pixels = width * height;
1841
 
        min_pixels = min_width * min_height;
1842
 
        max_pixels = max_width * max_height;
1843
 
 
1844
 
        if (required_pixels < min_pixels || required_pixels > max_pixels)
 
1945
    
 
1946
        if (width < min_width || width > max_width ||
 
1947
            height < min_height || height > max_height)
1845
1948
        {
1846
1949
            g_set_error (error, GNOME_RR_ERROR, GNOME_RR_ERROR_BOUNDS_ERROR,
1847
1950
                         /* Translators: the "requested", "minimum", and
1855
1958
            goto fail;
1856
1959
        }
1857
1960
 
 
1961
        /* Hack:
 
1962
         * This should either be solved by
 
1963
         * (a) Allowing the compositor to veto RandR changes
 
1964
         * (b) Fixing the compositor
 
1965
         * 
 
1966
         * Nethier of these are feasible at this point, so just fix Unity.
 
1967
         */
 
1968
 
 
1969
        if (unity_running ())
 
1970
        {
 
1971
            max_texture_size = get_max_texture_size (screen);
 
1972
            if (max_texture_size > 0 && (width > max_texture_size || height > max_texture_size))
 
1973
            {
 
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);
 
1979
                goto fail;
 
1980
            }
 
1981
        }
 
1982
            
 
1983
        
1858
1984
        assignment->screen = screen;
1859
1985
        
1860
1986
        return assignment;
1941
2067
     *
1942
2068
     * Firefox and Evince apparently believe what X tells them.
1943
2069
     */
1944
 
    width_mm = (width / 96.0) * 25.4 + 0.5;
1945
 
    height_mm = (height / 96.0) * 25.4 + 0.5;
 
2070
    width_mm = (width / DPI_FALLBACK) * 25.4 + 0.5;
 
2071
    height_mm = (height / DPI_FALLBACK) * 25.4 + 0.5;
1946
2072
 
1947
2073
    if (success)
1948
2074
    {