View | Details | Raw Unified | Return to bug 276144 | Differences between
and this patch

Collapse All | Expand All

(-)b/games/moonlight-embedded/Makefile (-1 / +11 lines)
Lines 1-5 Link Here
1
PORTNAME=	moonlight-embedded
1
PORTNAME=	moonlight-embedded
2
DISTVERSION=	2.6.1
2
DISTVERSION=	2.6.2
3
CATEGORIES=	games
3
CATEGORIES=	games
4
MASTER_SITES=	https://github.com/moonlight-stream/moonlight-embedded/releases/download/v${DISTVERSION}/
4
MASTER_SITES=	https://github.com/moonlight-stream/moonlight-embedded/releases/download/v${DISTVERSION}/
5
5
Lines 33-42 USE_XORG= x11 Link Here
33
NO_WRKSUBDIR=	yes
33
NO_WRKSUBDIR=	yes
34
CFLAGS+=	-DHAS_SOCKLEN_T=1 -I${LOCALBASE}/include/libepoll-shim/
34
CFLAGS+=	-DHAS_SOCKLEN_T=1 -I${LOCALBASE}/include/libepoll-shim/
35
LDFLAGS+=	-lepoll-shim
35
LDFLAGS+=	-lepoll-shim
36
CMAKE_OFF=	ENABLE_CEC ENABLE_PULSE
37
CMAKE_ON=	ENET_NO_INSTALL
38
39
PLIST_FILES=	bin/moonlight \
40
		"@sample etc/moonlight.conf.sample" \
41
		share/man/man1/moonlight.1.gz \
42
		share/moonlight/gamecontrollerdb.txt
36
43
37
post-patch:
44
post-patch:
38
	@${REINPLACE_CMD} -e 's@/usr/local@${PREFIX}@' \
45
	@${REINPLACE_CMD} -e 's@/usr/local@${PREFIX}@' \
39
		${WRKSRC}/docs/README.pod
46
		${WRKSRC}/docs/README.pod
47
	@${REINPLACE_CMD} -e 's@/usr/local@${PREFIX}@' \
48
                -e 's@/etc@${PREFIX}/etc@' \
49
		${WRKSRC}/src/config.c
40
50
41
post-install:
51
post-install:
42
	@${MV} ${STAGEDIR}${PREFIX}/etc/moonlight.conf \
52
	@${MV} ${STAGEDIR}${PREFIX}/etc/moonlight.conf \
(-)b/games/moonlight-embedded/distinfo (-3 / +3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1697067500
1
TIMESTAMP = 1701007066
2
SHA256 (moonlight-embedded-2.6.1.tar.xz) = 1a252e18ac637e0ad7180238fa868e04629a3d8e43232097d5ccaa3b4142fded
2
SHA256 (moonlight-embedded-2.6.2.tar.xz) = 8bcc69b403a628efaf8686d40c0d1428b46defe4c65b06ff6ccc3fe32f0b2356
3
SIZE (moonlight-embedded-2.6.1.tar.xz) = 327632
3
SIZE (moonlight-embedded-2.6.2.tar.xz) = 328660
(-)b/games/moonlight-embedded/files/patch-CMakeLists.txt (-42 / +11 lines)
Lines 1-45 Link Here
1
--- CMakeLists.txt.orig	2023-09-01 23:40:56 UTC
1
--- CMakeLists.txt.orig	2023-11-03 06:08:34 UTC
2
+++ CMakeLists.txt
2
+++ CMakeLists.txt
3
@@ -5,14 +5,11 @@ SET(CMAKE_C_STANDARD 99)
3
@@ -87,6 +87,11 @@ add_executable(moonlight ${SRC_LIST})
4
 include(${CMAKE_ROOT}/Modules/GNUInstallDirs.cmake)
4
 target_link_libraries(moonlight m)
5
 include(${CMAKE_SOURCE_DIR}/cmake/generate_version_header.cmake)
5
 target_link_libraries(moonlight gamestream)
6
 
6
 
7
-add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-pointer-sign -Wno-sign-compare -Wno-switch)
7
+if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
8
-
8
+  set(ALSA_FOUND FALSE)
9
 aux_source_directory(./src SRC_LIST)
9
+  target_sources(moonlight PRIVATE ./src/audio/oss.c)
10
 list(APPEND SRC_LIST ./src/input/evdev.c ./src/input/mapping.c ./src/input/udev.c)
10
+endif()
11
 
11
+
12
 set(MOONLIGHT_DEFINITIONS)
12
 if (CEC_FOUND)
13
 
14
-find_package(ALSA)
15
 find_package(Opus REQUIRED)
16
 find_package(Broadcom-OMX)
17
 find_package(Freescale)
18
@@ -46,10 +43,8 @@ if (ENABLE_FFMPEG)
19
   endif()
20
 endif()
21
 if (ENABLE_PULSE)
22
-  pkg_check_modules(PULSE libpulse-simple)
23
 endif()
24
 if (ENABLE_CEC)
25
-  pkg_check_modules(CEC libcec>=4)
26
 endif()
27
 
28
 pkg_check_modules(MMAL mmal)
29
@@ -91,7 +86,6 @@ if (CEC_FOUND)
30
   list(APPEND MOONLIGHT_DEFINITIONS HAVE_LIBCEC)
13
   list(APPEND MOONLIGHT_DEFINITIONS HAVE_LIBCEC)
31
   list(APPEND MOONLIGHT_OPTIONS CEC)
14
   list(APPEND MOONLIGHT_OPTIONS CEC)
32
   target_sources(moonlight PRIVATE ./src/input/cec.c)
33
-  target_include_directories(moonlight PRIVATE ./third_party/libcec ${CEC_INCLUDE_DIRS})
34
   target_link_libraries(moonlight ${CEC_LIBRARIES})
35
 endif()
36
 
37
@@ -158,7 +152,7 @@ if (SOFTWARE_FOUND)
38
   if(X11_FOUND)
39
     list(APPEND MOONLIGHT_DEFINITIONS HAVE_X11)
40
     list(APPEND MOONLIGHT_OPTIONS X11)
41
-    target_sources(moonlight PRIVATE ./src/video/x11.c ./src/video/egl.c ./src/input/x11.c)
42
+    target_sources(moonlight PRIVATE ./src/video/x11.c ./src/video/egl.c ./src/input/x11.c ./src/audio/oss.c)
43
     target_include_directories(moonlight PRIVATE ${XLIB_INCLUDE_DIRS} ${EGL_INCLUDE_DIRS} ${GLES_INCLUDE_DIRS})
44
     target_link_libraries(moonlight ${XLIB_LIBRARIES} ${EGL_LIBRARIES} ${GLES_LIBRARIES})
45
   endif()
(-)a/games/moonlight-embedded/files/patch-docs_CMakeLists.txt (-8 lines)
Removed Link Here
1
--- docs/CMakeLists.txt.orig	2023-09-01 23:40:56 UTC
2
+++ docs/CMakeLists.txt
3
@@ -1,4 +1,4 @@
4
-add_custom_command(OUTPUT moonlight.1 COMMAND pod2man --section=1 --center="Moonlight Embedded Manual" --name="MOONLIGHT" --release="moonlight 2.5.0" ${CMAKE_CURRENT_SOURCE_DIR}/README.pod > moonlight.1)
5
+add_custom_command(OUTPUT moonlight.1 COMMAND pod2man --section=1 --center="Moonlight Embedded Manual" --name="MOONLIGHT" --release="moonlight 2.6.0" ${CMAKE_CURRENT_SOURCE_DIR}/README.pod > moonlight.1)
6
 add_custom_target(docs ALL DEPENDS moonlight.1)
7
 
8
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/moonlight.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
(-)a/games/moonlight-embedded/files/patch-docs_README.pod (-120 lines)
Removed Link Here
1
--- docs/README.pod.orig	2023-10-11 15:50:11 UTC
2
+++ docs/README.pod
3
@@ -13,7 +13,10 @@ Usage: I<moonlight> E<lt>actionE<gt> [options] [host]
4
 
5
 =item B<pair>
6
 
7
-Pair this computer with the host.
8
+ Pair this computer with the host.
9
+ If [host] is not specified here,moonlight will auto discover host first.
10
+ It's need start avahi-daemon first.
11
+ NOTE:It's not work under wifibox.
12
 
13
 =item B<unpair>
14
 
15
@@ -22,6 +25,7 @@ Unpair this computer with the host.
16
 =item B<stream>
17
 
18
 Stream game from host to this computer.
19
+If [host] is not specified here,moonlight will auto discover host first.
20
 
21
 =item B<list>
22
 
23
@@ -99,9 +103,9 @@ By default, 1392 is used on LAN and 1024 on WAN.
24
 =item B<-codec> [I<CODEC>]
25
 
26
 Select codec to use.
27
-Can be 'auto', 'h264', 'h265', 'hevc', or 'av1'.
28
-Not all video decoders support H.265/HEVC or AV1.
29
-Will still use H.264 if server doesn't support HEVC or AV1.
30
+Can be 'auto', 'h264', 'h265', 'hevc' or 'av1'.
31
+Not all video decoders do support H.265/HEVC.
32
+Will still use H.264 if server doesn't support HEVC.
33
 
34
 =item B<-remote> [I<yes/no/auto>]
35
 
36
@@ -138,8 +142,10 @@ By default the gamecontrollerdb.txt provided by Moonli
37
 =item B<-platform> [I<PLATFORM>]
38
 
39
 Select platform for audio and video output and input.
40
-<PLATFORM> can be pi, imx, aml, x11, x11_vdpau, sdl or fake.
41
+<PLATFORM> can be x11, x11_vaapi, x11_vdpau, sdl or fake.
42
 
43
+NOTE:x11_vaapi need libva library be installed.For intel,install libva-intel-driver/libva-intel-media-driver
44
+
45
 =item B<-nounsupported>
46
 
47
 Don't stream if resolution is not officially supported by the server
48
@@ -170,10 +176,11 @@ Enable the I<INPUT> device.
49
 By default all available input devices are enabled.
50
 Only evdev devices /dev/input/event* are supported.
51
 
52
-=item B<-audio> [I<DEVICE>]
53
+=item B<-nosdl>
54
 
55
-Use <DEVICE> as audio output device.
56
-The default value is 'sysdefault' for ALSA and 'hdmi' for OMX on the Raspberry Pi.
57
+Use libevdev to drive game controller instead.
58
+SDL controller module have better compatibility for gamepad.
59
+So it's not recommended.
60
 
61
 =item B<-windowed>
62
 
63
@@ -182,22 +189,51 @@ Only available when X11 or SDL platform is used.
64
 
65
 =back
