1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
* Copyright (C) 2005-2009 Richard Hughes <richard@hughsie.com>
* Copyright (C) 2012-2021 MATE Developers
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#include <glib.h>
#include <glib/gi18n.h>
#include "egg-idletime.h"
#include "gpm-idle.h"
#include "gpm-load.h"
#include "gpm-session.h"
/* Sets the idle percent limit, i.e. how hard the computer can work
while considered "at idle" */
#define GPM_IDLE_CPU_LIMIT 5
#define GPM_IDLE_IDLETIME_ID 1
struct GpmIdlePrivate
{
EggIdletime *idletime;
GpmLoad *load;
GpmSession *session;
GpmIdleMode mode;
guint timeout_dim; /* in seconds */
guint timeout_blank; /* in seconds */
guint timeout_sleep; /* in seconds */
guint timeout_blank_id;
guint timeout_sleep_id;
gboolean x_idle;
gboolean check_type_cpu;
};
enum {
IDLE_CHANGED,
LAST_SIGNAL
};
static guint signals [LAST_SIGNAL] = { 0 };
static gpointer gpm_idle_object = NULL;
G_DEFINE_TYPE_WITH_PRIVATE (GpmIdle, gpm_idle, G_TYPE_OBJECT)
/**
* gpm_idle_mode_to_string:
**/
static const gchar *
gpm_idle_mode_to_string (GpmIdleMode mode)
{
if (mode == GPM_IDLE_MODE_NORMAL)
return "normal";
if (mode == GPM_IDLE_MODE_DIM)
return "dim";
if (mode == GPM_IDLE_MODE_BLANK)
return "blank";
if (mode == GPM_IDLE_MODE_SLEEP)
return "sleep";
return "unknown";
}
/**
* gpm_idle_set_mode:
* @mode: The new mode, e.g. GPM_IDLE_MODE_SLEEP
**/
static void
gpm_idle_set_mode (GpmIdle *idle, GpmIdleMode mode)
{
g_return_if_fail (GPM_IS_IDLE (idle));
if (mode != idle->priv->mode) {
idle->priv->mode = mode;
g_debug ("Doing a state transition: %s", gpm_idle_mode_to_string (mode));
g_signal_emit (idle, signals [IDLE_CHANGED], 0, mode);
}
}
/**
* gpm_idle_set_check_cpu:
* @check_type_cpu: If we should check the CPU before mode becomes
* GPM_IDLE_MODE_SLEEP and the event is done.
**/
void
gpm_idle_set_check_cpu (GpmIdle *idle, gboolean check_type_cpu)
{
g_return_if_fail (GPM_IS_IDLE (idle));
g_debug ("Setting the CPU load check to %i", check_type_cpu);
idle->priv->check_type_cpu = check_type_cpu;
}
/**
* gpm_idle_get_mode:
* Return value: The current mode, e.g. GPM_IDLE_MODE_SLEEP
**/
GpmIdleMode
gpm_idle_get_mode (GpmIdle *idle)
{
return idle->priv->mode;
}
/**
* gpm_idle_blank_cb:
**/
static gboolean
gpm_idle_blank_cb (GpmIdle *idle)
{
if (idle->priv->mode > GPM_IDLE_MODE_BLANK) {
g_debug ("ignoring current mode %s", gpm_idle_mode_to_string (idle->priv->mode));
return FALSE;
}
gpm_idle_set_mode (idle, GPM_IDLE_MODE_BLANK);
return FALSE;
}
/**
* gpm_idle_sleep_cb:
**/
static gboolean
gpm_idle_sleep_cb (GpmIdle *idle)
{
gdouble load;
gboolean ret = FALSE;
/* get our computed load value */
if (idle->priv->check_type_cpu) {
load = gpm_load_get_current (idle->priv->load);
if (load > GPM_IDLE_CPU_LIMIT) {
/* check if system is "idle" enough */
g_debug ("Detected that the CPU is busy");
ret = TRUE;
goto out;
}
}
gpm_idle_set_mode (idle, GPM_IDLE_MODE_SLEEP);
out:
return ret;
}
/**
* gpm_idle_evaluate:
**/
static void
gpm_idle_evaluate (GpmIdle *idle)
{
gboolean is_idle;
gboolean is_idle_inhibited;
gboolean is_suspend_inhibited;
is_idle = gpm_session_get_idle (idle->priv->session);
is_idle_inhibited = gpm_session_get_idle_inhibited (idle->priv->session);
is_suspend_inhibited = gpm_session_get_suspend_inhibited (idle->priv->session);
g_debug ("session_idle=%i, idle_inhibited=%i, suspend_inhibited=%i, x_idle=%i", is_idle, is_idle_inhibited, is_suspend_inhibited, idle->priv->x_idle);
/* check we are really idle */
if (!idle->priv->x_idle) {
gpm_idle_set_mode (idle, GPM_IDLE_MODE_NORMAL);
g_debug ("X not idle");
if (idle->priv->timeout_blank_id != 0) {
g_source_remove (idle->priv->timeout_blank_id);
idle->priv->timeout_blank_id = 0;
}
if (idle->priv->timeout_sleep_id != 0) {
g_source_remove (idle->priv->timeout_sleep_id);
idle->priv->timeout_sleep_id = 0;
}
goto out;
}
/* are we inhibited from going idle */
if (is_idle_inhibited) {
g_debug ("inhibited, so using normal state");
gpm_idle_set_mode (idle, GPM_IDLE_MODE_NORMAL);
if (idle->priv->timeout_blank_id != 0) {
g_source_remove (idle->priv->timeout_blank_id);
idle->priv->timeout_blank_id = 0;
}
if (idle->priv->timeout_sleep_id != 0) {
g_source_remove (idle->priv->timeout_sleep_id);
idle->priv->timeout_sleep_id = 0;
}
goto out;
}
/* normal to dim */
if (idle->priv->mode == GPM_IDLE_MODE_NORMAL) {
g_debug ("normal to dim");
gpm_idle_set_mode (idle, GPM_IDLE_MODE_DIM);
}
/* set up blank callback even when session is not idle,
* but only if we actually want to blank. */
if (idle->priv->timeout_blank_id == 0 &&
idle->priv->timeout_blank != 0) {
g_debug ("setting up blank callback for %is", idle->priv->timeout_blank);
idle->priv->timeout_blank_id = g_timeout_add_seconds (idle->priv->timeout_blank,
(GSourceFunc) gpm_idle_blank_cb, idle);
g_source_set_name_by_id (idle->priv->timeout_blank_id, "[GpmIdle] blank");
}
/* are we inhibited from sleeping */
if (is_suspend_inhibited) {
g_debug ("suspend inhibited");
if (idle->priv->timeout_sleep_id != 0) {
g_source_remove (idle->priv->timeout_sleep_id);
idle->priv->timeout_sleep_id = 0;
}
} else if (is_idle) {
/* only do the sleep timeout when the session is idle and we aren't inhibited from sleeping */
if (idle->priv->timeout_sleep_id == 0 &&
idle->priv->timeout_sleep != 0) {
g_debug ("setting up sleep callback %is", idle->priv->timeout_sleep);
idle->priv->timeout_sleep_id = g_timeout_add_seconds (idle->priv->timeout_sleep,
(GSourceFunc) gpm_idle_sleep_cb, idle);
g_source_set_name_by_id (idle->priv->timeout_sleep_id, "[GpmIdle] sleep");
}
}
out:
return;
}
/**
* gpm_idle_adjust_timeout_dim:
* @idle_time: The new timeout we want to set, in seconds.
* @timeout: Current idle time, in seconds.
*
* On slow machines, or machines that have lots to load duing login,
* the current idle time could be bigger than the requested timeout.
* In this case the scheduled idle timeout will never fire, unless
* some user activity (keyboard, mouse) resets the current idle time.
* Instead of relying on user activity to correct this issue, we need
* to adjust timeout, as related to current idle time, so the idle
* timeout will fire as designed.
*
* Return value: timeout to set, adjusted acccording to current idle time.
**/
static guint
gpm_idle_adjust_timeout_dim (guint idle_time, guint timeout)
{
/* allow 2 sec margin for messaging delay. */
idle_time += 2;
/* Double timeout until it's larger than current idle time.
* Give up for ultra slow machines. (86400 sec = 24 hours) */
while (timeout < idle_time && timeout < 86400 && timeout > 0) {
timeout *= 2;
}
return timeout;
}
/**
* gpm_idle_set_timeout_dim:
* @timeout: The new timeout we want to set, in seconds
**/
gboolean
gpm_idle_set_timeout_dim (GpmIdle *idle, guint timeout)
{
gint64 idle_time_in_msec;
guint timeout_adjusted;
g_return_val_if_fail (GPM_IS_IDLE (idle), FALSE);
idle_time_in_msec = egg_idletime_get_time (idle->priv->idletime);
timeout_adjusted = gpm_idle_adjust_timeout_dim (idle_time_in_msec / 1000, timeout);
g_debug ("Current idle time=%lldms, timeout was %us, becomes %us after adjustment",
(long long int)idle_time_in_msec, timeout, timeout_adjusted);
timeout = timeout_adjusted;
g_debug ("Setting dim idle timeout: %ds", timeout);
if (idle->priv->timeout_dim != timeout) {
idle->priv->timeout_dim = timeout;
if (timeout > 0)
egg_idletime_alarm_set (idle->priv->idletime, GPM_IDLE_IDLETIME_ID, timeout * 1000);
else
egg_idletime_alarm_remove (idle->priv->idletime, GPM_IDLE_IDLETIME_ID);
}
return TRUE;
}
/**
* gpm_idle_set_timeout_blank:
* @timeout: The new timeout we want to set, in seconds
**/
gboolean
gpm_idle_set_timeout_blank (GpmIdle *idle, guint timeout)
{
g_return_val_if_fail (GPM_IS_IDLE (idle), FALSE);
g_debug ("Setting blank idle timeout: %ds", timeout);
if (idle->priv->timeout_blank != timeout) {
idle->priv->timeout_blank = timeout;
gpm_idle_evaluate (idle);
}
return TRUE;
}
/**
* gpm_idle_set_timeout_sleep:
* @timeout: The new timeout we want to set, in seconds
**/
gboolean
gpm_idle_set_timeout_sleep (GpmIdle *idle, guint timeout)
{
g_return_val_if_fail (GPM_IS_IDLE (idle), FALSE);
g_debug ("Setting sleep idle timeout: %ds", timeout);
if (idle->priv->timeout_sleep != timeout) {
idle->priv->timeout_sleep = timeout;
gpm_idle_evaluate (idle);
}
return TRUE;
}
/**
* gpm_idle_session_idle_changed_cb:
* @is_idle: If the session is idle
*
* The SessionIdleChanged callback from mate-session.
**/
static void
gpm_idle_session_idle_changed_cb (GpmSession *session, gboolean is_idle, GpmIdle *idle)
{
g_debug ("Received mate session idle changed: %i", is_idle);
idle->priv->x_idle = is_idle;
gpm_idle_evaluate (idle);
}
/**
* gpm_idle_session_inhibited_changed_cb:
**/
static void
gpm_idle_session_inhibited_changed_cb (GpmSession *session, gboolean is_idle_inhibited, gboolean is_suspend_inhibited, GpmIdle *idle)
{
g_debug ("Received mate session inhibited changed: idle=(%i), suspend=(%i)", is_idle_inhibited, is_suspend_inhibited);
gpm_idle_evaluate (idle);
}
/**
* gpm_idle_idletime_alarm_expired_cb:
*
* We're idle, something timed out
**/
static void
gpm_idle_idletime_alarm_expired_cb (EggIdletime *idletime, guint alarm_id, GpmIdle *idle)
{
g_debug ("idletime alarm: %i", alarm_id);
/* set again */
idle->priv->x_idle = TRUE;
gpm_idle_evaluate (idle);
}
/**
* gpm_idle_idletime_reset_cb:
*
* We're no longer idle, the user moved
**/
static void
gpm_idle_idletime_reset_cb (EggIdletime *idletime, GpmIdle *idle)
{
g_debug ("idletime reset");
idle->priv->x_idle = FALSE;
gpm_idle_evaluate (idle);
}
/**
* gpm_idle_finalize:
* @object: This class instance
**/
static void
gpm_idle_finalize (GObject *object)
{
GpmIdle *idle;
g_return_if_fail (object != NULL);
g_return_if_fail (GPM_IS_IDLE (object));
idle = GPM_IDLE (object);
g_return_if_fail (idle->priv != NULL);
if (idle->priv->timeout_blank_id != 0) {
g_source_remove (idle->priv->timeout_blank_id);
idle->priv->timeout_blank_id = 0;
}
if (idle->priv->timeout_sleep_id != 0) {
g_source_remove (idle->priv->timeout_sleep_id);
idle->priv->timeout_sleep_id = 0;
}
g_object_unref (idle->priv->load);
g_object_unref (idle->priv->session);
egg_idletime_alarm_remove (idle->priv->idletime, GPM_IDLE_IDLETIME_ID);
g_object_unref (idle->priv->idletime);
G_OBJECT_CLASS (gpm_idle_parent_class)->finalize (object);
}
/**
* gpm_idle_class_init:
* @klass: This class instance
**/
static void
gpm_idle_class_init (GpmIdleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gpm_idle_finalize;
signals [IDLE_CHANGED] =
g_signal_new ("idle-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GpmIdleClass, idle_changed),
NULL, NULL, g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1, G_TYPE_INT);
}
/**
* gpm_idle_init:
*
* Gets a DBUS connection, and aquires the session connection so we can
* get session changed events.
*
**/
static void
gpm_idle_init (GpmIdle *idle)
{
idle->priv = gpm_idle_get_instance_private (idle);
idle->priv->timeout_dim = G_MAXUINT;
idle->priv->timeout_blank = G_MAXUINT;
idle->priv->timeout_sleep = G_MAXUINT;
idle->priv->timeout_blank_id = 0;
idle->priv->timeout_sleep_id = 0;
idle->priv->x_idle = FALSE;
idle->priv->load = gpm_load_new ();
idle->priv->session = gpm_session_new ();
g_signal_connect (idle->priv->session, "idle-changed", G_CALLBACK (gpm_idle_session_idle_changed_cb), idle);
g_signal_connect (idle->priv->session, "inhibited-changed", G_CALLBACK (gpm_idle_session_inhibited_changed_cb), idle);
idle->priv->idletime = egg_idletime_new ();
g_signal_connect (idle->priv->idletime, "reset", G_CALLBACK (gpm_idle_idletime_reset_cb), idle);
g_signal_connect (idle->priv->idletime, "alarm-expired", G_CALLBACK (gpm_idle_idletime_alarm_expired_cb), idle);
gpm_idle_evaluate (idle);
}
/**
* gpm_idle_new:
* Return value: A new GpmIdle instance.
**/
GpmIdle *
gpm_idle_new (void)
{
if (gpm_idle_object != NULL) {
g_object_ref (gpm_idle_object);
} else {
gpm_idle_object = g_object_new (GPM_TYPE_IDLE, NULL);
g_object_add_weak_pointer (gpm_idle_object, &gpm_idle_object);
}
return GPM_IDLE (gpm_idle_object);
}
/***************************************************************************
*** MAKE CHECK TESTS ***
***************************************************************************/
#ifdef EGG_TEST
#include "egg-test.h"
#include "gpm-dpms.h"
static GpmIdleMode _mode = 0;
static void
gpm_idle_test_idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, EggTest *test)
{
_mode = mode;
g_debug ("idle-changed %s", gpm_idle_mode_to_string (mode));
egg_test_loop_quit (test);
}
static gboolean
gpm_idle_test_delay_cb (EggTest *test)
{
g_warning ("timing out");
egg_test_loop_quit (test);
return FALSE;
}
void
gpm_idle_test (gpointer data)
{
GpmIdle *idle;
gboolean ret;
EggTest *test = (EggTest *) data;
GpmIdleMode mode;
GpmDpms *dpms;
if (!egg_test_start (test, "GpmIdle"))
return;
/************************************************************/
egg_test_title (test, "get object");
idle = gpm_idle_new ();
if (idle != NULL)
egg_test_success (test, NULL);
else
egg_test_failed (test, "got no object");
/* set up defaults */
gpm_idle_set_check_cpu (idle, FALSE);
gpm_idle_set_timeout_dim (idle, 4);
gpm_idle_set_timeout_blank (idle, 5);
gpm_idle_set_timeout_sleep (idle, 15);
g_signal_connect (idle, "idle-changed",
G_CALLBACK (gpm_idle_test_idle_changed_cb), test);
/************************************************************/
egg_test_title (test, "check cpu type");
egg_test_assert (test, (idle->priv->check_type_cpu == FALSE));
/************************************************************/
egg_test_title (test, "check timeout dim");
egg_test_assert (test, (idle->priv->timeout_dim == 4));
/************************************************************/
egg_test_title (test, "check timeout blank");
egg_test_assert (test, (idle->priv->timeout_blank == 5));
/************************************************************/
egg_test_title (test, "check timeout sleep");
egg_test_assert (test, (idle->priv->timeout_sleep == 15));
/************************************************************/
egg_test_title (test, "check x_idle");
egg_test_assert (test, (idle->priv->x_idle == FALSE));
/************************************************************/
egg_test_title (test, "check blank id");
egg_test_assert (test, (idle->priv->timeout_blank_id == 0));
/************************************************************/
egg_test_title (test, "check sleep id");
egg_test_assert (test, (idle->priv->timeout_sleep_id == 0));
/************************************************************/
egg_test_title (test, "check normal at startup");
mode = gpm_idle_get_mode (idle);
if (mode == GPM_IDLE_MODE_NORMAL)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
g_print ("*****************************\n");
g_print ("*** DO NOT MOVE THE MOUSE ***\n");
g_print ("*****************************\n");
egg_test_loop_wait (test, 2000 + 10000);
egg_test_loop_check (test);
/************************************************************/
egg_test_title (test, "check callback mode");
if (_mode == GPM_IDLE_MODE_DIM)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
egg_test_title (test, "check current mode");
mode = gpm_idle_get_mode (idle);
if (mode == GPM_IDLE_MODE_DIM)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
egg_test_title (test, "check x_idle");
egg_test_assert (test, (idle->priv->x_idle == TRUE));
/************************************************************/
egg_test_title (test, "check blank id");
egg_test_assert (test, (idle->priv->timeout_blank_id != 0));
/************************************************************/
egg_test_title (test, "check sleep id");
egg_test_assert (test, (idle->priv->timeout_sleep_id == 0));
/************************************************************/
egg_test_loop_wait (test, 5000 + 1000);
egg_test_loop_check (test);
/************************************************************/
egg_test_title (test, "check callback mode");
if (_mode == GPM_IDLE_MODE_BLANK)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
egg_test_title (test, "check current mode");
mode = gpm_idle_get_mode (idle);
if (mode == GPM_IDLE_MODE_BLANK)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
g_print ("**********************\n");
g_print ("*** MOVE THE MOUSE ***\n");
g_print ("**********************\n");
egg_test_loop_wait (test, G_MAXUINT);
egg_test_loop_check (test);
/************************************************************/
egg_test_title (test, "check callback mode");
if (_mode == GPM_IDLE_MODE_NORMAL)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
egg_test_title (test, "check current mode");
mode = gpm_idle_get_mode (idle);
if (mode == GPM_IDLE_MODE_NORMAL)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
egg_test_title (test, "check x_idle");
egg_test_assert (test, (idle->priv->x_idle == FALSE));
/************************************************************/
egg_test_title (test, "check blank id");
egg_test_assert (test, (idle->priv->timeout_blank_id == 0));
/************************************************************/
g_print ("*****************************\n");
g_print ("*** DO NOT MOVE THE MOUSE ***\n");
g_print ("*****************************\n");
egg_test_loop_wait (test, 4000 + 1500);
egg_test_loop_check (test);
/************************************************************/
egg_test_title (test, "check current mode");
mode = gpm_idle_get_mode (idle);
if (mode == GPM_IDLE_MODE_DIM)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
egg_test_title (test, "check x_idle");
egg_test_assert (test, (idle->priv->x_idle == TRUE));
egg_test_loop_wait (test, 15000);
egg_test_loop_check (test);
/************************************************************/
egg_test_title (test, "check current mode");
mode = gpm_idle_get_mode (idle);
if (mode == GPM_IDLE_MODE_BLANK)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
egg_test_title (test, "set dpms off");
dpms = gpm_dpms_new ();
ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_OFF, NULL);
egg_test_assert (test, ret);
/* wait for normal event to be suppressed */
g_timeout_add (2000, (GSourceFunc) gpm_idle_test_delay_cb, test);
egg_test_loop_wait (test, G_MAXUINT);
egg_test_loop_check (test);
/************************************************************/
egg_test_title (test, "check current mode");
mode = gpm_idle_get_mode (idle);
if (mode == GPM_IDLE_MODE_BLANK)
egg_test_success (test, NULL);
else
egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
/************************************************************/
egg_test_title (test, "check x_idle");
egg_test_assert (test, (idle->priv->x_idle == TRUE));
gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, NULL);
g_object_unref (idle);
g_object_unref (dpms);
egg_test_end (test);
}
#endif
|