ValveSoftware / gamescope

SteamOS session compositing window manager
Other
3.12k stars 211 forks source link

exiting the game using a keyboard shortcut will exit gamescope and not the game #885

Open beh-10257 opened 1 year ago

beh-10257 commented 1 year ago

in my system to exit any application I just use SUPER+C the default for Hyprland anyway so basically after pressing that key combination while running apex legends and after checking in htop we can see that gamescope actually closes but all his child processes don't aka the game so yeah I guess the expected behaviour is to gamescope to kill his child processes

MithicSpirit commented 10 months ago

Can reproduce on sway as well. IMO gamescope should wait for all windows inside it to close before closing itself.

Cloudef commented 10 months ago

bumping

misyltoad commented 10 months ago

Gamescope does try to kill its children when it dies but if you are forcing that it's likely not getting a chance.

MithicSpirit commented 10 months ago

I don't think that it's forcing. I'm pretty sure that it's the equivalent of pressing the "x" button to close a window. For example, doing the same on a LibreOffice Writer window still allows it to prompt the user on whether to save the document or not.

Cloudef commented 10 months ago

I think this might actually be issue with children that double fork

Cloudef commented 10 months ago

Hmm, I tried make gamescope call my reaper binary from here https://github.com/Cloudef/pid-defer And the reaper indeed does not seem to receive any sigterm from gamescope.

Wonder if wlroots/hyprland is being too agressive in closing the process, or gamescope does not handle wayland disconnect properly? Here are some logs from the end:

(EE) failed to read Wayland events: Broken pipe
X connection to :1 broken (explicit kill or server shutdown).
X connection to :1 broken (explicit kill or server shutdown).
X connection to :1 broken (explicit kill or server shutdown).
X connection to :1 broken (explicit kill or server shutdown).
X connection to :1 broken (explicit kill or server shutdown).

Currently I have to do some manual cleanup https://github.com/Cloudef/nixos-flake/blob/master/modules/steamdeck-experience.nix#L197 https://github.com/Cloudef/nixos-flake/blob/master/modules/steamdeck-experience.nix#L231-L235

EDIT: with more simple scenario with launching zenity it works. I'll see if I can make something easily reproducible.

sharkautarch commented 10 months ago

@Joshua-Ashton

Gamescope does try to kill its children when it dies but if you are forcing that it's likely not getting a chance.

Since gamescope uses sdl2’s event system, I wondered if sdl2 could be causing this issue (wherein gamescope runs SDL_Init( SDL_INIT_VIDEO | SDL_INIT_EVENTS ) this issue would only be seen in nested mode)

I found a stackoverflow post from 2013 that says that sdl2 (when initialized with SDL_INIT_EVENTS) registers its own signal handler that causes the process (in this case the gamescope process) to abort when it receives SIGINT or SIGTERM: (w/ SIGTERM being the signal for requesting an application to close) https://stackoverflow.com/questions/20049025/cant-ctrl-c-my-sdl-apps-anymore#20171501

ofc this is from 2013, not sure if sdl2 still does this

EDIT: I just realized there’s also an SDL2 wiki page mentioning this: https://wiki.libsdl.org/SDL2/SDL_HINT_NO_SIGNAL_HANDLERS

MithicSpirit commented 10 months ago

w/ SIGTERM being the signal for requesting an application to close

Are you sure? I've just tried to send SIGTERM to a LibreOffice Writer window and it just closed immediately without prompting to save the document (unlike when I close it via Sway).

sharkautarch commented 10 months ago

w/ SIGTERM being the signal for requesting an application to close

Are you sure? I've just tried to send SIGTERM to a LibreOffice Writer window and it just closed immediately without prompting to save the document (unlike when I close it via Sway).

programs are able to ignore SIGTERM signals, but not SIGKILL signals https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html

MithicSpirit commented 10 months ago

w/ SIGTERM being the signal for requesting an application to close

Are you sure? I've just tried to send SIGTERM to a LibreOffice Writer window and it just closed immediately without prompting to save the document (unlike when I close it via Sway).

programs are able to ignore SIGTERM signals, but not SIGKILL signals gnu.org/software/libc/manual/html_node/Termination-Signals.html

Sorry I think I misunderstood what you had said earlier. I just meant that SIGTERM is not what's used for an application's window to close.

I feel like the solution to this issue would be for gamescope to forward the window close event to all windows inside it and stay open until those windows close, rather than just immediately closing the gamescope window and trying to stop the processes in some other way (like SIGTERM).