class R3Status::Blocks::Volume

A block that acts as a volume indicator. It displays the current Master Volume, and allows to user to change it using scrolling, and muting using the middle mouse button.

States

:muted, :unmuted

Format values

Attributes

step[RW]

The amount of volume (in percents) to change with scroll.

Public Class Methods

new(**args, &block) click to toggle source

Creates a new instance of this class. If a block is passed, it will be stored and yielded when the block is clicked.

Calls superclass method R3Status::Blocks::Base::new
# File lib/r3status/blocks/volume.rb, line 17
def initialize(**args, &block)
  args = {formats: {muted: " %{volume}%", unmuted: " %{volume}%"},
          colors: {muted: '#7CCdCD', unmuted: '#ffffff'}, step: 5,
          name: "volume_master"}.merge(args)
  
  super(args, &block)
end

Public Instance Methods

clicked(button, x, y) click to toggle source

Handles mouse interaction with the block. If a block was supplied to the constructor, it will be yielded.

button (Fixnum)

The mouse button that was used.

x, y (Fixnum / Float)

The pointer coordinates on the screen.

Calls superclass method R3Status::Blocks::Base#clicked
# File lib/r3status/blocks/volume.rb, line 37
def clicked(button, x, y)
  super(button, x, y)
  case button
  when 4
    increase
  when 2
    toggle_mute
  when 5
    decrease
  end
end
decrease(step = nil) click to toggle source

Decreases the system volume by the given amount.

step

The amount of volume to decrease. If nil, the value default value,

or the one supplied in the constructor, will be used.

# File lib/r3status/blocks/volume.rb, line 64
def decrease(step = nil)
  `amixer -c 0 set Master #{step || @step}%- unmute`
end
increase(step = nil) click to toggle source

Increases the system volume by the given amount.

step

The amount of volume to increase. If nil, the value default value,

or the one supplied in the constructor, will be used.

# File lib/r3status/blocks/volume.rb, line 57
def increase(step = nil)
  `amixer -c 0 set Master #{step || @step}%+ unmute`
end
muted?() click to toggle source

Returns the mute state of the system volume.

# File lib/r3status/blocks/volume.rb, line 74
def muted?
  `amixer -c 0 get Master | grep Mono: | cut -d " " -f8 | tr -d [,]`.chomp == "off"
end
state() click to toggle source

Returns the current state of the block

# File lib/r3status/blocks/volume.rb, line 79
def state
  muted? ? :muted : :unmuted
end
toggle_mute() click to toggle source

Toggles the mute state of the system volume.

# File lib/r3status/blocks/volume.rb, line 50
def toggle_mute
  `amixer -q set Master toggle`
end
update() click to toggle source

Updates the text and color of this block.

# File lib/r3status/blocks/volume.rb, line 26
def update
  vol = volume
  muted = muted? ? :muted : :unmuted
  @text_color = colors[muted]
  @full_text = formats[muted] % {val: vol, volume: vol}
end
volume() click to toggle source

Returns the current system volume.

# File lib/r3status/blocks/volume.rb, line 69
def volume
  `amixer -c 0 get Master | grep Mono: | cut -d " " -f6 | tr -d [,],%`.to_i
end