https://bugs.kde.org/show_bug.cgi?id=424288

--- Comment #5 from basjetim...@yahoo.com ---
> Programs do crash sometimes, you know. 

Yes I do know, but my point stands, a crash in a program is not a bug in
powerdevil. Obviously I do see some benefit in powerdevil dealing with this
situation, but it is causing me much more trouble than it's solving. 

> It was actually a bug in PowerDevil
> not releasing those inhibitions properly when the program quit before the
> inhibition came into effe

Right, so it shouldn't inhibit if the inhibition was not yet accepted (the
first five seconds after requesting?). I see the same thing in the description
at d21102cc6c7a4db204a29f376ce5eb316ef57a6e ('remove from pending'). Now, this
has obviously been breaking my workflow a bit, but apparently the behavior
before was not correct. But now, even when I write a little program like this:

#include <QDBusConnection>
#include <QDBusMessage>
#include <QThread>
#include <QDebug>

class SuspendInhibitor
{
 private:
  bool d_inhibited;
  uint d_cookie;
 public:
  inline SuspendInhibitor() : d_inhibited(false), d_cookie(-1)
  {}

  void inhibitSuspend()
  {
    if (d_inhibited)
      return;
    QDBusMessage inhibitCall =
QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.PowerManagement.Inhibit"),
                                                             
QStringLiteral("/org/freedesktop/PowerManagement/Inhibit"),
                                                             
QStringLiteral("org.freedesktop.PowerManagement.Inhibit"),
                                                             
QStringLiteral("Inhibit"));
    inhibitCall.setArguments({"Application", "Playing Music"});
    QDBusMessage reply = QDBusConnection::sessionBus().call(inhibitCall,
QDBus::Block, 5000);
    if (reply.type() == QDBusMessage::ReplyMessage)
    {
      d_cookie = reply.arguments()[0];
      d_inhibited = true;
    }
  }

  void uninhibitSuspend()
  {
    if (!d_inhibited)
      return;

    QDBusMessage uninhibitcall =
QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.PowerManagement.Inhibit"),
                                                               
QStringLiteral("/org/freedesktop/PowerManagement/Inhibit"),
                                                               
QStringLiteral("org.freedesktop.PowerManagement.Inhibit"),
                                                               
QStringLiteral("UnInhibit"));
    uninhibitcall.setArguments({d_cookie});
    QDBusMessage reply = QDBusConnection::sessionBus().call(uninhibitcall,
QDBus::Block, 5000);
    if (reply.type() == QDBusMessage::ReplyMessage)
      d_inhibited = false;
  }
};

int main()
{
  SuspendInhibitor spnd;
  spnd.inhibitSuspend();

  // Wait for the inhibition to go into effect!!!
  for (uint i = 0; i < 10; ++i)
  {
    qInfo() << "Sleeping " << i + 1;
    QThread::msleep(1000);
  }

  //spnd.uninhibitSuspend();

  qInfo() << "Exiting";

  return 0;
}

And watch org.freedesktop.PowerManagement.Inhibit.HasInhibit, I see somewhere
during the 10 sec sleep that I get 'true' as a reply, but then when the program
exits, the inhibition is lifted. At this point the inhibit was not pending, it
had gone into effect, but it is still removed automatically.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to