Any reliable way to find the X11 display id and authority file for local session running in actual monitor.

Sai Prasanna sai.r.prasanna at gmail.com
Fri Aug 11 11:46:14 UTC 2017


Thanks for the help.

I am developing in go lang and found a perfect binding in dbusbindings.

The logind dbus api was not intutive at first,  but figured it out after
some examples.


Posting the  go lang POC of above loginctl code to get active display. (So
anyone following this thread can spend less effort).




package main

import (
    "fmt"
    "os"

    "github.com/godbus/dbus"
)

func main() {
    conn, err := dbus.SystemBus()
    if err != nil {
        fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)
        os.Exit(1)
    }

    logindDest := "org.freedesktop.login1"
    loginPath := dbus.ObjectPath("/org/freedesktop/login1")

    logindObj := conn.Object(logindDest, loginPath)

    var seat0Path dbus.ObjectPath
    err = logindObj.Call(logindDest+".Manager.GetSeat", 0,
"seat0").Store(&seat0Path)

    if err != nil {
        os.Exit(1)
    }

    seat0Obj := conn.Object(logindDest, seat0Path)
    activeSession, err := seat0Obj.GetProperty(logindDest +
".Seat.ActiveSession")
    if err != nil {
        os.Exit(1)
    }

    activeSessionPath :=
activeSession.Value().([]interface{})[1].(dbus.ObjectPath)

    activeSessionObj := conn.Object(logindDest, activeSessionPath)
    display, err := activeSessionObj.GetProperty(logindDest +
".Session.Display")
    if err != nil {
        os.Exit(1)
    }
    fmt.Println(display)

    // node, err := introspect.Call(conn.Object("org.freedesktop.login1",
"/org/freedesktop/login1/session/c2"))
    // if err != nil {
    //     panic(err)
    // }
    // data, _ := json.MarshalIndent(node, "", "    ")
    // os.Stdout.Write(data)
}





On Fri, Aug 11, 2017 at 1:18 PM, Michal Srb <msrb at suse.com> wrote:

> On Friday, August 11, 2017 12:29:01 PM CEST Sai Prasanna wrote:
> > Thanks Michal.  How to use Dbus API directly to get the same results?.
> > I think loginctl is missing in some old distros.
>
> Just pick a library that suits you:
> https://www.freedesktop.org/wiki/Software/DBusBindings/
>
> The logind dbus api:
> https://www.freedesktop.org/wiki/Software/systemd/logind/
>
> There is also C library that can get you some of the information without
> dbus:
> https://www.freedesktop.org/software/systemd/man/sd-login.html
>
> Michal Srb
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.x.org/archives/xorg/attachments/20170811/c02dffbd/attachment.html>


More information about the xorg mailing list