After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 646499 - inhibit screensaver via Session dbus api
inhibit screensaver via Session dbus api
Status: RESOLVED WONTFIX
Product: banshee
Classification: Other
Component: general
git master
Other Linux
: Normal normal
: 1.x
Assigned To: Banshee Maintainers
Banshee Maintainers
gnome[unmaintained]
: 655468 662886 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-04-02 00:30 UTC by Gabriel Burt
Modified: 2020-03-17 09:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
inhibit session dbus patch (3.18 KB, patch)
2011-04-19 13:37 UTC, olivier dufour
none Details | Review
use gnome session's dbus api to inhibit (4.07 KB, patch)
2011-07-30 04:35 UTC, Ulf Winkelvos
none Details | Review
Uses FreeDesktop API to Inhibit Idlness of Session. (3.14 KB, patch)
2014-08-02 13:01 UTC, Samuel Gyger (IRC: thinkabout)
none Details | Review
Creates a new Backend Banshee.FreeDesktop (21.03 KB, patch)
2014-08-02 18:21 UTC, Samuel Gyger (IRC: thinkabout)
needs-work Details | Review
Fixes the problems from MonoDevelop and adds --disable-freedesktop Switch (21.01 KB, patch)
2014-08-08 17:05 UTC, Samuel Gyger (IRC: thinkabout)
none Details | Review
Fixes the Coding Style of the previous commit. (3.07 KB, patch)
2014-08-08 17:05 UTC, Samuel Gyger (IRC: thinkabout)
none Details | Review

