BurntSushi / xgbutil

A utility library to make use of the X Go Binding easier. (Implements EWMH and ICCCM specs, key binding support, etc.)
Do What The F*ck You Want To Public License
195 stars 45 forks source link

Panic during ActiveWindowGet call when app runs with sudo #55

Closed yusufozturk closed 1 year ago

yusufozturk commented 1 year ago

I use ActiveWindowGet command to get currently active process. It runs perfectly. But if user starts the app with sudo, following part makes Panic and it crashes my entire app.

XGB: conn.go:47: Could not get authority info: open /root/.Xauthority: no such file or directory
XGB: conn.go:48: Trying connection without authority info...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xb48834]

goroutine 101 [running]:
github.com/BurntSushi/xgbutil/ewmh.ActiveWindowGet(0x7f4ce5424a68?)
        /github.com/BurntSushi/xgbutil/ewmh/ewmh.go:33 +0x14

So my questions would be:

  1. Can we handle panic here and return an error to user
  2. Is it possible to use ActiveWindowGet with sudo?

Thanks!

Edit: Oh, I'm sorry, totally my mistake. NewConn was giving an error but I didn't check that. Closing the issue, sorry for the mistake.