class FFMPEG::WindowTitles::WindowGrabber

@since 1.0.0-beta4

Public Instance Methods

available_windows_for(application) click to toggle source

Returns a cleaned up list of available window titles for the given application (process) name.

# File lib/ffmpeg/window_titles.rb, line 24
def available_windows_for(application)
  return windows_os_window(application) if OS.windows?
  return linux_os_window(application) if OS.linux?

  raise NotImplementedError, 'Your OS is not supported.'
end

Private Instance Methods

linux_os_window(application) click to toggle source

Returns list of window titles in FFmpeg expected format when using Linux

# File lib/ffmpeg/window_titles.rb, line 50
def linux_os_window(application)
  FFMPEG.logger.warn 'Default capture device on Linux (x11grab) does not support window recording.'
  raise DependencyNotFound, 'wmctrl is not installed. Run: sudo apt install wmctrl.' unless wmctrl_installed?

  titles = `wmctrl -l | awk '{$3=""; $2=""; $1=""; print $0}'` # Returns all open windows
             .split("\n")
             .map(&:strip)
             .select { |t| t.match?(/#{application}/i) } # Narrow down to given application
  raise RecorderErrors::ApplicationNotFound, "No open windows found for: #{application}" if titles.empty?

  titles
end
warn_on_mismatch(titles, application) click to toggle source

Prints a warning if the retrieved list of window titles does no include the given application process name, which applications commonly do.

# File lib/ffmpeg/window_titles.rb, line 74
def warn_on_mismatch(titles, application)
  unless titles.map(&:downcase).join(',').include? application.to_s
    FFMPEG.logger.warn "Process name and window title(s) do not match: #{titles}"
    FFMPEG.logger.warn "Please manually provide the displayed window title."
  end
end
windows_os_window(application) click to toggle source

Returns list of window titles in FFmpeg expected format when using Microsoft Windows

# File lib/ffmpeg/window_titles.rb, line 36
def windows_os_window(application)
  titles = `tasklist /v /fi "imagename eq #{application}.exe" /fo list | findstr  Window`
             .split("\n")
             .map { |i| i.gsub(FILTERED_TITLES, '') }
             .reject(&:empty?)
  raise RecorderErrors::ApplicationNotFound, "No open windows found for: #{application}.exe" if titles.empty?

  warn_on_mismatch(titles, application)
  titles
end
wmctrl_installed?() click to toggle source

Returns true if wmctrl is installed

# File lib/ffmpeg/window_titles.rb, line 66
def wmctrl_installed?
  !`which wmctrl`.empty? # "" when not found
end