bikeNomad has asked for the wisdom of the Perl Monks concerning the following question:

I've been wanting to write a program that can analyze my time spent at the computer (including the amount of time I spend on Perlmonks) by observing what I do. I figured that I could monitor which of the windows on my screen was frontmost, and get its title, or find the commandline of the process that owns the window, or analyze its open files, or something to help my program determine which of several tasks I'm working on.

I looked in CPAN and didn't find any way to interact with the window manager (I'm using X Windows under Linux, with the kdm window manager, but there is a semi-standard WM API under X).

Does anyone know how to:<bl>

  • Find which window has focus (has to be sensitive to multiple desktops, if it makes any difference)
  • Find which application (PID) owns that window </bl>

    I realize I could use XS, or my new favorite Inline, but I was hoping I wouldn't have to learn all about X to do this...

    Thanks!

    • Comment on Any way to query which X Window has focus from Perl?
  • Replies are listed 'Best First'.
    Re: Any way to query which X Window has focus from Perl?
    by Zaxo (Archbishop) on Jun 23, 2001 at 22:50 UTC

      The function I think you want is described in 'man 3 XGetInputFocus'. There is a last_focus_change variable which may be helpful. I've never called X directly from perl, can't help there.

      After Compline,
      Zaxo