Sha256: b181104196c5d1455d3509cd4cfe15cf3ead270a4e50438f51f8104ca7902d54

Contents?: true

Size: 1.85 KB

Versions: 18

Compression:

Stored size: 1.85 KB

Contents

gem "ffi"
require 'ffi'

module Redcar
  class ApplicationSWT
    class Window
        # it appears that swt offers no real way to
        # bring a window to the front
        # force_active doesn't seem to work as expected, at least on doze
        # http://stackoverflow.com/questions/2315560/how-do-you-force-a-java-swt-program-to-move-itself-to-the-foreground
        # this hack around seems to work for windows.
      module BringToFront
        extend FFI::Library
        ffi_lib 'user32', 'kernel32'
        ffi_convention :stdcall
        attach_function :GetForegroundWindow, [], :long
        attach_function :SetForegroundWindow, [:long], :int
        attach_function :GetWindowThreadProcessId, [:long, :pointer], :int
        attach_function :AttachThreadInput, [:int, :int, :int], :int
        attach_function :GetCurrentThreadId, [], :int # unused

        def self.bring_window_to_front hwnd_int
          wanted = hwnd_int
          top_window = BringToFront.GetForegroundWindow
          if top_window == 0
            # should be able to set it without delay?
            if(BringToFront.SetForegroundWindow(wanted) > 0)
              return true
            end
          end
          top_pid = BringToFront.GetWindowThreadProcessId(top_window, nil)
          wanted_pid = BringToFront.GetWindowThreadProcessId(hwnd_int, nil)
          if top_pid == wanted_pid
            if(BringToFront.SetForegroundWindow(wanted))
              return true
            end
          end
          if top_pid > 0 && wanted_pid > 0
            if (BringToFront.AttachThreadInput(wanted_pid,top_pid,1) == 0)
              return false
            end
            BringToFront.SetForegroundWindow(wanted) 
            BringToFront.AttachThreadInput(wanted_pid, top_pid,0)
            return true
          else
            return false
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
redcar-dev-0.12.21dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.20dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.19dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.18dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.17dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.16dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.15dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.14dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.13dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.12dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.11dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.10dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.9dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.8dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.7dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.6dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.4dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.3dev-java plugins/application_swt/lib/application_swt/bring_to_front.rb