mute the game while alt-tabbed

Ideas that are too old (too many things have changed since) and ones which won't be implemented for certain reasons or if there are obviously better suggestions.

Moderator: ickputzdirwech

User avatar
MarvinCZ
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Fri Jun 03, 2016 7:11 pm
Contact:

Re: mute the game while alt-tabbed

Post by MarvinCZ »

ptx0 wrote: Fri Feb 26, 2021 4:51 pm because you can solve the problem without Wube having to spend time on it.
It's called "User experience". 🙂

Lots of things could have been actually left out from the game, but in fact are there just because Factorio developers care for user's experience and quality of life.
This proposal is just another example of the same principle.

Let's leave the decision if such feature deserves to be spent time on for Wube, after all it's their time, their decision and their game.
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: mute the game while alt-tabbed

Post by ptx0 »

it's been 8 years since this thread was opened. if you want to keep waiting, be my guest.

if you want to fix it yourself, use AppleScript:

Code: Select all

tell application "Factorio"
  set currentVolume to sound volume
end tell
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: mute the game while alt-tabbed

Post by ptx0 »

nuhll wrote: Wed May 27, 2020 12:42 am Is it hard to implement it?!
actually yes. it's very buggy even in games that do support it. it's not a native Windows or OS X function and the devs have to resort to hacks for it to work, like using software resampling before it's sent to the OS audio backend.. increases CPU use for a dumb reason. Allegro audio is already high in CPU use.

that's why I said it's an OS level function that Wube has no business trying to implement.... and there's several offered tools in this thread that will do it for you using aforementioned hacks that Wube won't have to touch with a 40 foot pole.
User avatar
MarvinCZ
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Fri Jun 03, 2016 7:11 pm
Contact:

Re: mute the game while alt-tabbed

Post by MarvinCZ »

ptx0 wrote: Fri Feb 26, 2021 5:04 pm it's been 8 years since this thread was opened. if you want to keep waiting, be my guest.
Call me an incurable optimist.. ;-)
Rseding91
Factorio Staff
Factorio Staff
Posts: 14250
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: mute the game while alt-tabbed

Post by Rseding91 »

Not an answer to the suggestion but some developer info:

Detecting when a window is in focus or not is (apparently) a non-solved problem. Some operating systems with some drivers and some situations may have a program in focus but from a code perspective it never gets the "focus gained" and so the code thinks "not focused" and all kinds of issues happen.
If you want to get ahold of me I'm almost always on Discord.
User avatar
MarvinCZ
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Fri Jun 03, 2016 7:11 pm
Contact:

Re: mute the game while alt-tabbed

Post by MarvinCZ »

Rseding91 wrote: Sat Feb 27, 2021 5:33 pm Detecting when a window is in focus or not is (apparently) a non-solved problem. Some operating systems with some drivers and some situations may have a program in focus but from a code perspective it never gets the "focus gained" and so the code thinks "not focused" and all kinds of issues happen.
Thank you very much for this insight into this problem. I see it is not an easy task to do after all. 🤔
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: mute the game while alt-tabbed

Post by Optera »

At least in Windows it's trivial to read the focused window or make borderless fullscreen.
By now almost all games except Factorio have these features built in.

Though Borderless Gaming also adds it to games that for whatever reason won't support them. So this thread can continue running circles for another 7 years for all I care.
nuhll
Filter Inserter
Filter Inserter
Posts: 937
Joined: Mon Apr 04, 2016 9:48 pm
Contact:

Re: mute the game while alt-tabbed

Post by nuhll »

lol?

is that so? I dont know.

I just know many games have it and i never had any issues with it.

I just know wow did read the windows titles which was opend while running wow. So maybe just do a simple "if windows title is not *factorio*"?

ATLEAST whats about a keybind for mute unmute? :roll: (so i make it just alt tab :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: )

edit:
literally 5 min google.. ? Just get the current window, and if its not *factorio* mute sound, check every 10 sec or something. finish, atleast for windows.

GetForegroundWindow

https://docs.microsoft.com/en-us/window ... oundwindow
InPtr hwnd = GetForegroundWindow();

