Kaydet (Commit) e97b1b6c authored tarafından Andrzej Hunt's avatar Andrzej Hunt

Lambda'ise the almost identical FDO and GSM screensaver inhibition

This doesn't save us much for now, but could be useful when yet another
screensaver inhibition standard is introduced. (The GSM/gnome inhibition
currently requires passing the X11 window handle/id, which suggests that
at some point they will have to update their screensaver inhibition api.)

Change-Id: I4fa7bc15f089d112777fb166ab469045c002ae48
üst a50ac1f8
...@@ -37,11 +37,15 @@ void ScreenSaverInhibitor::inhibit( bool bInhibit, const OUString& sReason, bool ...@@ -37,11 +37,15 @@ void ScreenSaverInhibitor::inhibit( bool bInhibit, const OUString& sReason, bool
} }
} }
void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason ) void dbusInhibit( bool bInhibit,
const gchar* service, const gchar* path, const gchar* interface,
std::function<bool( DBusGProxy*, guint&, GError*& )> fInhibit,
std::function<bool( DBusGProxy*, const guint, GError*& )> fUnInhibit,
boost::optional<guint>& rCookie )
{ {
#ifdef ENABLE_DBUS #ifdef ENABLE_DBUS
if ( ( !bInhibit && ( mnFDOCookie == boost::none ) ) || if ( ( !bInhibit && ( rCookie == boost::none ) ) ||
( bInhibit && ( mnFDOCookie != boost::none ) ) ) ( bInhibit && ( rCookie != boost::none ) ) )
{ {
return; return;
} }
...@@ -58,46 +62,36 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, cons ...@@ -58,46 +62,36 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, cons
} }
proxy = dbus_g_proxy_new_for_name( session_connection, proxy = dbus_g_proxy_new_for_name( session_connection,
FDO_DBUS_SERVICE, service,
FDO_DBUS_PATH, path,
FDO_DBUS_INTERFACE ); interface );
if (proxy == NULL) { if (proxy == NULL) {
SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " FDO_DBUS_SERVICE ); SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " << service );
return; return;
} }
if ( bInhibit ) if ( bInhibit )
{ {
guint nCookie; guint nCookie;
res = dbus_g_proxy_call( proxy, res = fInhibit( proxy, nCookie, error );
"Inhibit", &error,
G_TYPE_STRING, appname,
G_TYPE_STRING, reason,
G_TYPE_INVALID,
G_TYPE_UINT, &nCookie,
G_TYPE_INVALID);
if (res) if (res)
{ {
mnFDOCookie = nCookie; rCookie = nCookie;
} }
else else
{ {
SAL_INFO( "vcl.screensaverinhibitor", FDO_DBUS_SERVICE ".Inhibit failed"); SAL_INFO( "vcl.screensaverinhibitor", service << ".Inhibit failed");
} }
} }
else else
{ {
res = dbus_g_proxy_call (proxy, res = fUnInhibit( proxy, rCookie.get(), error );
"UnInhibit", rCookie = boost::none;
&error,
G_TYPE_UINT, mnFDOCookie.get(),
G_TYPE_INVALID,
G_TYPE_INVALID);
mnFDOCookie = boost::none;
if (!res) if (!res)
{ {
SAL_INFO( "vcl.screensaverinhibitor", FDO_DBUS_SERVICE ".UnInhibit failed" ); SAL_INFO( "vcl.screensaverinhibitor", service << ".UnInhibit failed" );
} }
} }
...@@ -112,81 +106,52 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, cons ...@@ -112,81 +106,52 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, cons
#endif // ENABLE_DBUS #endif // ENABLE_DBUS
} }
void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, const guint xid ) void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason )
{ {
#ifdef ENABLE_DBUS dbusInhibit( bInhibit,
if ( ( !bInhibit && ( mnGSMCookie == boost::none ) ) || FDO_DBUS_SERVICE, FDO_DBUS_PATH, FDO_DBUS_INTERFACE,
( bInhibit && ( mnGSMCookie != boost::none ) ) ) [appname, reason] ( DBusGProxy *proxy, guint& nCookie, GError*& error ) -> bool {
{ return dbus_g_proxy_call( proxy,
return; "Inhibit", &error,
} G_TYPE_STRING, appname,
G_TYPE_STRING, reason,
gboolean res; G_TYPE_INVALID,
GError *error = NULL; G_TYPE_UINT, &nCookie,
DBusGProxy *proxy = NULL; G_TYPE_INVALID );
},
DBusGConnection *session_connection = dbus_g_bus_get( DBUS_BUS_SESSION, &error ); [] ( DBusGProxy *proxy, const guint nCookie, GError*& error ) -> bool {
if (error != NULL) { return dbus_g_proxy_call( proxy,
SAL_WARN( "vcl.screensaverinhibitor", "failed to connect to dbus session bus: " << error->message ); "UnInhibit", &error,
g_error_free( error ); G_TYPE_UINT, nCookie,
return; G_TYPE_INVALID,
} G_TYPE_INVALID );
},
proxy = dbus_g_proxy_new_for_name( session_connection, mnFDOCookie );
GSM_DBUS_SERVICE, }
GSM_DBUS_PATH,
GSM_DBUS_INTERFACE );
if (proxy == NULL) {
SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " GSM_DBUS_SERVICE );
return;
}
if ( bInhibit )
{
guint nCookie;
res = dbus_g_proxy_call (proxy,
"Inhibit", &error,
G_TYPE_STRING, appname,
G_TYPE_UINT, xid,
G_TYPE_STRING, reason,
G_TYPE_UINT, 8, //Inhibit the session being marked as idle
G_TYPE_INVALID,
G_TYPE_UINT, &nCookie,
G_TYPE_INVALID);
if ( res )
{
mnGSMCookie = nCookie;
}
else
{
SAL_INFO( "vcl.screensaverinhibitor", GSM_DBUS_SERVICE ".Inhibit failed" );
}
}
else
{
res = dbus_g_proxy_call (proxy,
"Uninhibit",
&error,
G_TYPE_UINT, mnGSMCookie.get(),
G_TYPE_INVALID,
G_TYPE_INVALID);
mnGSMCookie = boost::none;
if ( !res )
{
SAL_INFO( "vcl.screensaverinhibitor", GSM_DBUS_SERVICE ".Uninhibit failed" );
}
}
if (error != NULL)
{
SAL_INFO( "vcl.screensaverinhibitor", "Error: " << error->message );
g_error_free( error );
}
g_object_unref( G_OBJECT( proxy ) );
#endif // ENABLE_DBUS void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, const guint xid )
{
dbusInhibit( bInhibit,
GSM_DBUS_SERVICE, GSM_DBUS_PATH, GSM_DBUS_INTERFACE,
[appname, reason, xid] ( DBusGProxy *proxy, guint& nCookie, GError*& error ) -> bool {
return dbus_g_proxy_call( proxy,
"Inhibit", &error,
G_TYPE_STRING, appname,
G_TYPE_UINT, xid,
G_TYPE_STRING, reason,
G_TYPE_UINT, 8, //Inhibit the session being marked as idle
G_TYPE_INVALID,
G_TYPE_UINT, &nCookie,
G_TYPE_INVALID );
},
[] ( DBusGProxy *proxy, const guint nCookie, GError*& error ) -> bool {
return dbus_g_proxy_call( proxy,
"Uninhibit", &error,
G_TYPE_UINT, nCookie,
G_TYPE_INVALID,
G_TYPE_INVALID );
},
mnGSMCookie );
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment