~ubuntu-branches/ubuntu/oneiric/gnome-desktop3/oneiric

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-07-06 12:00:02 UTC
  • mfrom: (1.2.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20110706120002-72iyjlgzv90779dq
Tags: 3.1.3-0ubuntu1
* New upstream release.
* debian/rules:
  - Use --enable-static, as .a files are not built by default
* debian/watch:
  - Watch unstable series
* debian/libgnome-desktop-3.2-symbols:
  - Added new API symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
    guint8 *            edid_data;
101
101
    gsize               edid_size;
102
102
    char *              connector_type;
 
103
    gint                backlight_min;
 
104
    gint                backlight_max;
103
105
};
104
106
 
105
107
struct GnomeRROutputWrap
1399
1401
#endif
1400
1402
}
1401
1403
 
 
1404
static void
 
1405
update_brightness_limits (GnomeRROutput *output)
 
1406
{
 
1407
#ifdef HAVE_RANDR
 
1408
    gint rc;
 
1409
    Atom atom;
 
1410
    XRRPropertyInfo *info;
 
1411
 
 
1412
    gdk_error_trap_push ();
 
1413
    atom = XInternAtom (DISPLAY (output), "BACKLIGHT", FALSE);
 
1414
    info = XRRQueryOutputProperty (DISPLAY (output), output->id, atom);
 
1415
    rc = gdk_error_trap_pop ();
 
1416
    if (rc != 0)
 
1417
    {
 
1418
        g_warning ("could not get output property for %s, rc: %i",
 
1419
                   output->name, rc);
 
1420
        goto out;
 
1421
    }
 
1422
    if (info == NULL)
 
1423
    {
 
1424
        g_warning ("could not get output property for %s",
 
1425
                   output->name);
 
1426
        goto out;
 
1427
    }
 
1428
    if (!info->range || info->num_values != 2)
 
1429
    {
 
1430
        g_debug ("backlight %s was not range", output->name);
 
1431
        goto out;
 
1432
    }
 
1433
    output->backlight_min = info->values[0];
 
1434
    output->backlight_max = info->values[1];
 
1435
out:
 
1436
    XFree (info);
 
1437
#endif
 
1438
}
 
1439
 
1402
1440
#ifdef HAVE_RANDR
1403
1441
static gboolean
1404
1442
output_initialize (GnomeRROutput *output, XRRScreenResources *res, GError **error)
1470
1508
    
1471
1509
    /* Edid data */
1472
1510
    output->edid_data = read_edid_data (output, &output->edid_size);
1473
 
    
 
1511
 
 
1512
    /* brightness data */
 
1513
    if (output->connected)
 
1514
        update_brightness_limits (output);
 
1515
 
1474
1516
    XRRFreeOutputInfo (info);
1475
1517
 
1476
1518
    return TRUE;
1495
1537
    output->connected = from->connected;
1496
1538
    output->n_preferred = from->n_preferred;
1497
1539
    output->connector_type = g_strdup (from->connector_type);
 
1540
    output->backlight_min = -1;
 
1541
    output->backlight_max = -1;
1498
1542
 
1499
1543
    array = g_ptr_array_new ();
1500
1544
    for (p_crtc = from->possible_crtcs; *p_crtc != NULL; p_crtc++)
1553
1597
}
1554
1598
 
1555
1599
/**
 
1600
 * gnome_rr_output_get_backlight_min:
 
1601
 *
 
1602
 * Returns: The mimimum backlight value, or -1 if not supported
 
1603
 */
 
1604
gint
 
1605
gnome_rr_output_get_backlight_min (GnomeRROutput *output)
 
1606
{
 
1607
    g_return_val_if_fail (output != NULL, -1);
 
1608
    return output->backlight_min;
 
1609
}
 
1610
 
 
1611
/**
 
1612
 * gnome_rr_output_get_backlight_max:
 
1613
 *
 
1614
 * Returns: The maximum backlight value, or -1 if not supported
 
1615
 */
 
1616
gint
 
1617
gnome_rr_output_get_backlight_max (GnomeRROutput *output)
 
1618
{
 
1619
    g_return_val_if_fail (output != NULL, -1);
 
1620
    return output->backlight_max;
 
1621
}
 
1622
 
 
1623
/**
 
1624
 * gnome_rr_output_get_backlight:
 
1625
 *
 
1626
 * Returns: The currently set backlight brightness
 
1627
 */
 
1628
gint
 
1629
gnome_rr_output_get_backlight (GnomeRROutput *output, GError **error)
 
