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

« back to all changes in this revision

Viewing changes to libgnome-desktop/gnome-rr.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:
16
16
 * 
17
17
 * You should have received a copy of the GNU Library General Public
18
18
 * License along with the Gnome Library; see the file COPYING.LIB.  If not,
19
 
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
 * Boston, MA 02111-1307, USA.
 
19
 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
20
 * Boston, MA 02110-1301, USA.
21
21
 * 
22
22
 * Author: Soren Sandmann <sandmann@redhat.com>
23
23
 */
40
40
#include "gnome-rr.h"
41
41
#include "gnome-rr-config.h"
42
42
 
43
 
#include "private.h"
 
43
#include "edid.h"
44
44
#include "gnome-rr-private.h"
45
45
 
46
46
#define DISPLAY(o) ((o)->info->screen->priv->xdisplay)
68
68
    RROutput            id;
69
69
    
70
70
    char *              name;
 
71
    char *              display_name;
71
72
    GnomeRRCrtc *       current_crtc;
72
73
    gboolean            connected;
73
74
    gulong              width_mm;
834
835
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
835
836
    g_type_class_add_private (klass, sizeof (GnomeRRScreenPrivate));
836
837
 
 
838
    bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
 
839
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
840
 
837
841
    gobject_class->set_property = gnome_rr_screen_set_property;
838
842
    gobject_class->get_property = gnome_rr_screen_get_property;
839
843
    gobject_class->finalize = gnome_rr_screen_finalize;
946
950
 
947
951
/**
948
952
 * gnome_rr_screen_new:
949
 
 * Creates a unique #GnomeRRScreen instance for the specified @screen.
950
 
 *
951
953
 * @screen: the #GdkScreen on which to operate
952
954
 * @error: will be set if XRandR is not supported
953
955
 *
 
956
 * Creates a unique #GnomeRRScreen instance for the specified @screen.
 
957
 *
954
958
 * Returns: a unique #GnomeRRScreen instance, specific to the @screen, or NULL
955
959
 * if this could not be created, for instance if the driver does not support
956
960
 * Xrandr 1.2.  Each #GdkScreen thus has a single instance of #GnomeRRScreen.
968
972
    if (rr_screen)
969
973
        g_object_ref (rr_screen);
970
974
    else {
971
 
        _gnome_desktop_init_i18n ();
972
 
 
973
975
        rr_screen = g_initable_new (GNOME_TYPE_RR_SCREEN, NULL, error, "gdk-screen", screen, NULL);
974
976
        if (rr_screen) {
975
977
            g_object_set_data (G_OBJECT (screen), "GnomeRRScreen", rr_screen);
997
999
 
998
1000
/**
999
1001
 * gnome_rr_screen_get_ranges:
1000
 
 *
1001
 
 * Get the ranges of the screen
1002
1002
 * @screen: a #GnomeRRScreen
1003
1003
 * @min_width: (out): the minimum width
1004
1004
 * @max_width: (out): the maximum width
1005
1005
 * @min_height: (out): the minimum height
1006
1006
 * @max_height: (out): the maximum height
 
1007
 *
 
1008
 * Get the ranges of the screen
1007
1009
 */
