Skip to content

Commit

Permalink
Add --device=input permission
Browse files Browse the repository at this point in the history
This new permission exposes the host's /dev/input directory, providing
minimal game controller support without resorting to --device=all.
  • Loading branch information
foresto committed Sep 7, 2023
1 parent 0e2508a commit 19bbf80
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions common/flatpak-context-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef enum {
FLATPAK_CONTEXT_DEVICE_ALL = 1 << 1,
FLATPAK_CONTEXT_DEVICE_KVM = 1 << 2,
FLATPAK_CONTEXT_DEVICE_SHM = 1 << 3,
FLATPAK_CONTEXT_DEVICE_INPUT = 1 << 4,
} FlatpakContextDevices;

typedef enum {
Expand Down
1 change: 1 addition & 0 deletions common/flatpak-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const char *flatpak_context_devices[] = {
"all",
"kvm",
"shm",
"input",
NULL
};

Expand Down
8 changes: 8 additions & 0 deletions common/flatpak-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ flatpak_run_add_environment_args (FlatpakBwrap *bwrap,
}
}

if (context->devices & FLATPAK_CONTEXT_DEVICE_INPUT)
{
g_info ("Allowing input device access. Note: raw and virtual input currently require --device=all");

if (g_file_test ("/dev/input", G_FILE_TEST_IS_DIR))
flatpak_bwrap_add_args (bwrap, "--dev-bind", "/dev/input", "/dev/input", NULL);
}

if (context->devices & FLATPAK_CONTEXT_DEVICE_KVM)
{
g_info ("Allowing kvm access");
Expand Down
4 changes: 2 additions & 2 deletions doc/flatpak-build-finish.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<listitem><para>
Expose a device to the application. This updates
the [Context] group in the metadata.
DEVICE must be one of: dri, kvm, shm, all.
DEVICE must be one of: dri, input, kvm, shm, all.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand All @@ -173,7 +173,7 @@
<listitem><para>
Don't expose a device to the application. This updates
the [Context] group in the metadata.
DEVICE must be one of: dri, kvm, shm, all.
DEVICE must be one of: dri, input, kvm, shm, all.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand Down
4 changes: 2 additions & 2 deletions doc/flatpak-build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
<listitem><para>
Expose a device to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">DEVICE</arg> must be one of: dri, kvm, shm, all.
<arg choice="plain">DEVICE</arg> must be one of: dri, input, kvm, shm, all.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand All @@ -183,7 +183,7 @@
<listitem><para>
Don't expose a device to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">DEVICE</arg> must be one of: dri, kvm, shm, all.
<arg choice="plain">DEVICE</arg> must be one of: dri, input, kvm, shm, all.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand Down
6 changes: 6 additions & 0 deletions doc/flatpak-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@
Available since 0.3.
</para></listitem></varlistentry>

<varlistentry><term><option>input</option></term>
<listitem><para>
Input devices
(<filename>/dev/input</filename>).
</para></listitem></varlistentry>

<varlistentry><term><option>kvm</option></term>
<listitem><para>
Virtualization
Expand Down
4 changes: 2 additions & 2 deletions doc/flatpak-override.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<listitem><para>
Expose a device to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">DEVICE</arg> must be one of: dri, kvm, shm, all.
<arg choice="plain">DEVICE</arg> must be one of: dri, input, kvm, shm, all.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand All @@ -171,7 +171,7 @@
<listitem><para>
Don't expose a device to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">DEVICE</arg> must be one of: dri, kvm, shm, all.
<arg choice="plain">DEVICE</arg> must be one of: dri, input, kvm, shm, all.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand Down
4 changes: 2 additions & 2 deletions doc/flatpak-run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
<listitem><para>
Expose a device to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">DEVICE</arg> must be one of: dri, kvm, shm, all.
<arg choice="plain">DEVICE</arg> must be one of: dri, input, kvm, shm, all.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand All @@ -340,7 +340,7 @@
<listitem><para>
Don't expose a device to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">DEVICE</arg> must be one of: dri, kvm, shm, all.
<arg choice="plain">DEVICE</arg> must be one of: dri, input, kvm, shm, all.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand Down

0 comments on commit 19bbf80

Please sign in to comment.