66
 
67
+=head1 EXAMPLE
68
+
69
+Pair:
70
+  # moonlight pair 192.168.0.1
71
+
72
+Connect:
73
+ The following cmd means to connect 192.168.0.1 with a resolution 2560x1600.
74
+  # moonlight stream -app Desktop -width 2560 -height 1600 192.168.0.1
75
+ The following cmd means to connect 192.168.0.1 with a resolution 1080p and the fps 120.And try to decoding with GPU.
76
+  # moonlight stream -app Steam -width 1920 -height 1080 -fps 120 -platform 'x11_vaapi' 192.168.0.1
77
+
78
 =head1 CONFIG FILE
79
 
80
-Moonlight Embedded will load a confiuration file from:
81
+Moonlight Embedded will load a configuration file from:
82
 
83
-  $XDG_CONFIG_HOME/moonligt/moonlight.conf (fallback to ~/.config/moonligt/moonlight.conf)
84
+  $XDG_CONFIG_HOME/moonlight/moonlight.conf (fallback to ~/.config/moonlight/moonlight.conf)
85
 
86
 If no user specified configuration file is available the configuration will be loaded from:
87
 
88
-  /etc/moonlight/moonlight.conf
89
+  /usr/local/etc/moonlight.conf
90
 
91
-A documented example configuration file can be found at /etc/moonlight/moonlight.conf.
92
+A documented example configuration file can be found at /usr/local/etc/moonlight.conf.
93
 
94
+=head1 KEYBOARD SHORTCUTS
95
+
96
+ Use Ctrl+Alt+Shift+Q or Play+Back+LeftShoulder+RightShoulder to quit the streaming session.
97
+ Use Ctrl+Alt+Shift+Z to Grab/Ungrab keyboard.
98
+ It may not grab the keyboard Using sdl platform under wayland.
99
+
100
+=head1 GAMEPAD
101
+
102
+FreeBSD supports fewer controllers.Please see hgame(4) xb360gp(4) ps4dshock(4) and FreeBSD forums...
103
+SDL platforms have better compatibility for gamepad.
104
+
105
 =head1 COMMENTS
106
 
107
-Use Ctrl+Alt+Shift+Q or Play+Back+LeftShoulder+RightShoulder to quit the streaming session.
108
+Platform 'sdl' and 'x11' is soft decoding.'x11' is deprecated.
109
+Platform 'x11_vaapi' and 'x11_vdpau' is hard accel decoding.
110
+If you want to use GPU decoding for intel gpu,you must meet 3 conditions:
111
+  1.Use platform 'x11_vaapi'
112
+  2.Use intel GPU driver in xorg.conf but not modesetting.
113
+  3.Install package:libva-intel-driver/libva-intel-media-driver or libva-vdpau-driver.
114
 
115
+
116
 =head1 AUTHOR
117
 
118
-Iwan Timmer E<lt>irtimmer@gmail.comE<gt>
119
+ Thanks Iwan Timmer and every contributor!
120
+ Armin Zhu E<lt>lisp_25689@163.comE<gt>.
(-)b/games/moonlight-embedded/files/patch-libgamestream_CMakeLists.txt (-1 / +1 lines)
Lines 1-4 Link Here
1
--- libgamestream/CMakeLists.txt.orig	2023-09-01 23:40:56 UTC
1
--- libgamestream/CMakeLists.txt.orig	2023-11-03 06:08:34 UTC
2
+++ libgamestream/CMakeLists.txt
2
+++ libgamestream/CMakeLists.txt
3
@@ -3,7 +3,7 @@ set(SO_VERSION 4)
3
@@ -3,7 +3,7 @@ set(SO_VERSION 4)
4
 find_package(LibUUID REQUIRED)
4
 find_package(LibUUID REQUIRED)
(-)b/games/moonlight-embedded/files/patch-libgamestream_client.c (-4 / +9 lines)
Lines 1-13 Link Here
1
--- libgamestream/client.c.orig	2023-09-01 23:40:56 UTC
1
--- libgamestream/client.c.orig	2023-11-03 06:08:34 UTC
2
+++ libgamestream/client.c
2
+++ libgamestream/client.c
3
@@ -537,7 +537,11 @@ int gs_pair(PSERVER_DATA server, char* pin) {
3
@@ -537,7 +537,16 @@ int gs_pair(PSERVER_DATA server, char* pin) {
4
   RAND_bytes(client_secret_data, sizeof(client_secret_data));
4
   RAND_bytes(client_secret_data, sizeof(client_secret_data));
5
 
5
 
6
   const ASN1_BIT_STRING *asnSignature;
6
   const ASN1_BIT_STRING *asnSignature;
7
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
7
+
8
+#ifdef __FreeBSD__
9
+ #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
8
   X509_get0_signature(&asnSignature, NULL, cert);
10
   X509_get0_signature(&asnSignature, NULL, cert);
9
+#else
11
+ #else
10
+  asnSignature = cert->signature;
12
+  asnSignature = cert->signature;
13
+ #endif
14
+#else
15
+  X509_get0_signature(&asnSignature, NULL, cert);
11
+#endif
16
+#endif
12
 
17
 
13
   char challenge_response[16 + SIGNATURE_LEN + sizeof(client_secret_data)];
18
   char challenge_response[16 + SIGNATURE_LEN + sizeof(client_secret_data)];
(-)b/games/moonlight-embedded/files/patch-libgamestream_http.c (-3 / +3 lines)
Lines 1-12 Link Here
1
--- libgamestream/http.c.orig	2023-09-01 23:40:56 UTC
1
--- libgamestream/http.c.orig	2023-11-03 06:08:34 UTC
2
+++ libgamestream/http.c
2
+++ libgamestream/http.c
3
@@ -73,6 +73,9 @@ int http_init(const char* keyDirectory, int logLevel) 
3
@@ -73,6 +73,9 @@ int http_init(const char* keyDirectory, int logLevel) 
4
 int http_request(char* url, PHTTP_DATA data) {
4
 int http_request(char* url, PHTTP_DATA data) {
5
   curl_easy_setopt(curl, CURLOPT_WRITEDATA, data);
5
   curl_easy_setopt(curl, CURLOPT_WRITEDATA, data);
6
   curl_easy_setopt(curl, CURLOPT_URL, url);
6
   curl_easy_setopt(curl, CURLOPT_URL, url);
7
+  curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L);
7
+#ifdef __FreeBSD__
8
+  curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1);
9
+  curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);
8
+  curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);
9
+#endif
10
 
10
 
11
   if (debug)
11
   if (debug)
12
     printf("Request %s\n", url);
12
     printf("Request %s\n", url);
(-)b/games/moonlight-embedded/files/patch-src_audio_audio.h (-2 / +4 lines)
Lines 1-7 Link Here
1
--- src/audio/audio.h.orig	2023-09-01 23:40:56 UTC
1
--- src/audio/audio.h.orig	2023-11-03 06:08:34 UTC
2
+++ src/audio/audio.h
2
+++ src/audio/audio.h
3
@@ -31,3 +31,4 @@ extern AUDIO_RENDERER_CALLBACKS audio_callbacks_sdl;
3
@@ -31,3 +31,6 @@ extern AUDIO_RENDERER_CALLBACKS audio_callbacks_sdl;
4
 extern AUDIO_RENDERER_CALLBACKS audio_callbacks_pulse;
4
 extern AUDIO_RENDERER_CALLBACKS audio_callbacks_pulse;
5
 bool audio_pulse_init(char* audio_device);
5
 bool audio_pulse_init(char* audio_device);
6
 #endif
6
 #endif
