Title from current active window


#1

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?


#2

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.


#3

On Mon, Sep 15, 2008 at 4:05 PM, Gatis Tomsons
removed_email_address@domain.invalid 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. - http://zarb.org/~gc/


#4

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:

http://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Wnck.html
http://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Wnck/Screen.html

Cheers
Grant


#5

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:

http://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Wnck.html
http://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Wnck/Screen.html

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


#6

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. - http://zarb.org/~gc/

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:


#7

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


#8

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.


#9

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

#10

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.


#11

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
http://thegeekbird.blogspot.com/2008/08/opera-pdf.html


#12

On Tue, Sep 16, 2008 at 9:36 PM, Gatis Tomsons
removed_email_address@domain.invalid wrote:

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.

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