Closed singpolyma closed 1 year ago
That should be an unreleased feature. We should be updating the version of C libui that is wrapped by Glimmer DSL for LibUI in the near future.
Apparently, the C libui library included in Glimmer DSL for LibUI already includes access to the window focus APIs.
I just tested this Glimmer DSL for LibUI code sample and it worked!
require 'glimmer-dsl-libui'
include Glimmer
window { |w|
on_focus_changed do
puts 'focus changed'
puts w.focused
end
}.show
Basically, you can use:
on_focus_changed
listener on window
focused
property on window
(returns 1
for focused and 0
for unfocused)I hope this helps.
I just made a release of Glimmer DSL for LibUI that officially supports window
focused?
property as boolean and documents window
on_focus_changed
listener:
https://rubygems.org/gems/glimmer-dsl-libui/versions/0.6.0.pre.1
I also updated examples/basic_child_window.rb
to demo focused?
and on_focus_changed
:
require 'glimmer-dsl-libui'
include Glimmer
window('Main Window') { |main_window|
button('Spawn Child Window') {
on_clicked do
window('Child Window') { |child_window|
on_focus_changed do
puts 'Child window is focused' if child_window.focused?
end
on_closing do
puts 'Child window is closing'
end
}.show
end
}
on_focus_changed do
puts 'Main window is focused' if main_window.focused?
end
on_closing do
puts 'Main window is closing'
end
}.show
That should address this issue completely, so I am closing (you may still comment if you have further questions, or even re-open if you discover another related issue).
One thing I forgot to mention is that the 0.6.0.pre.1 version finally includes a newer version of the C libui library (wasn't needed for this issue though), so it supports a new open_folder
keyword, which works like open_file
, but opens a directory instead.
It looks like LIbUI has a callback for focus change on a window, but I'm not sure how to get at it from glimmer. That and also to ask a window if it has focus right now.