From 816350dbbf32e6e8edf6c21749889c1f22397c29 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 27 Jul 2012 19:45:49 +0200 Subject: [PATCH] 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. --- data/display-blanking-inhibit-icon.png | Bin 0 -> 1319 bytes debian/install | 1 + src/lib-display-blanking-status-menu-widget.c | 86 +++++++++++++++--- 3 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 data/display-blanking-inhibit-icon.png diff --git a/data/display-blanking-inhibit-icon.png b/data/display-blanking-inhibit-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f15a2e86729c3e529b46357f0d7c8360ba327904 GIT binary patch literal 1319 zcmV+?1=#wDP)!vYdz9H+6J zI1a*hH)rO(ch21R?tS+H6{}dq{?kTm1roZhyJnjX{Q*g81OV^&NZ!22EkK@(x4zuB zNWM@jyMW|7??08?&udtr*|*MEp4sG z5PGon4{>a7V+VliS@1RQ_{gj4jzWIF|0Mver6O-iCM}KceR!5sGV~&rvD>-Ox$et~ zhmltqHrU?Yerrtue!u_t=;-LRp`jt9)9I23=o}qGbAmHqm-au2F_$yv_ZEu<4Gj&L znVISA?d`qt$TPsQ?Arqa0~j72hAhi4nM|m!uSZQy&C)lrEF%yIfaAErk`6)OE$`!K zo;RM;pFD2#PfsBhi{%_g(=_7oI8;?V1K`mDqS2^55{W>T|M6rdlR+pHLOdQ{L55+N zf&}bi7<7hb4cMfO#uYOOMN$m&@jQ=ACId;5z_Kg|f`HHGvjV6BuuyOmDwJ%tIc+wa zkFW+zqDXwY*9U4Yv10y2B7s;e231wdA4VyP!YMg}YC$yMpVw96&$-0Xv!-c~Wf`I< zg5$U~$#04PilWe5<;05*f(Cqin+vx!b&0qnNf1R5x~>-%(Mm1Aq-4+)2pKSeAn>l; z0!5Y~2m(^6RKdhIO+Xiygd>aGCoTs#o?i+S>-s^ZB;TUulIwcWcHk;8s9f3{N4EV=8w__|E-r53mUB?S@dPT_W-?;<# z;%r`_u`B{KO@k zzY#jVFLBYDw}8dJoogRkb)efAaKJ;yg-xiqS6xD*T}bVD9wID=Mx)?)J|}sH!+~Df z0cTcibh&0XXb%H|AU59vBuRp2o`7)X2cV}F2tQm=4*-D4WWs5u8;!!e0sqEs#gEgI zn4h1=dd^s}0#a716^`j3gq~Jlau@(|7Boldd^j=387k8dN#J56j7U6Q^aU+fE#mX} z@)OYC-+z~3n4^ap|9$0a$vM#NcH@IU2vz)o0srb?6Amo!I8cJ^GBGi62Y|X(SE7kw zm=iQjKeJk0>vp?M=bX&`wprHjTYmAlgBN0djVOwuZ!~#HlJ0XHcNM_BeELFO0Mu%e zeYdOTV4K}>V>u>k+MT+G!PiQ7UR40`d_1sLL#hhEeE{{#U=F}j-tm#>W;e)+iPV>} z$OAxEImj0*fII!hSpb~|7kWH{JH`UHbzLt@qqv|g6x;W75}M{*mN58jUw_$RX*nDq z2twQP9x#vxV14EIDND=YV7bVz>pD%=)_&`{*mIL02nA)d;sn@iBijcDKEkpVU&Sg` dv5Nga?Qg#O>94btD8T>#002ovPDHLkV1lQkRW|?t literal 0 HcmV?d00001 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)); } -- 2.43.0