hastinbe / i3-volume

Volume control and volume notifications
GNU General Public License v2.0
340 stars 35 forks source link

i3-volume changes volume properly, but doesn't show notification #3

Closed GijsTimmers closed 6 years ago

GijsTimmers commented 6 years ago

Running the current git version of i3-volume on Ubuntu 17.10 x86_64 with i3 window manager

i3-volume changes the volume properly, but if run with the -n switch, the notification does not appear and errors show up:

$ notify-send --version
notify-send 0.7.7

$ ./volume -i 5 -n
./volume: line 117: [: : integer expression expected
./volume: line 119: [: : integer expression expected
./volume: line 121: [: : integer expression expected
./volume: line 123: [: : integer expression expected
Value "" of hint "value" could not be parsed as type "int".
GijsTimmers commented 6 years ago

Hi, thanks for getting back to me this quickly. I pulled commit 8374b9514adcd2ba0f1b4704a6fc49297a11ec35 but I'm still getting the same error.

Bash version:

$ bash --version
GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
GijsTimmers commented 6 years ago

I think that there's a problem parsing the volume in get_volume().

pacmd list-sinks output:

$ pacmd list-sinks
1 sink(s) available.
  * index: 0
    name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
    driver: <module-alsa-card.c>
    flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: SUSPENDED
    suspend cause: IDLE 
    priority: 9959
    volume: front-left: 29494 /  45% / -20,80 dB,   front-right: 29494 /  45% / -20,80 dB
            balance 0,00
    base volume: 65536 / 100% / 0,00 dB
    volume steps: 65537
    muted: no
    current latency: 0,00 ms
    max request: 0 KiB
    max rewind: 0 KiB
    monitor source: 0
    sample spec: s16le 2ch 44100Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 0
    configured latency: 0,00 ms; range is 0,50 .. 371,52 ms
    card: 0 <alsa_card.pci-0000_00_1b.0>
    module: 6
    properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "92HD81B1X5 Analog"
        alsa.id = "92HD81B1X5 Analog"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "0"
        alsa.card_name = "HDA Intel PCH"
        alsa.long_card_name = "HDA Intel PCH at 0xc2600000 irq 29"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:00:1b.0"
        sysfs.path = "/devices/pci0000:00/0000:00:1b.0/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "1c20"
        device.product.name = "6 Series/C200 Series Chipset Family High Definition Audio Controller"
        device.form_factor = "internal"
        device.string = "front:0"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "32768"
        device.access_mode = "mmap+timer"
        device.profile.name = "analog-stereo"
        device.profile.description = "Analog Stereo"
        device.description = "Built-in Audio Analog Stereo"
        alsa.mixer_name = "IDT 92HD81B1X5"
        alsa.components = "HDA:111d7605,103c166f,00100105 HDA:80862805,80860101,00100000"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown)
            properties:
                device.icon_name = "audio-speakers"
        analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: no)
            properties:
                device.icon_name = "audio-headphones"
    active port: <analog-output-speaker>
hastinbe commented 6 years ago

Can you paste the output from pacmd stat?

GijsTimmers commented 6 years ago

Yes:

$ pacmd stat
Memory blocks currently allocated: 1, size: 63,9 KiB.
Memory blocks allocated during the whole lifetime: 65, size: 2,0 MiB.
Memory blocks imported from other processes: 0, size: 0 B.
Memory blocks exported to other processes: 0, size: 0 B.
Total sample cache size: 0 B.
Default sample spec: s16le 2ch 44100Hz
Default channel map: front-left,front-right
Default sink name: alsa_output.pci-0000_00_1b.0.analog-stereo
Default source name: alsa_input.pci-0000_00_1b.0.analog-stereo
Memory blocks of type POOL: 1 allocated/1 accumulated.
Memory blocks of type POOL_EXTERNAL: 0 allocated/0 accumulated.
Memory blocks of type APPENDED: 0 allocated/0 accumulated.
Memory blocks of type USER: 0 allocated/0 accumulated.
Memory blocks of type FIXED: 0 allocated/64 accumulated.
Memory blocks of type IMPORTED: 0 allocated/0 accumulated.
hastinbe commented 6 years ago

I'm unable to reproduce the error message using the output of your pacmd stat and pacmd list-sinks as input to the script.

If you run pacmd stat | awk -F": " '/^Default sink name: /{print $2}' it should print alsa_output.pci-0000_00_1b.0.analog-stereo

If it does, then running pacmd list-sinks | awk -v 'RS=\r?\n' '/^\s+name: /{indefault = $2 == "<alsa_output.pci-0000_00_1b.0.analog-stereo>"} /^\s+volume: / && indefault {print $5; exit}' | sed 's/%//' should print a number

GijsTimmers commented 6 years ago

If you run pacmd stat | awk -F": " '/^Default sink name: /{print $2}' it should print alsa_output.pci-0000_00_1b.0.analog-stereo

Yes, that works:

$ pacmd stat | awk -F": " '/^Default sink name: /{print $2}'
alsa_output.pci-0000_00_1b.0.analog-stereo

If it does, then running pacmd list-sinks | awk -v 'RS=\r?\n' '/^\s+name: /{indefault = $2 == "<alsa_output.pci-0000_00_1b.0.analog-stereo>"} /^\s+volume: / && indefault {print $5; exit}' | sed 's/%//' should print a number

That one fails: no output:

$ pacmd list-sinks | awk -v 'RS=\r?\n' '/^\s+name: /{indefault = $2 == "<alsa_output.pci-0000_00_1b.0.analog-stereo>"} /^\s+volume: / && indefault {print $5; exit}' | sed 's/%//'
hastinbe commented 6 years ago

Can you pull master and see if it's working? Thanks

GijsTimmers commented 6 years ago

Thanks for your hard work concerning this issue.

Still getting the same error:

$ git rev-parse HEAD
1c016805d52d987c4129ccf062b7a710f63794b4

$ ./volume -i 5 -n
./volume: line 118: [: : integer expression expected
./volume: line 119: [: : integer expression expected
./volume: line 120: [: : integer expression expected
./volume: line 121: [: : integer expression expected
Value "" of hint "value" could not be parsed as type "int".
hastinbe commented 6 years ago

Which version of awk? Can you paste the output of pacmd list-sinks | xxd?

GijsTimmers commented 6 years ago
$ awk -W version 
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan

compiled limits:
max NF             32767
sprintf buffer      2040

$ pacmd list-sinks | xxd
00000000: 3120 7369 6e6b 2873 2920 6176 6169 6c61  1 sink(s) availa
00000010: 626c 652e 0a20 202a 2069 6e64 6578 3a20  ble..  * index: 
00000020: 300a 096e 616d 653a 203c 616c 7361 5f6f  0..name: <alsa_o
00000030: 7574 7075 742e 7063 692d 3030 3030 5f30  utput.pci-0000_0
00000040: 305f 3162 2e30 2e61 6e61 6c6f 672d 7374  0_1b.0.analog-st
00000050: 6572 656f 3e0a 0964 7269 7665 723a 203c  ereo>..driver: <
00000060: 6d6f 6475 6c65 2d61 6c73 612d 6361 7264  module-alsa-card
00000070: 2e63 3e0a 0966 6c61 6773 3a20 4841 5244  .c>..flags: HARD
00000080: 5741 5245 2048 575f 4d55 5445 5f43 5452  WARE HW_MUTE_CTR
00000090: 4c20 4857 5f56 4f4c 554d 455f 4354 524c  L HW_VOLUME_CTRL
000000a0: 2044 4543 4942 454c 5f56 4f4c 554d 4520   DECIBEL_VOLUME 
000000b0: 4c41 5445 4e43 5920 4459 4e41 4d49 435f  LATENCY DYNAMIC_
000000c0: 4c41 5445 4e43 590a 0973 7461 7465 3a20  LATENCY..state: 
000000d0: 5355 5350 454e 4445 440a 0973 7573 7065  SUSPENDED..suspe
000000e0: 6e64 2063 6175 7365 3a20 4944 4c45 200a  nd cause: IDLE .
000000f0: 0970 7269 6f72 6974 793a 2039 3935 390a  .priority: 9959.
00000100: 0976 6f6c 756d 653a 2066 726f 6e74 2d6c  .volume: front-l
00000110: 6566 743a 2032 3032 3536 202f 2020 3331  eft: 20256 /  31
00000120: 2520 2f20 2d33 302c 3630 2064 422c 2020  % / -30,60 dB,  
00000130: 2066 726f 6e74 2d72 6967 6874 3a20 3230   front-right: 20
00000140: 3235 3620 2f20 2033 3125 202f 202d 3330  256 /  31% / -30
00000150: 2c36 3020 6442 0a09 2020 2020 2020 2020  ,60 dB..        
00000160: 6261 6c61 6e63 6520 302c 3030 0a09 6261  balance 0,00..ba
00000170: 7365 2076 6f6c 756d 653a 2036 3535 3336  se volume: 65536
00000180: 202f 2031 3030 2520 2f20 302c 3030 2064   / 100% / 0,00 d
00000190: 420a 0976 6f6c 756d 6520 7374 6570 733a  B..volume steps:
000001a0: 2036 3535 3337 0a09 6d75 7465 643a 206e   65537..muted: n
000001b0: 6f0a 0963 7572 7265 6e74 206c 6174 656e  o..current laten
000001c0: 6379 3a20 302c 3030 206d 730a 096d 6178  cy: 0,00 ms..max
000001d0: 2072 6571 7565 7374 3a20 3020 4b69 420a   request: 0 KiB.
000001e0: 096d 6178 2072 6577 696e 643a 2030 204b  .max rewind: 0 K
000001f0: 6942 0a09 6d6f 6e69 746f 7220 736f 7572  iB..monitor sour
00000200: 6365 3a20 300a 0973 616d 706c 6520 7370  ce: 0..sample sp
00000210: 6563 3a20 7331 366c 6520 3263 6820 3434  ec: s16le 2ch 44
00000220: 3130 3048 7a0a 0963 6861 6e6e 656c 206d  100Hz..channel m
00000230: 6170 3a20 6672 6f6e 742d 6c65 6674 2c66  ap: front-left,f
00000240: 726f 6e74 2d72 6967 6874 0a09 2020 2020  ront-right..    
00000250: 2020 2020 2020 2020 2053 7465 7265 6f0a           Stereo.
00000260: 0975 7365 6420 6279 3a20 300a 096c 696e  .used by: 0..lin
00000270: 6b65 6420 6279 3a20 300a 0963 6f6e 6669  ked by: 0..confi
00000280: 6775 7265 6420 6c61 7465 6e63 793a 2030  gured latency: 0
00000290: 2c30 3020 6d73 3b20 7261 6e67 6520 6973  ,00 ms; range is
000002a0: 2030 2c35 3020 2e2e 2033 3731 2c35 3220   0,50 .. 371,52 
000002b0: 6d73 0a09 6361 7264 3a20 3020 3c61 6c73  ms..card: 0 <als
000002c0: 615f 6361 7264 2e70 6369 2d30 3030 305f  a_card.pci-0000_
000002d0: 3030 5f31 622e 303e 0a09 6d6f 6475 6c65  00_1b.0>..module
000002e0: 3a20 360a 0970 726f 7065 7274 6965 733a  : 6..properties:
000002f0: 0a09 0961 6c73 612e 7265 736f 6c75 7469  ...alsa.resoluti
00000300: 6f6e 5f62 6974 7320 3d20 2231 3622 0a09  on_bits = "16"..
00000310: 0964 6576 6963 652e 6170 6920 3d20 2261  .device.api = "a
00000320: 6c73 6122 0a09 0964 6576 6963 652e 636c  lsa"...device.cl
00000330: 6173 7320 3d20 2273 6f75 6e64 220a 0909  ass = "sound"...
00000340: 616c 7361 2e63 6c61 7373 203d 2022 6765  alsa.class = "ge
00000350: 6e65 7269 6322 0a09 0961 6c73 612e 7375  neric"...alsa.su
00000360: 6263 6c61 7373 203d 2022 6765 6e65 7269  bclass = "generi
00000370: 632d 6d69 7822 0a09 0961 6c73 612e 6e61  c-mix"...alsa.na
00000380: 6d65 203d 2022 4144 3139 3834 4120 416e  me = "AD1984A An
00000390: 616c 6f67 220a 0909 616c 7361 2e69 6420  alog"...alsa.id 
000003a0: 3d20 2241 4431 3938 3441 2041 6e61 6c6f  = "AD1984A Analo
000003b0: 6722 0a09 0961 6c73 612e 7375 6264 6576  g"...alsa.subdev
000003c0: 6963 6520 3d20 2230 220a 0909 616c 7361  ice = "0"...alsa
000003d0: 2e73 7562 6465 7669 6365 5f6e 616d 6520  .subdevice_name 
000003e0: 3d20 2273 7562 6465 7669 6365 2023 3022  = "subdevice #0"
000003f0: 0a09 0961 6c73 612e 6465 7669 6365 203d  ...alsa.device =
00000400: 2022 3022 0a09 0961 6c73 612e 6361 7264   "0"...alsa.card
00000410: 203d 2022 3022 0a09 0961 6c73 612e 6361   = "0"...alsa.ca
00000420: 7264 5f6e 616d 6520 3d20 2248 4441 2049  rd_name = "HDA I
00000430: 6e74 656c 220a 0909 616c 7361 2e6c 6f6e  ntel"...alsa.lon
00000440: 675f 6361 7264 5f6e 616d 6520 3d20 2248  g_card_name = "H
00000450: 4441 2049 6e74 656c 2061 7420 3078 6438  DA Intel at 0xd8
00000460: 3432 3030 3030 2069 7271 2033 3422 0a09  420000 irq 34"..
00000470: 0961 6c73 612e 6472 6976 6572 5f6e 616d  .alsa.driver_nam
00000480: 6520 3d20 2273 6e64 5f68 6461 5f69 6e74  e = "snd_hda_int
00000490: 656c 220a 0909 6465 7669 6365 2e62 7573  el"...device.bus
000004a0: 5f70 6174 6820 3d20 2270 6369 2d30 3030  _path = "pci-000
000004b0: 303a 3030 3a31 622e 3022 0a09 0973 7973  0:00:1b.0"...sys
000004c0: 6673 2e70 6174 6820 3d20 222f 6465 7669  fs.path = "/devi
000004d0: 6365 732f 7063 6930 3030 303a 3030 2f30  ces/pci0000:00/0
000004e0: 3030 303a 3030 3a31 622e 302f 736f 756e  000:00:1b.0/soun
000004f0: 642f 6361 7264 3022 0a09 0964 6576 6963  d/card0"...devic
00000500: 652e 6275 7320 3d20 2270 6369 220a 0909  e.bus = "pci"...
00000510: 6465 7669 6365 2e76 656e 646f 722e 6964  device.vendor.id
00000520: 203d 2022 3830 3836 220a 0909 6465 7669   = "8086"...devi
00000530: 6365 2e76 656e 646f 722e 6e61 6d65 203d  ce.vendor.name =
00000540: 2022 496e 7465 6c20 436f 7270 6f72 6174   "Intel Corporat
00000550: 696f 6e22 0a09 0964 6576 6963 652e 7072  ion"...device.pr
00000560: 6f64 7563 742e 6964 203d 2022 3239 3365  oduct.id = "293e
00000570: 220a 0909 6465 7669 6365 2e70 726f 6475  "...device.produ
00000580: 6374 2e6e 616d 6520 3d20 2238 3238 3031  ct.name = "82801
00000590: 4920 2849 4348 3920 4661 6d69 6c79 2920  I (ICH9 Family) 
000005a0: 4844 2041 7564 696f 2043 6f6e 7472 6f6c  HD Audio Control
000005b0: 6c65 7222 0a09 0964 6576 6963 652e 666f  ler"...device.fo
000005c0: 726d 5f66 6163 746f 7220 3d20 2269 6e74  rm_factor = "int
000005d0: 6572 6e61 6c22 0a09 0964 6576 6963 652e  ernal"...device.
000005e0: 7374 7269 6e67 203d 2022 6672 6f6e 743a  string = "front:
000005f0: 3022 0a09 0964 6576 6963 652e 6275 6666  0"...device.buff
00000600: 6572 696e 672e 6275 6666 6572 5f73 697a  ering.buffer_siz
00000610: 6520 3d20 2236 3535 3336 220a 0909 6465  e = "65536"...de
00000620: 7669 6365 2e62 7566 6665 7269 6e67 2e66  vice.buffering.f
00000630: 7261 676d 656e 745f 7369 7a65 203d 2022  ragment_size = "
00000640: 3332 3736 3822 0a09 0964 6576 6963 652e  32768"...device.
00000650: 6163 6365 7373 5f6d 6f64 6520 3d20 226d  access_mode = "m
00000660: 6d61 702b 7469 6d65 7222 0a09 0964 6576  map+timer"...dev
00000670: 6963 652e 7072 6f66 696c 652e 6e61 6d65  ice.profile.name
00000680: 203d 2022 616e 616c 6f67 2d73 7465 7265   = "analog-stere
00000690: 6f22 0a09 0964 6576 6963 652e 7072 6f66  o"...device.prof
000006a0: 696c 652e 6465 7363 7269 7074 696f 6e20  ile.description 
000006b0: 3d20 2241 6e61 6c6f 6f67 2073 7465 7265  = "Analoog stere
000006c0: 6f22 0a09 0964 6576 6963 652e 6465 7363  o"...device.desc
000006d0: 7269 7074 696f 6e20 3d20 2249 6e74 6572  ription = "Inter
000006e0: 6e20 6765 6c75 6964 2041 6e61 6c6f 6f67  n geluid Analoog
000006f0: 2073 7465 7265 6f22 0a09 0961 6c73 612e   stereo"...alsa.
00000700: 6d69 7865 725f 6e61 6d65 203d 2022 416e  mixer_name = "An
00000710: 616c 6f67 2044 6576 6963 6573 2041 4431  alog Devices AD1
00000720: 3938 3441 220a 0909 616c 7361 2e63 6f6d  984A"...alsa.com
00000730: 706f 6e65 6e74 7320 3d20 2248 4441 3a31  ponents = "HDA:1
00000740: 3164 3431 3934 612c 3130 3363 3330 6463  1d4194a,103c30dc
00000750: 2c30 3031 3030 3430 3020 4844 413a 3131  ,00100400 HDA:11
00000760: 6331 3130 3430 2c31 3033 6331 3337 382c  c11040,103c1378,
00000770: 3030 3130 3032 3030 220a 0909 6d6f 6475  00100200"...modu
00000780: 6c65 2d75 6465 762d 6465 7465 6374 2e64  le-udev-detect.d
00000790: 6973 636f 7665 7265 6420 3d20 2231 220a  iscovered = "1".
000007a0: 0909 6465 7669 6365 2e69 636f 6e5f 6e61  ..device.icon_na
000007b0: 6d65 203d 2022 6175 6469 6f2d 6361 7264  me = "audio-card
000007c0: 2d70 6369 220a 0970 6f72 7473 3a0a 0909  -pci"..ports:...
000007d0: 616e 616c 6f67 2d6f 7574 7075 742d 6c69  analog-output-li
000007e0: 6e65 6f75 743a 204c 696e 6520 4f75 7420  neout: Line Out 
000007f0: 2870 7269 6f72 6974 7920 3939 3030 2c20  (priority 9900, 
00000800: 6c61 7465 6e63 7920 6f66 6673 6574 2030  latency offset 0
00000810: 2075 7365 632c 2061 7661 696c 6162 6c65   usec, available
00000820: 3a20 6e6f 290a 0909 0970 726f 7065 7274  : no)....propert
00000830: 6965 733a 0a09 0909 090a 0909 616e 616c  ies:........anal
00000840: 6f67 2d6f 7574 7075 742d 7370 6561 6b65  og-output-speake
00000850: 723a 204c 7569 6473 7072 656b 6572 7320  r: Luidsprekers 
00000860: 2870 7269 6f72 6974 7920 3130 3030 302c  (priority 10000,
00000870: 206c 6174 656e 6379 206f 6666 7365 7420   latency offset 
00000880: 3020 7573 6563 2c20 6176 6169 6c61 626c  0 usec, availabl
00000890: 653a 2075 6e6b 6e6f 776e 290a 0909 0970  e: unknown)....p
000008a0: 726f 7065 7274 6965 733a 0a09 0909 0964  roperties:.....d
000008b0: 6576 6963 652e 6963 6f6e 5f6e 616d 6520  evice.icon_name 
000008c0: 3d20 2261 7564 696f 2d73 7065 616b 6572  = "audio-speaker
000008d0: 7322 0a09 0961 6e61 6c6f 672d 6f75 7470  s"...analog-outp
000008e0: 7574 2d68 6561 6470 686f 6e65 733a 2041  ut-headphones: A
000008f0: 6e61 6c6f 6765 206b 6f70 7465 6c65 666f  naloge koptelefo
00000900: 6f6e 2028 7072 696f 7269 7479 2039 3030  on (priority 900
00000910: 302c 206c 6174 656e 6379 206f 6666 7365  0, latency offse
00000920: 7420 3020 7573 6563 2c20 6176 6169 6c61  t 0 usec, availa
00000930: 626c 653a 206e 6f29 0a09 0909 7072 6f70  ble: no)....prop
00000940: 6572 7469 6573 3a0a 0909 0909 6465 7669  erties:.....devi
00000950: 6365 2e69 636f 6e5f 6e61 6d65 203d 2022  ce.icon_name = "
00000960: 6175 6469 6f2d 6865 6164 7068 6f6e 6573  audio-headphones
00000970: 220a 0961 6374 6976 6520 706f 7274 3a20  "..active port: 
00000980: 3c61 6e61 6c6f 672d 6f75 7470 7574 2d73  <analog-output-s
00000990: 7065 616b 6572 3e0a                      peaker>.
hastinbe commented 6 years ago

Alright, think we have this figured out. So this script was written using gawk. Upon troubleshooting your issue I was able to duplicate it using gawk in POSIX compatibility mode, I thought that had to be it so I updated it to be POSIX compliant. But it turns out you're using mawk 1.3.3 (this version comes with Debian/Ubuntu) which does not completely support POSIX regular expressions. Version 1.3.4 does, but why they chose to support 1.3.3 (not updated since 1996) over 1.3.4 is a good question. But go ahead and pull master, we should be working on all 3 awks now

GijsTimmers commented 6 years ago

Thanks. It works now.