volay 2.0.0 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 688ccbdc75ceb9062fb138563fa72504509a2afaffbc2b1aae9e8f9f24a3dd32
4
- data.tar.gz: 2e2c26689b143f3011d04a3d522eb9bbae829254d36618b5e853b9ecc8d64006
3
+ metadata.gz: 3e383f672606a89520f19cc97e3704539037a44b65cd8f97b4e965ba8b3bd2a0
4
+ data.tar.gz: b0cfb666b0b3cdce544bb105fb58986311c72660a377df8fab2863e67e535e6b
5
5
  SHA512:
6
- metadata.gz: a13b3fb7690cf4bf04bbc210deaf6317d18fbb13743877dc330b345a084aeaae1242865bf72e2cbfe8319525fbbba09eeae4be0d66e1c05609f4f270a4a81dd7
7
- data.tar.gz: 6cd5dcc83ccd294308644e5b45c9871a02447ec28c13fa14bc60c2fe44403996a58490128155ef4b523fb58998f89e117f87c7874b1bc3b98a71245f05164e7f
6
+ metadata.gz: f157a6475a185d45d55b0348c8b96c0164eeab49d23f0bc8bb793e109548e729f36f95f72fdde2a8762fc2984f34e4a9c14b8a2668e7fe3718cced3623e3524b
7
+ data.tar.gz: 59a3bec0c005d48f56e51eb8591e34718334a1f33fbefa62653d412a735e37a2afa1161fb5038b5ba871f8155412e8c4547d5d834e219d9c41128040af64090b
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'bundler/gem_tasks'
data/bin/volay CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require File.expand_path('../../lib/volay', __FILE__)
4
+ require File.expand_path('../lib/volay', __dir__)
5
5
 
6
6
  # Module volay
7
7
  module Volay
@@ -26,7 +26,7 @@ module Volay
26
26
  end
27
27
 
28
28
  def app
29
- Volay::App.new(File.expand_path('../../glade/volay.glade', __FILE__))
29
+ Volay::App.new(File.expand_path('../glade/volay.glade', __dir__))
30
30
  Gtk.main
31
31
  end
32
32
  end
@@ -13,6 +13,14 @@
13
13
  <object class="GtkMenu" id="popup_menu">
14
14
  <property name="visible">True</property>
15
15
  <property name="can_focus">False</property>
16
+ <property name="no_show_all">True</property>
17
+ <child>
18
+ <object class="GtkMenuItem" id="popup_menu_cards">
19
+ <property name="can_focus">False</property>
20
+ <property name="label">Cards</property>
21
+ <property name="use_underline">True</property>
22
+ </object>
23
+ </child>
16
24
  <child>
17
25
  <object class="GtkImageMenuItem" id="popup_menu_quit">
18
26
  <property name="label">gtk-quit</property>
@@ -5,8 +5,8 @@ require 'logger'
5
5
  require 'mixlib/cli'
6
6
  require 'mixlib/shellout'
7
7
 
8
- unless $LOAD_PATH.include?(File.expand_path('../', __FILE__))
9
- $LOAD_PATH.unshift(File.expand_path('../', __FILE__))
8
+ unless $LOAD_PATH.include?(File.expand_path('', __dir__))
9
+ $LOAD_PATH.unshift(File.expand_path('', __dir__))
10
10
  end
11
11
 
12
12
  require 'volay/version'
@@ -55,9 +55,13 @@ module Volay
55
55
  # Override Icon path to prevent
56
56
  # Gtk-CRITICAL **:gtk_icon_source_set_filename:
57
57
  ui = File.read(path)
58
- ui.gsub!(%r{/glade/icons},
59
- File.expand_path('../../glade/icons',
60
- File.dirname(__FILE__)))
58
+ ui.gsub!(
59
+ %r{/glade/icons},
60
+ File.expand_path(
61
+ '../glade/icons',
62
+ File.dirname(__dir__)
63
+ )
64
+ )
61
65
  add_from_string(ui)
62
66
  end
63
67
  end
@@ -60,6 +60,7 @@ module Volay
60
60
  #
61
61
  def self.mixer
62
62
  raise MixerNotFound unless which('pacmd')
63
+
63
64
  @mixer ||= Volay::Mixer::Pulse.new
64
65
  end
65
66
 
