Search code examples
clinuxkernelinterruptudev

How can I get know when I plug my headphones into the 3.5 interface?


I want to write a small program in C: When I plug my headphones in my notebook, it should turn the volume lower. Then, when I remove headphone from my notebook, it should turn the volume back up.

I am using the alsa driver, and I know how to control the volume.

The question is: How to get notified, when the headphone gets plugged in?

Before I asked this question, I tried to use IRQ. I used watch -d0.5 cat /proc/stat to see if any interrupts are experienced by the system when I plug in or remove my headphone, and I see 8 interrupts. I don't know with IRQ is the right one so, I have no idea.


Solution

  • Maybe you don't need to write any program. Alsamixer should let you specify the volume of the speaker and the volume of the headphones. You just set the headphones' volume a little lower, and that's all.