public static void GetAppActiveWindow(IntPtr hwnd)
{
uint remoteThreadId = GetWindowThreadProcessId(hwnd, IntPtr.Zero);
uint currentThreadId = GetCurrentThreadId();
//AttachTrheadInput is needed so we can get the handle of a focused window in another app
AttachThreadInput(remoteThreadId, currentThreadId, true);
//Get the handle of a focused window
IntPtr focussed = GetFocus();

StringBuilder activechild = new StringBuilder(256);
GetWindowText(focussed, activechild, 256);
string textchld = activechild.ToString();
if (textchld.Length > 0)
{
Console.WriteLine("The active Child window is " + textchld + " .");

}
//Now detach since we got the focused handle
AttachThreadInput(remoteThreadId, currentThreadId, false);
}
???
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: mute the game while alt-tabbed

Post by Optera »

When you program the window yourself there's not even a need to poll.
https://docs.microsoft.com/en-us/dotnet ... ew=net-5.0

or with 1min more google-foo for cpp: https://stackoverflow.com/questions/142 ... focus-in-c
posila
Factorio Staff
Factorio Staff
Posts: 5341
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: mute the game while alt-tabbed

Post by posila »

nuhll: you guys should do this, it's super easy, barely an inconvenience, here's stackoverflow link on how to do it
also nuhll: I have this weird hang issue nobody else has, that went away after rebooting my computer, but I decided it is somehow your bug that you should fix, and you have not fixed it yet
:D

Dev: I don't want to do this, because it'll be just code that won't randomly work properly on some computers for unknown reasons
nuhll: lol? is that so? I dont know.
:lol: :lol: :lol:

Dude, if you want me forever to step into another pile of technical support shit, make me at least feel like it is worth it (if you know what I mean, huehuehue) and don't frame it like "it's super easy, why have you not done it yet"

Anyway, since you guys are linking sites on how to achieve this using WinAPI, in 1.1.27 there is directsound-global-focus in config.ini, if you change it to false, sound will be muted when the game window doesn't have input focus. It's done through DirectSound flag, so if it doesn't work for you in any way (sound doesn't get muted when the window loses focus, or doesn't get unmuted when it regains focus, or it gets muted randomly while not losing focus, ...), I don't care, I can't fix it and it's not my problem.
User avatar
MarvinCZ
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Fri Jun 03, 2016 7:11 pm
Contact:

Re: mute the game while alt-tabbed

Post by MarvinCZ »

And would it please be possible to at least have a key binding for "Mute"?
It could be unset by default so users won't mute game by mistake, but other users could map it themselves if they wanted.
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: mute the game while alt-tabbed

Post by ptx0 »

Optera wrote: Fri Mar 12, 2021 5:59 am When you program the window yourself there's not even a need to poll.
https://docs.microsoft.com/en-us/dotnet ... ew=net-5.0

or with 1min more google-foo for cpp: https://stackoverflow.com/questions/142 ... focus-in-c
not for full screen games!
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: mute the game while alt-tabbed

Post by ptx0 »

posila wrote: Fri Mar 12, 2021 9:19 am will be muted when the game window doesn't have input focus. It's done through DirectSound flag, so if it doesn't work for you in any way (sound doesn't get muted when the window loses focus, or doesn't get unmuted when it regains focus, or it gets muted randomly while not losing focus, ...), I don't care, I can't fix it and it's not my problem.
yeah, DirectSound is deprecated.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: mute the game while alt-tabbed

Post by Optera »

ptx0 wrote: Fri Mar 12, 2021 2:48 pm
Optera wrote: Fri Mar 12, 2021 5:59 am When you program the window yourself there's not even a need to poll.
https://docs.microsoft.com/en-us/dotnet ... ew=net-5.0

or with 1min more google-foo for cpp: https://stackoverflow.com/questions/142 ... focus-in-c
not for full screen games!
That's one of the reasons I prefer borderless windowed over fullscreen.
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: mute the game while alt-tabbed

Post by ptx0 »

Optera wrote: Fri Mar 12, 2021 2:53 pm That's one of the reasons I prefer borderless windowed over fullscreen.
https://devblogs.microsoft.com/directx/ ... mizations/

it has substantial performance overhead due to compositing.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: mute the game while alt-tabbed

