~ubuntu-branches/ubuntu/trusty/powerd/trusty-proposed

« back to all changes in this revision

Viewing changes to src/display.c

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Ricardo Mendoza, Ubuntu daily release
  • Date: 2013-09-26 18:34:30 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20130926183430-96ol5ngzsbnqp0sz
Tags: 0.13+13.10.20130926-0ubuntu1
[ Ricardo Mendoza ]
* Allow powerd to work with unity-mir's DBus API for screen power
  control, selective using the backend available according to the
  running display server. (LP: #1193222)

[ Ubuntu daily release ]
* Automatic snapshot from revision 94

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "device-config.h"
40
40
#include "log.h"
41
41
 
 
42
/* Mir usage hint file path */
 
43
#define MIR_HINT_PATH   "/home/phablet/.display-mir"
 
44
 
42
45
/* Treat "don't care" display state as off */
43
46
#define DISPLAY_STATE_OFF POWERD_DISPLAY_STATE_DONT_CARE
44
47
 
50
53
static gint saved_brightness = 255;
51
54
static gint target_brightness;
52
55
static gint dim_brightness;
 
56
static gboolean running_mir = FALSE;
53
57
 
54
58
/* Assume screen is off to start; we will force it on */
55
59
static uuid_t internal_request_cookie;
103
107
    return (flags & AB_ENABLED_MASK) == AB_ENABLED;
104
108
}
105
109
 
 
110
void display_set_power_mode(int display, char *power_mode)
 
111
{
 
112
    GError *error = NULL;
 
113
    GDBusProxy *unity_proxy = NULL;
 
114
 
 
115
    powerd_debug("display_set_power_mode(%s)", power_mode);
 
116
 
 
117
    if (!running_mir) {
 
118
        if (strcmp(power_mode, "off") == 0)
 
119
            sf_blank(display);
 
120
        else
 
121
            sf_unblank(display);
 
122
    } else {
 
123
        unity_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
 
124
                    G_DBUS_PROXY_FLAGS_NONE,
 
125
                    NULL,
 
126
                    "com.canonical.Unity.Screen",
 
127
                    "/com/canonical/Unity/Screen",
 
128
                    "com.canonical.Unity.Screen",
 
129
                    NULL,
 
130
                    &error);
 
131
 
 
132
        if (error != NULL) {
 
133
            powerd_warn("could not connect to Unity: %s", error->message);
 
134
            g_error_free(error);
 
135
            return;
 
136
        }
 
137
 
 
138
        GVariant *ret = g_dbus_proxy_call_sync(unity_proxy,
 
139
                "setScreenPowerMode",
 
140
                g_variant_new("(s)", power_mode),
 
141
                G_DBUS_CALL_FLAGS_NONE,
 
142
                -1,
 
143
                NULL,
 
144
                &error);
 
145
 
 
146
        if (ret == NULL) {
 
147
            powerd_warn("screen power setting failed: %s", error->message);
 
148
            g_error_free(error);
 
149
        }
 
150
 
 
151
        g_object_unref(unity_proxy);
 
152
    }
 
153
}
 
154
 
106
155
static void turn_on_display(gboolean autobrightness) {
107
156
    powerd_debug("turning on display");
108
 
    sf_unblank(0);
 
157
    display_set_power_mode(0, "on");
109
158
    if (autobrightness)
110
159
        powerd_autobrightness_enable();
111
160
    else
174
223
        if (using_ab)
175
224
            powerd_autobrightness_disable();
176
225
        powerd_set_brightness(0);
177
 
        sf_blank(0);
 
226
        display_set_power_mode(0, "off");
178
227
 
179
228
        powerd_debug("Releasing internal active state request");
180
229
        ret = clear_sys_state_internal(internal_request_cookie);
382
431
    GError *error;
383
432
    GValue v = G_VALUE_INIT;
384
433
    int brightness, max_brightness;
 
434
    struct stat stats;
385
435
 
386
436
    /*
387
437
     * Warning: much hand waving follows
423
473
 
424
474
    target_brightness = saved_brightness;
425
475
 
 
476
    /* decide whether we are running on Mir or SF */
 
477
    if (stat(MIR_HINT_PATH, &stats) == 0)
 
478
        running_mir = TRUE;
 
479
 
426
480
    /* If kernel supports earlysuspend, start thread to monitor fb state */
427
481
    if (!access(fb_file_names[FB_SLEEP], F_OK))
428
482
        g_thread_new("powerd_fb_wake_monitor", wait_for_fb_thread, &error);