Register
It is currently Thu Dec 18, 2014 1:44 pm

Cycle through X11 windows.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Thu Aug 06, 2009 12:07 pm   

Joined: Thu Aug 06, 2009 10:45 am
Posts: 4
Hi,

I'm trying to write a script that when called cycles through open X11 windows using wmctrl http://tripie.sweb.cz/utils/wmctrl/.

Each time it is called it will cycle to the next window. I actually want to make two scripts one to cycle forwards and one to cycle backwards.

When I type "wmctrl -l" it lists the windows like this:

Code:
[joe@arch ~]$ wmctrl -l
0x01000452  0 arch joe - File Manager
0x01800003  0 arch cycle-up
0x01c00020  0 arch BashScripts.org • Post a new topic
0x01a00020  0 arch wmctrl - A command line tool to interact with an EWMH/NetWM compatible X Window Manager.
0x01e00003  0 arch Terminal


The windows are listed in the same order each time I type "wmctrl -l".

And I can use "wmctrl -ai" to switch to a window; for example "wmctrl -ai 0x01000452" to focus and raise the File Manager window.

So I think I should be able to use wmctrl to cycle through windows.

But there's two main things I don't know how to do. Firstly the script will need to know which window is currently focused, (otherwize it couldn't know which window to cycle to next) and I don't know how to find this out. There seems to be an X11 command called "XGetInputFocus" but I can't work out how to use it. "man XGetInputFocus" doesn't help. Secondly I don't know how to parse the output of "wmctrl -l".

Note that when it gets to the end of the list of windows I want it to go back to the beginning of the list, so it can cycle endlessly.

This is what I have so far:

Code:
#!/bin/sh
A = 'wmctrl -l'


Thanks.


Last edited by hyd98a on Thu Aug 06, 2009 12:13 pm, edited 1 time in total.

Top
 Profile  
 PostPosted: Tue Sep 01, 2009 5:29 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
XGetInputFocus is C function in the C library, xlib (Wikipedia page: http://en.wikipedia.org/wiki/Xlib, another useful site: http://tronche.com/gui/x/xlib/). You won't be able to reasonably interact with it in a bash script. I recommend doing this project in C. Note that you can make use of bash scripts in a C program by using system() (http://en.wikipedia.org/wiki/System_(C_standard_library)).

It's not obvious, but most of the man pages that you are interested in are in sections 1 or 8; these are the commands you will typically use. You can tell what section a man page is in by looking at the top of the man page. It looks something like this:
Quote:
XSetInputFocus(3) XLIB FUNCTIONS XSetInputFocus(3)

You can see that XSetInputFocus in section 3; if you type "man man", you'll see that section 3 deals with library calls.

I hope that clears up some things for you. By the way, I'm sure you're aware that you can use CTRL+TAB to cycle through windows in X. Did it just seem like an interesting project?


Top
 Profile  
 PostPosted: Thu Sep 10, 2009 9:37 am   

Joined: Thu Aug 06, 2009 10:45 am
Posts: 4
That was helpfull, thankyou.

But pressing CTRL+TAB does not do anything for me. Might it be that my window manager (xfwm4) is intercepting the keypresses? Or do I need to recompile X11?


Top
 Profile  
 PostPosted: Thu Sep 10, 2009 3:12 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
I suppose CTRL-TAB window cycling is not an X feature, but a WM feature. I'm not sure what the best solution would be for you. It's a bit outside the realm of bash scripts, though.

Good luck to you!

- thobbs


Top
 Profile  
 PostPosted: Mon Oct 05, 2009 8:30 pm   

Joined: Mon Oct 05, 2009 6:31 pm
Posts: 6
ALT+TAB alternates through windows in most WM's, is this not an option for you?

I read that you are using fvwm4, which I'll admit I have little experience with. If you were using KDE then you could simply make a dcop call to KWIN to cycle through windows, desktops, tabs, etc. Very easily scriptable.

Sometimes knowing why you want to do something helps people to grasp the concept instead of getting hung up on a specific implementation. Maybe even suggest a better method. Just a thought B-)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP