LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Getting the name of the top-level or focused window in KDE (https://www.linuxquestions.org/questions/linux-desktop-74/getting-the-name-of-the-top-level-or-focused-window-in-kde-665644/)

narc 08-26-2008 08:42 PM

Getting the name of the top-level or focused window in KDE
 
Hello.

I want to send into a file the top-level window, or the focused window currently in use under KDE. Is there a way to capture such informaton at any time ?

Thanks.

aus9 08-30-2008 12:31 AM

I am not sure what your question is and as no-one has replied forgive me for my attempt.

If you want to capture the output of a command in a window ...generally this is achieved by

Code:

command > /pathwaytosavefile/newfilename
eg

$ ls > /home/gordy/ls
gordy@siduxbox:~$ cat ls
01dox
2008-08-27-09-03-31.011-VirtualBox-3329.log
Desktop
firefox
ls

narc 08-30-2008 05:19 AM

Thank you for your reply but I'm already familiar with stream redirection.

I want to know if the focused window in KDE (or in X for that matter), say my web browser currently used to respond to you, is available by some command that would put its name into a file. Of course, it would be a background job (by cron for instance) because if I actually used the command line, I'd always have "xterm" or "konsole" on the ouput. ;-)

(Using Firefox)
% some_script_running_by_cron > my_file.
% cat my_file
Firefox.

A list of the windows stack would be interesting.

I found a more generic command that helped me:
% ps -A | cut -c25- | sort | uniq

But I need to clean up the final list by removing non-X processes. And it doesn't tell me which is the current one (i.e. top-level) used in X.

Cheers.

tredegar 08-30-2008 06:44 AM

Maybe dcop can do what you want?
http://www.linuxformat.co.uk/wiki/in...9.tut_dcop.pdf

narc 08-30-2008 08:38 AM

I suspected that KDE had the power to do that through DCOP.

Don't know how to control it to get what I want but I'll try.

Cool tutorial, BTW. Thanks.

pwc101 08-30-2008 08:55 AM

Perhaps this is of some use? http://www.oreillynet.com/linux/blog...y_time_go.html

The C code in its current form outputs the name of the window which has focus to standard output once a second. For example, I just ran it for a little while, and got this output:
Code:

pwc101@example:~> watch_focus
Focus in window 'Yakuake'
Focus in window 'Yakuake'
Focus in window 'Yakuake'
Focus in window 'Getting the name of the top-level or focused window in KDE - LinuxQuestions.org - Mozilla Firefox'
Focus in window 'Getting the name of the top-level or focused window in KDE - LinuxQuestions.org - Mozilla Firefox'
Focus in window 'Getting the name of the top-level or focused window in KDE - LinuxQuestions.org - Mozilla Firefox'
Focus in window 'Yakuake'
Focus in window 'Yakuake'
Focus in window 'Yakuake'
Focus in window 'Yakuake'
Focus in window 'Getting the name of the top-level or focused window in KDE - LinuxQuestions.org - Mozilla Firefox'
Focus in window 'Getting the name of the top-level or focused window in KDE - LinuxQuestions.org - Mozilla Firefox'
Focus in window 'Getting the name of the top-level or focused window in KDE - LinuxQuestions.org - Mozilla Firefox'
Focus in window 'Yakuake'
Focus in window 'Yakuake'
Focus in window 'Yakuake'
pwc101@example:~>


narc 08-30-2008 09:17 AM

Impressive. Right on the button. The author also gives an *actual legitimate use for it* ;-)

Cheers.


All times are GMT -5. The time now is 10:35 AM.