1630
{
 
1631
    guint now = -1;
 
1632
#ifdef HAVE_RANDR
 
1633
    unsigned long nitems;
 
1634
    unsigned long bytes_after;
 
1635
    guint *prop;
 
1636
    Atom atom;
 
1637
    Atom actual_type;
 
1638
    int actual_format;
 
1639
    gint retval;
 
1640
 
 
1641
    g_return_val_if_fail (output != NULL, -1);
 
1642
 
 
1643
    gdk_error_trap_push ();
 
1644
    atom = XInternAtom (DISPLAY (output), "BACKLIGHT", FALSE);
 
1645
    retval = XRRGetOutputProperty (DISPLAY (output), output->id, atom,
 
1646
                                   0, 4, False, False, None,
 
1647
                                   &actual_type, &actual_format,
 
1648
                                   &nitems, &bytes_after, ((unsigned char **)&prop));
 
1649
    gdk_flush ();
 
1650
    if (gdk_error_trap_pop ())
 
1651
    {
 
1652
        g_set_error_literal (error,
 
1653
                             GNOME_RR_ERROR,
 
1654
                             GNOME_RR_ERROR_UNKNOWN,
 
1655
                             "unhandled X error while getting the range of backlight values");
 
1656
        goto out;
 
1657
    }
 
1658
 
 
1659
    if (retval != Success) {
 
1660
        g_set_error_literal (error,
 
1661
                             GNOME_RR_ERROR,
 
1662
                             GNOME_RR_ERROR_RANDR_ERROR,
 
1663
                             "could not get the range of backlight values");
 
1664
        goto out;
 
1665
    }
 
1666
    if (actual_type == XA_INTEGER &&
 
1667
        nitems == 1 &&
 
1668
        actual_format == 32)
 
1669
    {
 
1670
        memcpy (&now, prop, sizeof (guint));
 
1671
    }
 
1672
    else
 
1673
    {
 
1674
        g_set_error (error,
 
1675
                     GNOME_RR_ERROR,
 
1676
                     GNOME_RR_ERROR_RANDR_ERROR,
 
1677
                     "failed to get correct property type, got %lu,%i",
 
1678
                     nitems, actual_format);
 
1679
    }
 
1680
out:
 
1681
    XFree (prop);
 
1682
#else
 
1683
    g_set_error_literal (error,
 
1684
                         GNOME_RR_ERROR,
 
1685
                         GNOME_RR_ERROR_NO_RANDR_EXTENSION,
 
1686
                         "not compiled with RANDR support");
 
1687
#endif /* HAVE_RANDR */
 
1688
    return now;
 
1689
}
 
1690
 
 
1691
/**
 
1692
 * gnome_rr_output_set_backlight:
 
1693
 * @value: the absolute value which is min >= this <= max
 
1694
 *
 
1695
 * Returns: %TRUE for success
 
1696
 */
 
1697
gboolean
 
1698
gnome_rr_output_set_backlight (GnomeRROutput *output, gint value, GError **error)
 
1699
{
 
1700
    gboolean ret = FALSE;
 
1701
#ifdef HAVE_RANDR
 
1702
    Atom atom;
 
1703
 
 
1704
    g_return_val_if_fail (output != NULL, FALSE);
 
1705
 
 
1706
    /* check this is sane */
 
1707
    if (value < output->backlight_min ||
 
1708
        value > output->backlight_max)
 
1709
    {
 
1710
        g_set_error (error,
 
1711
                     GNOME_RR_ERROR,
 
1712
                     GNOME_RR_ERROR_BOUNDS_ERROR,
 
1713
                     "out of brightness range: %i, has to be %i -> %i",
 
1714
                     value,
 
1715
                     output->backlight_max, output->backlight_min);
 
1716
        goto out;
 
1717
    }
 
1718
 
 
1719
    /* don't abort on error */
 
1720
    gdk_error_trap_push ();
 
1721
    atom = XInternAtom (DISPLAY (output), "BACKLIGHT", FALSE);
 
1722
    XRRChangeOutputProperty (DISPLAY (output), output->id, atom,
 
1723
                             XA_INTEGER, 32, PropModeReplace,
 
1724
                             (unsigned char *) &value, 1);
 
1725
    if (gdk_error_trap_pop ())
 
1726
    {
 
1727
        g_set_error_literal (error,
 
1728
                             GNOME_RR_ERROR,
 
1729
                             GNOME_RR_ERROR_UNKNOWN,
 
1730
                             "unhandled X error while setting the backlight values");
 
1731
        goto out;
 
1732
    }
 
1733
 
 
1734
    /* we assume this succeeded as there's no return value */
 
1735
    ret = TRUE;
 
1736
#else
 
1737
    g_set_error_literal (error,
 
1738
                         GNOME_RR_ERROR,
 
1739
                         GNOME_RR_ERROR_NO_RANDR_EXTENSION,
 
1740
                         "not compiled with RANDR support");
 
1741
#endif /* HAVE_RANDR */
 
1742
out:
 
1743
    return ret;
 
1744
}
 
1745
 
 
1746
/**
1556
1747
 * gnome_rr_screen_get_output_by_id:
1557
1748
 *
1558
1749
 * Returns: (transfer none): the output identified by @name