From: Leandro Lucarella Date: Fri, 27 Jul 2012 17:45:49 +0000 (+0200) Subject: Add display blanking inhibition button X-Git-Tag: v0.4~1 X-Git-Url: https://git.llucax.com/software/sadba.git/commitdiff_plain/816350dbbf32e6e8edf6c21749889c1f22397c29 Add display blanking inhibition button This new button inhibits display blanking without changing the display blanking mode. It uses the dbus interface to call the MCE request method to prevent blanking. --- diff --git a/data/display-blanking-inhibit-icon.png b/data/display-blanking-inhibit-icon.png new file mode 100644 index 0000000..f15a2e8 Binary files /dev/null and b/data/display-blanking-inhibit-icon.png differ diff --git a/debian/install b/debian/install index 5d7fa8c..22ccaf1 100644 --- a/debian/install +++ b/debian/install @@ -3,5 +3,6 @@ data/display-blanking-icon.1.png usr/share/icons/hicolor/48x48/hildon data/display-blanking-icon.2.png usr/share/icons/hicolor/48x48/hildon data/display-blanking-icon.3.png usr/share/icons/hicolor/48x48/hildon data/display-blanking-icon.4.png usr/share/icons/hicolor/48x48/hildon +data/display-blanking-inhibit-icon.png usr/share/icons/hicolor/48x48/hildon src/lib-displayblanking-status-menu.so usr/lib/hildon-desktop data/status-area-displayblanking-applet.desktop usr/share/applications/hildon-status-menu diff --git a/src/lib-display-blanking-status-menu-widget.c b/src/lib-display-blanking-status-menu-widget.c index 51e200d..ef448c2 100644 --- a/src/lib-display-blanking-status-menu-widget.c +++ b/src/lib-display-blanking-status-menu-widget.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #define TYPE_DISPLAY_BLANKING_STATUS_PLUGIN (display_blanking_status_plugin_get_type ()) @@ -98,12 +100,16 @@ static const char *mode_icon_name[BLANKING_MODES] = "display-blanking-icon.3", "display-blanking-icon.4", }; +#define INHIBIT_ICON_NAME "display-blanking-inhibit-icon" struct _DisplayBlankingStatusPluginPrivate { GConfClient *gconf_client; + DBusConnection* dbus_conn; + DBusMessage* dbus_msg; GtkWidget *mode_button; GtkWidget *mode_dialog; + gint inhibit_timer_id; // if == 0, no timer is set gpointer data; }; @@ -125,11 +131,19 @@ display_blanking_status_plugin_class_init (DisplayBlankingStatusPluginClass *c) static void update_mode_gui (gint mode, DisplayBlankingStatusPluginPrivate *priv) { - hildon_button_set_value (HILDON_BUTTON (priv->mode_button), - dgettext (GETTEXT_DOM, _DisplayBlankingDescription[mode])); GtkWidget *icon = gtk_image_new_from_icon_name (mode_icon_name[mode], GTK_ICON_SIZE_DIALOG); - hildon_button_set_image (HILDON_BUTTON (priv->mode_button), icon); + gtk_button_set_image (GTK_BUTTON (priv->mode_button), icon); +} + +static gboolean +on_timeout (DisplayBlankingStatusPluginPrivate *priv) +{ + dbus_bool_t ok = dbus_connection_send (priv->dbus_conn, priv->dbus_msg, + NULL); + g_assert (ok == TRUE); + + return TRUE; } static void @@ -210,6 +224,26 @@ on_mode_button_clicked (GtkWidget *button, priv->mode_dialog = NULL; } +static void +on_inhibit_button_clicked (GtkWidget *button, + DisplayBlankingStatusPluginPrivate *priv) +{ + GtkWidget *parent = gtk_widget_get_ancestor (GTK_WIDGET (priv->mode_button), + GTK_TYPE_WINDOW); + gtk_widget_hide (parent); + + if (priv->inhibit_timer_id) { + gboolean ok = g_source_remove (priv->inhibit_timer_id); + g_assert (ok == TRUE); + priv->inhibit_timer_id = 0; + } + else { + priv->inhibit_timer_id = g_timeout_add_seconds (INHIBIT_MSG_INTERVAL, + (GSourceFunc) on_timeout, priv); + g_assert (priv->inhibit_timer_id > 0); + } +} + static void on_gconf_notify (GConfClient* client, guint cnxn_id, GConfEntry* entry, DisplayBlankingStatusPluginPrivate* priv) @@ -247,17 +281,28 @@ init_gconf (DisplayBlankingStatusPluginPrivate *priv) g_assert (error == NULL); } +static void +init_dbus (DisplayBlankingStatusPluginPrivate *priv) +{ + DBusError error; + dbus_error_init (&error); + + priv->dbus_conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error); + g_assert (!dbus_error_is_set (&error)); + g_assert (priv->dbus_conn != NULL); + + priv->dbus_msg = dbus_message_new_method_call (MCE_SERVICE, + MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_PREVENT_BLANK_REQ); + g_assert (priv->dbus_msg != NULL); + dbus_message_set_no_reply (priv->dbus_msg, TRUE); +} + static void init_mode_gui (DisplayBlankingStatusPluginPrivate *priv) { priv->mode_dialog = NULL; - priv->mode_button = hildon_button_new (HILDON_SIZE_FINGER_HEIGHT | - HILDON_SIZE_AUTO_WIDTH, HILDON_BUTTON_ARRANGEMENT_VERTICAL); - gtk_button_set_alignment (GTK_BUTTON (priv->mode_button), 0, 0); - hildon_button_set_style (HILDON_BUTTON (priv->mode_button), - HILDON_BUTTON_STYLE_PICKER); - hildon_button_set_title (HILDON_BUTTON (priv->mode_button), - dgettext (GETTEXT_DOM, "Display blanking mode")); + priv->mode_button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | + HILDON_SIZE_AUTO_WIDTH); GError* error = NULL; gint mode = gconf_client_get_int (priv->gconf_client, MODE_GCONF_KEY, @@ -278,12 +323,27 @@ display_blanking_status_plugin_init (DisplayBlankingStatusPlugin *plugin) plugin->priv = priv; init_gconf (priv); + init_dbus (priv); init_mode_gui (priv); - gtk_container_add (GTK_CONTAINER (plugin), priv->mode_button); + priv->inhibit_timer_id = 0; + GtkWidget *inhibit_button = hildon_gtk_toggle_button_new ( + HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(inhibit_button), FALSE); + GtkWidget *icon = gtk_image_new_from_icon_name (INHIBIT_ICON_NAME, + GTK_ICON_SIZE_DIALOG); + gtk_button_set_image (GTK_BUTTON (inhibit_button), icon); + g_signal_connect (inhibit_button, "clicked", + G_CALLBACK (on_inhibit_button_clicked), priv); + + GtkWidget *hbbox = gtk_hbutton_box_new (); //gtk_hbox_new (FALSE, 0); + g_assert (hbbox != NULL); + + gtk_container_add (GTK_CONTAINER (hbbox), priv->mode_button); + gtk_container_add (GTK_CONTAINER (hbbox), inhibit_button); - gtk_widget_show_all (priv->mode_button); + gtk_container_add (GTK_CONTAINER (plugin), hbbox); - gtk_widget_show (GTK_WIDGET (plugin)); + gtk_widget_show_all (GTK_WIDGET (plugin)); }