@@ -77,17 +77,6 @@ module Volay
77
77
  refresh
78
78
  end
79
79
 
80
- private
81
-
82
- ##
83
- # Get volume percent
84
- #
85
- # @return Integer
86
- #
87
- def volume_percent(value)
88
- value * 100 / MAX_VALUE
89
- end
90
-
91
80
  ##
92
81
  # Refresh cards data
93
82
  #
@@ -110,6 +99,17 @@ module Volay
110
99
  set_long_names
111
100
  end
112
101
 
102
+ private
103
+
104
+ ##
105
+ # Get volume percent
106
+ #
107
+ # @return Integer
108
+ #
109
+ def volume_percent(value)
110
+ value * 100 / MAX_VALUE
111
+ end
112
+
113
113
  ##
114
114
  # Set cards data such as default sink
115
115
  # volume and if card is muted
@@ -119,6 +119,7 @@ module Volay
119
119
  def set_data(args)
120
120
  @cards.each do |id, card|
121
121
  next if args[1].nil? || !args[1].include?(card['name'])
122
+
122
123
  case args[0]
123
124
  when 'set-default-sink'
124
125
  @default_sink_id = id
@@ -29,6 +29,7 @@ module Volay
29
29
 
30
30
  def status_icon
31
31
  return 'volume-muted' if @app.mixer.muted?
32
+
32
33
  if (66..100).cover?(@app.mixer.percent)
33
34
  'volume-high'
34
35
  elsif (33..65).cover?(@app.mixer.percent)
@@ -1,4 +1,4 @@
1
1
  # Volay module
2
2
  module Volay
3
- VERSION = '2.0.0'.freeze
3
+ VERSION = '2.1.0'.freeze
4
4
  end
@@ -3,8 +3,8 @@
3
3
  require 'gtk3'
4
4
  require 'mixlib-cli'
5
5
 
6
- unless $LOAD_PATH.include?(File.expand_path('../', __FILE__))
7
- $LOAD_PATH.unshift(File.expand_path('../', __FILE__))
6
+ unless $LOAD_PATH.include?(File.expand_path('', __dir__))
7
+ $LOAD_PATH.unshift(File.expand_path('', __dir__))
8
8
  end
9
9
 
10
10
  require 'volay/version'
@@ -16,6 +16,7 @@ module Volay
16
16
 
17
17
  methods.each do |name|
18
18
  next unless name =~ /^on_/
19
+
19
20
  @app.signals_list[name.to_s] = method(name)
20
21
  end
21
22
 
@@ -6,36 +6,15 @@ module Volay
6
6
  module Widget
7
7
  # Events class
8
8
  class SystemTray < Events
9
- LEFT_CLICK = 1
10
- RIGHT_CLICK = 3
11
- M_KEYCODE = 47
9
+ KEYCODE_MOUSE_CLICK_LEFT = 1
10
+ KEYCODE_MOUSE_CLICK_RIGHT = 3
11
+ KEYCODE_M = 47
12
12
 
13
13
  ##
14
14
  # When popup window menu is draw
15
15
  #
16
16
  def init
17
- return unless @app&.mixer&.cards
18
-
19
- cards_menu = Gtk::MenuItem.new(label: 'Cards')
20
- menu = Gtk::Menu.new
21
- last_item = nil
22
- @app.mixer.cards.each do |id, card|
23
- radio_menu_item = Gtk::RadioMenuItem.new(nil, card['long_name'])
24
- radio_menu_item.join_group(last_item) if last_item
25
- radio_menu_item.name = "card_menu_#{id}"
26
- radio_menu_item.active = @app.mixer.default_sink_id == id
27
- last_item = radio_menu_item
28
- menu.append(radio_menu_item)
29
-
30
- radio_menu_item.signal_connect('activate') do |widget|
31
- next unless widget.active?
32
- @app.mixer.change_card(id)
33
- @app.utils.update_status_icon
34
- end
35
- end
36
-
37
- cards_menu.submenu = menu
38
- @app.get_object('popup_menu').prepend(cards_menu)
17
+ refresh_cards_menu
39
18
  end
40
19
 
41
20
  ##
@@ -46,7 +25,8 @@ module Volay
46
25
  #
47
26
  def on_status_icon_button_press_event(_widget, event)
48
27
  return unless event.is_a?(Gdk::EventButton) &&
