summaryrefslogtreecommitdiffstats
path: root/opensuse/tdebase/suspend-kpowersave.diff
blob: 13aaa131ca5f604da929e20c658020f6809f1197 (plain)
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
Subject: Use KPowersave for suspend if available
From: Lubos Lunak
Bug: bnc#326848
Patch-upstream: No

--- kicker/kicker/ui/k_new_mnu.cpp.sav	2008-11-20 10:12:42.000000000 +0100
+++ kicker/kicker/ui/k_new_mnu.cpp	2008-11-20 13:49:20.000000000 +0100
@@ -3691,6 +3691,9 @@ int KMenu::max_items(int category) const
 
 #ifdef KDELIBS_SUSE
 #include <liblazy.h>
+
+#include <X11/Xlib.h>
+#include <fixx11h.h>
 #endif
 
 void KMenu::insertSuspendOption( int &nId, int &index )
@@ -3699,6 +3702,14 @@ void KMenu::insertSuspendOption( int &nI
     int supported = -1;
     bool suspend_ram, suspend_disk, standby;
 
+    DCOPRef kpowersave( "kpowersave", "KPowersaveIface" );
+    DCOPReply reply = kpowersave.call( "allowed_sleepingStates" );
+    if( reply.isValid()) {
+        QStringList supported = reply;
+        suspend_ram = supported.contains( "suspendToRAM" );
+        suspend_disk = supported.contains( "suspendToDisk" );
+        standby = supported.contains( "standBy" );
+    } else {
     liblazy_hal_get_property_bool(HAL_UDI_COMPUTER, "power_management.can_suspend", &supported);
     if (supported == 1)
         suspend_ram = true;
@@ -3721,6 +3732,7 @@ void KMenu::insertSuspendOption( int &nI
 	     suspend_ram = false;
 	if (liblazy_hal_is_caller_privileged("org.freedesktop.hal.power-management.standby") != 1)
 	    standby = false;
+    }
 
 	if ( ! ( standby + suspend_ram + suspend_disk ) )
             return;
@@ -3745,6 +3757,25 @@ void KMenu::slotSuspend(int id)
 {
 #ifdef KDELIBS_SUSE
     int error = 0;
+
+    DCOPRef kpowersave( "kpowersave", "KPowersaveIface" );
+    DCOPReply reply = kpowersave.call( "allowed_sleepingStates" );
+    if( reply.isValid()) {
+	bool ok;
+	extern Time qt_x_time;
+	XUngrabKeyboard( qt_xdisplay(), qt_x_time );
+	XUngrabPointer( qt_xdisplay(), qt_x_time );
+	XSync( qt_xdisplay(), False );
+	if( id == 1 )
+	    ok = kpowersave.call( "do_suspendToDisk" );
+	else if( id == 2 )
+	    ok = kpowersave.call( "do_suspendToRAM" );
+	else if( id == 3 )
+	    ok = kpowersave.call( "do_standBy" );
+	else
+	    return;
+	error = ok ? 0 : 1;
+    } else {
     int wake = 0;
     DBusMessage *reply = 0;
 
@@ -3773,6 +3804,8 @@ void KMenu::slotSuspend(int id)
                                                      DBUS_TYPE_INVALID);
     else
         return;
+    }
+
     if (error)
 #endif
         KMessageBox::error(this, i18n("Suspend failed"));
--- ksmserver/shutdowndlg.cpp.sav	2008-11-20 10:12:41.000000000 +0100
+++ ksmserver/shutdowndlg.cpp	2008-11-20 13:34:19.000000000 +0100
@@ -40,6 +40,7 @@ Copyright (C) 2000 Matthias Ettrich <ett
 #include <kdialog.h>
 #include <kseparator.h>
 #include <kmessagebox.h>
+#include <dcopref.h>
 
 #include <sys/types.h>
 #include <sys/utsname.h>
@@ -264,6 +265,14 @@ KSMShutdownDlg::KSMShutdownDlg( QWidget*
 	} else
             QToolTip::add( btnReboot, i18n( "<qt><h3>Restart Computer</h3><p>Log out of the current session and restart the computer</p></qt>" ) );
 
+	DCOPRef kpowersave( "kpowersave", "KPowersaveIface" );
+	DCOPReply reply = kpowersave.call( "allowed_sleepingStates" );
+	if( reply.isValid()) {
+	    QStringList supported = reply;
+	    suspend_ram = supported.contains( "suspendToRAM" );
+	    suspend_disk = supported.contains( "suspendToDisk" );
+	    standby = supported.contains( "standBy" );
+	} else {
 	int supported = -1;
 	liblazy_hal_get_property_bool(HAL_UDI_COMPUTER, "power_management.can_suspend", &supported);
 	if (supported == 1)
@@ -287,6 +296,7 @@ KSMShutdownDlg::KSMShutdownDlg( QWidget*
 	     suspend_ram = false;
 	if (liblazy_hal_is_caller_privileged("org.freedesktop.hal.power-management.standby") != 1) 
 	    standby = false;
+	}
 	
 	int sum = standby + suspend_ram + suspend_disk;
 	if ( sum ) {
@@ -325,6 +335,24 @@ KSMShutdownDlg::KSMShutdownDlg( QWidget*
 void KSMShutdownDlg::slotSuspend()
 {
   int error = 0;
+    DCOPRef kpowersave( "kpowersave", "KPowersaveIface" );
+    DCOPReply reply = kpowersave.call( "allowed_sleepingStates" );
+    if( reply.isValid()) {
+	bool ok;
+	// so that screen locking can take place
+	extern Time qt_x_time;
+	XUngrabKeyboard( qt_xdisplay(), qt_x_time );
+	XUngrabPointer( qt_xdisplay(), qt_x_time );
+	XSync( qt_xdisplay(), False );
+	if( suspend_disk )
+	    ok = kpowersave.call( "do_suspendToDisk" );
+	else if( suspend_ram )
+	    ok = kpowersave.call( "do_suspendToRAM" );
+	else
+	    ok = kpowersave.call( "do_standBy" );
+	error = ok ? 0 : 1;
+    } else {
+  
   int wake = 0;
   DBusMessage *reply;
 
@@ -351,6 +379,7 @@ void KSMShutdownDlg::slotSuspend()
 						    "Standby",
 						    &reply,
 						    DBUS_TYPE_INVALID);
+    }
   
   if (error)
        KMessageBox::error(this, i18n("Suspend failed"));
@@ -362,6 +391,27 @@ void KSMShutdownDlg::slotSuspend()
 void KSMShutdownDlg::slotSuspend(int id)
 {
   int error = 0;
+
+    DCOPRef kpowersave( "kpowersave", "KPowersaveIface" );
+    DCOPReply reply = kpowersave.call( "allowed_sleepingStates" );
+    if( reply.isValid()) {
+	bool ok;
+	extern Time qt_x_time;
+	XUngrabKeyboard( qt_xdisplay(), qt_x_time );
+	XUngrabPointer( qt_xdisplay(), qt_x_time );
+	XSync( qt_xdisplay(), False );
+	if( suspend_disk && id == 1 )
+	    ok = kpowersave.call( "do_suspendToDisk" );
+	else if( suspend_ram && id == 2 )
+	    ok = kpowersave.call( "do_suspendToRAM" );
+	else if( standby && id == 3 )
+	    ok = kpowersave.call( "do_standBy" );
+	else
+	    return;
+	error = ok ? 0 : 1;
+    } else {
+
+
   int wake = 0;
   DBusMessage *reply;
 
@@ -390,6 +440,8 @@ void KSMShutdownDlg::slotSuspend(int id)
 						  DBUS_TYPE_INVALID);
   else
        return;
+    }
+
   if (error)
        KMessageBox::error(this, i18n("Suspend failed"));