1008
1010
void
1009
1011
gnome_rr_screen_get_ranges (GnomeRRScreen *screen,
1141
1143
 
1142
1144
/**
1143
1145
 * gnome_rr_screen_get_dpms_mode:
 
1146
 * @mode: (out): The current #GnomeRRDpmsMode of this screen
1144
1147
 **/
1145
1148
gboolean
1146
1149
gnome_rr_screen_get_dpms_mode (GnomeRRScreen *screen,
1267
1270
    gdk_error_trap_push ();
1268
1271
    /* DPMSForceLevel() return value is often a lie, so ignore it */
1269
1272
    DPMSForceLevel (screen->priv->xdisplay, state);
 
1273
    XSync (screen->priv->xdisplay, False);
1270
1274
    if (gdk_error_trap_pop ()) {
1271
1275
        ret = FALSE;
1272
1276
        g_set_error_literal (error,
1462
1466
                               output->id, edid_atom, len);
1463
1467
    }
1464
1468
 
 
1469
    if (!result)
 
1470
    {
 
1471
        edid_atom = XInternAtom (DISPLAY (output), "XFree86_DDC_EDID1_RAWDATA", FALSE);
 
1472
        result = get_property (DISPLAY (output),
 
1473
                               output->id, edid_atom, len);
 
1474
    }
 
1475
 
1465
1476
    if (result)
1466
1477
    {
1467
1478
        if (*len % 128 == 0)
1572
1583
    }
1573
1584
    
1574
1585
    output->name = g_strdup (info->name); /* FIXME: what is nameLen used for? */
 
1586
    output->display_name = NULL; /* set first time the getter is used */
1575
1587
    output->current_crtc = crtc_by_id (output->info, info->crtc);
1576
1588
    output->width_mm = info->mm_width;
1577
1589
    output->height_mm = info->mm_height;
1685
1697
    g_free (output->possible_crtcs);
1686
1698
    g_free (output->edid_data);
1687
1699
    g_free (output->name);
 
1700
    g_free (output->display_name);
1688
1701
    g_free (output->connector_type);
1689
1702
    g_slice_free (GnomeRROutput, output);
1690
1703
}
1707
1720
}
1708
1721
 
1709
1722
/**
 
1723
 * gnome_rr_output_get_ids_from_edid:
 
1724
 * @output: a #GnomeRROutput
 
1725
 * @vendor: (out) (allow-none):
 
1726
 * @product: (out) (allow-none):
 
1727
 * @serial: (out) (allow-none):
 
1728
 */
 
1729
gboolean
 
1730
gnome_rr_output_get_ids_from_edid (GnomeRROutput         *output,
 
1731
                                   char                 **vendor,
 
1732
                                   int                   *product,
 
1733
                                   int                   *serial)
 
1734
{
 
1735
    MonitorInfo *info;
 
1736
 
 
1737
    g_return_val_if_fail (output != NULL, FALSE);
 
1738
 
 
1739
    if (!output->edid_data)
 
1740
        return FALSE;
 
1741
    info = decode_edid (output->edid_data);
 
1742
    if (!info)
 
1743
        return FALSE;
 
1744
    if (vendor)
 
1745
        *vendor = g_memdup (info->manufacturer_code, 4);
 
1746
    if (product)
 
1747
        *product = info->product_code;
 
1748
    if (serial)
 
1749
        *serial = info->serial_number;
 
1750
 
 
1751
    g_free (info);
 
1752
 
 
1753
    return TRUE;
 
1754
 
 
1755
}
 
1756
 
 
1757
static void
 
1758
ensure_display_name (GnomeRROutput *output)
 
1759
{
 
1760
    if (output->display_name != NULL)
 
1761
        return;
 
1762
 
 
1763
    if (gnome_rr_output_is_laptop (output))
 
1764
        output->display_name = g_strdup (_("Built-in Display"));
 
1765
 
 
1766
    if (output->display_name == NULL
 
1767
        && output->edid_data != NULL) {
 
1768
        MonitorInfo *info;
 
1769
 
 
1770
        info = decode_edid (output->edid_data);
 
1771
        if (info != NULL)
 
1772
            output->display_name = make_display_name (info);
 
1773
 
 
1774
        g_free (info);
 
1775
    }
 
1776
 
 
1777
    if (output->display_name == NULL) {
 
1778
        char *inches;
 
1779
        inches = make_display_size_string (output->width_mm, output->height_mm);
 
1780
        if (inches != NULL) {
 
1781
            /* Translators: %s is the size of the monitor in inches */
 
1782
            output->display_name = g_strdup_printf (_("%s Display"), inches);
 
1783
        }
 
1784
        g_free (inches);
 
1785
    }
 
1786
 
 
1787
    /* last chance on the stairway */
 
1788
    if (output->display_name == NULL) {
 
1789
      output->display_name = g_strdup (_("Unknown Display"));
 
1790
    }
 
1791
}
 
1792
 
 
1793
const char *
 
1794
gnome_rr_output_get_display_name (GnomeRROutput *output)
 
1795
{
 
1796
    g_return_val_if_fail (output != NULL, NULL);
 
1797
 
 
1798
    ensure_display_name (output);
 
1799
 
 
1800
    return output->display_name;
 
1801
}
 
