~ubuntu-branches/ubuntu/precise/xfce4-power-manager/precise

« back to all changes in this revision

Viewing changes to src/xfpm-dpms.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2009-10-02 20:15:41 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091002201541-ognqyxyov51epj84
Tags: 0.8.4-1ubuntu1
* New upstream bugfix release (LP: #438754), merge from Debian unstable,
  remaining Ubuntu changes:
  - debian/patches:
    + xubuntu-use-notification-icons.patch: use our notification-* icons for
      notification bubbles instead of the normal ones LP: #437374
    + 10_pc.patch: added patched files to POTFILES.skip
    + series: created, with these two patches
  - debian/rules: add --with quilt
  - debian/control: build-depends on quilt (>= 0.46-7).

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <libxfce4util/libxfce4util.h>
38
38
 
39
39
#include "libxfpm/xfpm-string.h"
 
40
#include "libxfpm/xfpm-common.h"
40
41
 
41
42
#include "xfpm-dpms.h"
42
43
#include "xfpm-adapter.h"
43
44
#include "xfpm-xfconf.h"
44
45
#include "xfpm-screen-saver.h"
 
46
#include "xfpm-button-hal.h"
45
47
#include "xfpm-config.h"
46
48
 
47
49
#ifdef HAVE_DPMS
56
58
    XfpmXfconf      *conf;
57
59
    XfpmAdapter     *adapter;
58
60
    XfpmScreenSaver *saver;
 
61
    XfpmButtonHal   *bt_hal;
59
62
    
60
63
    gboolean       dpms_capable;
61
64
    gboolean       inhibited;
62
65
    gboolean       on_battery;
 
66
    
 
67
    gulong         switch_off_timeout_id;
 
68
    gulong         switch_on_timeout_id;
63
69
};
64
70
 
65
71
G_DEFINE_TYPE(XfpmDpms, xfpm_dpms, G_TYPE_OBJECT)
219
225
    xfpm_dpms_refresh (dpms);
220
226
}
221
227
 
 
228
static gboolean
 
229
xfpm_dpms_force_off (gpointer data)
 
230
 
231
    XfpmDpms *dpms;
 
232
    CARD16 power_level;
 
233
    BOOL state;
 
234
    
 
235
    dpms = XFPM_DPMS (data);
 
236
    
 
237
    TRACE ("Start");
 
238
    
 
239
    if ( G_UNLIKELY (!DPMSInfo (GDK_DISPLAY (), &power_level, &state)) )
 
240
    {
 
241
        g_warning ("Cannot get DPMSInfo");
 
242
        goto out;
 
243
    }
 
244
 
 
245
    if ( power_level != DPMSModeOff )
 
246
    {
 
247
        if ( xfpm_is_multihead_connected () )
 
248
            goto out;
 
249
        
 
250
        TRACE ("Checking if we have multiple monitor : no");
 
251
        TRACE ("Forcing DPMSModeOff");
 
252
        if ( !DPMSForceLevel (GDK_DISPLAY (), DPMSModeOff ) )
 
253
        {
 
254
            g_warning ("Cannot set Force DPMSModeOff");
 
255
        }
 
256
    }
 
257
    
 
258
out:
 
259
    dpms->priv->switch_off_timeout_id = 0;
 
260
    return FALSE;
 
261
}
 
262
 
 
263
static gboolean
 
264
xfpm_dpms_force_on (gpointer data)
 
265
{
 
266
    XfpmDpms *dpms;
 
267
    CARD16 power_level;
 
268
    BOOL state;
 
269
    
 
270
    dpms = XFPM_DPMS (data);
 
271
    
 
272
    TRACE ("start");
 
273
    
 
274
    if ( G_UNLIKELY (!DPMSInfo (GDK_DISPLAY (), &power_level, &state)) )
 
275
    {
 
276
        g_warning ("Cannot get DPMSInfo");
 
277
        goto out;
 
278
    }
 
279
 
 
280
    if ( power_level != DPMSModeOn )
 
281
    {
 
282
        TRACE ("Forcing DPMSModeOn");
 
283
        if ( !DPMSForceLevel (GDK_DISPLAY (), DPMSModeOn ) )
 
284
        {
 
285
            g_warning ("Cannot set Force DPMSModeOn");
 
286
        }
 
287
    }
 
288
    
 
289
out:
 
290
    dpms->priv->switch_on_timeout_id = 0;
 
291
    return FALSE;
 
292
}
 
293
 
 
294
static void
 
295
xfpm_dpms_lid_event_cb (XfpmButtonHal *bt, gboolean pressed, XfpmDpms *dpms)
 
296
{
 
297
    TRACE ("pressed: %s", xfpm_bool_to_string (pressed));
 
298
 
 
299
    if ( dpms->priv->switch_off_timeout_id != 0 )
 
300
    {
 
301
        g_source_remove (dpms->priv->switch_off_timeout_id);
 
302
        dpms->priv->switch_off_timeout_id = 0;
 
303
    }
 
304
    
 
305
    if ( dpms->priv->switch_on_timeout_id != 0 )
 
306
    {
 
307
        g_source_remove (dpms->priv->switch_on_timeout_id );
 
308
        dpms->priv->switch_on_timeout_id = 0;
 
309
    }
 
310
        
 
311
    if ( pressed )
 
312
    {
 
313
        g_timeout_add (100, (GSourceFunc) xfpm_dpms_force_off, dpms);
 
314
    }
 
315
    else
 
316
    {
 
317
        g_timeout_add (100, (GSourceFunc) xfpm_dpms_force_on, dpms);
 
318
    }
 
319
}
 
320
 
222
321
static void
223
322
xfpm_dpms_class_init(XfpmDpmsClass *klass)
224
323
{
238
337
    dpms->priv = XFPM_DPMS_GET_PRIVATE(dpms);
239
338
    
240
339
    dpms->priv->dpms_capable = DPMSCapable (GDK_DISPLAY());
 
340
    dpms->priv->switch_off_timeout_id = 0;
 
341
    dpms->priv->switch_on_timeout_id = 0;
241
342
 
242
343
    if ( dpms->priv->dpms_capable )
243
344
    {
244
345
        dpms->priv->adapter = xfpm_adapter_new ();
245
346
        dpms->priv->saver   = xfpm_screen_saver_new ();
246
347
        dpms->priv->conf    = xfpm_xfconf_new  ();
 
348
        dpms->priv->bt_hal  = xfpm_button_hal_get ();
247
349
    
248
350
        g_signal_connect (dpms->priv->saver, "screen-saver-inhibited",
249
351
                          G_CALLBACK(xfpm_dpms_inhibit_changed_cb), dpms);
254
356
        g_signal_connect (dpms->priv->conf, "notify",
255
357
                          G_CALLBACK (xfpm_dpms_settings_changed_cb), dpms);
256
358
                          
 
359
        g_signal_connect (dpms->priv->bt_hal, "lid-event",
 
360
                          G_CALLBACK (xfpm_dpms_lid_event_cb), dpms);
 
361
                          
257
362
        dpms->priv->on_battery = !xfpm_adapter_get_present (dpms->priv->adapter);
258
363
        xfpm_dpms_refresh (dpms);
259
364
    }
275
380
    g_object_unref (dpms->priv->adapter);
276
381
        
277
382
    g_object_unref ( dpms->priv->saver);
 
383
    g_object_unref ( dpms->priv->bt_hal);
278
384
 
279
385
    G_OBJECT_CLASS(xfpm_dpms_parent_class)->finalize(object);
280
386
}