Sha256: e738e46133add47af9b97a85493bab538538e49d2f3f77aeba3ba768de502a6b

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module GirFFIGtk
  # Override init to automatically use ARGV as its argument.
  module AutoArgv
    def self.included base
      base.extend ClassMethods
      class << base
        alias_method :init_without_auto_argv, :init
        alias_method :init, :init_with_auto_argv
      end
    end

    # Implementation of class methods for AutoArgv
    module ClassMethods
      def init_with_auto_argv
        remaining = init_without_auto_argv([$PROGRAM_NAME, *ARGV]).to_a
        remaining.shift
        ARGV.replace remaining
      end
    end
  end

  # Override main to start an idle thread to allow Ruby threads to run during
  # the main loop.
  module ThreadEnabler
    def self.included base
      base.extend ClassMethods
      class << base
        alias_method :main_without_thread_enabler, :main
        alias_method :main, :main_with_thread_enabler
      end
    end

    # Implementation of class methods for ThreadEnabler
    module ClassMethods
      def main_with_thread_enabler
        case RUBY_ENGINE
        when 'jruby'
        when 'rbx'
        else # 'ruby' most likely
          GLib::MainLoop::ThreadEnabler.instance.setup_idle_handler
        end
        main_without_thread_enabler
      end
    end
  end
end

# Overrides for Gtk module functions
module Gtk
  setup_method "init"
  setup_method "main"

  include GirFFIGtk::AutoArgv
  include GirFFIGtk::ThreadEnabler
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gir_ffi-gtk-0.8.0 lib/gir_ffi-gtk/base.rb