1802
 
 
1803
/**
1710
1804
 * gnome_rr_output_get_backlight_min:
1711
1805
 *
1712
1806
 * Returns: The mimimum backlight value, or -1 if not supported
1840
1934
}
1841
1935
 
1842
1936
/**
1843
 
 * gnome_rr_screen_get_output_by_id:
 
1937
 * gnome_rr_screen_get_output_by_name:
1844
1938
 *
1845
1939
 * Returns: (transfer none): the output identified by @name
1846
1940
 */
1882
1976
}
1883
1977
 
1884
1978
gboolean
 
1979
_gnome_rr_output_name_is_laptop (const char *name)
 
1980
{
 
1981
    if (!name)
 
1982
        return FALSE;
 
1983
 
 
1984
    if (strstr (name, "lvds") ||  /* Most drivers use an "LVDS" prefix... */
 
1985
        strstr (name, "LVDS") ||
 
1986
        strstr (name, "Lvds") ||
 
1987
        strstr (name, "LCD")  ||  /* ... but fglrx uses "LCD" in some versions.  Shoot me now, kthxbye. */
 
1988
        strstr (name, "eDP")  ||  /* eDP is for internal laptop panel connections */
 
1989
        strstr (name, "default")) /* Finally, NVidia and all others that don't bother to do RANDR properly */
 
1990
        return TRUE;
 
1991
 
 
1992
    return FALSE;
 
1993
}
 
1994
 
 
1995
gboolean
1885
1996
gnome_rr_output_is_laptop (GnomeRROutput *output)
1886
1997
{
1887
 
    const char *connector_type;
1888
 
 
1889
1998
    g_return_val_if_fail (output != NULL, FALSE);
1890
1999
 
1891
2000
    if (!output->connected)
1892
2001
        return FALSE;
1893
2002
 
1894
2003
    /* The ConnectorType property is present in RANDR 1.3 and greater */
1895
 
 
1896
 
    connector_type = gnome_rr_output_get_connector_type (output);
1897
 
    if (connector_type && strcmp (connector_type, GNOME_RR_CONNECTOR_TYPE_PANEL) == 0)
 
2004
    if (g_strcmp0 (output->connector_type, GNOME_RR_CONNECTOR_TYPE_PANEL) == 0)
1898
2005
        return TRUE;
1899
2006
 
1900
2007
    /* Older versions of RANDR - this is a best guess, as @#$% RANDR doesn't have standard output names,
1901
2008
     * so drivers can use whatever they like.
1902
2009
     */
1903
 
 
1904
 
    if (output->name
1905
 
        && (strstr (output->name, "lvds") ||  /* Most drivers use an "LVDS" prefix... */
1906
 
            strstr (output->name, "LVDS") ||
1907
 
            strstr (output->name, "Lvds") ||
1908
 
            strstr (output->name, "LCD")  ||  /* ... but fglrx uses "LCD" in some versions.  Shoot me now, kthxbye. */
1909
 
            strstr (output->name, "eDP")  ||  /* eDP is for internal laptop panel connections */
1910
 
            strstr (output->name, "DFP")))    /* DFP is also an internal laptop display */
1911
 
        return TRUE;
 
2010
    if (_gnome_rr_output_name_is_laptop (output->name))
 
2011
        return TRUE;
1912
2012
 
1913
2013
    return FALSE;
1914
2014
}
1926
2026
    return NULL;
1927
2027
}
1928
2028
 
 
2029
/**
 
2030
 * gnome_rr_output_get_position:
 
2031
 * @output: a #GnomeRROutput
 
2032
 * @x: (out) (allow-none):
 
2033
 * @y: (out) (allow-none):
 
2034
 */
1929
2035
void
1930
2036
gnome_rr_output_get_position (GnomeRROutput   *output,
1931
2037
                              int             *x,
2203
2309
}
2204
2310
 
2205
2311
/* FIXME: merge with get_mode()? */
 
2312
/**
 
2313
 * gnome_rr_crtc_get_position:
 
2314
 * @crtc: a #GnomeRRCrtc
 
2315
 * @x: (out) (allow-none):
 
2316
 * @y: (out) (allow-none):
 
2317
 */
2206
2318
void
2207
2319
gnome_rr_crtc_get_position (GnomeRRCrtc *crtc,
2208
2320
                            int         *x,