Title from current active window

How can I get the title of current active window? But not only from my
application windows, but from all. And if the active window is changed
can I get the signal?

Gatis Tomsons wrote:

How can I get the title of current active window? But not only from my
application windows, but from all. And if the active window is changed
can I get the signal?

I unfortunately do not have a solution but I would be interested too.

I tried the normal route and it seems you can do

w = Gtk::Window.new
w.title = “foo”

puts w.title # => “foo”

I am not sure which signal is emitted if the active window is changed
(do you mean button over event) but you can iterate over all events
easily to find out, I assume.

On Mon, Sep 15, 2008 at 4:05 PM, Gatis Tomsons
[email protected] wrote:

How can I get the title of current active window? But not only from my
application windows, but from all. And if the active window is changed

This looks like it’s beyond ruby-gnome2’s scope. I’d try looking at
the desktop (window manager) or X side…


Guillaume C. - Guillaume Cottenceau

On Tue, 2008-09-16 at 07:13 +0200, Gatis Tomsons wrote:

Guillaume C. wrote:

This looks like it’s beyond ruby-gnome2’s scope. I’d try looking at
the desktop (window manager) or X side…

You’re probably right, but is there any libs to access these data? It’s
not ruby-gnome2 but it’s very close to it :slight_smile:

I’m pretty sure the Window Navigator Construction Kit (GNOME WNCK) can
do what you want. I don’t think there are Ruby bindings but there are
Perl bindings:

Gnome2::Wnck
Gnome2::Wnck::Screen

Cheers
Grant

On Tue, 2008-09-16 at 21:09 +1200, Grant McLean wrote:

I’m pretty sure the Window Navigator Construction Kit (GNOME WNCK) can
do what you want. I don’t think there are Ruby bindings but there are
Perl bindings:

Gnome2::Wnck
Gnome2::Wnck::Screen

Sorry, I meant to attach a sample script to get you going …

Guillaume C. wrote:

This looks like it’s beyond ruby-gnome2’s scope. I’d try looking at
the desktop (window manager) or X side…


Guillaume C. - Guillaume Cottenceau

You’re probably right, but is there any libs to access these data? It’s
not ruby-gnome2 but it’s very close to it :slight_smile:

hmm… it will work, but then I need extra packages like perl gnome,
thats not good :confused:

Mike C. wrote:

Maybe just writing your own bindings would be the best.
I think what you need is in libxext, but I admit that
it’s been more than a decade since I looked in there.
It should be only one or two functions you need to
bind, so it would be pretty easy (probably easier
than finding another library that does it).

          MikeC

I’m new to ruby, my main work is web development and all this GUI stuff
is just for fun. I have no clue how to code the bindings, but I will
try. Thanks for help.

Maybe just writing your own bindings would be the best.
I think what you need is in libxext, but I admit that
it’s been more than a decade since I looked in there.
It should be only one or two functions you need to
bind, so it would be pretty easy (probably easier
than finding another library that does it).

          MikeC

Gatis Tomsons wrote:

Mike C. wrote:

Maybe just writing your own bindings would be the best.
I think what you need is in libxext, but I admit that
it’s been more than a decade since I looked in there.
It should be only one or two functions you need to
bind, so it would be pretty easy (probably easier
than finding another library that does it).

          MikeC

I’m new to ruby, my main work is web development and all this GUI stuff
is just for fun. I have no clue how to code the bindings, but I will
try. Thanks for help.

I found grate tutorial
http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html
now I just need to understand the libxext.

I found a solution. To get all info about active window I will use
command line tool “xprop and xwininfo” it’s included in ubuntu package
called “x11-utils” I think it’s base package, so it will be available on
any linux.

So, to get active window ID we type

xprop -root | grep “_NET_ACTIVE_WINDOW(WINDOW)”| cut -d ’ ’ -f 5

and then

xwininfo -id WIN_ID |awk ‘BEGIN {FS=“"”}/xwininfo: Window id/{print
$2}’ | sed ‘s/-[^-]*$//g’

replace the WIN_ID with the real id. Thats all :slight_smile:

I got this example from

On Tue, Sep 16, 2008 at 9:36 PM, Gatis Tomsons
[email protected] wrote:

I found grate tutorial
How to create a Ruby extension in C in under 5 minutes
now I just need to understand the libxext.

Thanks for that! I probably need to do something with it soon too :-).

I had a quick look at the man pages for libxext and I can’t find
what I was trying to remember. A long time ago I was doing some
work on window managers and I remember playing with this
kind of thing. If you look at the code for something like blackbox
I’m sure you’ll find what you are looking for (but beware… there
are some race conditions when you query the X server for things
like the window titles. If you query and the window doesn’t
exist, you will crash your app).

Now, having said all that, I’m now thinking there must be
functionality in Gnome to do this. Otherwise you couldn’t
build the pager applet. Unfortunately, it’s been even longer
since I looked at Gnome code… sigh…

Sorry I can’t be of more help.

              MikeC