49
- event.button == LEFT_CLICK
28
+ event.button == KEYCODE_MOUSE_CLICK_LEFT
29
+
50
30
  return on_system_tray_window_focus_out_event if
51
31
  @app.get_object('system_tray_window').visible?
52
32
 
@@ -68,7 +48,8 @@ module Volay
68
48
  #
69
49
  def on_system_tray_window_key_release_event(_widget, event)
70
50
  return unless event.is_a?(Gdk::EventKey) &&
71
- event.hardware_keycode == M_KEYCODE
51
+ event.hardware_keycode == KEYCODE_M
52
+
72
53
  @app.mixer.toggle
73
54
  @app.utils.update_status_icon
74
55
  end
@@ -92,6 +73,18 @@ module Volay
92
73
  Gtk.main_quit
93
74
  end
94
75
 
76
+ ##
77
+ # When system tray window is showed
78
+ #
79
+ def on_system_tray_window_show
80
+ @app.mixer.refresh
81
+ refresh_cards_menu
82
+
83
+ @app.get_object('volume_adjustement')
84
+ .value = @app.mixer.percent
85
+ @app.utils.update_status_icon
86
+ end
87
+
95
88
  ##
96
89
  # Retrieve the good position to be above
97
90
  # the status icon
@@ -129,6 +122,40 @@ module Volay
129
122
 
130
123
  [posx, posy]
131
124
  end
125
+
126
+ private
127
+
128
+ ##
129
+ # Refresh card menu items
130
+ #
131
+ def refresh_cards_menu
132
+ @app.get_object('popup_menu_cards').visible = false
133
+
134
+ return unless @app&.mixer&.cards
135
+ return if @app.mixer.cards.keys.count <= 1
136
+
137
+ menu = Gtk::Menu.new
138
+ last_item = nil
139
+ @app.mixer.cards.each do |id, card|
140
+ radio_menu_item = Gtk::RadioMenuItem.new(nil, card['long_name'])
141
+ radio_menu_item.join_group(last_item) if last_item
142
+ radio_menu_item.name = "card_menu_#{id}"
143
+ radio_menu_item.visible = true
144
+ radio_menu_item.active = @app.mixer.default_sink_id == id
145
+ last_item = radio_menu_item
146
+ menu.append(radio_menu_item)
147
+
148
+ radio_menu_item.signal_connect('activate') do |widget|
149
+ next unless widget.active?
150
+
151
+ @app.mixer.change_card(id)
152
+ @app.utils.update_status_icon
153
+ end
154
+ end
155
+
156
+ @app.get_object('popup_menu_cards').visible = true
157
+ @app.get_object('popup_menu_cards').submenu = menu
158
+ end
132
159
  end
133
160
  end
134
161
  end
@@ -6,15 +6,6 @@ module Volay
6
6
  module Widget
7
7
  # Events class
8
8
  class VolumeControl < Events
9
- ##
10
- # When system tray window is showed
11
- #
12
- def on_system_tray_window_show
13
- @app.get_object('volume_adjustement')
14
- .value = @app.mixer.percent
15
- @app.utils.update_status_icon
16
- end
17
-
18
9
  ##
19
10
  # When slider have its adjustement value changed
20
11
  #
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH << File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH << File.expand_path('lib', __dir__)
4
4
 
5
5
  require 'simplecov'
6
6
 
@@ -16,15 +16,26 @@ describe 'Volay::App' do
16
16
  include FakeFS::SpecHelpers
17
17
 
18
18
  context '#events' do
19
+ let(:popup_menu_cards) do
20
+ pmc = double
21
+ allow(pmc).to receive(:visible=).and_return(true)
22
+
23
+ pmc
24
+ end
25
+
19
26
  it 'should initiliaze events' do
20
27
  allow_any_instance_of(Volay::App).to receive(:initialize_mixer)
21
28
  allow_any_instance_of(Volay::App).to receive(:initialize_ui)
22
29
  allow_any_instance_of(Volay::Utils).to receive(:update_status_icon)
23
30
  allow_any_instance_of(Volay::App).to receive(:connect_signals)
24
31
  .and_yield('on_status_icon_button_press_event')
32
+ allow_any_instance_of(Volay::App).to receive(:get_object)
33
+ .with('popup_menu_cards')
34
+ .and_return(popup_menu_cards)
25
35
 
26
36
  File.write('something', '')
27
37
  app = Volay::App.new('something')
38
+
28
39
  expect(app.signals_list).to be_a(Hash)
29
40
  end
30
41
  end
@@ -45,7 +56,7 @@ describe 'Volay::App' do
45
56
  </sources>
46
57
  </object>
47
58
  </interface>
48
- XML
59
+ XML
49
60
 
50
61
  File.write('something', xml)
51
62
  app = Volay::App.new('something')
@@ -26,13 +26,13 @@ describe 'Volay::Mixer::Pulse' do
26
26
  stub_shellout(
27
27
  'dump',
28
28
  File.read(
29
- File.expand_path('../stubs/pulse_dump.stub', __FILE__)
29
+ File.expand_path('stubs/pulse_dump.stub', __dir__)
30
30
  )
31
31
  )
32
32
  stub_shellout(
33
33
  "list-cards | grep -e device.string -e 'name:' -e 'card_name'",
34
34
  File.read(
35
- File.expand_path('../stubs/pulse_list-cards.stub', __FILE__)
35
+ File.expand_path('stubs/pulse_list-cards.stub', __dir__)
36
36
  )
37
37
  )
38
38
  end
@@ -12,18 +12,34 @@ describe 'Volay::Widget::VolumeControl' do
12
12
  end
13
13
 
14
14
  let(:vc) do
15
+ allow(Thread).to receive(:new).and_yield
15
16
  Volay::Widget::VolumeControl.new(app)
16
17
  end
17
18
 
18
19
  it 'on volume scale' do
19
20
  utils = double
20
21
  volume = double
21
- allow(volume).to receive(:value=).and_return(20)
22
- allow(app).to receive(:get_object).once.with('volume_adjustement')
23
- .and_return(volume)
22
+
23
+ allow(volume).to receive(:value).once.and_return(20)
24
+ allow(utils).to receive(:update_status_icon).once.and_return(true)
25
+
24
26
  allow(app).to receive(:utils).once.and_return(utils)
27
+ allow(app.mixer).to receive(:value=).with(20).once
28
+
29
+ vc.on_volume_adjustement_value_changed(volume)
30
+ end
31
+
32
+ it 'no volume mute' do
33
+ utils = double
34
+ volume = double
35
+
36
+ allow(volume).to receive(:active?).once.and_return(true)
25
37
  allow(utils).to receive(:update_status_icon).once.and_return(true)
26
- allow(app.mixer).to receive(:percent).and_return(20)
27
- expect(vc.on_system_tray_window_show).to be_truthy
38
+
39
+ allow(app).to receive(:utils).once.and_return(utils)
40
+ allow(app.mixer).to receive(:muted?).once.and_return(true)
41
+ allow(app.mixer).to receive(:toggle).once
42
+
43
+ vc.on_toggle_mute_toggled(volume)
28
44
  end
29
45
  end
@@ -3,7 +3,7 @@
3
3
  desc 'Generates the MANIFEST file'
4
4
  task :manifest do
5
5
  files = `git ls-files`.split("\n").sort
6
- handle = File.open(File.expand_path('../../MANIFEST', __FILE__), 'w')
6
+ handle = File.open(File.expand_path('../MANIFEST', __dir__), 'w')
7
7
 
8
8
  handle.write(files.join("\n"))
9
9
  handle.close
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../lib/volay/version', __FILE__)
3
+ require File.expand_path('lib/volay/version', __dir__)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'volay'
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.homepage = 'http://github.com/PierreRambaud/volay'
13
13
  s.description = 'Really simple volume system tray written in ruby.'
14
14
  s.executables = ['volay']
15
- s.files = File.read(File.expand_path('../MANIFEST', __FILE__)).split("\n")
15
+ s.files = File.read(File.expand_path('MANIFEST', __dir__)).split("\n")
16
16
 
17
17
  s.required_ruby_version = '> 2.3'
18
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volay
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Rambaud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2018-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glib2
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  version: '0'
230
230
  requirements: []
231
231
  rubyforge_project:
232
- rubygems_version: 2.7.4
232
+ rubygems_version: 2.7.3
233
233
  signing_key:
234
234
  specification_version: 4
235
235
  summary: The Volume system tray