Description Gabriel Burt 2011-04-02 00:30:27 UTC
the Inhibit method was removed from org.gnome.ScreenSaver in 2.91.91 (http://git.gnome.org/browse/gnome-screensaver/tree/NEWS).  The replacement is to call org.gnome.SessionManager's Inhibit w/ a Flag of 8 (http://people.gnome.org/~mccann/gnome-session/docs/gnome-session.html#org.gnome.SessionManager.Inhibit) == prevent session from being idle'd
Comment 1 olivier dufour 2011-04-19 13:37:30 UTC
Created attachment 186285 [details] [review]
inhibit session dbus patch

Here is the patch to use the new api but I am not on gnome 3 so can not test it...
NB: I have an issue to get x window id because do not find how get it. It seems that best way is to use gekWindows and function GDK_DRAWABLE_XID but I heard that GTK 3 do not use GDK anymore and use cairo to replace it. So for moment set toplevel x window param to 0.
Comment 2 Ulf Winkelvos 2011-07-30 03:24:52 UTC
*** Bug 655468 has been marked as a duplicate of this bug. ***
Comment 3 Ulf Winkelvos 2011-07-30 04:35:29 UTC
Created attachment 192896 [details] [review]
use gnome session's dbus api to inhibit

I overlooked this bugreport... the attached patch is essentialy the same i attached to my bugreport with the inhibit flags as in oliver's. Its working for me.

Notes:
- in IGnomeSessionManager it has to be "Uninhibit" and not "UnInhibit" otherwise the dbus method is not mapped correctly.
- see https://bugzilla.gnome.org/show_bug.cgi?id=655468#c1 for my reasons to also inhibit suspend. I think the api IScreensaverManager should be changed. i.e. Inhibit() -> Inhibit(string reason, uint flags) So any module using this api can decide what to suspend. e.g. while playing music the screensaver or dpms might be activated but sleep should still be inhibited.
- I created a very basic inhibit extension to inhibit while playing any media. see: https://gitorious.org/~uwinkelvos/banshee-community-extensions/uwinkelvos-banshee-community-extensions/trees/master/src/Inhibit
Comment 4 Ulf Winkelvos 2011-08-21 21:06:39 UTC
anyone willing to review the patch?
Comment 5 Bertrand Lorentz 2012-01-29 21:23:59 UTC
*** Bug 662886 has been marked as a duplicate of this bug. ***
Comment 6 Daniel Isenmann 2012-03-29 16:21:21 UTC
Anyone who can review this patch? We have also an open bug report in our bugtracker. Please review this patch.
Comment 7 Samuel Gyger (IRC: thinkabout) 2014-08-02 12:26:55 UTC
I think the right way would be to do it with the org.freedesktop.screensaver api, then it would work on all platforms. http://people.freedesktop.org/~hadess/idle-inhibition-spec/re01.html
Comment 8 Samuel Gyger (IRC: thinkabout) 2014-08-02 13:01:58 UTC
Created attachment 282333 [details] [review]
Uses FreeDesktop API to Inhibit Idlness of Session.

This fixes also:
bug #676903
and
bug #601672
Comment 9 Samuel Gyger (IRC: thinkabout) 2014-08-02 18:21:07 UTC
Created attachment 282348 [details] [review]
Creates a new Backend Banshee.FreeDesktop
Comment 10 Andrés G. Aragoneses (IRC: knocte) 2014-08-07 11:58:14 UTC
Comment on attachment 282348 [details] [review]
Creates a new Backend Banshee.FreeDesktop

> From d64c787cf938d422ed193f1e0acf835c9d310339 Mon Sep 17 00:00:00 2001
> From: Samuel Gyger <samuel@gyger.at>
> Date: Sat, 2 Aug 2014 20:17:47 +0200
> Subject: [PATCH] ScreensaverManager: Use the FreeDesktop Specification for the
>  ScreensaverManager. (bgo#646499)

The first line of the commit message shouldn't be so long, how about "ScreenSaverManager: new FreeDesktop backend (bgo#646499)".


> 
> Creates a new Backend Banshee.FreeDesktop for the new ScreensaverManager

The paragraph after the first line of the commit message should ideally be more elaborated, for example putting the "why", not just the "what" (why the GnomeScreenSaverManager is gone).


> ---
>  Banshee.sln                                        |   6 ++
>  build/build.environment.mk                         |   1 +
>  configure.ac                                       |   1 +
>  .../Banshee.FreeDesktop.addin.xml                  |  20 ++++
>  .../Banshee.FreeDesktop/Banshee.FreeDesktop.csproj |  87 ++++++++++++++++++
>  .../FreeDesktopScreensaverManager.cs               | 101 +++++++++++++++++++++
>  src/Backends/Banshee.FreeDesktop/Makefile.am       |  11 +++
>  src/Backends/Banshee.Gnome/Banshee.Gnome.addin.xml |   4 -
>  src/Backends/Banshee.Gnome/Banshee.Gnome.csproj    |  11 +--
>  .../GnomeScreensaverManager.cs                     | 101 ---------------------
>  src/Backends/Banshee.Gnome/Makefile.am             |   1 -
>  src/Backends/Makefile.am                           |   1 +
>  12 files changed, 232 insertions(+), 113 deletions(-)
>  create mode 100644 src/Backends/Banshee.FreeDesktop/Banshee.FreeDesktop.addin.xml
>  create mode 100644 src/Backends/Banshee.FreeDesktop/Banshee.FreeDesktop.csproj
>  create mode 100644 src/Backends/Banshee.FreeDesktop/Banshee.FreeDesktopBackend/FreeDesktopScreensaverManager.cs
>  create mode 100644 src/Backends/Banshee.FreeDesktop/Makefile.am
>  delete mode 100644 src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeScreensaverManager.cs
> diff --git a/src/Backends/Banshee.FreeDesktop/Banshee.FreeDesktopBackend/FreeDesktopScreensaverManager.cs b/src/Backends/Banshee.FreeDesktop/Banshee.FreeDesktopBackend/FreeDesktopScreensaverManager.cs
> new file mode 100644
> index 0000000..5ded7dc
> --- /dev/null
> +++ b/src/Backends/Banshee.FreeDesktop/Banshee.FreeDesktopBackend/FreeDesktopScreensaverManager.cs
> @@ -0,0 +1,101 @@
> +//
> +// GnomeScreensaverManager.cs

Wrong file name.

> +//
> +// Author:
> +//   Christopher James Halse Rogers <raof@ubuntu.com>
> +//
> +// Copyright (C) 2008 Novell, Inc.
> +//
> +// Permission is hereby granted, free of charge, to any person obtaining
> +// a copy of this software and associated documentation files (the
> +// "Software"), to deal in the Software without restriction, including
> +// without limitation the rights to use, copy, modify, merge, publish,
> +// distribute, sublicense, and/or sell copies of the Software, and to
> +// permit persons to whom the Software is furnished to do so, subject to
> +// the following conditions:
> +//
> +// The above copyright notice and this permission notice shall be
> +// included in all copies or substantial portions of the Software.
> +//
> +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> +//
> +using System;

Please leave a blank line separation between file headers and first 'using'.

> +using DBus;
> +using Mono.Unix;
> +
> +using Banshee.PlatformServices;
> +
> +namespace Banshee.FreeDesktopBackend
> +{
> +    [Interface("org.freedesktop.ScreenSaver")]
> +    internal interface IFreeDesktopScreensaver
> +    {
> +        uint Inhibit (string application_name, string reason);
> +        void UnInhibit (uint cookie);
> +    }
> +
> +    class FreeDesktopScreensaverManager : IScreensaverManager
> +    {
> +        const string DBUS_INTERFACE = "org.freedesktop.ScreenSaver";
> +        const string DBUS_PATH = "/org/freedesktop/ScreenSaver";
> +
> +        IFreeDesktopScreensaver manager;
> +        uint? cookie;
> +
> +        public FreeDesktopScreensaverManager ()
> +        {
> +            if (Manager == null) {
> +                Hyena.Log.Information ("Freedesktop screensaver service not found");

Sounds like this should be a Warning, not Information.

Also, please use "using Hyena;" at the beginning to avoid specifying "Hyena." all the time you call the Log class.


> +            }
> +        }
> +
> +        private IFreeDesktopScreensaver Manager {
> +            get {
> +                if (manager == null) {
> +                    if (!Bus.Session.NameHasOwner (DBUS_INTERFACE)) {
> +                        return null;
> +                    }
> +
> +                    manager = Bus.Session.GetObject<IFreeDesktopScreensaver> (DBUS_INTERFACE, new ObjectPath (DBUS_PATH));
> +
> +                    if (manager == null) {
> +                        Hyena.Log.ErrorFormat ("The {0} object could not be located on the DBus interface {1}",
> +                            DBUS_PATH, DBUS_INTERFACE);
> +                    }
> +                }
> +                return manager;
> +            }
> +        }
> +
> +        static bool logged_error;
> +        public void Inhibit ()
> +        {
> +            try {
> +                if (!cookie.HasValue && Manager != null) {
> +                    cookie = Manager.Inhibit ("Banshee", Catalog.GetString ("Fullscreen video playback active"));
> +                }
> +            } catch (Exception e) {
> +                if (!logged_error) {
> +                    Hyena.Log.Error ("Unable to Inhibit FreeDesktop screensaver.", e.Message);
> +                    logged_error = true;
> +                }
> +            }
> +        }
> +
> +        public void UnInhibit ()
> +        {
> +            try {
> +                if (cookie.HasValue && Manager != null) {
> +                    Manager.UnInhibit (cookie.Value);
> +                    cookie = null;
> +                }
> +            } catch {}

Please don't use empty generic catch blocks, at least send the exception to Hyena.Log.Warning.


> +        }
> +    }
> +}
> diff --git a/src/Backends/Banshee.FreeDesktop/Makefile.am b/src/Backends/Banshee.FreeDesktop/Makefile.am
> new file mode 100644
> index 0000000..8a02d77
> --- /dev/null
> +++ b/src/Backends/Banshee.FreeDesktop/Makefile.am
> @@ -0,0 +1,11 @@
> +ASSEMBLY = Banshee.FreeDesktop
> +TARGET = library
> +LINK = $(REF_BACKEND_FREEDESKTOP)
> +INSTALL_DIR = $(BACKENDS_INSTALL_DIR)
> +
> +SOURCES = Banshee.FreeDesktopBackend/FreeDesktopScreensaverManager.cs
> +
> +RESOURCES = Banshee.FreeDesktop.addin.xml
> +
> +include $(top_srcdir)/build/build.mk
> +
> diff --git a/src/Backends/Banshee.Gnome/Banshee.Gnome.addin.xml b/src/Backends/Banshee.Gnome/Banshee.Gnome.addin.xml
> index 47ad5c6..d2ba174 100644
> --- a/src/Backends/Banshee.Gnome/Banshee.Gnome.addin.xml
> +++ b/src/Backends/Banshee.Gnome/Banshee.Gnome.addin.xml
> @@ -29,8 +29,4 @@
>    <!--<Extension path="/Banshee/Platform/DefaultApplicationHelper">
>      <Helper class="Banshee.GnomeBackend.DefaultApplicationHelper"/>
>  </Extension>-->
> -  
> -  <Extension path="/Banshee/PlatformServices/ScreensaverManager">
> -    <ScreensaverManager class="Banshee.GnomeBackend.GnomeScreensaverManager"/>
> -  </Extension>
>  </Addin>
> diff --git a/src/Backends/Banshee.Gnome/Banshee.Gnome.csproj b/src/Backends/Banshee.Gnome/Banshee.Gnome.csproj
> index ff12ca7..ec4dd98 100644
> --- a/src/Backends/Banshee.Gnome/Banshee.Gnome.csproj
> +++ b/src/Backends/Banshee.Gnome/Banshee.Gnome.csproj
> @@ -69,9 +69,7 @@
>      <Reference Include="System" />
>      <Reference Include="glib-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
>      <Reference Include="gtk-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
> -    <Reference Include="gconf-sharp">
> -      <Package>gconf-sharp-2.0</Package>
> -    </Reference>
> +    <Reference Include="gconf-sharp" />

This change is unrelated (I know it's MonoDevelop the culprit, but you should try to not include it in your patch).


>      <Reference Include="Mono.Posix">
>        <HintPath>..\..\..\bin\bin\Mono.Posix.dll</HintPath>
>      </Reference>
> @@ -87,7 +85,6 @@
>      <Compile Include="Banshee.GnomeBackend\GnomeService.cs" />
>      <Compile Include="Banshee.GnomeBackend\Brasero.cs" />
>      <Compile Include="Banshee.GnomeBackend\DiscDuplicator.cs" />
> -    <Compile Include="Banshee.GnomeBackend\GnomeScreensaverManager.cs" />
>      <Compile Include="Banshee.GnomeBackend\GConfProxy.cs" />
>    </ItemGroup>
>    <ItemGroup>
> @@ -102,10 +99,10 @@
>    <ProjectExtensions>
>      <MonoDevelop>
>        <Properties>
> -        <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am">
> -          <BuildFilesVar Sync="True" Name="SOURCES" />
> +        <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="true" RelativeMakefileName="Makefile.am">
> +          <BuildFilesVar Sync="true" Name="SOURCES" />

Same here.

>            <DeployFilesVar />
> -          <ResourcesVar Sync="True" Name="RESOURCES" />
> +          <ResourcesVar Sync="true" Name="RESOURCES" />

Same here.

>            <OthersVar />
>            <GacRefVar />
>            <AsmRefVar />
> diff --git a/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeScreensaverManager.cs b/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeScreensaverManager.cs
> deleted file mode 100644
> index 9a7ac7f..0000000
> --- a/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeScreensaverManager.cs
> +++ /dev/null
> @@ -1,101 +0,0 @@
> -//
> -// GnomeScreensaverManager.cs
> -//
> -// Author:
> -//   Christopher James Halse Rogers <raof@ubuntu.com>
> -//
> -// Copyright (C) 2008 Novell, Inc.
> -//
> -// Permission is hereby granted, free of charge, to any person obtaining
> -// a copy of this software and associated documentation files (the
> -// "Software"), to deal in the Software without restriction, including
> -// without limitation the rights to use, copy, modify, merge, publish,
> -// distribute, sublicense, and/or sell copies of the Software, and to
> -// permit persons to whom the Software is furnished to do so, subject to
> -// the following conditions:
> -//
> -// The above copyright notice and this permission notice shall be
> -// included in all copies or substantial portions of the Software.
> -//
> -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> -//
> -using System;
> -using DBus;
> -using Mono.Unix;
> -
> -using Banshee.PlatformServices;
> -
> -namespace Banshee.GnomeBackend
> -{
> -    [Interface("org.gnome.ScreenSaver")]
> -    internal interface IGnomeScreensaver
> -    {
> -        uint Inhibit (string application_name, string reason);
> -        void UnInhibit (uint cookie);
> -    }
> -
> -    class GnomeScreensaverManager : IScreensaverManager
> -    {
> -        const string DBUS_INTERFACE = "org.gnome.ScreenSaver";
> -        const string DBUS_PATH = "/org/gnome/ScreenSaver";
> -
> -        IGnomeScreensaver manager;
> -        uint? cookie;
> -
> -        public GnomeScreensaverManager ()
> -        {
> -            if (Manager == null) {
> -                Hyena.Log.Information ("GNOME screensaver service not found");
> -            }
> -        }
> -
> -        private IGnomeScreensaver Manager {
> -            get {
> -                if (manager == null) {
> -                    if (!Bus.Session.NameHasOwner (DBUS_INTERFACE)) {
> -                        return null;
> -                    }
> -
> -                    manager = Bus.Session.GetObject<IGnomeScreensaver> (DBUS_INTERFACE, new ObjectPath (DBUS_PATH));
> -
> -                    if (manager == null) {
> -                        Hyena.Log.ErrorFormat ("The {0} object could not be located on the DBus interface {1}",
> -                            DBUS_PATH, DBUS_INTERFACE);
> -                    }
> -                }
> -                return manager;
> -            }
> -        }
> -
> -        static bool logged_error;
> -        public void Inhibit ()
> -        {
> -            try {
> -                if (!cookie.HasValue && Manager != null) {
> -                    cookie = Manager.Inhibit ("Banshee", Catalog.GetString ("Fullscreen video playback active"));
> -                }
> -            } catch (Exception e) {
> -                if (!logged_error) {
> -                    Hyena.Log.Error ("Unable to Inhibit GNOME screensaver; probably running >= 2.91.91 gnome-screensaver which removed this API", e.Message);
> -                    logged_error = true;
> -                }
> -            }
> -        }
> -
> -        public void UnInhibit ()
> -        {
> -            try {
> -                if (cookie.HasValue && Manager != null) {
> -                    Manager.UnInhibit (cookie.Value);
> -                    cookie = null;
> -                }
> -            } catch {}
> -        }
> -    }
> -}
> diff --git a/src/Backends/Banshee.Gnome/Makefile.am b/src/Backends/Banshee.Gnome/Makefile.am
> index 4a1b0bc..14ad7b6 100644
> --- a/src/Backends/Banshee.Gnome/Makefile.am
> +++ b/src/Backends/Banshee.Gnome/Makefile.am
> @@ -8,7 +8,6 @@ SOURCES =  \
>  	Banshee.GnomeBackend/DiscDuplicator.cs \
>  	Banshee.GnomeBackend/GConfConfigurationClient.cs \
>  	Banshee.GnomeBackend/GConfProxy.cs \
> -	Banshee.GnomeBackend/GnomeScreensaverManager.cs \
>  	Banshee.GnomeBackend/GnomeService.cs
>  
>  RESOURCES =  \
> diff --git a/src/Backends/Makefile.am b/src/Backends/Makefile.am
> index 524051e..8b234f0 100644
> --- a/src/Backends/Makefile.am
> +++ b/src/Backends/Makefile.am
> @@ -1,6 +1,7 @@
>  SUBDIRS = \
>  	Banshee.Gio \
>  	Banshee.Gnome \
> +	Banshee.FreeDesktop \
>  	Banshee.GStreamer \
>  	Banshee.GStreamerSharp \
>  	Banshee.Unix \
> -- 
> 1.9.3


One thing missing from the patch is a way to disable the build of Banshee.FreeDesktop via --disable-freedesktop (this way you can add this flag in profile-configure, to not include this assembly when we build Banshee's OSX installer).

PS: I've just realised that the nitpicks I noted for the file FreeDesktopScreensaverManager.cs were already there in GnomeScreensaverManager.cs, then please add those improvements in a 2nd commit (do two commits and combine them in a one individual patch via git format-patch HEAD~2).

Thanks!
Comment 11 Samuel Gyger (IRC: thinkabout) 2014-08-08 17:05:06 UTC
Created attachment 282935 [details] [review]
Fixes the problems from MonoDevelop and adds --disable-freedesktop Switch

After a lot of autotools guessing and copying and stealing code from other files, disable-freedesktop works.
Comment 12 Samuel Gyger (IRC: thinkabout) 2014-08-08 17:05:53 UTC
Created attachment 282936 [details] [review]
Fixes the Coding Style of the previous commit. 

Fixes the codeing style as requested.
Comment 13 André Klapper 2020-03-17 09:19:49 UTC
Banshee is not under active development anymore and had its last code changes more than three years ago. Its codebase has been archived.

Closing this report as WONTFIX as part of Bugzilla Housekeeping to reflect
reality. Please feel free to reopen this ticket (or rather transfer the project
to GNOME Gitlab, as GNOME Bugzilla is being shut down) if anyone takes the
responsibility for active development again.
See https://gitlab.gnome.org/Infrastructure/Infrastructure/issues/264 for more info.