class Fusuma::Plugin::Executors::WmctrlExecutor

Control Window or Workspaces by executing wctrl

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fusuma/plugin/executors/wmctrl_executor.rb, line 24
def initialize
  super()
  @workspace = Workspace.new(
    wrap_navigation: config_params(:'wrap-navigation'),
    matrix_col_size: config_params(:'matrix-col-size')
  )
  @window = Window.new
end

Public Instance Methods

config_param_types() click to toggle source
# File lib/fusuma/plugin/executors/wmctrl_executor.rb, line 17
def config_param_types
  {
    'wrap-navigation': [TrueClass, FalseClass],
    'matrix-col-size': [Integer]
  }
end
executable?(event) click to toggle source

check executable @param event [Event] @return [TrueClass, FalseClass]

# File lib/fusuma/plugin/executors/wmctrl_executor.rb, line 47
def executable?(event)
  event.tag.end_with?('_detector') &&
    event.record.type == :index &&
    search_command(event)
end
execute(event) click to toggle source

execute wmctrl command @param event [Event] @return [nil]

# File lib/fusuma/plugin/executors/wmctrl_executor.rb, line 36
def execute(event)
  return if search_command(event).nil?

  MultiLogger.info(wmctrl: search_command(event))
  pid = Process.spawn(search_command(event))
  Process.detach(pid)
end
execute_keys() click to toggle source

executor properties on config.yml @return [Array<Symbol>]

# File lib/fusuma/plugin/executors/wmctrl_executor.rb, line 13
def execute_keys
  %i[workspace window]
end
search_command(event) click to toggle source

@param event [Event] @return [String] @return [NilClass]

# File lib/fusuma/plugin/executors/wmctrl_executor.rb, line 56
def search_command(event)
  search_workspace_command(event) || search_window_command(event)
rescue Workspace::InvalidOption => e
  MultiLogger.error(e.message)
  exit 1
end

Private Instance Methods

search_window_command(event) click to toggle source

@param event [Event] @return [String] @return [NilClass]

# File lib/fusuma/plugin/executors/wmctrl_executor.rb, line 86
def search_window_command(event)
  index = Config::Index.new([*event.record.index.keys, :window])

  case property = Config.search(index)
  when 'prev', 'next'
    @workspace.move_window_command(direction: property)
  when 'left', 'right', 'up', 'down'
    @workspace.move_window_command_for_matrix(direction: property)
  when 'fullscreen'
    @window.fullscreen(method: 'toggle')
  when 'maximized'
    @window.maximized(method: 'toggle')
  when 'close'
    @window.close
  when Hash
    if property[:fullscreen]
      @window.fullscreen(method: property[:fullscreen])
    elsif property[:maximized]
      @window.maximized(method: property[:maximized])
    end
  when nil
    nil
  else
    raise "#{property} is invalid key"
  end
end
search_workspace_command(event) click to toggle source

@param event [Event] @return [String] @return [NilClass]

# File lib/fusuma/plugin/executors/wmctrl_executor.rb, line 68
def search_workspace_command(event)
  index = Config::Index.new([*event.record.index.keys, :workspace])

  case property = Config.search(index)
  when 'prev', 'next'
    @workspace.move_command(direction: property)
  when 'left', 'right', 'up', 'down'
    @workspace.move_command_for_matrix(direction: property)
  when nil
    nil
  else
    raise "#{property} is invalid key"
  end
end