Send a message using Gio::Dbus




Hello everybody out there!

        I need to inhibit screen-saver while an application is in full-screen
mode (and uninhibit it when switching back into windowed mode). If I am
not mistaken, according to
<http://people.gnome.org/~mccann/gnome-screensaver/docs/gnome-screensaver.html>,
I need to send method « Inhibit » to service « org.gnome.ScreenSaver »
through D-Bus current session bus.

        To achieve this, I have read D-Bus tutorial from Freedesktop
(<http://dbus.freedesktop.org/doc/dbus-tutorial.html>) and dive into
Glibmm D-BUS API documentation
(<https://developer.gnome.org/glibmm/2.34/group__DBus.html>). I got
totally lost, I need help finding my way out.

        So far, I have made the following code:

void inhibitScreenSaver () {
  /* Proxy connected to D-Bus. */
  Glib::RefPtr<Gio::DBus::Proxy> proxy;
  /* Message to be send. */
  Glib::RefPtr<Gio::DBus::Message> message =
    Gio::DBus::Message::create_method_call(proxy->get_name(),
                                           "/org/gnome/ScreenSaver",
                                           proxy->get_interface_name(),
                                           "Inhibit");
  /* Connexion to current session bus from D-Bud. */
  Glib::RefPtr<Gio::DBus::Connection> connection =
    Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SESSION);

  if (!connection->send_message(message))
    g_warning("Impossible to inhibit screen-saver.");
}

Of course, this code generates a segmentation fault, as "proxy" is not
initialised. The thing is, I do not have a clue on how to initialise the
proxy in a proper way. Also, "connection" initialisation does not seem
quite right. Actually, I am not sure I am not using a completely wrong
approach.

        Can someone help me out this?

        Best regards.

                                                        Yoann


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]