Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for flatpak portal #146

Merged
merged 2 commits into from
May 24, 2019

Conversation

gicmo
Copy link
Contributor

@gicmo gicmo commented May 20, 2019

Add support to transparently use the portal when running inside a flatpak. This is necessary because flatpak uses pid namespace isolation (see #73) and therefore process ids need to be translated for the gamemode daemon .

This is a draft PR because it depends on flatpak/xdg-desktop-portal#314

That gives some meaning to the strings and makes it easier to see
what the arguments of sd_bus_call_method mean without checking the
function docs.
Copy link
Contributor

@mdiluz mdiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/client_impl.c:106 should use the correct bus name on the error message. Other than that, really nice simple change on the part of gamemode - glad a solution was found for Flatpak

@gicmo
Copy link
Contributor Author

gicmo commented May 20, 2019

lib/client_impl.c:106 should use the correct bus name on the error message.

Good point! Fixed.

@gicmo gicmo marked this pull request as ready for review May 20, 2019 22:31
@gicmo
Copy link
Contributor Author

gicmo commented May 20, 2019

The portal landed, so I guess this can go in.

When we detect that we are running inside a flatpak, talk to the
flatpak portal D-Bus service instead of the session daemon. This
is necessary because flatpak uses pid namespace isolation (see
man pid_namespaces(7)) and thus the pid needs to be translated
from the flatpak pid namespace to the host namespace. This
translation is happening inside the GameMode xdg-desktop-portal.
@aejsmith aejsmith merged commit 6e5e4a1 into FeralInteractive:master May 24, 2019
@aejsmith
Copy link
Contributor

Merged. Thanks a lot for working on a solution for this!

@FLAGEL
Copy link

FLAGEL commented Jan 2, 2024

Disclaimer: I am just a tinkerer, and not familiar with the inner workings of GameMode, Flatpak, or DBus.

Executing gamemoderun %command% within the Steam Flatpak [1] enables and disables GameMode on the host [2]. This can be verified via dbus-monitor --session (below) or gamemoded -s [3]. Within the Steam Flatpak it can also be verified via mangohud gamemoderun %command%, given that MangoHud is available.

However, the following errors are logged to Steam Flatpak stderr as gamemoderun exits:

** (process:562044): WARNING **: 17:55:10.780: Invalid client serial
dbus[3720]: arguments to dbus_pending_call_block() were incorrect, assertion "pending != NULL" failed in file ../../dbus/dbus-pending-call.c line 766.
This is normally a bug in some application using the D-Bus library.

dbus[3720]: arguments to dbus_pending_call_steal_reply() were incorrect, assertion "pending != NULL" failed in file ../../dbus/dbus-pending-call.c line 733.
This is normally a bug in some application using the D-Bus library.

GameMode ERROR: D-Bus error: Did not receive a reply
gamemodeauto: D-Bus error: Did not receive a reply

DBus registration:

method call time=1704210321.074698 sender=:1.3277 -> destination=org.freedesktop.portal.Desktop serial=26 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.portal.GameMode; member=RegisterGameByPIDFd
   file descriptor
         inode: 2099
         type:    file descriptor
         inode: 2099
         type: method call time=1704210321.074737 sender=:1.44 -> destination=org.freedesktop.DBus serial=7943 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetConnectionUnixProcessID
   string ":1.3277"
method return time=1704210321.074746 sender=org.freedesktop.DBus -> destination=:1.44 serial=1739 reply_serial=7943
   uint32 562044
signal time=1704210321.109850 sender=:1.3018 -> destination=(null destination) serial=384 path=/com/feralinteractive/GameMode; interface=com.feralinteractive.GameMode; member=GameRegistered
   int32 565669
   object path "/com/feralinteractive/GameMode/Games/565669"
signal time=1704210321.109889 sender=:1.3018 -> destination=(null destination) serial=385 path=/com/feralinteractive/GameMode; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "com.feralinteractive.GameMode"
   array [
      dict entry(
         string "ClientCount"
         variant             int32 1
      )
   ]
   array [
   ]
method return time=1704210321.109935 sender=:1.3018 -> destination=:1.44 serial=386 reply_serial=7945
   int32 0
signal time=1704210321.110067 sender=:1.44 -> destination=(null destination) serial=7946 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.freedesktop.portal.GameMode"
   array [
      dict entry(
         string "Active"
         variant             boolean true
      )
   ]
   array [
   ]

DBus deregistration:

signal time=1704210743.041465 sender=:1.3018 -> destination=(null destination) serial=408 path=/com/feralinteractive/GameMode; interface=com.feralinteractive.GameMode; member=GameUnregistered
   int32 565685
   object path "/com/feralinteractive/GameMode/Games/565685"
signal time=1704210743.041517 sender=:1.3018 -> destination=(null destination) serial=409 path=/com/feralinteractive/GameMode; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "com.feralinteractive.GameMode"
   array [
      dict entry(
         string "ClientCount"
         variant             int32 0
      )
   ]
   array [
   ]
signal time=1704210743.041752 sender=:1.44 -> destination=(null destination) serial=8002 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.freedesktop.portal.GameMode"
   array [
      dict entry(
         string "Active"
         variant             boolean false
      )
   ]
   array [
   ]

Setup
[1] com.valvesoftware.Steam 1.0.0.78
[2] Linux host 6.6.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:01:01 +0000 x86_64 GNU/Linux
[3] dbus 1.14.10-1, gamemode 1.8.1-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants