This is an automated email from the git hooks/post-receive script.

ochosi pushed a 
commit to branch 
master
in repository xfce/xfce4-power-manager.

commit ebb984e33b6daf6ce320140ff4c31d533d6a3cee
Author: Viktor Odintsev <nine...@xfce.org>
Date:   Mon Dec 4 14:15:31 2017 +0300

    Add support for XF86Battery button (Bug #14055)
---
 common/xfpm-config.h             |  1 +
 common/xfpm-enum.h               |  3 +-
 data/interfaces/xfpm-settings.ui | 34 ++++++++++++++-
 settings/xfpm-settings-app.c     |  4 +-
 settings/xfpm-settings.c         | 91 +++++++++++++++++++++++++++++++++++++---
 settings/xfpm-settings.h         |  1 +
 src/xfpm-button.c                |  7 ++--
 src/xfpm-button.h                |  2 +-
 src/xfpm-main.c                  |  4 ++
 src/xfpm-manager.c               | 12 +++++-
 src/xfpm-xfconf.c                | 13 ++++++
 11 files changed, 158 insertions(+), 14 deletions(-)

diff --git a/common/xfpm-config.h b/common/xfpm-config.h
index da0ff89..35f646d 100644
--- a/common/xfpm-config.h
+++ b/common/xfpm-config.h
@@ -60,6 +60,7 @@ G_BEGIN_DECLS
 #define POWER_SWITCH_CFG                     "power-button-action"
 #define HIBERNATE_SWITCH_CFG                 "hibernate-button-action"
 #define SLEEP_SWITCH_CFG                     "sleep-button-action"
+#define BATTERY_SWITCH_CFG                   "battery-button-action"
 #define LID_SWITCH_ON_AC_CFG                 "lid-action-on-ac"
 #define LID_SWITCH_ON_BATTERY_CFG            "lid-action-on-battery"
 
diff --git a/common/xfpm-enum.h b/common/xfpm-enum.h
index 0146f6e..ce5d5f7 100644
--- a/common/xfpm-enum.h
+++ b/common/xfpm-enum.h
@@ -47,7 +47,8 @@ typedef enum
     HIBERNATE_KEY              = (1 << 4),
     POWER_KEY                  = (1 << 5),
     KBD_BRIGHTNESS_KEY_UP      = (1 << 6),
-    KBD_BRIGHTNESS_KEY_DOWN    = (1 << 7)
+    KBD_BRIGHTNESS_KEY_DOWN    = (1 << 7),
+    BATTERY_KEY                 = (1 << 8)
 
 } XfpmKeys;
 
diff --git a/data/interfaces/xfpm-settings.ui b/data/interfaces/xfpm-settings.ui
index 143d1d2..bd09980 100644
--- a/data/interfaces/xfpm-settings.ui
+++ b/data/interfaces/xfpm-settings.ui
@@ -345,6 +345,18 @@
                                   </packing>
                                 </child>
                                 <child>
+                                  <object class="GtkLabel" 
id="button-battery-label">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="xalign">0</property>
+                                    <property name="label" 
translatable="yes">When battery button is pressed:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">0</property>
+                                    <property name="top_attach">3</property>
+                                  </packing>
+                                </child>
+                                <child>
                                   <object class="GtkComboBox" 
id="button-power-combo">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
@@ -399,6 +411,24 @@
                                   </packing>
                                 </child>
                                 <child>
+                                  <object class="GtkComboBox" 
id="button-battery-combo">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="hexpand">True</property>
+                                    <signal name="changed" 
handler="button_battery_changed_cb" swapped="no"/>
+                                    <child>
+                                      <object class="GtkCellRendererText" 
id="renderer5"/>
+                                      <attributes>
+                                        <attribute name="text">0</attribute>
+                                      </attributes>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="top_attach">3</property>
+                                  </packing>
+                                </child>
+                                <child>
                                   <object class="GtkSwitch" 
id="handle-brightness-keys">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
@@ -406,7 +436,7 @@
                                   </object>
                                   <packing>
                                     <property name="left_attach">1</property>
-                                    <property name="top_attach">3</property>
+                                    <property name="top_attach">4</property>
                                   </packing>
                                 </child>
                                 <child>
@@ -420,7 +450,7 @@
                                   </object>
                                   <packing>
                                     <property name="left_attach">0</property>
-                                    <property name="top_attach">3</property>
+                                    <property name="top_attach">4</property>
                                   </packing>
                                 </child>
                               </object>
diff --git a/settings/xfpm-settings-app.c b/settings/xfpm-settings-app.c
index 790e22d..72c48a1 100644
--- a/settings/xfpm-settings-app.c
+++ b/settings/xfpm-settings-app.c
@@ -140,6 +140,7 @@ xfpm_settings_app_launch (GApplication *app)
     gboolean has_sleep_button;
     gboolean has_hibernate_button;
     gboolean has_power_button;
+    gboolean has_battery_button;
     gboolean has_lid;
     gint     start_xfpm_if_not_running;
 
@@ -250,6 +251,7 @@ xfpm_settings_app_launch (GApplication *app)
     has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"sleep-button"));
     has_power_button = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"power-button"));
     has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"hibernate-button"));
+    has_battery_button = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"battery-button"));
     can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"can-shutdown"));
 
     DBG("socket_id %i", (int)priv->socket_id);
@@ -257,7 +259,7 @@ xfpm_settings_app_launch (GApplication *app)
 
     dialog = xfpm_settings_dialog_new (channel, auth_suspend, auth_hibernate,
                                        can_suspend, can_hibernate, 
can_shutdown, has_battery, has_lcd_brightness,
-                                       has_lid, has_sleep_button, 
has_hibernate_button, has_power_button,
+                                       has_lid, has_sleep_button, 
has_hibernate_button, has_power_button, has_battery_button,
                                        priv->socket_id, priv->device_id, 
GTK_APPLICATION (app));
 
     g_hash_table_destroy (hash);
diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
index 4bdda9c..6d3a4f0 100644
--- a/settings/xfpm-settings.c
+++ b/settings/xfpm-settings.c
@@ -125,6 +125,9 @@ void        button_power_changed_cb                 
(GtkWidget *w,
 void        button_hibernate_changed_cb            (GtkWidget *w, 
                                                    XfconfChannel *channel);
 
+void        button_battery_changed_cb              (GtkWidget *w,
+                                                    XfconfChannel *channel);
+
 void        on_sleep_mode_changed_cb      (GtkWidget *w,
                                                    XfconfChannel *channel);
 
@@ -347,6 +350,30 @@ button_hibernate_changed_cb (GtkWidget *w, XfconfChannel 
*channel)
 }
 
 void
