r3status 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/r3status/blocks/async.rb +33 -0
- data/lib/r3status/blocks/base.rb +91 -0
- data/lib/r3status/blocks/clock.rb +28 -0
- data/lib/r3status/blocks/keyboard_layout.rb +39 -0
- data/lib/r3status/blocks/power.rb +59 -0
- data/lib/r3status/{shell_block.rb → blocks/shell.rb} +3 -2
- data/lib/r3status/blocks/volume.rb +83 -0
- data/lib/r3status/blocks.rb +34 -8
- data/lib/r3status.rb +52 -28
- metadata +24 -11
- data/lib/r3status/async_block.rb +0 -24
- data/lib/r3status/battery_block.rb +0 -23
- data/lib/r3status/block.rb +0 -37
- data/lib/r3status/keyboard_layout_block.rb +0 -17
- data/lib/r3status/static_block.rb +0 -22
- data/lib/r3status/time_block.rb +0 -13
- data/lib/r3status/volume_block.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bafcfeb5316e7a7e409f3a17553495aa16c245ba
|
4
|
+
data.tar.gz: 23b1bdd423b22a0477455529117a6ff345580a11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 617319555169430b21f652e533283527b259fad49d806bc11ac2bdf5543efb57187ebf350880640b3abe270aef48586f47208dd9deb0ef77f286de505295eca3
|
7
|
+
data.tar.gz: f3dc133d86ae42da95eb48d895f2ea1933265262dc561447cf33fb3a7e6939cc0102e182124169fe120dae54d5beccef8e06bd9d9ee1cfa674dc22cb45f66eee
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module R3Status::Blocks
|
2
|
+
# A base block for blocks who need to run the update procedure at a
|
3
|
+
# different interval than general update interval, or ones who need
|
4
|
+
# to run in the background.
|
5
|
+
class Async < Base
|
6
|
+
# The update interval (in seconds) of the block.
|
7
|
+
attr_accessor :update_interval
|
8
|
+
|
9
|
+
# Creates a new instance of this class.
|
10
|
+
# If a block is passed, it will be stored and yielded when the block is clicked.
|
11
|
+
def initialize(**args, &block)
|
12
|
+
args = {update_interval: 3}.merge(args)
|
13
|
+
super(args, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
# When first called, starts the update loop. Ignored afterwards.
|
17
|
+
def update
|
18
|
+
return unless @updater_thread.nil?
|
19
|
+
@updater_thread = Thread.new do
|
20
|
+
loop_with_interval(update_interval) { async_update }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Signals the block to release any resources.
|
25
|
+
def terminate
|
26
|
+
@updater_thread.kill
|
27
|
+
end
|
28
|
+
|
29
|
+
# When implemented in derived classes, updates the text and color of this block.
|
30
|
+
# Implmentations should set the #full_text and #text_color attributes.
|
31
|
+
def async_update; end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
# Contains the default blocks that can be used using StatusLine.
|
3
|
+
module R3Status::Blocks
|
4
|
+
# A base class for blocks, providing the needed methods and attributes.
|
5
|
+
# Can be use both as a base for other blocks and as a block in itself.
|
6
|
+
#
|
7
|
+
# ==== Examples
|
8
|
+
# b = Blocks::Base.new(full_text: "0") do |block, button|
|
9
|
+
# block.full_text = button.to_s
|
10
|
+
# end
|
11
|
+
class Base
|
12
|
+
# The default text color. Will be used if no color was supplied, or +nil+ was given.
|
13
|
+
DEFAULT_COLOR = '#ffffff'
|
14
|
+
# The default format. Will be used if no format was supplied, or +nil+ was given.
|
15
|
+
DEFAULT_FORMAT = '%{val}'
|
16
|
+
|
17
|
+
attr_accessor(
|
18
|
+
:full_text,
|
19
|
+
:text_color,
|
20
|
+
:name,
|
21
|
+
:formats,
|
22
|
+
:colors,
|
23
|
+
:clicked_block
|
24
|
+
)
|
25
|
+
|
26
|
+
# Creates a new instance of this class.
|
27
|
+
# If a block is passed, it will be stored and yielded when the block is clicked.
|
28
|
+
def initialize(**args, &block)
|
29
|
+
@colors ||= {}
|
30
|
+
@formats ||= Hash.new(DEFAULT_FORMAT)
|
31
|
+
|
32
|
+
args.each do |k, v|
|
33
|
+
v.default = v[:default] if (v.is_a? Hash) && (v.key? :default)
|
34
|
+
send "#{k}=", v
|
35
|
+
end
|
36
|
+
|
37
|
+
@clicked_block = block
|
38
|
+
@name ||= SecureRandom.uuid
|
39
|
+
@full_text ||= format
|
40
|
+
end
|
41
|
+
|
42
|
+
# When implemented in derived classes, updates the text and color of this block.
|
43
|
+
# Implmentations should set the #full_text and #text_color attributes.
|
44
|
+
def update; end
|
45
|
+
|
46
|
+
# Handles mouse interaction with the block.
|
47
|
+
# If a block was supplied to the constructor, it will be yielded.
|
48
|
+
# button (Fixnum):: The mouse button that was used.
|
49
|
+
# x, y (Fixnum / Float):: The pointer coordinates on the screen.
|
50
|
+
def clicked(button, x, y)
|
51
|
+
return if @clicked_block.nil?
|
52
|
+
args = [self, button, x, y].take(@clicked_block.arity)
|
53
|
+
@clicked_block.(*args)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the string representation of this block.
|
57
|
+
# prefix::
|
58
|
+
def to_s(prefix: nil, postfix: nil)
|
59
|
+
%({"full_text": "#{prefix}#{full_text}#{postfix}",
|
60
|
+
"color": "#{text_color || DEFAULT_COLOR}", "name": "#{name}",
|
61
|
+
"separator": false})
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns the default format string.
|
65
|
+
def format
|
66
|
+
formats.default
|
67
|
+
end
|
68
|
+
|
69
|
+
# Sets the default format string.
|
70
|
+
def format=(fmt)
|
71
|
+
formats.default = fmt
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns the default color.
|
75
|
+
def color
|
76
|
+
colors.default
|
77
|
+
end
|
78
|
+
|
79
|
+
# Sets the default color.
|
80
|
+
def color=(color)
|
81
|
+
colors.default = color
|
82
|
+
end
|
83
|
+
|
84
|
+
# Signals the block to release any resources.
|
85
|
+
def terminate; end
|
86
|
+
|
87
|
+
# When implemented in derived class, returns the current state of the block,
|
88
|
+
# if available.
|
89
|
+
def state; end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module R3Status::Blocks
|
2
|
+
# A block that displays the current date and time.
|
3
|
+
#
|
4
|
+
# ==== States
|
5
|
+
# :am, :pm
|
6
|
+
#
|
7
|
+
# ==== Format values
|
8
|
+
# See http://www.ruby-doc.org/core-2.1.3/Time.html#method-i-strftime
|
9
|
+
class Clock < Base
|
10
|
+
|
11
|
+
# Creates a new instance of this class.
|
12
|
+
# If a block is passed, it will be stored and yielded when the block is clicked.
|
13
|
+
def initialize(**args, &block)
|
14
|
+
args = {format: "%H:%m %e/%M/%Y"}.merge(args)
|
15
|
+
super(args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Updates the text and color of this block.
|
19
|
+
def update
|
20
|
+
self.full_text = Time.now.strftime(formats[state])
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the current state of the block
|
24
|
+
def state
|
25
|
+
Time.now.strftime('%P').to_sym
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module R3Status::Blocks
|
2
|
+
# A block that acts as a keyboard layout indicator.
|
3
|
+
#
|
4
|
+
# ==== States
|
5
|
+
# There are no constant states. A state is the current keyboard layout,
|
6
|
+
# as specified by the system. (e.g. +:us+ for US English, +:ru+ for Russian)
|
7
|
+
#
|
8
|
+
# ==== Format values
|
9
|
+
# +%{val}+, +%{sym}+: The current language symbol.
|
10
|
+
class KeyboardLayout < Base
|
11
|
+
|
12
|
+
# Creates a new instance of this class.
|
13
|
+
# If a block is passed, it will be stored and yielded when the block is clicked.
|
14
|
+
def initialize(**args, &block)
|
15
|
+
super(args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Updates the text and color of this block.
|
19
|
+
def update
|
20
|
+
sym = state
|
21
|
+
@full_text = formats[sym] % {val: sym, sym: sym}
|
22
|
+
@text_color = colors[sym]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the current state of the block.
|
26
|
+
def state
|
27
|
+
if command? "xkblayout-state"
|
28
|
+
`xkblayout-state print %s`
|
29
|
+
else
|
30
|
+
`setxkbmap -query | awk -F"(|[ ]+)" '/layout:/ { print $2 }'`
|
31
|
+
end.chomp.to_sym
|
32
|
+
end
|
33
|
+
|
34
|
+
# Determines if a shell command exists.
|
35
|
+
def command?(command)
|
36
|
+
system("which #{command} > /dev/null 2>&1")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module R3Status::Blocks
|
2
|
+
# A block that acts as a power indicator.
|
3
|
+
#
|
4
|
+
# ==== States:
|
5
|
+
# :charging, :discharging, :full, :unknown, :no_battery
|
6
|
+
#
|
7
|
+
# ==== Format Values
|
8
|
+
# +%{val}+, +%{capacity}+: The current battery capacity.
|
9
|
+
class Power < Base
|
10
|
+
# The path of the battery on the disk. Examples:
|
11
|
+
# * /sys/class/power_supply/BAT1/
|
12
|
+
# * /proc/acpi/battery/BAT0/
|
13
|
+
attr_accessor :path
|
14
|
+
|
15
|
+
# Creates a new instance of this class.
|
16
|
+
# If a block is passed, it will be stored and yielded when the block is clicked.
|
17
|
+
def initialize(**args, &block)
|
18
|
+
args = {colors: {charging: '#6DBB45', discharging: '#F4C91D'},
|
19
|
+
formats: {charging: 'Bat(charge) %{capacity}%',
|
20
|
+
default: 'Bat %{capacity}%'}}.merge(args)
|
21
|
+
super(args, &block)
|
22
|
+
|
23
|
+
|
24
|
+
@path = get_battery_path if path.nil?
|
25
|
+
path << '/' if path[-1] != '/'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Updates the text and color of this block.
|
29
|
+
def update
|
30
|
+
cap, st = capacity, state
|
31
|
+
|
32
|
+
@full_text = formats[st] % {val: cap, capacity: cap, state: st}
|
33
|
+
@text_color = colors[st]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the current state of the block
|
37
|
+
def state
|
38
|
+
return :no_battery unless File.exist? path
|
39
|
+
`cat #{path}status`.chomp.downcase.to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns the current capacity of the battery, or +nil+ if no battery found.
|
43
|
+
def capacity
|
44
|
+
return nil if state == :no_battery
|
45
|
+
`cat #{path}capacity`.chomp.to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
# Try to find a valid battery path.
|
49
|
+
def get_battery_path
|
50
|
+
base_paths = ["/proc/acpi/battery/", "/sys/class/power_supply/"]
|
51
|
+
base_paths.each do |p|
|
52
|
+
if Dir.exist? p
|
53
|
+
return p + (Dir.entries(p) - %w{ . .. }).last
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module R3Status
|
2
|
-
class
|
1
|
+
module R3Status::Blocks
|
2
|
+
class Shell < Base
|
3
3
|
attr_accessor :command, :click_commands
|
4
4
|
|
5
5
|
def initialize(**args, &block)
|
@@ -28,5 +28,6 @@ module R3Status
|
|
28
28
|
`#{click_commands[button]}`
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
31
32
|
end
|
32
33
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module R3Status::Blocks
|
2
|
+
# A block that acts as a volume indicator.
|
3
|
+
# It displays the current Master Volume, and allows to user to change it using scrolling,
|
4
|
+
# and muting using the middle mouse button.
|
5
|
+
#
|
6
|
+
# ==== States
|
7
|
+
# :muted, :unmuted
|
8
|
+
#
|
9
|
+
# ==== Format values
|
10
|
+
# +%{val}+, +%{volume}+: The current system volume.
|
11
|
+
class Volume < Base
|
12
|
+
# The amount of volume (in percents) to change with scroll.
|
13
|
+
attr_accessor :step
|
14
|
+
|
15
|
+
# Creates a new instance of this class.
|
16
|
+
# If a block is passed, it will be stored and yielded when the block is clicked.
|
17
|
+
def initialize(**args, &block)
|
18
|
+
args = {formats: {muted: " %{volume}%", unmuted: " %{volume}%"},
|
19
|
+
colors: {muted: '#7CCdCD', unmuted: '#ffffff'}, step: 5,
|
20
|
+
name: "volume_master"}.merge(args)
|
21
|
+
|
22
|
+
super(args, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Updates the text and color of this block.
|
26
|
+
def update
|
27
|
+
vol = volume
|
28
|
+
muted = muted? ? :muted : :unmuted
|
29
|
+
@text_color = colors[muted]
|
30
|
+
@full_text = formats[muted] % {val: vol, volume: vol}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Handles mouse interaction with the block.
|
34
|
+
# If a block was supplied to the constructor, it will be yielded.
|
35
|
+
# button (Fixnum):: The mouse button that was used.
|
36
|
+
# x, y (Fixnum / Float):: The pointer coordinates on the screen.
|
37
|
+
def clicked(button, x, y)
|
38
|
+
super(button, x, y)
|
39
|
+
case button
|
40
|
+
when 4
|
41
|
+
increase
|
42
|
+
when 2
|
43
|
+
toggle_mute
|
44
|
+
when 5
|
45
|
+
decrease
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Toggles the mute state of the system volume.
|
50
|
+
def toggle_mute
|
51
|
+
`amixer -q set Master toggle`
|
52
|
+
end
|
53
|
+
|
54
|
+
# Increases the system volume by the given amount.
|
55
|
+
# step:: The amount of volume to increase. If +nil+, the value default value,
|
56
|
+
# or the one supplied in the constructor, will be used.
|
57
|
+
def increase(step = nil)
|
58
|
+
`amixer -c 0 set Master #{step || @step}%+ unmute`
|
59
|
+
end
|
60
|
+
|
61
|
+
# Decreases the system volume by the given amount.
|
62
|
+
# step:: The amount of volume to decrease. If +nil+, the value default value,
|
63
|
+
# or the one supplied in the constructor, will be used.
|
64
|
+
def decrease(step = nil)
|
65
|
+
`amixer -c 0 set Master #{step || @step}%- unmute`
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns the current system volume.
|
69
|
+
def volume
|
70
|
+
`amixer -c 0 get Master | grep Mono: | cut -d " " -f6 | tr -d [,],%`.to_i
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns the mute state of the system volume.
|
74
|
+
def muted?
|
75
|
+
`amixer -c 0 get Master | grep Mono: | cut -d " " -f8 | tr -d [,]`.chomp == "off"
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns the current state of the block
|
79
|
+
def state
|
80
|
+
muted? ? :muted : :unmuted
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/r3status/blocks.rb
CHANGED
@@ -1,15 +1,41 @@
|
|
1
|
-
|
1
|
+
module R3Status; end
|
2
2
|
|
3
|
-
require_relative './
|
3
|
+
require_relative './blocks/base.rb'
|
4
4
|
|
5
|
-
require_relative './
|
5
|
+
require_relative './blocks/clock.rb'
|
6
6
|
|
7
|
-
require_relative './
|
7
|
+
require_relative './blocks/volume.rb'
|
8
8
|
|
9
|
-
require_relative './
|
9
|
+
require_relative './blocks/power.rb'
|
10
10
|
|
11
|
-
require_relative './
|
11
|
+
require_relative './blocks/keyboard_layout.rb'
|
12
12
|
|
13
|
-
require_relative './
|
13
|
+
require_relative './blocks/shell.rb'
|
14
14
|
|
15
|
-
require_relative './
|
15
|
+
require_relative './blocks/async.rb'
|
16
|
+
|
17
|
+
module R3Status
|
18
|
+
# Alias for Blocks::Base
|
19
|
+
Block = Blocks::Base
|
20
|
+
|
21
|
+
# Alias for Blocks::Base
|
22
|
+
StaticBlock = Blocks::Base
|
23
|
+
|
24
|
+
# Alias for Blocks::Volume
|
25
|
+
VolumeBlock = Blocks::Volume
|
26
|
+
|
27
|
+
# Alias for Blocks::Clock
|
28
|
+
TimeBlock = Blocks::Clock
|
29
|
+
|
30
|
+
# Alias for Blocks::Power
|
31
|
+
BatteryBlock = Blocks::Power
|
32
|
+
|
33
|
+
# Alias for Blocks::KeyboardLayout
|
34
|
+
KeyboardLayoutBlock = Blocks::KeyboardLayout
|
35
|
+
|
36
|
+
# Alias for Blocks::Async
|
37
|
+
AsyncBlock = Blocks::Async
|
38
|
+
|
39
|
+
# Alias for Blocks::Shell
|
40
|
+
ShellBlock = Blocks::Shell
|
41
|
+
end
|
data/lib/r3status.rb
CHANGED
@@ -2,7 +2,11 @@ require_relative './r3status/blocks.rb'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
module R3Status
|
5
|
-
|
5
|
+
# Specifies the mouse buttons and their IDs.
|
6
|
+
MOUSE_BUTTONS = {primary: 1, middle: 2, secondary: 3, scroll_up: 4, scroll_down: 5}
|
7
|
+
|
8
|
+
# Loops over the given block at the specified interval.
|
9
|
+
# The interval is the time between yields, not between a yield's ends the next's start.
|
6
10
|
def loop_with_interval secs
|
7
11
|
loop do
|
8
12
|
start = Time.now
|
@@ -11,10 +15,27 @@ module R3Status
|
|
11
15
|
sleep(interval) if interval > 0
|
12
16
|
end
|
13
17
|
end
|
14
|
-
|
18
|
+
|
19
|
+
# This class encapsulates a status output.
|
20
|
+
# Blocks are added by the user and are displayed each iteration.
|
21
|
+
# ==== Example
|
22
|
+
# s = StatusLine.new
|
23
|
+
# s = StatusLine.new update_interval: 3
|
24
|
+
#
|
25
|
+
# s << Blocks::Volume.new
|
26
|
+
#
|
27
|
+
# s.run
|
15
28
|
class StatusLine
|
16
|
-
|
29
|
+
# A list blocks to display, right to left, in the bar.
|
30
|
+
attr_reader :blocks
|
31
|
+
# An object (e.g. _String_) that will be inserted at the start of a block's text. Default: _" "_.
|
32
|
+
attr_accessor :prefix
|
33
|
+
# An object (e.g. _String_)that will be inserted at the ebd of a block's text. Default: _nil_.
|
34
|
+
attr_accessor :postfix
|
35
|
+
# The time (in seconds) between iterations. Default: _0.4_.
|
36
|
+
attr_accessor :update_interval
|
17
37
|
|
38
|
+
# Creates a new StatusLine object.
|
18
39
|
def initialize(prefix: " ", postfix: nil, update_interval: 0.4)
|
19
40
|
@blocks = []
|
20
41
|
@prefix = prefix
|
@@ -22,41 +43,20 @@ module R3Status
|
|
22
43
|
@update_interval = update_interval
|
23
44
|
end
|
24
45
|
|
46
|
+
# Appends a new block to this StatusLine object.
|
25
47
|
def << block
|
26
48
|
@blocks << block
|
27
49
|
end
|
28
50
|
|
29
|
-
|
30
|
-
@blocks.map { |i| i.to_s(postfix: @postfix, prefix: @prefix) }.
|
31
|
-
reject { |i| i.nil? }.inject { |i, j| i << ",#{j}"}
|
32
|
-
end
|
33
|
-
|
34
|
-
def parse str
|
35
|
-
return if str.length < 2
|
36
|
-
obj = nil
|
37
|
-
str = str.strip.sub(/\A\,/ , "")
|
38
|
-
|
39
|
-
begin
|
40
|
-
obj = JSON.parse(str)
|
41
|
-
rescue Exception => e
|
42
|
-
return
|
43
|
-
end
|
44
|
-
|
45
|
-
block = @blocks.find { |b| b.name == obj["name"] }
|
46
|
-
block.clicked(obj["button"], obj["x"], obj["y"]) unless block.nil?
|
47
|
-
end
|
48
|
-
|
51
|
+
# Starts the operation of the status line and the output of the data to the standard output.
|
49
52
|
def run
|
50
53
|
@reader_thread = Thread.new do
|
51
|
-
begin
|
52
54
|
loop do
|
53
55
|
s = gets.chomp
|
54
56
|
parse s
|
55
57
|
end
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
end.run
|
58
|
+
end
|
59
|
+
@reader_thread.run
|
60
60
|
|
61
61
|
at_exit do
|
62
62
|
@reader_thread.kill
|
@@ -70,5 +70,29 @@ module R3Status
|
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
# Generates a single transmission.
|
76
|
+
def transmission
|
77
|
+
@blocks.map { |i| i.to_s(postfix: @postfix, prefix:
|
78
|
+
@prefix) }.
|
79
|
+
reject { |i| i.nil? }.inject { |i, j| i << ",#{j}"}
|
80
|
+
end
|
81
|
+
|
82
|
+
# Parses a single input from i3bar.
|
83
|
+
def parse(str)
|
84
|
+
return if str.length < 2
|
85
|
+
obj = nil
|
86
|
+
str = str.strip.sub(/\A\,/ , "")
|
87
|
+
|
88
|
+
begin
|
89
|
+
obj = JSON.parse(str)
|
90
|
+
rescue Exception => e
|
91
|
+
return
|
92
|
+
end
|
93
|
+
|
94
|
+
block = @blocks.find { |b| b.name == obj["name"] }
|
95
|
+
block.clicked(obj["button"], obj["x"], obj["y"]) unless block.nil?
|
96
|
+
end
|
73
97
|
end
|
74
98
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r3status
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilad Naaman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
12
|
-
dependencies:
|
11
|
+
date: 2014-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: r3status is ruby implmentation of the i3bar protocol, and is an alternative
|
14
28
|
to the default i3status.
|
15
29
|
email: gilad.doom@gmail.com
|
@@ -18,15 +32,14 @@ extensions: []
|
|
18
32
|
extra_rdoc_files: []
|
19
33
|
files:
|
20
34
|
- lib/r3status.rb
|
21
|
-
- lib/r3status/async_block.rb
|
22
|
-
- lib/r3status/battery_block.rb
|
23
|
-
- lib/r3status/block.rb
|
24
35
|
- lib/r3status/blocks.rb
|
25
|
-
- lib/r3status/
|
26
|
-
- lib/r3status/
|
27
|
-
- lib/r3status/
|
28
|
-
- lib/r3status/
|
29
|
-
- lib/r3status/
|
36
|
+
- lib/r3status/blocks/async.rb
|
37
|
+
- lib/r3status/blocks/base.rb
|
38
|
+
- lib/r3status/blocks/clock.rb
|
39
|
+
- lib/r3status/blocks/keyboard_layout.rb
|
40
|
+
- lib/r3status/blocks/power.rb
|
41
|
+
- lib/r3status/blocks/shell.rb
|
42
|
+
- lib/r3status/blocks/volume.rb
|
30
43
|
homepage: https://github.com/Gilnaa/R3Status
|
31
44
|
licenses:
|
32
45
|
- LGPL3
|
data/lib/r3status/async_block.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module R3Status
|
2
|
-
class AsyncBlock < Block
|
3
|
-
attr_accessor :update_interval, :updater_thread
|
4
|
-
|
5
|
-
def initialize(**args)
|
6
|
-
args = {update_interval: 3}.merge(args)
|
7
|
-
super(args)
|
8
|
-
end
|
9
|
-
|
10
|
-
def update
|
11
|
-
@full_text
|
12
|
-
return if @updater_pid.is_a? Fixnum
|
13
|
-
@updater_thread = Thread.new do
|
14
|
-
loop_with_interval(update_interval) { async_update }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def terminate
|
19
|
-
@updater_thread.kill
|
20
|
-
end
|
21
|
-
|
22
|
-
def async_update; end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module R3Status
|
2
|
-
class BatteryBlock < Block
|
3
|
-
attr_accessor :path
|
4
|
-
|
5
|
-
def initialize(**args)
|
6
|
-
args = {colors: {charging: '#6DBB45', discharging: '#F4C91D'},
|
7
|
-
formats: {charging: 'Bat(charge) %{capacity}%',
|
8
|
-
default: 'Bat %{capacity}%'}}.merge(args)
|
9
|
-
super(args)
|
10
|
-
end
|
11
|
-
|
12
|
-
def update
|
13
|
-
cap, st = capacity, status
|
14
|
-
|
15
|
-
@full_text = formats[st] % {val: cap, capacity: cap, status: st}
|
16
|
-
@text_color = colors[st]
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
def status; `cat #{path}status`.chomp.downcase.to_sym end
|
21
|
-
def capacity; `cat #{path}capacity`.chomp end
|
22
|
-
end
|
23
|
-
end
|
data/lib/r3status/block.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module R3Status
|
2
|
-
class Block
|
3
|
-
DEFAULT_COLOR = '#ffffff'
|
4
|
-
DEFAULT_FORMAT = '%{val}'
|
5
|
-
|
6
|
-
attr_accessor :full_text, :text_color, :name, :formats, :colors
|
7
|
-
|
8
|
-
def initialize(**args)
|
9
|
-
self.colors ||= {}
|
10
|
-
self.formats ||= Hash.new(DEFAULT_FORMAT)
|
11
|
-
args.each do |k, v|
|
12
|
-
v.default = v[:default] if (v.is_a? Hash) && (v.key? :default)
|
13
|
-
send "#{k}=", v
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def update; end
|
18
|
-
|
19
|
-
def terminate; end
|
20
|
-
|
21
|
-
def clicked(button, x, y); end
|
22
|
-
|
23
|
-
def to_s(prefix: nil, postfix: nil)
|
24
|
-
%({"full_text": "#{prefix}#{full_text}#{postfix}",
|
25
|
-
"color": "#{text_color || DEFAULT_COLOR}", "name": "#{name}",
|
26
|
-
"separator": false})
|
27
|
-
end
|
28
|
-
|
29
|
-
def format
|
30
|
-
formats.default
|
31
|
-
end
|
32
|
-
|
33
|
-
def format=(fmt)
|
34
|
-
@formats.default = fmt
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module R3Status
|
2
|
-
class KeyboardLayoutBlock < Block
|
3
|
-
def initialize(**args)
|
4
|
-
super(args)
|
5
|
-
end
|
6
|
-
|
7
|
-
def update
|
8
|
-
sym = language_symbol
|
9
|
-
@full_text = formats[sym] % {val: sym, sym: sym}
|
10
|
-
@text_color = colors[sym]
|
11
|
-
end
|
12
|
-
|
13
|
-
def language_symbol
|
14
|
-
`xkblayout-state print %s`.chomp.to_sym
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
|
3
|
-
module R3Status
|
4
|
-
class StaticBlock < Block
|
5
|
-
attr_accessor :clicked_block
|
6
|
-
|
7
|
-
def initialize(**args, &block)
|
8
|
-
@clicked_block = block
|
9
|
-
|
10
|
-
super(args)
|
11
|
-
|
12
|
-
@full_text ||= format
|
13
|
-
@name ||= SecureRandom.uuid
|
14
|
-
end
|
15
|
-
|
16
|
-
def clicked(button, x, y)
|
17
|
-
return if @clicked_block.nil?
|
18
|
-
args = [self, button, x, y].take(@clicked_block.arity)
|
19
|
-
@clicked_block.(*args)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/r3status/time_block.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
module R3Status
|
2
|
-
class VolumeBlock < Block
|
3
|
-
attr_accessor :step
|
4
|
-
|
5
|
-
def initialize(**args)
|
6
|
-
args = {formats: {muted: " %{volume}%", unmuted: " %{volume}%"},
|
7
|
-
colors: {muted: '#7CCdCD', unmuted: '#ffffff'}, step: 5,
|
8
|
-
name: "volume_master"}.merge(args)
|
9
|
-
|
10
|
-
super(args)
|
11
|
-
end
|
12
|
-
|
13
|
-
def update
|
14
|
-
vol = volume
|
15
|
-
muted = muted? ? :muted : :unmuted
|
16
|
-
@text_color = colors[muted]
|
17
|
-
@full_text = formats[muted] % {val: vol, volume: vol}
|
18
|
-
end
|
19
|
-
|
20
|
-
def clicked button, x, y
|
21
|
-
case button
|
22
|
-
when 4
|
23
|
-
increase
|
24
|
-
when 2
|
25
|
-
toggle_mute
|
26
|
-
when 5
|
27
|
-
decrease
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def toggle_mute
|
33
|
-
`amixer -q set Master toggle`
|
34
|
-
end
|
35
|
-
def increase
|
36
|
-
`amixer -c 0 set Master #{step}%+ unmute`
|
37
|
-
end
|
38
|
-
def decrease
|
39
|
-
`amixer -c 0 set Master #{step}%- unmute`
|
40
|
-
end
|
41
|
-
def volume
|
42
|
-
`amixer -c 0 get Master | grep Mono: | cut -d " " -f6 | tr -d [,],%`.to_i
|
43
|
-
end
|
44
|
-
def muted?
|
45
|
-
`amixer -c 0 get Master | grep Mono: | cut -d " " -f8 | tr -d [,]`.chomp == "off"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|