Class: Mani

Inherits:
Object
  • Object
show all
Defined in:
lib/mani.rb,
lib/mani/x.rb,
lib/mani/window.rb,
lib/mani/version.rb,
lib/mani/tokenizer.rb

Overview

The base class.

Defined Under Namespace

Classes: Tokenizer, Version, Window, X

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Mani

Initializes the windowing system, as well as the window manager options.

Parameters:

  • options (Hash) (defaults to: {})

    The options

    • :window_manager (Symbol) The window manager (currently only handles :xmonad)

    • :switch_to_workspace (Proc) Optional The proc which, when called, returns a string which, when interpreted, will switch to the specified workspace

  • block (Proc)

    The code to execute after initialization



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mani.rb', line 15

def initialize(options = {}, &block)
  window_manager = options.delete :window_manager
  case window_manager
  when :xmonad
    require 'mani/x'

    @windowing_system = Mani::X.new
    @window_manager_options = {
      switch_to_workspace: ->(space) { "super+#{space}" }
    }.merge options
  else
    fail 'Unrecognized :window_manager.'
  end

  @windows = {}

  instance_eval(&block)
end

Instance Method Details

#window(name, options = {}, &block) ⇒ Object

Creates a new window object, or defers execution of the supplied block to an existing window object.

Parameters:

  • name (Symbol)

    The window name

  • options (Hash) (defaults to: {})

    The options

    • :launch (String) Optional The program to launch. If specified, any remaining options, as well as the supplied block, will be passed to Mani::Window#launch. If not specified, the supplied block will be executed (within the context of the window).

  • block (Proc)

    The code to execute



44
45
46
47
48
49
50
51
52
53
# File 'lib/mani.rb', line 44

def window(name, options = {}, &block)
  @windows[name] = Window.new @windowing_system unless @windows[name]

  program = options.delete :launch
  if program
    @windows[name].launch program, options, &block
  else
    @windows[name].instance_eval(&block)
  end
end

#workspace(space, &block) ⇒ Object

Switches to the specified workspace.

Parameters:

  • space (Integer)

    The space number

  • block (Proc)

    The code to execute after switching to the workspace



59
60
61
62
63
64
# File 'lib/mani.rb', line 59

def workspace(space, &block)
  sequence = @window_manager_options[:switch_to_workspace].call space
  @windowing_system.type_keysequence sequence

  instance_eval(&block) if block
end