Sha256: b6de4de1b47de5457a6ec16a74730fe03cc4fe2a8534e67bf2f3a6f2d235e3d7

Contents?: true

Size: 1.92 KB

Versions: 15

Compression:

Stored size: 1.92 KB

Contents

$:.unshift(File.expand_path("../../../../../vendor/ffi-1.0.11-java/lib", __FILE__))
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

15 entries across 15 versions & 2 rubygems

Version Path
redcar-0.13 plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.13.5dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.13.4dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.13.3dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.13.2dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.13.1dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-0.12.1 plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.13.0dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-0.12 plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.27dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.26dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.25dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.24dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.23dev plugins/application_swt/lib/application_swt/bring_to_front.rb
redcar-dev-0.12.22dev plugins/application_swt/lib/application_swt/bring_to_front.rb