+button_battery_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    GtkTreeModel     *model;
+    GtkTreeIter       selected_row;
+    gint value = 0;
+
+    if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+        return;
+
+    model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+
+    gtk_tree_model_get(model,
+                       &selected_row,
+                       1,
+                       &value,
+                       -1);
+
+    if (!xfconf_channel_set_uint (channel, PROPERTIES_PREFIX 
BATTERY_SWITCH_CFG, value ) )
+    {
+        g_critical ("Cannot set value for property %s\n", BATTERY_SWITCH_CFG);
+    }
+}
+
+void
 on_ac_sleep_mode_changed_cb (GtkWidget *w, XfconfChannel *channel)
 {
     GtkTreeModel     *model;
@@ -1224,7 +1251,7 @@ xfpm_settings_general (XfconfChannel *channel, gboolean 
auth_suspend,
                        gboolean auth_hibernate, gboolean can_suspend,
                        gboolean can_hibernate, gboolean can_shutdown,
                        gboolean has_sleep_button, gboolean 
has_hibernate_button,
-                       gboolean has_power_button)
+                       gboolean has_power_button, gboolean has_battery_button)
 {
     GtkWidget *power;
     GtkWidget *power_label;
@@ -1232,6 +1259,8 @@ xfpm_settings_general (XfconfChannel *channel, gboolean 
auth_suspend,
     GtkWidget *hibernate_label;
     GtkWidget *sleep_w;
     GtkWidget *sleep_label;
+    GtkWidget *battery_w;
+    GtkWidget *battery_label;
     GtkWidget *dpms;
 
     guint  value;
@@ -1409,6 +1438,57 @@ xfpm_settings_general (XfconfChannel *channel, gboolean 
auth_suspend,
        gtk_widget_hide (sleep_w);
        gtk_widget_hide (sleep_label);
     }
+
+    /*
+     * Battery button
+     */
+    list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+    battery_w = GTK_WIDGET (gtk_builder_get_object (xml, 
"button-battery-combo"));
+    battery_label = GTK_WIDGET (gtk_builder_get_object (xml, 
"button-battery-label"));
+
+    if ( has_battery_button )
+    {
+        gtk_combo_box_set_model (GTK_COMBO_BOX(battery_w), 
GTK_TREE_MODEL(list_store));
+
+        gtk_list_store_append (list_store, &iter);
+        gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, 
XFPM_DO_NOTHING, -1);
+
+        if ( can_suspend && auth_suspend )
+        {
+            gtk_list_store_append (list_store, &iter);
+            gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, 
XFPM_DO_SUSPEND, -1);
+        }
+
+        if ( can_hibernate && auth_hibernate)
+        {
+            gtk_list_store_append (list_store, &iter);
+            gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, 
XFPM_DO_HIBERNATE, -1);
+        }
+
+        gtk_list_store_append (list_store, &iter);
+        gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
+
+        gtk_combo_box_set_active (GTK_COMBO_BOX (battery_w), 0);
+
+        value = xfconf_channel_get_uint (channel, PROPERTIES_PREFIX 
BATTERY_SWITCH_CFG, XFPM_DO_NOTHING);
+        for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL 
(list_store), &iter);
+              valid;
+              valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), 
&iter) )
+        {
+            gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+                                1, &list_value, -1);
+            if ( value == list_value )
+            {
+                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (battery_w), 
&iter);
+                break;
+            }
+        }
+    }
+    else
+    {
+        gtk_widget_hide (battery_w);
+        gtk_widget_hide (battery_label);
+    }
 }
 
 static void
@@ -2178,7 +2258,8 @@ xfpm_settings_dialog_new (XfconfChannel *channel, 
gboolean auth_suspend,
                           gboolean has_battery, gboolean has_lcd_brightness,
                           gboolean has_lid, gboolean has_sleep_button,
                           gboolean has_hibernate_button, gboolean 
has_power_button,
-                          Window id, gchar *device_id, GtkApplication *gtk_app)
+                          gboolean has_battery_button,  Window id, gchar 
*device_id,
+                          GtkApplication *gtk_app)
 {
     GtkWidget *plug;
     GtkWidget *parent;
@@ -2197,13 +2278,13 @@ xfpm_settings_dialog_new (XfconfChannel *channel, 
gboolean auth_suspend,
 
     XFPM_DEBUG ("auth_hibernate=%s auth_suspend=%s can_shutdown=%s 
can_suspend=%s can_hibernate=%s " \
                 "has_battery=%s has_lcd_brightness=%s has_lid=%s 
has_sleep_button=%s " \
-                "has_hibernate_button=%s has_power_button=%s",
+                "has_hibernate_button=%s has_power_button=%s 
has_battery_button=%s",
       xfpm_bool_to_string (has_battery), xfpm_bool_to_string (auth_hibernate),
          xfpm_bool_to_string (can_shutdown), xfpm_bool_to_string 
(auth_suspend),
          xfpm_bool_to_string (can_suspend), xfpm_bool_to_string 
(can_hibernate),
          xfpm_bool_to_string (has_lcd_brightness), xfpm_bool_to_string 
(has_lid),
          xfpm_bool_to_string (has_sleep_button), xfpm_bool_to_string 
(has_hibernate_button),
-         xfpm_bool_to_string (has_power_button));
+         xfpm_bool_to_string (has_power_button), xfpm_bool_to_string 
(has_battery_button));
 
     xml = xfpm_builder_new_from_string (xfpm_settings_ui, &error);
     
@@ -2341,7 +2422,7 @@ xfpm_settings_dialog_new (XfconfChannel *channel, 
gboolean auth_suspend,
     }
     
     xfpm_settings_general (channel, auth_suspend, auth_hibernate, can_suspend, 
can_hibernate, can_shutdown,
-                           has_sleep_button, has_hibernate_button, 
has_power_button );
+                           has_sleep_button, has_hibernate_button, 
has_power_button, has_battery_button);
 
     xfpm_settings_advanced (channel, auth_suspend, auth_hibernate, 
can_suspend, can_hibernate, has_battery);
 
