1 Note: tiny modification (in place) at 1.26.0 to get the
2 gpm_manager_correct_policy(manager, &policy);
3 to apply after minor nearby changes.
5 We want to have 'hibernate/sleep' policy by default, when it's supported, but if suspend/hibernate is
6 not supported, we avoid doing anything excepting critical actions.
7 So we correct policy: set it to "Do nothing" when shutdown/hibernate/sleep is not supported and
8 set default policy for action-critical-battery to shutdown, as it has more chances to be supported.
10 diff -ur mate-power-manager-1.18.1-1/data/org.mate.power-manager.gschema.xml.in mate-power-manager-1.18.1/data/org.mate.power-manager.gschema.xml.in
11 --- mate-power-manager-1.18.1-1/data/org.mate.power-manager.gschema.xml.in 2018-01-16 11:29:39.040541678 +0000
12 +++ mate-power-manager-1.18.1/data/org.mate.power-manager.gschema.xml.in 2018-01-16 11:52:06.994940315 +0000
14 <description>The type of sleeping that should be performed when the computer is inactive.</description>
16 <key name="action-critical-battery" enum="org.mate.power-manager.ActionType">
17 - <default>'hibernate'</default>
18 + <default>'shutdown'</default>
19 <summary>Battery critical low action</summary>
20 <description>The action to take when the battery is critically low.</description>
22 diff -ur mate-power-manager-1.18.1-1/src/gpm-manager.c mate-power-manager-1.18.1/src/gpm-manager.c
23 --- mate-power-manager-1.18.1-1/src/gpm-manager.c 2018-01-16 11:29:39.046702244 +0000
24 +++ mate-power-manager-1.18.1/src/gpm-manager.c 2018-01-16 12:04:22.087910646 +0000
30 +gpm_manager_correct_policy(GpmManager *manager, GpmActionPolicy *policy)
32 + gboolean allowed = FALSE;
34 + if (*policy == GPM_ACTION_POLICY_SUSPEND) {
35 + egg_console_kit_can_suspend (manager->priv->console, &allowed, NULL);
36 + } else if (*policy == GPM_ACTION_POLICY_HIBERNATE) {
37 + egg_console_kit_can_hibernate (manager->priv->console, &allowed, NULL);
38 + } else if (*policy == GPM_ACTION_POLICY_SHUTDOWN) {
39 + egg_console_kit_can_stop(manager->priv->console, &allowed, NULL);
41 + if ((*policy == GPM_ACTION_POLICY_SUSPEND || *policy == GPM_ACTION_POLICY_HIBERNATE || *policy == GPM_ACTION_POLICY_SHUTDOWN)
42 + && (allowed == FALSE)){
43 + GpmActionPolicy old_policy;
45 + old_policy = *policy;
46 + *policy = GPM_ACTION_POLICY_NOTHING;
47 + g_debug ("corrected policy: set policy to %i (as %i is not supported or allowed)", *policy, old_policy);
52 * gpm_manager_perform_policy:
53 * @manager: This class instance
56 policy = g_settings_get_enum (manager->priv->settings, policy_key);
57 g_debug ("action: %s set to %i (%s)", policy_key, policy, reason);
59 + gpm_manager_correct_policy(manager, &policy);
61 if (policy == GPM_ACTION_POLICY_NOTHING) {
62 g_debug ("doing nothing, reason: %s", reason);
65 policy = g_settings_get_enum (manager->priv->settings, GPM_SETTINGS_ACTION_SLEEP_TYPE_BATT);
67 + gpm_manager_correct_policy(manager, &policy);
69 if (policy == GPM_ACTION_POLICY_NOTHING) {
70 egg_debug ("doing nothing as system idle action");
73 /* we have to do different warnings depending on the policy */
74 policy = g_settings_get_enum (manager->priv->settings, GPM_SETTINGS_ACTION_CRITICAL_BATT);
76 + gpm_manager_correct_policy(manager, &policy);
78 /* use different text for different actions */
79 if (policy == GPM_ACTION_POLICY_NOTHING) {
80 /* TRANSLATORS: tell the use to insert the plug, as we're not going to do anything */
82 /* we have to do different warnings depending on the policy */
83 policy = g_settings_get_enum (manager->priv->settings, GPM_SETTINGS_ACTION_CRITICAL_BATT);
85 + gpm_manager_correct_policy(manager, &policy);
87 /* use different text for different actions */
88 if (policy == GPM_ACTION_POLICY_NOTHING) {
89 /* TRANSLATORS: computer will shutdown without saving data */
90 diff -ur mate-power-manager-1.18.1-1/src/gpm-prefs-core.c mate-power-manager-1.18.1/src/gpm-prefs-core.c
91 --- mate-power-manager-1.18.1-1/src/gpm-prefs-core.c 2018-01-16 11:29:39.048575717 +0000
92 +++ mate-power-manager-1.18.1/src/gpm-prefs-core.c 2018-01-16 12:05:03.956736871 +0000
94 g_object_set_data (G_OBJECT (widget), "settings_key", (gpointer) gpm_pref_key);
95 g_signal_connect (G_OBJECT (widget), "changed",
96 G_CALLBACK (gpm_prefs_action_combo_changed_cb), prefs);
98 + if (value == GPM_ACTION_POLICY_SUSPEND && !prefs->priv->can_suspend ||
99 + value == GPM_ACTION_POLICY_HIBERNATE && !prefs->priv->can_hibernate ||
100 + value == GPM_ACTION_POLICY_SHUTDOWN && !prefs->priv->can_shutdown ) {
101 + value = GPM_ACTION_POLICY_NOTHING;
104 for (i=0; actions[i] != -1; i++) {