Post by Optera »

ptx0 wrote: Fri Mar 12, 2021 3:20 pm https://devblogs.microsoft.com/directx/ ... mizations/

it has substantial performance overhead due to compositing.
About time MS realizes FSE is an overall worse gaming experience than BW.
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: mute the game while alt-tabbed

Post by ptx0 »

Optera wrote: Fri Mar 12, 2021 6:45 pm About time MS realizes FSE is an overall worse gaming experience than BW.
it's that the demand for a pretty, composited, interface conflicts with the demand for seamless and highly performant environments.
nuhll
Filter Inserter
Filter Inserter
Posts: 937
Joined: Mon Apr 04, 2016 9:48 pm
Contact:

Re: mute the game while alt-tabbed

Post by nuhll »

posila wrote: Fri Mar 12, 2021 9:19 am nuhll: you guys should do this, it's super easy, barely an inconvenience, here's stackoverflow link on how to do it
also nuhll: I have this weird hang issue nobody else has, that went away after rebooting my computer, but I decided it is somehow your bug that you should fix, and you have not fixed it yet
:D

Dev: I don't want to do this, because it'll be just code that won't randomly work properly on some computers for unknown reasons
nuhll: lol? is that so? I dont know.
:lol: :lol: :lol:

Dude, if you want me forever to step into another pile of technical support shit, make me at least feel like it is worth it (if you know what I mean, huehuehue) and don't frame it like "it's super easy, why have you not done it yet"

Anyway, since you guys are linking sites on how to achieve this using WinAPI, in 1.1.27 there is directsound-global-focus in config.ini, if you change it to false, sound will be muted when the game window doesn't have input focus. It's done through DirectSound flag, so if it doesn't work for you in any way (sound doesn't get muted when the window loses focus, or doesn't get unmuted when it regains focus, or it gets muted randomly while not losing focus, ...), I don't care, I can't fix it and it's not my problem.
I posted a strange bug, which resolved itself and i even reported that correctly. And it happend on different days (where i also rebootet, else i wouldnt have posted it) Dont know how it shouldnt be YOUR bug when its ONLY YOUR GAME hanging, other games and programs working. :roll: Should i reverse engineer it as a customer? Ask microsoft about it?

I dont have any programming knowledge i just wanted to help. Thats why i searched it and instant found something. I thought it might be helpfull.

I dont have any directsound* in config.ini in Roaming\Factorio, im on .27 (added it to [sound] as directsound-global-focus=true ) - dont work

This feature is asked for years from different people why so aggro i dont get it. Its not my fault windows sucks or something. I just know its possible and there are different ways to archieve it.

edit:
directsound-global-focus=false works

nice,thanks
User avatar
bormand
Fast Inserter
Fast Inserter
Posts: 201
Joined: Fri Jun 05, 2020 9:59 am
Contact:

Re: mute the game while alt-tabbed

Post by bormand »

nuhll wrote: Sun Mar 14, 2021 1:05 am I dont have any programming knowledge i just wanted to help. Thats why i searched it and instant found something. I thought it might be helpfull.
I'm sorry for being rude, but do you think devs can't google themselves?

The real cost of a feature is not an implementation, which might be rather trivial, but research, testing and support. If you add a feature, you must support it for years across many hardware and software configurations. People will blame you if something doesn't work 5 years later with a heavily customized OS and/or broken hardware. So, prepare to spend your time reading bug reports. And random snippets from the internet usually lack some important details, so prepare to spend some time searching for known bugs and pitfalls.

If you had more experience with programming, that hidden cost should be quite obvious to you.
posila
Factorio Staff
Factorio Staff
Posts: 5341
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: mute the game while alt-tabbed

Post by posila »

nuhll wrote: Sun Mar 14, 2021 1:05 am...
You reported it correctly. I ment you as an example of someone who experienced strange random software issue, that also randomly resolved itself (but despite that you still saw it as something wrong on our side) ... and at the same time as someone who seems to have hard time to imagine, that strange random software issues happen.

However, what I wanted to say in my aggrevatingly written post was that I, personally, don't want to get into implementing suggestions or requests that assess the difficulty of implementation.
Post Reply

Return to “Outdated/Not implemented”