diff --git a/settings/xfpm-settings.h b/settings/xfpm-settings.h
index 25e5630..1588849 100644
--- a/settings/xfpm-settings.h
+++ b/settings/xfpm-settings.h
@@ -36,6 +36,7 @@ GtkWidget *xfpm_settings_dialog_new (XfconfChannel *channel,
                                      gboolean has_sleep_button,
                                      gboolean has_hibernate_button,
                                      gboolean has_power_button,
+                                     gboolean has_battery_button,
                                      Window id,
                                      gchar *device_id,
                                      GtkApplication *gtk_app);
diff --git a/src/xfpm-button.c b/src/xfpm-button.c
index 3f8f966..dcf639c 100644
--- a/src/xfpm-button.c
+++ b/src/xfpm-button.c
@@ -68,7 +68,7 @@ struct XfpmButtonPrivate
     GdkScreen  *screen;
     GdkWindow   *window;
     
-    guint8       mapped_buttons;
+    guint16      mapped_buttons;
 };
 
 enum
@@ -216,7 +216,8 @@ xfpm_button_setup (XfpmButton *button)
     if (xfpm_button_xevent_key (button, XF86XK_MonBrightnessDown, 
BUTTON_MON_BRIGHTNESS_DOWN) )
        button->priv->mapped_buttons |= BRIGHTNESS_KEY_DOWN;
        
-    xfpm_button_xevent_key (button, XF86XK_Battery, BUTTON_BATTERY);
+    if (xfpm_button_xevent_key (button, XF86XK_Battery, BUTTON_BATTERY))
+        button->priv->mapped_buttons |= BATTERY_KEY;
 
     if ( xfpm_button_xevent_key (button, XF86XK_KbdBrightnessUp, 
BUTTON_KBD_BRIGHTNESS_UP) )
        button->priv->mapped_buttons |= KBD_BRIGHTNESS_KEY_UP;
@@ -283,7 +284,7 @@ xfpm_button_new (void)
     return XFPM_BUTTON (xfpm_button_object);
 }
 
-guint8 xfpm_button_get_mapped (XfpmButton *button)
+guint16 xfpm_button_get_mapped (XfpmButton *button)
 {
     g_return_val_if_fail (XFPM_IS_BUTTON (button), 0);
     
diff --git a/src/xfpm-button.h b/src/xfpm-button.h
index fc9bd97..11ed187 100644
--- a/src/xfpm-button.h
+++ b/src/xfpm-button.h
@@ -53,7 +53,7 @@ GType                                 xfpm_button_get_type    
                (void) G_GNUC_CONST;
 
 XfpmButton                    *xfpm_button_new                         (void);
 
-guint8                         xfpm_button_get_mapped                  
(XfpmButton *button) G_GNUC_PURE;
+guint16                        xfpm_button_get_mapped                  
(XfpmButton *button) G_GNUC_PURE;
 
 G_END_DECLS
 
diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index ab2e179..6e60d2f 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -90,6 +90,7 @@ xfpm_dump (GHashTable *hash)
     gboolean has_sleep_button;
     gboolean has_hibernate_button;
     gboolean has_power_button;
+    gboolean has_battery_button;
     gboolean has_lid;
     
     has_battery = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"has-battery"));
@@ -102,6 +103,7 @@ xfpm_dump (GHashTable *hash)
     has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"sleep-button"));
     has_power_button = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"power-button"));
     has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"hibernate-button"));
+    has_battery_button = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"battery-button"));
     can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (hash, 
"can-shutdown"));
        
     g_print ("---------------------------------------------------\n");
@@ -148,6 +150,8 @@ xfpm_dump (GHashTable *hash)
             xfpm_bool_to_local_string (has_hibernate_button),
             _("Has sleep button"),
              xfpm_bool_to_local_string (has_sleep_button),
