Class: RMonitor::Profiles

Inherits:
Object
  • Object
show all
Extended by:
ProfileHelpers, XRandRWriteHelpers
Includes:
DSLHelpers
Defined in:
lib/rmonitor/profiles.rb

Class Method Summary collapse

Methods included from ProfileHelpers

best_matching_configuration, has_matching_configuration, invokable?, necessary_devices_present?, user_defined_rules_satisfied?

Methods included from XRandRWriteHelpers

turn_off, turn_on

Class Method Details

.parse(config_data) ⇒ Object



11
12
13
14
15
# File 'lib/rmonitor/profiles.rb', line 11

def self.parse(config_data)
  profile_builder = ProfileBuilder.new
  profile_builder.instance_eval(config_data)
  profile_builder.profiles
end

.to_xrandr(devices, profile) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rmonitor/profiles.rb', line 17

def self.to_xrandr(devices, profile)
  xrandr = 'xrandr'

  # Devices that are currently enabled, but not contained in the profile
  to_disable = devices.select { |d| d[:enabled ]}.map { |d| d[:name] } -
      profile[:devices].map { |d| d[:name] }

  unless to_disable.empty?
    to_disable.each do |name|
      xrandr << ' ' << turn_off(name)
    end

    xrandr << ' && xrandr'
  end

  if profile[:options] and profile[:options][:dpi]
    xrandr << ' --dpi ' << profile[:options][:dpi].to_s
  end

  # The devices contained in the profile are to be turned on and configured
  profile[:devices].each do |wanted_device|
    device = devices.find { |d| d[:name] == wanted_device[:name] }

    configuration = best_matching_configuration(device,
                                                wanted_device[:mode],
                                                wanted_device[:rate])

    xrandr << ' ' << turn_on(device[:name],
                             configuration.merge(wanted_device))
  end

  xrandr
end