7
+#ifdef __FreeBSD__
7
+extern AUDIO_RENDERER_CALLBACKS audio_callbacks_oss;
8
+extern AUDIO_RENDERER_CALLBACKS audio_callbacks_oss;
9
+#endif
(-)b/games/moonlight-embedded/files/patch-src_audio_oss.c (-17 / +20 lines)
Lines 1-6 Link Here
1
--- src/audio/oss.c.orig	2023-09-24 06:52:39 UTC
1
--- src/audio/oss.c.orig	2024-01-01 05:31:28 UTC
2
+++ src/audio/oss.c
2
+++ src/audio/oss.c
3
@@ -0,0 +1,102 @@
3
@@ -0,0 +1,105 @@
4
+/*
4
+/*
5
+ * This file is part of Moonlight Embedded.
5
+ * This file is part of Moonlight Embedded.
6
+ *
6
+ *
Lines 20-40 Link Here
20
+ * along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
20
+ * along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
21
+ */
21
+ */
22
+
22
+
23
+#ifdef __FreeBSD__
23
+#include <sys/soundcard.h>
24
+#include <sys/soundcard.h>
25
+#include <sys/ioctl.h>
24
+#include "audio.h"
26
+#include "audio.h"
25
+
27
+
26
+#include <stdio.h>
27
+#include <opus_multistream.h>
28
+#include <opus_multistream.h>
28
+
29
+
29
+#include <sys/ioctl.h>
30
+#include <errno.h>
30
+#include <unistd.h>
31
+#include <fcntl.h>
31
+#include <fcntl.h>
32
+#include <stdio.h>
33
+#include <stdlib.h>
34
+#include <unistd.h>
32
+
35
+
33
+static OpusMSDecoder* decoder;
36
+static OpusMSDecoder* decoder;
34
+static short* pcmBuffer;
37
+static short* pcmBuffer;
35
+static int samplesPerFrame;
38
+static int samplesPerFrame;
36
+static int channelCount;
39
+static int channelCount;
37
+static int fd;
40
+static int fd = -1;
38
+
41
+
39
+static int oss_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig, void* context, int arFlags) {
42
+static int oss_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig, void* context, int arFlags) {
40
+  int rc;
43
+  int rc;
Lines 46-72 Link Here
46
+  if (pcmBuffer == NULL)
49
+  if (pcmBuffer == NULL)
47
+    return -1;
50
+    return -1;
48
+
51
+
49
+  char* oss_name = "/dev/dsp";
52
+  const char* oss_name = "/dev/dsp";
50
+  fd = open(oss_name, O_WRONLY);
53
+  fd = open(oss_name, O_WRONLY);
51
+  // buffer size for fragment ,selector 12 is 4096;11 is 2048;10 is 1024; 13is 8192
52
+  if (fd == -1) {
54
+  if (fd == -1) {
53
+    close(fd);
55
+    printf("Open audio device /dev/dsp failed! error %d\n", errno);
54
+    printf("Open audio device /dev/dsp faild!!!");
55
+    return -1;
56
+    return -1;
56
+  }
57
+  }
58
+  // buffer size for fragment ,selector 12 is 4096;11 is 2048;10 is 1024; 13is 8192
57
+  int frag = 12;
59
+  int frag = 12;
58
+  if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag) == -1)
60
+  if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag) == -1)
59
+    printf("Set framgment for /dev/dsp faild.");
61
+    printf("Set fragment for /dev/dsp failed.");
60
+
62
+
61
+  int format = AFMT_S16_LE;
63
+  int format = AFMT_S16_LE;
62
+  int channels = opusConfig->channelCount;
64
+  int channels = opusConfig->channelCount;
63
+  int rate = opusConfig->sampleRate;
65
+  int rate = opusConfig->sampleRate;
64
+  if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) == -1)
66
+  if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) == -1)
65
+    printf("Set framgment for /dev/dsp faild.");
67
+    printf("Set format for /dev/dsp failed.");
66
+  if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1)
68
+  if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1)
67
+    printf("Set channels for /dev/dsp faild.");
69
+    printf("Set channels for /dev/dsp failed.");
68
+  if (ioctl(fd, SNDCTL_DSP_SPEED, &rate) == -1)
70
+  if (ioctl(fd, SNDCTL_DSP_SPEED, &rate) == -1)
69
+    printf("Set sameple rate for /dev/dsp faild.");
71
+    printf("Set sample rate for /dev/dsp failed.");
70
+
72
+
71
+  return 0;
73
+  return 0;
72
+}
74
+}
Lines 82-90 Link Here
82
+    pcmBuffer = NULL;
84
+    pcmBuffer = NULL;
83
+  }
85
+  }
84
+
86
+
85
+  if (fd != 0) {
87
+  if (fd != -1) {
86
+    close(fd);
88
+    close(fd);
87
+    fd = 0;
89
+    fd = -1;
88
+  }
90
+  }
89
+}
91
+}
90
+
92
+
Lines 92-98 Link Here
92
+  int decodeLen = opus_multistream_decode(decoder, data, length, pcmBuffer, samplesPerFrame, 0);
94
+  int decodeLen = opus_multistream_decode(decoder, data, length, pcmBuffer, samplesPerFrame, 0);
93
+  if (decodeLen > 0) {
95
+  if (decodeLen > 0) {
94
+    write(fd, pcmBuffer, decodeLen * channelCount * sizeof(short));
96
+    write(fd, pcmBuffer, decodeLen * channelCount * sizeof(short));
95
+  } else {
97
+  } else if (decodeLen < 0) {
96
+    printf("Opus error from decode: %d\n", decodeLen);
98
+    printf("Opus error from decode: %d\n", decodeLen);
97
+  }
99
+  }
98
+}
100
+}
Lines 103-105 Link Here
103
+  .decodeAndPlaySample = oss_renderer_decode_and_play_sample,
105
+  .decodeAndPlaySample = oss_renderer_decode_and_play_sample,
104
+  .capabilities = CAPABILITY_DIRECT_SUBMIT | CAPABILITY_SUPPORTS_ARBITRARY_AUDIO_DURATION,
106
+  .capabilities = CAPABILITY_DIRECT_SUBMIT | CAPABILITY_SUPPORTS_ARBITRARY_AUDIO_DURATION,
105
+};
107
+};
108
+#endif
(-)a/games/moonlight-embedded/files/patch-src_config.c (-28 lines)
Removed Link Here
1
--- src/config.c.orig	2023-10-11 15:50:11 UTC
2
+++ src/config.c
3
@@ -42,6 +42,7 @@
4
 #define write_config_bool(fd, key, value) fprintf(fd, "%s = %s\n", key, value ? "true":"false")
5
 
6
 bool inputAdded = false;
7
+bool isNoSdl = false;
8
 
