How to get xid on Windows?

How to get xid on Windows?

Hi folks,

When I ran the following tiny snippet on my Windows 7,

require ‘gtk2’
win = Gtk::Window.new
win.signal_connect(‘expose-event’) do
p win.window.xid
end
win.show_all
Gtk.main

I got the error: undefined method `xid’ for #<Gdk::Window:02735E38
ptr=026D9170>

But on Ubuntu on VirtualBox for Windows 7, it works well.
(I got the number of xid.)

Could you show me how to get a xid on Windows?

Thanks,
ashbb

hi ash,

interesting - confirmed the same issue comparing Ubuntu and WinXP.

running this…

require ‘gtk2’
win = Gtk::Window.new
win.signal_connect(‘expose-event’) do
win.window.methods.sort.each{|m| p m}
end
win.show_all
Gtk.main

…shows that the #xid method exists in ubuntu, but not in windows.
strange…

  • j

Satoshi A. wrote in post #1024450:

How to get xid on Windows?

Hi folks,

When I ran the following tiny snippet on my Windows 7,

require ‘gtk2’
win = Gtk::Window.new
win.signal_connect(‘expose-event’) do
p win.window.xid
end
win.show_all
Gtk.main

I got the error: undefined method `xid’ for #<Gdk::window:02735E38
ptr=026D9170>

http://ruby-gnome2.sourceforge.jp/hiki.cgi?cmd=view&p=Gdk%3A%3ADrawable&key=xid#xid
:
Returns the X11 (X Window) XID of this Gdk::Drawable, as a number. X
only

Notice the “X only”. Windows does not use X.

Simon

@J,
Thank you for the confirmation. :slight_smile:

@Simon,
I see. Thank you for the information.

@all,
Now then, I have two more questions.

1st:
“Windows does not use X.” … I see.
But can I use xid on Windows or can’t?

I ran the following snippet on my Windows 7 and I got a xid for a video
window created by playbin2 plugin.

require ‘gtk2’
require ‘gst’
play_bin = Gst::ElementFactory.make(‘playbin2’)
bus = play_bin.bus
bus.add_watch do |bus, message|
case message.type
when Gst::Message::ELEMENT
p message.structure[“xwindow-id”] #=> Got a number, e.g. 18023540
end
true
end
play_bin.uri = ‘file://d/tmp/input.mp4’
window = Gtk::Window.new
window.show_all
play_bin.play
Gtk.main

2nd: If the above first questions’s answer is “can’t”,
are there any alternative ways to identify a window on Windows?
A native window handler or somthing…

I’m now looking for the way to embed the video window in my Ruby/GTK2
application.
I found GstXOverlay[*1]. So, I want to know how to identify a window.

ashbb

*1:
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-gstxoverlay.html#GstXOverlay

hi ashbb,

maybe this could help?

FindWindowA function (winuser.h) - Win32 apps | Microsoft Learn

i don’t know if the handle returned by the FindWindow function relates
in any way to the value returned by the GstStructure, but maybe?
hopefully :wink:

  • j

Satoshi A. wrote in post #1024748:

1st:
“Windows does not use X.” … I see.
But can I use xid on Windows or can’t?

You can’t. The source is :
#ifdef GDK_WINDOWING_X11
rb_define_method(gdkDrawable, “xid”, gdkdraw_get_xid, 0);
#endif

And, as I said, windows does not use X.

I ran the following snippet on my Windows 7 and I got a xid for a video
window created by playbin2 plugin.

require ‘gtk2’
require ‘gst’
play_bin = Gst::ElementFactory.make(‘playbin2’)
bus = play_bin.bus
bus.add_watch do |bus, message|
case message.type
when Gst::Message::ELEMENT
p message.structure[“xwindow-id”] #=> Got a number, e.g. 18023540
end
true
end
play_bin.uri = ‘file://d/tmp/input.mp4’
window = Gtk::Window.new
window.show_all
play_bin.play
Gtk.main

You do not get a ‘xid’, you retrieve a value from a GstStructure, with
the key ‘xwindow-id’. I don’t know how GStreamer fills this value.

2nd: If the above first questions’s answer is “can’t”,
are there any alternative ways to identify a window on Windows?
A native window handler or somthing…

I’m now looking for the way to embed the video window in my Ruby/GTK2
application.
I found GstXOverlay[*1]. So, I want to know how to identify a window.

I think GstXOverlay is only for X too, but I don’t know much GStreamer.

This discussion Gstreamer: linking playbin2 - Ruby-Gnome 2 - Ruby-Forum talks about
that, and it seems no solution was found.

I’m not sure you will be able to do what you want with ruby.

Simon

Hi J, Simon at al,

Win32API- GetForegroundWindows() - Ruby - Ruby-Forum
Wow, bingo!

Try out the following. The video is embedded in my Ruby/GTK2 app window!

require ‘gtk2’
require ‘gst’
require ‘win32api’
play_bin = Gst::ElementFactory.make(‘playbin2’)
play_bin.uri = ‘file://d/tmp/input.mp4’
play_bin.video_sink = Gst::ElementFactory.make(‘dshowvideosink’)
window = Gtk::Window.new
window.signal_connect(‘expose-event’)do
play_bin.video_sink.xwindow_id = Win32API.new(‘user32’,
‘GetForegroundWindow’, [], ‘N’).call
end
window.show_all
play_bin.play
Gtk.main

Thanks,
ashbb

and maybe these?

Win32-api 1.0.0 - Ruby - Ruby-Forum

ruby - Win32 - Can one Enumerate the windows belonging to the calling thread? - Stack Overflow

Win32API- GetForegroundWindows() - Ruby - Ruby-Forum

again, i’m not sure that these are at all useful, but hopefully!

  • j

awesome! glad to hear it!

  • j

Wow, very useful!

Shall I add this to the Wiki or is this too platform specific?

Figured that it could be helpful for windows users…