The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
0

hook on output change

asked 2013-07-14 06:05:02 +0000

anonymous user

Anonymous

updated 2013-07-15 04:07:43 +0000

Hi,

I have another sound card for my external monitor and I'd like to change my default output sink when switching from one monitor to the other:

echo set-default-sink 0 | pacmd (laptop) echo set-default-sink 3 | pacmd (ext. monitor)

What I need is a hook where I can issue these commands when I change to a workspace which is on the other monitor. Is this possible (4.5.1)?

Best regards

edit retag flag offensive close merge delete

Comments

Actually my commands are wrong but the should be issued on **output** change. The correct command is 'move-sink-input index sink-index'. Sink 0 is my laptop and sink 3 is my monitor.

grml gravatar imagegrml ( 2013-07-14 18:25:12 +0000 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2013-07-14 06:52:29 +0000

joepd gravatar image

updated 2013-07-14 10:03:20 +0000

New answer: Yes this is possible, but you'll have to cross the line between configuration and writing code. You could subscribe to the workspace event with some IPC-library. Feel free to post your solution :)

Old answer: AFAIK, this is not possible. But there is also a more correct level to address this wish: udev. Then you can have your machine react to the hardware event 'new sound card', instead of some unrelated but correlated change in a user application.

Someone with a very similar wish has written about it: http://stavrakisblog.blogspot.de/2012...

edit flag offensive delete link more

Comments

Oops, did not read your question properly. You really want to change the default sound based on which workspace is active?

joepd gravatar imagejoepd ( 2013-07-14 06:54:14 +0000 )edit

The sink should change depending on which screen my app (mplayer) is. If the window is on my laptop I'd like to hear the sound from it. If I move the window to the ext. monitor the sound should "follow". The necessary commands are in my above comment of the original question.

grml gravatar imagegrml ( 2013-07-14 18:34:13 +0000 )edit

It should be possible to fix this with IPC, but it will take time. Have a look at the links I provided. Guess it would be faster to write a toggle script for pacmd which sends the sound to the other device, though.

joepd gravatar imagejoepd ( 2013-07-14 19:03:23 +0000 )edit

A toggle command has to know the pulse audio index of the program in question. I also need another running server process for the IPC callback, right? What I really miss is a possibility to issue shell commands on callback in the i3 config file, or an integrated extension language to do such things.

grml gravatar imagegrml ( 2013-07-15 03:49:26 +0000 )edit

There is no integrated language extension, but there is an IPC interface for external libraries. A few of the latter have been created. that make it not too difficult to do exactly that. Yes, you would need to start another process that listens to the events.

joepd gravatar imagejoepd ( 2013-07-15 09:10:28 +0000 )edit
0

answered 2013-07-14 11:11:55 +0000

If you are talking about getting the sound output to change dynamically, you might get answers on different forums. For i3, considering you know which one to trigger this change, you can make the keybind do something else:

bindsym Mod4+1 exec ~/.i3/workspace 1

And for the workspace script:

#!/bin/bash

#
# do whatever you want
#    

i3-msg "workspace $1"
edit flag offensive delete link more
0

answered 2013-07-17 13:37:08 +0000

grml gravatar image

I can start mplayer and redirect sound directly with the -ao option:

mplayer -ao pulse::$([ "$output" == "VGA1" ] && echo 3 || echo 1) myvideo.mp4

But how can I find out on which output the window will open? I'm still looking for a simple way to switch sound depending on the monitor where mplayer is started.

edit flag offensive delete link more

Comments

As said before, look into the IPC. `i3-msg -t get_tree | json_pp` should get you going.

joepd gravatar imagejoepd ( 2013-07-18 05:29:10 +0000 )edit

Question Tools

Stats

Asked: 2013-07-14 06:05:02 +0000

Seen: 427 times

Last updated: Jul 17 '13