9
 static struct option long_options[] = {
10
   {"720", no_argument, NULL, 'a'},
11
@@ -49,6 +50,7 @@ static struct option long_options[] = {
12
   {"4k", no_argument, NULL, '0'},
13
   {"width", required_argument, NULL, 'c'},
14
   {"height", required_argument, NULL, 'd'},
15
+  {"nosdl", no_argument, NULL, 'e'},
16
   {"bitrate", required_argument, NULL, 'g'},
17
   {"packetsize", required_argument, NULL, 'h'},
18
   {"app", required_argument, NULL, 'i'},
19
@@ -149,6 +151,9 @@ static void parse_argument(int c, char* value, PCONFIG
20
     break;
21
   case 'd':
22
     config->stream.height = atoi(value);
23
+    break;
24
+  case 'e':
25
+    isNoSdl = true;
26
     break;
27
   case 'g':
28
     config->stream.bitrate = atoi(value);
(-)a/games/moonlight-embedded/files/patch-src_config.h (-10 lines)
Removed Link Here
1
--- src/config.h.orig	2023-10-11 15:50:11 UTC
2
+++ src/config.h
3
@@ -51,6 +51,7 @@ typedef struct _CONFIGURATION {
4
 } CONFIGURATION, *PCONFIGURATION;
5
 
6
 extern bool inputAdded;
7
+extern bool isNoSdl;
8
 
9
 bool config_file_parse(char* filename, PCONFIGURATION config);
10
 void config_parse(int argc, char* argv[], PCONFIGURATION config);
(-)b/games/moonlight-embedded/files/patch-src_input_evdev.c (-172 / +76 lines)
Lines 1-211 Link Here
1
--- src/input/evdev.c.orig	2023-10-11 15:50:11 UTC
1
--- src/input/evdev.c.orig	2023-11-03 06:08:34 UTC
2
+++ src/input/evdev.c
2
+++ src/input/evdev.c
3
@@ -38,10 +38,16 @@
3
@@ -38,9 +38,15 @@
4
 #include <limits.h>
4
 #include <limits.h>
5
 #include <unistd.h>
5
 #include <unistd.h>
6
 #include <pthread.h>
6
 #include <pthread.h>
7
-#include <endian.h>
7
+#ifdef __linux__
8
 #include <endian.h>
9
+#else
8
+#include <sys/endian.h>
10
+#include <sys/endian.h>
11
+#endif
9
 #include <math.h>
12
 #include <math.h>
10
 
13
 
11
-#if __BYTE_ORDER == __LITTLE_ENDIAN
14
+static bool isUseKbdmux = false;
12
+extern bool isNoSdl;
13
+bool iskeyboardgrab = false;
14
+void grab_window(bool grabstat);
15
+static bool waitingToSwitchGrabOnModifierUp = false;
16
+static bool isgrabkeyrelease = false;
17
+
15
+
18
+#if _BYTE_ORDER == _LITTLE_ENDIAN
16
 #if __BYTE_ORDER == __LITTLE_ENDIAN
19
 #define int16_to_le(val) val
17
 #define int16_to_le(val) val
20
 #else
18
 #else
21
 #define int16_to_le(val) ((((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00))
19
@@ -66,8 +72,13 @@ struct input_device {
22
@@ -66,8 +72,8 @@ struct input_device {
23
   int hats_state[3][2];
20
   int hats_state[3][2];
24
   int fd;
21
   int fd;
25
   char modifiers;
22
   char modifiers;
26
-  __s32 mouseDeltaX, mouseDeltaY, mouseVScroll, mouseHScroll;
23
+  #ifdef __linux__
27
-  __s32 touchDownX, touchDownY, touchX, touchY;
24
   __s32 mouseDeltaX, mouseDeltaY, mouseVScroll, mouseHScroll;
25
   __s32 touchDownX, touchDownY, touchX, touchY;
26
+  #else
28
+  int32_t mouseDeltaX, mouseDeltaY, mouseVScroll, mouseHScroll;
27
+  int32_t mouseDeltaX, mouseDeltaY, mouseVScroll, mouseHScroll;
29
+  int32_t touchDownX, touchDownY, touchX, touchY;
28
+  int32_t touchDownX, touchDownY, touchX, touchY;
29
+  #endif
30
   struct timeval touchDownTime;
30
   struct timeval touchDownTime;
31
   struct timeval btnDownTime;
31
   struct timeval btnDownTime;
32
   short controllerId;
32
   short controllerId;
33
@@ -127,6 +133,7 @@ int evdev_gamepads = 0;
33
@@ -749,7 +760,7 @@ static int evdev_handle(int fd) {
34
 
35
 #define ACTION_MODIFIERS (MODIFIER_SHIFT|MODIFIER_ALT|MODIFIER_CTRL)
36
 #define QUIT_KEY KEY_Q
37
+#define GRAB_KEY KEY_Z
38
 #define QUIT_BUTTONS (PLAY_FLAG|BACK_FLAG|LB_FLAG|RB_FLAG)
39
 
40
 static bool (*handler) (struct input_event*, struct input_device*);
41
@@ -139,6 +146,22 @@ static int evdev_get_map(int* map, int length, int val
42
   return -1;
43
 }
44
 
45
+static short keystatlist[0xFF];
46
+static void keyrelease(int keycode) {
47
+  keystatlist[keycode] = 0;
48
+}
49
+static void keypress(int keycode) {
50
+  keystatlist[keycode] = 1;
51
+}
52
+static void freeallkey () {
53
+  for (int i=0;i<0xFF;i++) {
54
+    if (keystatlist[i] == 1) {
55
+      keystatlist[i] = 0;
56
+      LiSendKeyboardEvent(0x80 << 8 | keyCodes[i], KEY_ACTION_UP, 0);
57
+    }
58
+  }
59
+}
60
+
61
 static bool evdev_init_parms(struct input_device *dev, struct input_abs_parms *parms, int code) {
62
   int abs = evdev_get_map(dev->abs_map, ABS_MAX, code);
63
 
64
@@ -343,7 +366,7 @@ static bool evdev_handle_event(struct input_event *ev,
65
     if (dev->mouseHScroll != 0) {
66
       LiSendHScrollEvent(dev->mouseHScroll);
67
       dev->mouseHScroll = 0;
68
-    }
69
+    } 
70
     if (dev->gamepadModified) {
71
       if (dev->controllerId < 0) {
72
         for (int i = 0; i < MAX_GAMEPADS; i++) {
73
@@ -398,15 +421,41 @@ static bool evdev_handle_event(struct input_event *ev,
74
       }
75
 
76
       // After the quit key combo is pressed, quit once all keys are raised
77
-      if ((dev->modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS &&
78
-          ev->code == QUIT_KEY && ev->value != 0) {
79
-        waitingToExitOnModifiersUp = true;
80
-        return true;
81
-      } else if (waitingToExitOnModifiersUp && dev->modifiers == 0)
82
+      if ((dev->modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && ev->value != 0) {
83
+        if (ev->code == QUIT_KEY) {
84
+          waitingToExitOnModifiersUp = true;
85
+          return true;
86
+        } else if (ev->code == GRAB_KEY && iskeyboardgrab) {
87
+          waitingToSwitchGrabOnModifierUp = true;
88
+          return true;
89
+        }
90
+      }
91
+      if (waitingToSwitchGrabOnModifierUp) {
92
+        if (ev->code == GRAB_KEY && ev->value == 0) {
93
+          isgrabkeyrelease = true;
94
+          if (dev->modifiers != 0)
95
+            return true;
96
+        }
97
+        if (dev->modifiers == 0 && isgrabkeyrelease) {
98
+          waitingToSwitchGrabOnModifierUp = false;
99
+          isgrabkeyrelease = false;
100
+	  freeallkey();
101
+          grab_window(!iskeyboardgrab);
102
+          return true;
103
+        }
104
+      } else if (waitingToExitOnModifiersUp && dev->modifiers == 0) {
105
+	freeallkey();
106
+        grab_window(false);
107
         return false;
108
+      }
109
 
110
+      if (ev->value)
111
+        keypress(ev->code);
112
+      else
113
+        keyrelease(ev->code);
114
       short code = 0x80 << 8 | keyCodes[ev->code];
115
       LiSendKeyboardEvent(code, ev->value?KEY_ACTION_DOWN:KEY_ACTION_UP, dev->modifiers);
116
+
117
     } else {
118
       int mouseCode = 0;
119
       int gamepadCode = 0;
120
@@ -749,8 +798,10 @@ static int evdev_handle(int fd) {
121
       struct input_event ev;
34
       struct input_event ev;
122
       while ((rc = libevdev_next_event(devices[i].dev, LIBEVDEV_READ_FLAG_NORMAL, &ev)) >= 0) {
35
       while ((rc = libevdev_next_event(devices[i].dev, LIBEVDEV_READ_FLAG_NORMAL, &ev)) >= 0) {
123
         if (rc == LIBEVDEV_READ_STATUS_SYNC)
36
         if (rc == LIBEVDEV_READ_STATUS_SYNC)
124
-          fprintf(stderr, "Error: cannot keep up\n");
37
-          fprintf(stderr, "Error: cannot keep up\n");
125
+          fprintf(stderr, "Error:%s(%d) cannot keep up\n", libevdev_get_name(devices[i].dev), i);
38
+          fprintf(stderr, "Error:%s(%d) cannot keep up\n", libevdev_get_name(devices[i].dev), i);
126
         else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {
39
         else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {
127
+	  if (!iskeyboardgrab)
128
+	    break;
129
           if (!handler(&ev, &devices[i]))
40
           if (!handler(&ev, &devices[i]))
130
             return LOOP_RETURN;
41
             return LOOP_RETURN;
131
         }
42
@@ -766,6 +777,39 @@ static int evdev_handle(int fd) {
132
@@ -840,7 +891,28 @@ void evdev_create(const char* device, struct mapping* 
43
   return LOOP_OK;
44
 }
45
 
46
+void is_use_kbdmux() {
47
+  const char* tryFirstInput = "/dev/input/event0";
48
+  const char* trySecondInput = "/dev/input/event1";
49
+
50
+  int fdFirst = open(tryFirstInput, O_RDWR|O_NONBLOCK);
51
+  int fdSecond = open(trySecondInput, O_RDWR|O_NONBLOCK);
52
+  if (fdFirst <= 0 && fdSecond <= 0) {
53
+    //Suppose use kbdmux because of default behavior
54
+    isUseKbdmux = true;
55
+    return;
56
+  }
57
+
58
+  struct libevdev *evdevFirst = libevdev_new();
59
+  libevdev_set_fd(evdevFirst, fdFirst);
60
+  const char* nameFirst = libevdev_get_name(evdevFirst);
61
+  struct libevdev *evdevSecond = libevdev_new();
62
+  libevdev_set_fd(evdevSecond, fdSecond);
63
+  const char* nameSecond = libevdev_get_name(evdevSecond);
64
+
65
+  libevdev_free(evdevFirst);
66
+  libevdev_free(evdevSecond);
67
+  close(fdFirst);
68
+  close(fdSecond);
69
+
70
+  if (strcmp(nameFirst, "System keyboard multiplexer") == 0 ||
71
+      strcmp(nameSecond, "System keyboard multiplexer") == 0) {
72
+    isUseKbdmux = true;
73
+    return;
74
+  }
75
+
76
+  return;
77
+}
78
+
79
 void evdev_create(const char* device, struct mapping* mappings, bool verbose, int rotate) {
80
   int fd = open(device, O_RDWR|O_NONBLOCK);
81
   if (fd <= 0) {
82
@@ -840,6 +884,33 @@ void evdev_create(const char* device, struct mapping* 
133
      libevdev_has_event_code(evdev, EV_ABS, ABS_WHEEL) ||
83
      libevdev_has_event_code(evdev, EV_ABS, ABS_WHEEL) ||
134
      libevdev_has_event_code(evdev, EV_ABS, ABS_GAS) ||
84
      libevdev_has_event_code(evdev, EV_ABS, ABS_GAS) ||
135
      libevdev_has_event_code(evdev, EV_ABS, ABS_BRAKE));
85
      libevdev_has_event_code(evdev, EV_ABS, ABS_BRAKE));
136
+  bool is_acpibutton = 
86
+  bool is_acpibutton =
137
+    is_keyboard && 
87
+    strcmp(name, "Sleep Button") == 0 ||
138
+    (strcmp(libevdev_get_name(evdev), "Sleep Button") == 0 ||
88
+    strcmp(name, "Power Button") == 0;
139
+    strcmp(libevdev_get_name(evdev), "Power Button") == 0);
89
+  // Just use System keyboard multiplexer for FreeBSD,see kbdcontrol(1) and kbdmux(4)
140
+  bool is_likekeyboard = 
90
+  // Trying to grab kbdmux0 and keyboard it's self at the same time results in
141
+    is_keyboard &&
91
+  // the keyboard becoming unresponsive on FreeBSD.
142
+    (libevdev_get_id_version(evdev) > 1000 ||
92
+  bool is_likekeyboard =
143
+    libevdev_get_id_bustype(evdev) <= 3);
93
+    is_keyboard && isUseKbdmux && strcmp(name, "System keyboard multiplexer") != 0;
144
 
94
+/*
95
+    (is_keyboard && guid[0] <= 3) ||
96
+    strcmp(name, "AT keyboard") == 0;
97
+*/
98
+
145
+  // In some cases,acpibutton can be mistaken for a keyboard and freeze the keyboard when tring grab.
99
+  // In some cases,acpibutton can be mistaken for a keyboard and freeze the keyboard when tring grab.
146
+  if (is_acpibutton) {
100
+  if (is_acpibutton) {
147
+    if (verbose)
101
+    if (verbose)
148
+      printf("Do Not grab acpibutton: %s\n", libevdev_get_name(evdev));
102
+      printf("Skip acpibutton: %s\n", name);
149
+    is_keyboard = false;
103
+    libevdev_free(evdev);
104
+    close(fd);
105
+    return;
150
+  }
106
+  }
151
+  // In some cases,tring grab "Logitech USB Receiver Keyboard" will freeze the keyboard.
107
+  // In some cases,Do not grab likekeyboard for avoiding keyboard unresponsive
152
+  if (is_likekeyboard) {
108
+  if (is_likekeyboard) {
153
+    if (verbose)
109
+    if (verbose)
154
+      printf("Do Not grab likekeyboard: %s,version: %d,bustype: %d\n", libevdev_get_name(evdev), libevdev_get_id_version(evdev), libevdev_get_id_bustype(evdev));
110
+      printf("Do NOT grab like-keyboard: %s,version: %d,bustype: %d\n", name, guid[6], guid[0]);
155
+    is_keyboard = false;
111
+    is_keyboard = false;
156
+  }
112
+  }
157
+
113
 
158
   if (is_accelerometer) {
114
   if (is_accelerometer) {
159
     if (verbose)
115
     if (verbose)
160
       printf("Ignoring accelerometer: %s\n", name);
161
@@ -850,6 +922,13 @@ void evdev_create(const char* device, struct mapping* 
162
   }
163
 
164
   if (is_gamepad) {
165
+    if (!isNoSdl) {
166
+      if (verbose)
167
+        printf("Gamepad %s ignored,use sdl instead.\n", name);
168
+      libevdev_free(evdev);
169
+      close(fd);
170
+      return;
171
+    }
172
     evdev_gamepads++;
173
 
174
     if (mappings == NULL) {
175
@@ -1054,11 +1133,7 @@ void evdev_start() {
176
   // code looks for. For this reason, we wait to grab until
177
   // we're ready to take input events. Ctrl+C works up until
178
   // this point.
179
-  for (int i = 0; i < numDevices; i++) {
180
-    if ((devices[i].is_keyboard || devices[i].is_mouse || devices[i].is_touchscreen) && ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) {
181
-      fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno);
182
-    }
183
-  }
184
+  grab_window(true);
185
 
186
   // Any new input devices detected after this point will be grabbed immediately
187
   grabbingDevices = true;
188
@@ -1111,4 +1186,23 @@ void evdev_rumble(unsigned short controller_id, unsign
189
   event.value = 1;
190
   write(device->fd, (const void*) &event, sizeof(event));
191
   device->haptic_effect_id = effect.id;
192
+}
193
+
194
+void grab_window(bool grabstat) {
195
+  if (grabstat != iskeyboardgrab) {
196
+    int grabnum;
197
+    if (iskeyboardgrab) {
198
+      grabnum = 0;
199
+      iskeyboardgrab = false;
200
+    } else {
201
+      grabnum = 1;
202
+      iskeyboardgrab = true;
203
+    }
204
+    for (int i = 0; i < numDevices; i++) {
205
+      if (devices[i].is_keyboard || devices[i].is_mouse || devices[i].is_touchscreen) {
206
+        if (ioctl(devices[i].fd, EVIOCGRAB, grabnum) < 0)
207
+          fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno);
208
+      }
209
+    }
210
+  }
211
 }
(-)a/games/moonlight-embedded/files/patch-src_input_sdl.c (-309 lines)
Removed Link Here
1
--- src/input/sdl.c.orig	2023-10-08 02:12:37 UTC
2
+++ src/input/sdl.c
3
@@ -19,15 +19,23 @@
4
 
5
 #include "sdl.h"
6
 #include "../sdl.h"
7
+#include "../loop.h"
8
 
9
+#include <poll.h>
10
+#include <fcntl.h>
11
+#include <unistd.h>
12
 #include <Limelight.h>
13
 
14
 #define ACTION_MODIFIERS (MODIFIER_SHIFT|MODIFIER_ALT|MODIFIER_CTRL)
15
 #define QUIT_KEY SDLK_q
16
 #define QUIT_BUTTONS (PLAY_FLAG|BACK_FLAG|LB_FLAG|RB_FLAG)
17
 #define FULLSCREEN_KEY SDLK_f
18
-#define UNGRAB_KEY SDLK_z
19
+#define UNGRAB_MOUSE_KEY SDLK_m
20
+#define UNGRAB_WINDOW_KEY SDLK_z
21
 
22
+static bool isx11sdlcall = false;
23
+static int x11_sdl_event_handle(int fd);
24
+
25
 static const int SDL_TO_LI_BUTTON_MAP[] = {
26
   A_FLAG, B_FLAG, X_FLAG, Y_FLAG,
27
   BACK_FLAG, SPECIAL_FLAG, PLAY_FLAG,
28
@@ -51,6 +59,8 @@ typedef struct _GAMEPAD_STATE {
29
   int haptic_effect_id;
30
 #endif
31
   short id;
32
+  int fd;
33
+  bool fdadded;
34
   bool initialized;
35
 } GAMEPAD_STATE, *PGAMEPAD_STATE;
36
 
37
@@ -62,6 +72,22 @@ static GAMEPAD_STATE gamepads[MAX_GAMEPADS];
38
 static int keyboard_modifiers;
39
 static int activeGamepadMask = 0;
40
 
41
+static short keystatlist[0xFF];
42
+static void keyrelease(int keycode) {
43
+  keystatlist[keycode] = 0;
44
+}
45
+static void keypress(int keycode) {
46
+  keystatlist[keycode] = 1;
47
+}
48
+static void freeallkey () {
49
+  for (int i=0;i<0xFF;i++) {
50
+    if (keystatlist[i] == 1) {
51
+      keystatlist[i] = 0;
52
+      LiSendKeyboardEvent(0x80 << 8 | i, KEY_ACTION_UP, 0);
53
+    }
54
+  }
55
+}
56
+
57
 int sdl_gamepads = 0;
58
 
59
 static void send_controller_arrival(PGAMEPAD_STATE state) {
60
@@ -142,12 +168,22 @@ static PGAMEPAD_STATE get_gamepad(SDL_JoystickID sdl_i
61
 }
62
 
63
 static void add_gamepad(int joystick_index) {
64
+  int fd;
65
   SDL_GameController* controller = SDL_GameControllerOpen(joystick_index);
66
   if (!controller) {
67
     fprintf(stderr, "Could not open gamecontroller %i: %s\n", joystick_index, SDL_GetError());
68
     return;
69
   }
70
-
71
+  if (isx11sdlcall) {
72
+    char* controllerpath = SDL_GameControllerPath(controller);
73
+    fd = open(controllerpath, O_RDWR|O_NONBLOCK);
74
+    if (fd == -1) {
75
+       close(fd);
76
+       fprintf(stderr, "Could not open gamecontroller from path: %s\n", controllerpath);
77
+       return;
78
+    }
79
+  }
80
+  
81
   SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controller);
82
   SDL_JoystickID joystick_id = SDL_JoystickInstanceID(joystick);
83
 
84
@@ -166,10 +202,15 @@ static void add_gamepad(int joystick_index) {
85
   // Create a new gamepad state
86
   state = get_gamepad(joystick_id, true);
87
   state->controller = controller;
88
+  if (isx11sdlcall) {
89
+    state->fd = fd;
90
+    loop_add_fd(state->fd, &x11_sdl_event_handle, POLLIN);
91
+    state->fdadded = true;
92
+  }
93
 
94
 #if !SDL_VERSION_ATLEAST(2, 0, 9)
95
   state->haptic = SDL_HapticOpenFromJoystick(joystick);
96
-  if (haptic && (SDL_HapticQuery(state->haptic) & SDL_HAPTIC_LEFTRIGHT) == 0) {
97
+  if (state->haptic && (SDL_HapticQuery(state->haptic) & SDL_HAPTIC_LEFTRIGHT) == 0) {
98
     SDL_HapticClose(state->haptic);
99
     state->haptic = NULL;
100
   }
101
@@ -182,6 +223,11 @@ static void add_gamepad(int joystick_index) {
102
   sdl_gamepads++;
103
 }
104
 
105
+static void x11_add_gamepad(int joystick_index) {
106
+  isx11sdlcall = true;
107
+  add_gamepad(joystick_index);
108
+}
109
+
110
 static void remove_gamepad(SDL_JoystickID sdl_id) {
111
   for (int i = 0;i<MAX_GAMEPADS;i++) {
112
     if (gamepads[i].initialized && gamepads[i].sdl_id == sdl_id) {
113
@@ -208,6 +254,20 @@ static void remove_gamepad(SDL_JoystickID sdl_id) {
114
   }
115
 }
116
 
117
+static void x11_remove_gamepad(SDL_JoystickID sdl_id) {
118
+  for (int i=0;i<MAX_GAMEPADS;i++) {
119
+    if (gamepads[i].initialized && gamepads[i].sdl_id == sdl_id) {
120
+      if (gamepads[i].fdadded) {
121
+        loop_remove_fd(gamepads[i].fd);
122
+        gamepads[i].fdadded = false;
123
+        close(gamepads[i].fd);
124
+      }
125
+      remove_gamepad(gamepads[i].sdl_id);
126
+      return;
127
+    }
128
+  }
129
+}
130
+
131
 void sdlinput_init(char* mappings) {
132
   memset(gamepads, 0, sizeof(gamepads));
133
 
134
@@ -317,15 +377,28 @@ int sdlinput_handle_event(SDL_Window* window, SDL_Even
135
         keyboard_modifiers &= ~modifier;
136
     }
137
 
138
-    LiSendKeyboardEvent(0x80 << 8 | button, event->type==SDL_KEYDOWN?KEY_ACTION_DOWN:KEY_ACTION_UP, keyboard_modifiers);
139
-
140
     // Quit the stream if all the required quit keys are down
141
-    if ((keyboard_modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && event->key.keysym.sym == QUIT_KEY && event->type==SDL_KEYUP)
142
+    if ((keyboard_modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && event->key.keysym.sym == QUIT_KEY && event->type==SDL_KEYUP) {
143
+      freeallkey();
144
       return SDL_QUIT_APPLICATION;
145
-    else if ((keyboard_modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && event->key.keysym.sym == FULLSCREEN_KEY && event->type==SDL_KEYUP)
146
+    } else if ((keyboard_modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && event->key.keysym.sym == FULLSCREEN_KEY && event->type==SDL_KEYUP) {
147
+      freeallkey();
148
       return SDL_TOGGLE_FULLSCREEN;
149
-    else if ((keyboard_modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && event->key.keysym.sym == UNGRAB_KEY && event->type==SDL_KEYUP)
150
+    } else if ((keyboard_modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && event->key.keysym.sym == UNGRAB_MOUSE_KEY && event->type==SDL_KEYUP) {
151
+      freeallkey();
152
       return SDL_GetRelativeMouseMode() ? SDL_MOUSE_UNGRAB : SDL_MOUSE_GRAB;
153
+    } else if ((keyboard_modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && event->key.keysym.sym == UNGRAB_WINDOW_KEY && event->type==SDL_KEYUP) {
154
+      freeallkey();
155
+      return iskeyboardgrab ? SDL_WINDOW_UNGRAB : SDL_WINDOW_GRAB;
156
+    }
157
+    
158
+    if (event->type==SDL_KEYDOWN)
159
+        keypress(button);
160
+    else
161
+        keyrelease(button);
162
+
163
+    
164
+    LiSendKeyboardEvent(0x80 << 8 | button, event->type==SDL_KEYDOWN?KEY_ACTION_DOWN:KEY_ACTION_UP, keyboard_modifiers);
165
     break;
166
   case SDL_FINGERDOWN:
167
   case SDL_FINGERMOTION:
168
@@ -524,4 +597,139 @@ void sdlinput_set_controller_led(unsigned short contro
169
 #if SDL_VERSION_ATLEAST(2, 0, 14)
170
   SDL_GameControllerSetLED(state->controller, r, g, b);
171
 #endif
172
-}
173
\ No newline at end of file
174
+}
175
+
176
+static int x11_sdlinput_handle_event(SDL_Event* event) {
177
+  int button = 0;
178
+  unsigned char touchEventType;
179
+  PGAMEPAD_STATE gamepad;
180
+  switch (event->type) {
181
+  case SDL_CONTROLLERAXISMOTION:
182
+    gamepad = get_gamepad(event->caxis.which, false);
183
+    if (!gamepad)
184
+      return SDL_NOTHING;
185
+    switch (event->caxis.axis) {
186
+    case SDL_CONTROLLER_AXIS_LEFTX:
187
+      gamepad->leftStickX = event->caxis.value;
188
+      break;
189
+    case SDL_CONTROLLER_AXIS_LEFTY:
190
+      gamepad->leftStickY = -SDL_max(event->caxis.value, (short)-32767);
191
+      break;
192
+    case SDL_CONTROLLER_AXIS_RIGHTX:
193
+      gamepad->rightStickX = event->caxis.value;
194
+      break;
195
+    case SDL_CONTROLLER_AXIS_RIGHTY:
196
+      gamepad->rightStickY = -SDL_max(event->caxis.value, (short)-32767);
197
+      break;
198
+    case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
199
+      gamepad->leftTrigger = (unsigned char)(event->caxis.value * 255UL / 32767);
200
+      break;
201
+    case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
202
+      gamepad->rightTrigger = (unsigned char)(event->caxis.value * 255UL / 32767);
203
+      break;
204
+    default:
205
+      return SDL_NOTHING;
206
+    }
207
+    LiSendMultiControllerEvent(gamepad->id, activeGamepadMask, gamepad->buttons, gamepad->leftTrigger, gamepad->rightTrigger, gamepad->leftStickX, gamepad->leftStickY, gamepad->rightStickX, gamepad->rightStickY);
208
+    break;
209
+  case SDL_CONTROLLERBUTTONDOWN:
210
+  case SDL_CONTROLLERBUTTONUP:
211
+    gamepad = get_gamepad(event->cbutton.which, false);
212
+    if (!gamepad)
213
+      return SDL_NOTHING;
214
+    if (event->cbutton.button >= SDL_arraysize(SDL_TO_LI_BUTTON_MAP))
215
+      return SDL_NOTHING;
216
+
217
+    if (event->type == SDL_CONTROLLERBUTTONDOWN)
218
+      gamepad->buttons |= SDL_TO_LI_BUTTON_MAP[event->cbutton.button];
219
+    else
220
+      gamepad->buttons &= ~SDL_TO_LI_BUTTON_MAP[event->cbutton.button];
221
+
222
+    if ((gamepad->buttons & QUIT_BUTTONS) == QUIT_BUTTONS)
223
+      return SDL_QUIT_APPLICATION;
224
+
225
+    LiSendMultiControllerEvent(gamepad->id, activeGamepadMask, gamepad->buttons, gamepad->leftTrigger, gamepad->rightTrigger, gamepad->leftStickX, gamepad->leftStickY, gamepad->rightStickX, gamepad->rightStickY);
226
+    break;
227
+  case SDL_CONTROLLERDEVICEADDED:
228
+    x11_add_gamepad(event->cdevice.which);
229
+    break;
230
+  case SDL_CONTROLLERDEVICEREMOVED:
231
+    x11_remove_gamepad(event->cdevice.which);
232
+    break;
233
+#if SDL_VERSION_ATLEAST(2, 0, 14)
234
+  case SDL_CONTROLLERSENSORUPDATE:
235
+    gamepad = get_gamepad(event->csensor.which, false);
236
+    if (!gamepad)
237
+      return SDL_NOTHING;
238
+    switch (event->csensor.sensor) {
239
+    case SDL_SENSOR_ACCEL:
240
+      LiSendControllerMotionEvent(gamepad->id, LI_MOTION_TYPE_ACCEL, event->csensor.data[0], event->csensor.data[1], event->csensor.data[2]);
241
+      break;
242
+    case SDL_SENSOR_GYRO:
243
+      // Convert rad/s to deg/s
244
+      LiSendControllerMotionEvent(gamepad->id, LI_MOTION_TYPE_GYRO,
245
+                                  event->csensor.data[0] * 57.2957795f,
246
+                                  event->csensor.data[1] * 57.2957795f,
247
+                                  event->csensor.data[2] * 57.2957795f);
248
+      break;
249
+    }
250
+    break;
251
+  case SDL_CONTROLLERTOUCHPADDOWN:
252
+  case SDL_CONTROLLERTOUCHPADUP:
253
+  case SDL_CONTROLLERTOUCHPADMOTION:
254
+    gamepad = get_gamepad(event->ctouchpad.which, false);
255
+    if (!gamepad)
256
+      return SDL_NOTHING;
257
+    switch (event->type) {
258
+    case SDL_CONTROLLERTOUCHPADDOWN:
259
+      touchEventType = LI_TOUCH_EVENT_DOWN;
260
+      break;
261
+    case SDL_CONTROLLERTOUCHPADUP:
262
+      touchEventType = LI_TOUCH_EVENT_UP;
263
+      break;
264
+    case SDL_CONTROLLERTOUCHPADMOTION:
265
+      touchEventType = LI_TOUCH_EVENT_MOVE;
266
+      break;
267
+    default:
268
+      return SDL_NOTHING;
269
+    }
270
+    LiSendControllerTouchEvent(gamepad->id, touchEventType, event->ctouchpad.finger,
271
+                               event->ctouchpad.x, event->ctouchpad.y, event->ctouchpad.pressure);
272
+    break;
273
+#endif
274
+  }
275
+
276
+  return SDL_NOTHING;
277
+}
278
+
279
+static int x11_sdl_event_handle(int fd) {
280
+  SDL_Event event;
281
+  for (int i=0;i<MAX_GAMEPADS;i++) {
282
+    if (gamepads[i].fd == fd) {
283
+      int rc;
284
+      while (SDL_PollEvent(&event)) {
285
+        rc = x11_sdlinput_handle_event(&event);
286
+        if (rc == SDL_QUIT_APPLICATION)
287
+          return LOOP_RETURN;
288
+      }
289
+    }
290
+  }
291
+  return LOOP_OK;
292
+}
293
+
294
+void x11_sdl_init(char* mappings) {
295
+  isx11sdlcall = true;
296
+  sdlinput_init(mappings);
297
+}
298
+
299
+void x11_sdl_stop() {
300
+  for (int i=0;i<MAX_GAMEPADS;i++) {
301
+    if (gamepads[i].initialized && gamepads[i].fdadded) {
302
+      loop_remove_fd(gamepads[i].fd);
303
+      gamepads[i].fdadded = false;
304
+      close(gamepads[i].fd);
305
+      remove_gamepad(gamepads[i].sdl_id);
306
+    }
307
+  }
308
+  SDL_Quit();
309
+}
(-)a/games/moonlight-embedded/files/patch-src_input_sdl.h (-8 lines)
Removed Link Here
1
--- src/input/sdl.h.orig	2023-10-11 15:50:11 UTC
2
+++ src/input/sdl.h
3
@@ -105,3 +105,5 @@ void sdlinput_rumble(unsigned short controller_id, uns
4
 void sdlinput_rumble_triggers(unsigned short controller_id, unsigned short left_trigger, unsigned short right_trigger);
5
 void sdlinput_set_motion_event_state(unsigned short controller_id, unsigned char motion_type, unsigned short report_rate_hz);
6
 void sdlinput_set_controller_led(unsigned short controller_id, unsigned char r, unsigned char g, unsigned char b);
7
+void x11_sdl_init(char* mappings);
8
+void x11_sdl_stop();
(-)a/games/moonlight-embedded/files/patch-src_input_x11.c (-185 lines)
Removed Link Here
1
--- src/input/x11.c.orig	2023-10-08 02:12:37 UTC
2
+++ src/input/x11.c
3
@@ -33,6 +33,8 @@
4
 
5
 #define ACTION_MODIFIERS (MODIFIER_SHIFT|MODIFIER_ALT|MODIFIER_CTRL)
6
 #define QUIT_KEY 0x18  /* KEY_Q */
7
+#define GRAB_KEY 0x34  /* KEY_Z */
8
+#define TAB_KEY 0x17  /* KEY_Tab */
9
 
10
 static Display *display;
11
 static Window window;
12
@@ -46,6 +48,35 @@ static const char data[1] = {0};
13
 static Cursor cursor;
14
 static bool grabbed = True;
15
 
16
+static bool isgrabkeyrelease = false;
17
+static bool waitingToSwitchGrabOnModifierUp = false;
18
+static bool waitingToExitOnModifiersUp = false;
19
+extern bool iskeyboardgrab;
20
+extern void grab_window(bool grabstat);
21
+
22
+static short keystatlist[0xFF];
23
+static void keyrelease(int keycode) {
24
+  keystatlist[keycode] = 0;
25
+}
26
+static void keypress(int keycode) {
27
+  keystatlist[keycode] = 1;
28
+}
29
+static void freeallkey () {
30
+  for (int i=0;i<0xFF;i++) {
31
+    if (keystatlist[i] == 1) {
32
+      keystatlist[i] = 0;
33
+      LiSendKeyboardEvent(0x80 << 8 | keyCodes[i - 8], KEY_ACTION_UP, 0);
34
+    }
35
+  }
36
+}
37
+static void clearallkey () {
38
+  for (int i=0;i<0xFF;i++) {
39
+    if (keystatlist[i] == 1) {
40
+      keystatlist[i] = 0;
41
+    }
42
+  }
43
+}
44
+
45
 static int x11_handler(int fd) {
46
   XEvent event;
47
   int button = 0;
48
@@ -54,18 +85,24 @@ static int x11_handler(int fd) {
49
   while (XPending(display)) {
50
     XNextEvent(display, &event);
51
     switch (event.type) {
52
+    case FocusIn:
53
+    case FocusOut:
54
+      if (event.type == FocusIn) {
55
+        clearallkey();
56
+        keyboard_modifiers = 0;
57
+        grabbed = true;
58
+      } else {
59
+        if (iskeyboardgrab)
60
+          break;
61
+        freeallkey();
62
+        keyboard_modifiers = 0;
63
+        grabbed = false;
64
+      }
65
+      XDefineCursor(display, window, grabbed ? cursor : 0);
66
+      break;
67
     case KeyPress:
68
     case KeyRelease:
69
       if (event.xkey.keycode >= 8 && event.xkey.keycode < (sizeof(keyCodes)/sizeof(keyCodes[0]) + 8)) {
70
-        if ((keyboard_modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && event.type == KeyRelease) {
71
-          if (event.xkey.keycode == QUIT_KEY)
72
-            return LOOP_RETURN;
73
-          else {
74
-            grabbed = !grabbed;
75
-            XDefineCursor(display, window, grabbed ? cursor : 0);
76
-          }
77
-        }
78
-
79
         int modifier = 0;
80
         switch (event.xkey.keycode) {
81
         case 0x32:
82
@@ -89,8 +126,58 @@ static int x11_handler(int fd) {
83
             keyboard_modifiers &= ~modifier;
84
         }
85
 
86
+        if ((keyboard_modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && event.type == KeyPress) {
87
+          if (event.xkey.keycode == QUIT_KEY) {
88
+            waitingToExitOnModifiersUp = true;
89
+            break;
90
+          } else if (event.xkey.keycode == GRAB_KEY) {
91
+            if (event.type == KeyPress) {
92
+              waitingToSwitchGrabOnModifierUp = true;
93
+              break;
94
+            }
95
+          }
96
+        }
97
+        if (waitingToSwitchGrabOnModifierUp) {
98
+          if (event.xkey.keycode == GRAB_KEY && event.type == KeyRelease) {
99
+            isgrabkeyrelease = true;
100
+            if (keyboard_modifiers != 0)
101
+              break;
102
+          }
103
+          if (keyboard_modifiers == 0 && isgrabkeyrelease) {
104
+            waitingToSwitchGrabOnModifierUp = false;
105
+            isgrabkeyrelease = false;
106
+            XDefineCursor(display, window, cursor);
107
+            freeallkey();
108
+            grab_window(true);
109
+            break;
110
+          }
111
+        } else if (waitingToExitOnModifiersUp) {
112
+          if (event.xkey.keycode == QUIT_KEY) {
113
+            if (keyboard_modifiers != 0)
114
+              break;
115
+          }
116
+          if (keyboard_modifiers == 0) {
117
+            freeallkey();
118
+            waitingToExitOnModifiersUp = false;
119
+            return LOOP_RETURN;
120
+          }
121
+        }
122
+        if (event.xkey.keycode == TAB_KEY && keyboard_modifiers == MODIFIER_ALT) {
123
+          freeallkey();
124
+          keyboard_modifiers = 0;
125
+          break;
126
+        }
127
+        if (event.xkey.keycode == 0x40 || event.xkey.keycode == 0x6c)
128
+          break;
129
+
130
+        if (event.type == KeyPress)
131
+            keypress(event.xkey.keycode);
132
+        else
133
+            keyrelease(event.xkey.keycode);
134
+
135
         short code = 0x80 << 8 | keyCodes[event.xkey.keycode - 8];
136
-        LiSendKeyboardEvent(code, event.type == KeyPress ? KEY_ACTION_DOWN : KEY_ACTION_UP, keyboard_modifiers);
137
+        if (!iskeyboardgrab)
138
+          LiSendKeyboardEvent(code, event.type == KeyPress ? KEY_ACTION_DOWN : KEY_ACTION_UP, keyboard_modifiers);
139
       }
140
       break;
141
     case ButtonPress:
142
@@ -106,16 +193,20 @@ static int x11_handler(int fd) {
143
         button = BUTTON_RIGHT;
144
         break;
145
       case Button4:
146
-        LiSendScrollEvent(1);
147
+        if (!iskeyboardgrab)
148
+          LiSendScrollEvent(1);
149
         break;
150
       case Button5:
151
-        LiSendScrollEvent(-1);
152
+        if (!iskeyboardgrab)
153
+          LiSendScrollEvent(-1);
154
         break;
155
       case 6:
156
-        LiSendHScrollEvent(-1);
157
+        if (!iskeyboardgrab)
158
+          LiSendHScrollEvent(-1);
159
         break;
160
       case 7:
161
-        LiSendHScrollEvent(1);
162
+        if (!iskeyboardgrab)
163
+          LiSendHScrollEvent(1);
164
         break;
165
       case 8:
166
         button = BUTTON_X1;
167
@@ -125,14 +216,16 @@ static int x11_handler(int fd) {
168
         break;
169
       }
170
 
171
-      if (button != 0)
172
+      if (button != 0 && !iskeyboardgrab)
173
         LiSendMouseButtonEvent(event.type==ButtonPress ? BUTTON_ACTION_PRESS : BUTTON_ACTION_RELEASE, button);
174
       break;
175
     case MotionNotify:
176
+      if (!grabbed)
177
+        break;
178
       motion_x = event.xmotion.x - last_x;
179
       motion_y = event.xmotion.y - last_y;
180
       if (abs(motion_x) > 0 || abs(motion_y) > 0) {
181
-        if (last_x >= 0 && last_y >= 0)
182
+        if (last_x >= 0 && last_y >= 0 && !iskeyboardgrab)
183
           LiSendMouseMoveEvent(motion_x, motion_y);
184
 
185
         if (grabbed)
(-)b/games/moonlight-embedded/files/patch-src_main.c (-48 / +16 lines)
Lines 1-4 Link Here
1
--- src/main.c.orig	2023-10-11 15:50:11 UTC
1
--- src/main.c.orig	2023-11-03 06:08:34 UTC
2
+++ src/main.c
2
+++ src/main.c
3
@@ -42,6 +42,7 @@
3
@@ -42,6 +42,7 @@
4
 #include <client.h>
4
 #include <client.h>
Lines 8-33 Link Here
8
 #include <stdio.h>
8
 #include <stdio.h>
9
 #include <stdlib.h>
9
 #include <stdlib.h>
10
 #include <stdbool.h>
10
 #include <stdbool.h>
11
@@ -52,7 +53,6 @@
11
@@ -52,7 +53,8 @@
12
 #include <netinet/in.h>
12
 #include <netinet/in.h>
13
 #include <netdb.h>
13
 #include <netdb.h>
14
 #include <arpa/inet.h>
14
 #include <arpa/inet.h>
15
-#include <openssl/rand.h>
15
-#include <openssl/rand.h>
16
+ 
17
+extern void is_use_kbdmux();
16
 
18
 
17
 static void applist(PSERVER_DATA server) {
19
 static void applist(PSERVER_DATA server) {
18
   PAPP_LIST list = NULL;
20
   PAPP_LIST list = NULL;
19
@@ -149,6 +149,10 @@ static void stream(PSERVER_DATA server, PCONFIGURATION
21
@@ -202,7 +204,6 @@ static void help() {
20
     if (!config->viewonly)
21
       evdev_start();
22
     loop_main();
23
+    #ifdef HAVE_SDL
24
+    if (!isNoSdl)
25
+      x11_sdl_stop();
26
+    #endif
27
     if (!config->viewonly)
28
       evdev_stop();
29
   }
30
@@ -202,7 +206,6 @@ static void help() {
31
   printf("\t-bitrate <bitrate>\tSpecify the bitrate in Kbps\n");
22
   printf("\t-bitrate <bitrate>\tSpecify the bitrate in Kbps\n");
32
   printf("\t-packetsize <size>\tSpecify the maximum packetsize in bytes\n");
23
   printf("\t-packetsize <size>\tSpecify the maximum packetsize in bytes\n");
33
   printf("\t-codec <codec>\t\tSelect used codec: auto/h264/h265/av1 (default auto)\n");
24
   printf("\t-codec <codec>\t\tSelect used codec: auto/h264/h265/av1 (default auto)\n");
Lines 35-53 Link Here
35
   printf("\t-remote <yes/no/auto>\t\t\tEnable optimizations for WAN streaming (default auto)\n");
26
   printf("\t-remote <yes/no/auto>\t\t\tEnable optimizations for WAN streaming (default auto)\n");
36
   printf("\t-app <app>\t\tName of app to stream\n");
27
   printf("\t-app <app>\t\tName of app to stream\n");
37
   printf("\t-nosops\t\t\tDon't allow GFE to modify game settings\n");
28
   printf("\t-nosops\t\t\tDon't allow GFE to modify game settings\n");
38
@@ -238,7 +241,10 @@ static void pair_check(PSERVER_DATA server) {
29
@@ -322,19 +323,19 @@ int main(int argc, char* argv[]) {
39
 int main(int argc, char* argv[]) {
40
   CONFIGURATION config;
41
   config_parse(argc, argv, &config);
42
-
43
+  #ifndef HAVE_SDL
44
+  isNoSdl = true;
45
+  #endif
46
+  
47
   if (config.action == NULL || strcmp("help", config.action) == 0)
48
     help();
49
 
50
@@ -322,19 +328,19 @@ int main(int argc, char* argv[]) {
51
     config.stream.supportedVideoFormats = VIDEO_FORMAT_H264;
30
     config.stream.supportedVideoFormats = VIDEO_FORMAT_H264;
52
     if (config.codec == CODEC_HEVC || (config.codec == CODEC_UNSPECIFIED && platform_prefers_codec(system, CODEC_HEVC))) {
31
     if (config.codec == CODEC_HEVC || (config.codec == CODEC_UNSPECIFIED && platform_prefers_codec(system, CODEC_HEVC))) {
53
       config.stream.supportedVideoFormats |= VIDEO_FORMAT_H265;
32
       config.stream.supportedVideoFormats |= VIDEO_FORMAT_H265;
Lines 75-101 Link Here
75
 
54
 
76
     #ifdef HAVE_SDL
55
     #ifdef HAVE_SDL
77
     if (system == SDL)
56
     if (system == SDL)
78
@@ -371,7 +377,19 @@ int main(int argc, char* argv[]) {
57
@@ -362,6 +363,8 @@ int main(int argc, char* argv[]) {
58
           mappings = map;
59
         }
79
 
60
 
80
         udev_init(!inputAdded, mappings, config.debug_level > 0, config.rotate);
61
+        // test is use kbdmux driver
81
         evdev_init(config.mouse_emulation);
62
+        is_use_kbdmux();
82
+        #ifdef HAVE_SDL
63
         for (int i=0;i<config.inputsCount;i++) {
83
+        if (isNoSdl)
64
           if (config.debug_level > 0)
84
+          rumble_handler = evdev_rumble;
65
             printf("Adding input device %s...\n", config.inputs[i]);
85
+        else {
66
@@ -398,7 +401,8 @@ int main(int argc, char* argv[]) {
86
+          x11_sdl_init(config.mapping);
87
+          rumble_handler = sdlinput_rumble;
88
+          rumble_triggers_handler = sdlinput_rumble_triggers;
89
+          set_motion_event_state_handler = sdlinput_set_motion_event_state;
90
+          set_controller_led_handler = sdlinput_set_controller_led;
91
+        }
92
+        #else
93
         rumble_handler = evdev_rumble;
94
+        #endif
95
         #ifdef HAVE_LIBCEC
96
         cec_init();
97
         #endif /* HAVE_LIBCEC */
98
@@ -398,7 +416,8 @@ int main(int argc, char* argv[]) {
99
     if (config.pin > 0 && config.pin <= 9999) {
67
     if (config.pin > 0 && config.pin <= 9999) {
100
       sprintf(pin, "%04d", config.pin);
68
       sprintf(pin, "%04d", config.pin);
101
     } else {
69
     } else {
Lines 105-111 Link Here
105
     }
73
     }
106
     printf("Please enter the following PIN on the target PC: %s\n", pin);
74
     printf("Please enter the following PIN on the target PC: %s\n", pin);
107
     fflush(stdout);
75
     fflush(stdout);
108
@@ -406,6 +425,7 @@ int main(int argc, char* argv[]) {
76
@@ -406,6 +410,7 @@ int main(int argc, char* argv[]) {
109
       fprintf(stderr, "Failed to pair to server: %s\n", gs_error);
77
       fprintf(stderr, "Failed to pair to server: %s\n", gs_error);
110
     } else {
78
     } else {
111
       printf("Succesfully paired\n");
79
       printf("Succesfully paired\n");
(-)b/games/moonlight-embedded/files/patch-src_platform.c (-34 / +6 lines)
Lines 1-40 Link Here
1
--- src/platform.c.orig	2023-09-01 23:40:56 UTC
1
--- src/platform.c.orig	2023-11-03 06:08:34 UTC
2
+++ src/platform.c
2
+++ src/platform.c
3
@@ -77,8 +77,8 @@ enum platform platform_check(char* name) {
3
@@ -202,6 +202,9 @@ AUDIO_RENDERER_CALLBACKS* platform_get_audio(enum plat
4
   bool x11 = strcmp(name, "x11") == 0;
4
     #ifdef HAVE_ALSA
5
   bool vdpau = strcmp(name, "x11_vdpau") == 0;
5
     return &audio_callbacks_alsa;
6
   bool vaapi = strcmp(name, "x11_vaapi") == 0;
7
-  if (std || x11 || vdpau || vaapi) {
8
-    int init = x11_init(std || vdpau, std || vaapi);
9
+  if (x11 || vdpau || vaapi) {
10
+    int init = x11_init(vdpau, vaapi);
11
     #ifdef HAVE_VAAPI
12
     if (init == INIT_VAAPI)
13
       return X11_VAAPI;
14
@@ -87,11 +87,7 @@ enum platform platform_check(char* name) {
15
     if (init == INIT_VDPAU)
16
       return X11_VDPAU;
17
     #endif
6
     #endif
18
-    #ifdef HAVE_SDL
7
+    #ifdef __FreeBSD__
19
-    return SDL;
20
-    #else
21
     return X11;
22
-    #endif
23
   }
24
   #endif
25
   #ifdef HAVE_SDL
26
@@ -195,13 +191,7 @@ AUDIO_RENDERER_CALLBACKS* platform_get_audio(enum plat
27
     // fall-through
28
   #endif
29
   default:
30
-    #ifdef HAVE_PULSE
31
-    if (audio_pulse_init(audio_device))
32
-      return &audio_callbacks_pulse;
33
-    #endif
34
-    #ifdef HAVE_ALSA
35
-    return &audio_callbacks_alsa;
36
-    #endif
37
+    return &audio_callbacks_oss;
8
+    return &audio_callbacks_oss;
9
+    #endif
38
   }
10
   }
39
   return NULL;
11
   return NULL;
40
 }
12
 }
(-)a/games/moonlight-embedded/files/patch-src_sdl.c (-64 lines)
Removed Link Here
1
--- src/sdl.c.orig	2023-10-11 15:50:11 UTC
2
+++ src/sdl.c
3
@@ -42,6 +42,10 @@ void sdl_init(int width, int height, bool fullscreen) 
4
     fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
5
     exit(1);
6
   }
7
+  if(!SDL_SetHint(SDL_HINT_GRAB_KEYBOARD,"1"))
8
+    printf("Override SDL_HINT_GRAB_KEYBOARD to 1 failed.\n");
9
+  if(!SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED,"0"))
10
+    printf("Override SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED to 0 failed.\n");
11
 
12
   fullscreen_flags = fullscreen?SDL_WINDOW_FULLSCREEN:0;
13
   window = SDL_CreateWindow("Moonlight", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL | fullscreen_flags);
14
@@ -72,8 +76,19 @@ void sdl_init(int width, int height, bool fullscreen) 
15
 void sdl_loop() {
16
   SDL_Event event;
17
 
18
+  iskeyboardgrab = true;
19
   SDL_SetRelativeMouseMode(SDL_TRUE);
20
+#if SDL_VERSION_ATLEAST(2, 0, 15)
21
+  // On SDL 2.0.15+, we can get keyboard-only grab on Win32, X11, and Wayland.
22
+  // SDL 2.0.18 adds keyboard grab on macOS (if built with non-AppStore APIs).
23
+  SDL_SetWindowKeyboardGrab(window, SDL_TRUE);
24
+  if(!SDL_GetWindowKeyboardGrab(window))
25
+    printf("Try to grab window failed.\n");
26
+#else
27
+  SDL_SetWindowGrab(window, SDL_TRUE);
28
+#endif
29
 
30
+
31
   while(!done && SDL_WaitEvent(&event)) {
32
     switch (sdlinput_handle_event(window, &event)) {
33
     case SDL_QUIT_APPLICATION:
34
@@ -90,6 +105,30 @@ void sdl_loop() {
35
     case SDL_MOUSE_UNGRAB:
36
       SDL_SetRelativeMouseMode(SDL_FALSE);
37
       SDL_ShowCursor(SDL_DISABLE);
38
+      break;
39
+    case SDL_WINDOW_GRAB:
40
+      if(!SDL_SetHintWithPriority(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED,"0",SDL_HINT_OVERRIDE))
41
+        printf("Override SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED to 0 failed.\n");
42
+      SDL_ShowCursor(SDL_ENABLE);
43
+      SDL_SetRelativeMouseMode(SDL_TRUE);
44
+      iskeyboardgrab = true;
45
+#if SDL_VERSION_ATLEAST(2, 0, 15)
46
+      SDL_SetWindowKeyboardGrab(window, SDL_TRUE);
47
+#else
48
+      SDL_SetWindowGrab(window, SDL_TRUE);
49
+#endif
50
+      break;
51
+    case SDL_WINDOW_UNGRAB:
52
+      if(!SDL_SetHintWithPriority(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED,"1",SDL_HINT_OVERRIDE))
53
+        printf("Override SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED to 1 failed.\n");
54
+      SDL_SetRelativeMouseMode(SDL_FALSE);
55
+      SDL_ShowCursor(SDL_DISABLE);
56
+      iskeyboardgrab = false;
57
+#if SDL_VERSION_ATLEAST(2, 0, 15)
58
+      SDL_SetWindowKeyboardGrab(window, SDL_FALSE);
59
+#else
60
+      SDL_SetWindowGrab(window, SDL_FALSE);
61
+#endif
62
       break;
63
     default:
64
       if (event.type == SDL_QUIT)
(-)a/games/moonlight-embedded/files/patch-src_sdl.h (-19 lines)
Removed Link Here
1
--- src/sdl.h.orig	2023-10-11 15:50:11 UTC
2
+++ src/sdl.h
3
@@ -28,6 +28,8 @@
4
 #define SDL_MOUSE_GRAB 2
5
 #define SDL_MOUSE_UNGRAB 3
6
 #define SDL_TOGGLE_FULLSCREEN 4
7
+#define SDL_WINDOW_GRAB 5
8
+#define SDL_WINDOW_UNGRAB 6
9
 
10
 #define SDL_CODE_FRAME 0
11
 
12
@@ -36,6 +38,7 @@
13
 void sdl_init(int width, int height, bool fullscreen);
14
 void sdl_loop();
15
 
16
+extern bool iskeyboardgrab;
17
 extern SDL_mutex *mutex;
18
 extern int sdlCurrentFrame, sdlNextFrame;
19
 
(-)a/games/moonlight-embedded/files/patch-src_video_ffmpeg__vaapi.c (-19 lines)
Removed Link Here
1
--- src/video/ffmpeg_vaapi.c.orig	2023-09-01 23:40:56 UTC
2
+++ src/video/ffmpeg_vaapi.c
3
@@ -23,6 +23,7 @@
4
 #include <libavutil/hwcontext.h>
5
 #include <libavutil/hwcontext_vaapi.h>
6
 #include <X11/Xlib.h>
7
+#include <stdlib.h>
8
 
9
 #define MAX_SURFACES 16
10
 
11
@@ -59,7 +60,7 @@ static int va_get_buffer(AVCodecContext* context, AVFr
12
 }
13
 
14
 int vaapi_init_lib() {
15
-  return av_hwdevice_ctx_create(&device_ref, AV_HWDEVICE_TYPE_VAAPI, ":0", NULL, 0);
16
+  return av_hwdevice_ctx_create(&device_ref, AV_HWDEVICE_TYPE_VAAPI, getenv("DISPLAY") == NULL ? ":0" : getenv("DISPLAY"), NULL, 0);
17
 }
18
 
19
 int vaapi_init(AVCodecContext* decoder_ctx) {
(-)a/games/moonlight-embedded/files/patch-src_video_x11.c (-42 lines)
Removed Link Here
1
--- src/video/x11.c.orig	2023-10-08 02:12:37 UTC
2
+++ src/video/x11.c
3
@@ -53,6 +53,16 @@ static int pipefd[2];
4
 static int display_width;
5
 static int display_height;
6
 
7
+static void resetcursor() {
8
+  XColor dummy;
9
+  Cursor cursor;
10
+  const char data[1] = {0};
11
+  Pixmap blank = XCreateBitmapFromData(display, window, data, 1, 1);
12
+  cursor = XCreatePixmapCursor(display, blank, blank, &dummy, &dummy, 0, 0);
13
+  XFreePixmap(display, blank);
14
+  XDefineCursor(display, window, cursor);
15
+}
16
+
17
 static int frame_handle(int pipefd) {
18
   AVFrame* frame = NULL;
19
   while (read(pipefd, &frame, sizeof(void*)) > 0);
20
@@ -75,7 +85,7 @@ int x11_init(bool vdpau, bool vaapi) {
21
     return 0;
22
 
23
   #ifdef HAVE_VAAPI
24
-  if (vaapi && vaapi_init_lib(display) == 0)
25
+  if (vaapi && vaapi_init_lib() == 0)
26
     return INIT_VAAPI;
27
   #endif
28
 
29
@@ -100,10 +110,12 @@ int x11_setup(int videoFormat, int width, int height, 
30
   }
31
 
32
   Window root = DefaultRootWindow(display);
33
-  XSetWindowAttributes winattr = { .event_mask = PointerMotionMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask };
34
+  XSetWindowAttributes winattr = { .event_mask = PointerMotionMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | FocusChangeMask };
35
   window = XCreateWindow(display, root, 0, 0, display_width, display_height, 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &winattr);
36
   XMapWindow(display, window);
37
   XStoreName(display, window, "Moonlight");
38
+  // Fix the bug that the default cursor keep in screen when streaming.
39
+  resetcursor();
40
 
41
   if (drFlags & DISPLAY_FULLSCREEN) {
42
     Atom wm_state = XInternAtom(display, "_NET_WM_STATE", False);
(-)a/games/moonlight-embedded/files/patch-third__party_moonlight-common-c_enet_CMakeLists.txt (-26 lines)
Removed Link Here
1
--- third_party/moonlight-common-c/enet/CMakeLists.txt.orig	2023-09-21 01:51:32 UTC
2
+++ third_party/moonlight-common-c/enet/CMakeLists.txt
3
@@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 2.8.12...3.20)
4
 
5
 project(enet)
6
 
7
-option(ENET_NO_INSTALL "Disable installation of headers and libraries" OFF)
8
-
9
 # The "configure" step.
10
 include(CheckFunctionExists)
11
 include(CheckStructHasMember)
12
@@ -108,14 +106,4 @@ target_include_directories(enet SYSTEM PUBLIC include)
13
 
14
 if (MINGW)
15
     target_link_libraries(enet winmm ws2_32)
16
-endif()
17
-
18
-if(NOT ENET_NO_INSTALL)
19
-    install(TARGETS enet
20
-        RUNTIME DESTINATION bin
21
-        ARCHIVE DESTINATION lib/static
22
-        LIBRARY DESTINATION lib)
23
-
24
-    install(DIRECTORY include/
25
-            DESTINATION include)
26
 endif()
(-)a/games/moonlight-embedded/pkg-plist (-5 lines)
Removed Link Here
1
bin/moonlight
2
@sample etc/moonlight.conf.sample
3
share/man/man1/moonlight.1.gz
4
share/moonlight/gamecontrollerdb.txt
5
- 

Return to bug 276144