+             _("Has battery button"),
+              xfpm_bool_to_local_string (has_battery_button),
             _("Has LID"),
              xfpm_bool_to_local_string (has_lid));
 }
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index 2b52eb5..1890058 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -392,6 +392,12 @@ xfpm_manager_button_pressed_cb (XfpmButton *bt, 
XfpmButtonKey type, XfpmManager
                       HIBERNATE_SWITCH_CFG, &req,
                       NULL);
     }
+    else if ( type == BUTTON_BATTERY )
+    {
+        g_object_get (G_OBJECT (manager->priv->conf),
+                      BATTERY_SWITCH_CFG, &req,
+                      NULL);
+    }
     else
     {
         g_return_if_reached ();
@@ -945,7 +951,7 @@ GHashTable *xfpm_manager_get_config (XfpmManager *manager)
 {
     GHashTable *hash;
 
-    guint8 mapped_buttons;
+    guint16 mapped_buttons;
     gboolean auth_hibernate = FALSE;
     gboolean auth_suspend = FALSE;
     gboolean can_suspend = FALSE;
@@ -953,6 +959,7 @@ GHashTable *xfpm_manager_get_config (XfpmManager *manager)
     gboolean has_sleep_button = FALSE;
     gboolean has_hibernate_button = FALSE;
     gboolean has_power_button = FALSE;
+    gboolean has_battery_button = FALSE;
     gboolean has_battery = TRUE;
     gboolean has_lcd_brightness = TRUE;
     gboolean can_shutdown = TRUE;
@@ -992,10 +999,13 @@ GHashTable *xfpm_manager_get_config (XfpmManager *manager)
         has_hibernate_button = TRUE;
     if ( mapped_buttons & POWER_KEY )
         has_power_button = TRUE;
+    if ( mapped_buttons & BATTERY_KEY )
+        has_battery_button = TRUE;
 
     g_hash_table_insert (hash, g_strdup ("sleep-button"), g_strdup 
(xfpm_bool_to_string (has_sleep_button)));
     g_hash_table_insert (hash, g_strdup ("power-button"), g_strdup 
(xfpm_bool_to_string (has_power_button)));
     g_hash_table_insert (hash, g_strdup ("hibernate-button"), g_strdup 
(xfpm_bool_to_string (has_hibernate_button)));
+    g_hash_table_insert (hash, g_strdup ("battery-button"), g_strdup 
(xfpm_bool_to_string (has_battery_button)));
     g_hash_table_insert (hash, g_strdup ("auth-suspend"), g_strdup 
(xfpm_bool_to_string (auth_suspend)));
     g_hash_table_insert (hash, g_strdup ("auth-hibernate"), g_strdup 
(xfpm_bool_to_string (auth_hibernate)));
     g_hash_table_insert (hash, g_strdup ("can-suspend"), g_strdup 
(xfpm_bool_to_string (can_suspend)));
diff --git a/src/xfpm-xfconf.c b/src/xfpm-xfconf.c
index 48ec992..1697266 100644
--- a/src/xfpm-xfconf.c
+++ b/src/xfpm-xfconf.c
@@ -65,6 +65,7 @@ enum
     PROP_POWER_BUTTON,
     PROP_HIBERNATE_BUTTON,
     PROP_SLEEP_BUTTON,
+    PROP_BATTERY_BUTTON,
     PROP_LID_ACTION_ON_AC,
     PROP_LID_ACTION_ON_BATTERY,
     PROP_BRIGHTNESS_LEVEL_ON_AC,
@@ -348,6 +349,18 @@ xfpm_xfconf_class_init (XfpmXfconfClass *klass)
                                                        XFPM_DO_SHUTDOWN,
                                                        XFPM_DO_NOTHING,
                                                         G_PARAM_READWRITE));
+
+    /**
+     * XfpmXfconf::battery-switch-action
+     **/
+    g_object_class_install_property (object_class,
+                                     PROP_BATTERY_BUTTON,
+                                     g_param_spec_uint (BATTERY_SWITCH_CFG,
+                                                        NULL, NULL,
+                                                        XFPM_DO_NOTHING,
+                                                        XFPM_DO_SHUTDOWN,
+                                                        XFPM_DO_NOTHING,
+                                                        G_PARAM_READWRITE));
     
     /**
      * XfpmXfconf::lid-action-on-ac

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
https://mail.xfce.org/mailman/listinfo/xfce4-commits

Reply via email to