Get tty device for the application that lost focus



I am not sure whether this is possible, but here goes...

I am writing a Gtk3 application whilst learning the API and I am pushing
it by trying to achieve some edgy things!

My application, which is suitably privileged, can inject some arbitrary
text into the tty of another application. It does this like so (Ruby
example):

  tty = '/dev/pts/5' # need to determine this!
  File.open(tty, File::WRONLY|File::NONBLOCK) do |f|
    content.split('').each { |c| f.ioctl(0x5412,c) }
  end

It works if I hard-code the device (the '/dev/pts/5' exemplified above)
but I would like to be able to ascertain this from within my
application: I want to find the tty for the application that lost the
input focus to my application.

My application receives the focus at the expense of the application
window that it should inject input to. My application can receive focus
either by a mouse click or through a global keybinding applied using the
keybinder[1] api.

Is there a way for a Gtk3+ application to discover the tty device of the
application that lost focus to it ?

Although my example is in Ruby, any pointers in C, Ruby or Python would
be helpful - I can work out the bindings if I know how it is done in C.

[1] https://lazka.github.io/pgi-docs/#Keybinder-3.0



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