Module: Doom::Platform::GosuWindow::SDLKeyboardGrab
- Defined in:
- lib/doom/platform/gosu_window.rb
Overview
SDL2 keyboard grab via Gosu’s bundled SDL – prevents OS key interception
Class Method Summary collapse
Class Method Details
.grab! ⇒ Object
30 31 32 33 |
# File 'lib/doom/platform/gosu_window.rb', line 30 def self.grab! return unless @ready @set_kb_grab.call(@shared_window.call, 1) end |
.release! ⇒ Object
35 36 37 38 |
# File 'lib/doom/platform/gosu_window.rb', line 35 def self.release! return unless @ready @set_kb_grab.call(@shared_window.call, 0) end |
.setup ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/doom/platform/gosu_window.rb', line 12 def self.setup require "fiddle" gosu_spec = Gem.loaded_specs["gosu"] lib_ext = RbConfig::CONFIG["DLEXT"] || "so" bundle = File.join(gosu_spec.full_gem_path, "lib", "gosu.#{lib_ext}") @lib = Fiddle.dlopen(bundle) @shared_window = Fiddle::Function.new( @lib["_ZN4Gosu13shared_windowEv"], [], Fiddle::TYPE_VOIDP ) @set_kb_grab = Fiddle::Function.new( @lib["SDL_SetWindowKeyboardGrab"], [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT], Fiddle::TYPE_VOID ) @ready = true rescue @ready = false end |