Skip to content

Commit a117050

Browse files
committed
Termux x11 port
1 parent 958d783 commit a117050

File tree

136 files changed

+19410
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+19410
-92
lines changed

.gitmodules

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,71 @@
77
[submodule "android/extern/wolfssl"]
88
path = android/extern/wolfssl
99
url = https://github.com/wolfSSL/wolfssl.git
10+
[submodule "android/app/src/main/cpp/libtirpc"]
11+
path = android/app/src/main/cpp/libtirpc
12+
url = https://github.com/alisw/libtirpc
13+
ignore = dirty
14+
[submodule "android/app/src/main/cpp/pixman"]
15+
path = android/app/src/main/cpp/pixman
16+
url = https://gitlab.freedesktop.org/pixman/pixman
17+
ignore = dirty
18+
[submodule "android/app/src/main/cpp/libfontenc"]
19+
path = android/app/src/main/cpp/libfontenc
20+
url = https://gitlab.freedesktop.org/xorg/lib/libfontenc
21+
ignore = dirty
22+
[submodule "android/app/src/main/cpp/libxau"]
23+
path = android/app/src/main/cpp/libxau
24+
url = https://gitlab.freedesktop.org/xorg/lib/libxau
25+
ignore = dirty
26+
[submodule "android/app/src/main/cpp/libxdmcp"]
27+
path = android/app/src/main/cpp/libxdmcp
28+
url = https://gitlab.freedesktop.org/xorg/lib/libxdmcp
29+
ignore = dirty
30+
[submodule "android/app/src/main/cpp/libxfont"]
31+
path = android/app/src/main/cpp/libxfont
32+
url = https://gitlab.freedesktop.org/xorg/lib/libxfont
33+
ignore = dirty
34+
[submodule "android/app/src/main/cpp/libxkbfile"]
35+
path = android/app/src/main/cpp/libxkbfile
36+
url = https://gitlab.freedesktop.org/xorg/lib/libxkbfile
37+
ignore = dirty
38+
[submodule "android/app/src/main/cpp/libxshmfence"]
39+
path = android/app/src/main/cpp/libxshmfence
40+
url = https://gitlab.freedesktop.org/xorg/lib/libxshmfence
41+
ignore = dirty
42+
[submodule "android/app/src/main/cpp/libxtrans"]
43+
path = android/app/src/main/cpp/libxtrans
44+
url = https://gitlab.freedesktop.org/xorg/lib/libxtrans
45+
ignore = dirty
46+
[submodule "android/app/src/main/cpp/libepoxy"]
47+
path = android/app/src/main/cpp/libepoxy
48+
url = https://github.com/anholt/libepoxy
49+
ignore = dirty
50+
[submodule "android/app/src/main/cpp/libxcvt"]
51+
path = android/app/src/main/cpp/libxcvt
52+
url = https://gitlab.freedesktop.org/xorg/lib/libxcvt
53+
ignore = dirty
54+
[submodule "android/app/src/main/cpp/libx11"]
55+
path = android/app/src/main/cpp/libx11
56+
url = https://gitlab.freedesktop.org/xorg/lib/libx11
57+
ignore = dirty
58+
[submodule "android/app/src/main/cpp/xorgproto"]
59+
path = android/app/src/main/cpp/xorgproto
60+
url = https://gitlab.freedesktop.org/xorg/proto/xorgproto
61+
ignore = dirty
62+
[submodule "android/app/src/main/cpp/xkbcomp"]
63+
path = android/app/src/main/cpp/xkbcomp
64+
url = https://gitlab.freedesktop.org/xorg/app/xkbcomp
65+
ignore = dirty
66+
[submodule "android/app/src/main/cpp/xserver"]
67+
path = android/app/src/main/cpp/xserver
68+
url = https://gitlab.freedesktop.org/xorg/xserver
69+
ignore = dirty
70+
[submodule "android/app/src/main/cpp/bzip2"]
71+
path = android/app/src/main/cpp/bzip2
72+
url = https://gitlab.com/bzip2/bzip2
73+
ignore = dirty
74+
[submodule "android/app/src/main/cpp/OpenXR-SDK"]
75+
path = android/app/src/main/cpp/OpenXR-SDK
76+
url = https://github.com/KhronosGroup/OpenXR-SDK.git
77+
ignore = dirty

android/app/CMakeLists.txt

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
cmake_minimum_required(VERSION 3.10)
32

43
project(NativeVNC C CXX ASM)
@@ -13,20 +12,17 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared Libs" FORCE)
1312
# Make sure given submodule is checked out
1413
macro(avnc_check_submodule name)
1514
if (NOT EXISTS "${AVNC_EXTERN_DIR}/${name}/CMakeLists.txt")
16-
message(FATAL_ERROR "git submodule for ${name} is not initialized.
17-
Please run 'git submodule update --init'.")
15+
message(FATAL_ERROR "git submodule for ${name} is not initialized. Please run 'git submodule update --init'.")
1816
endif ()
1917
endmacro()
2018

21-
2219
# Required to enable SIMD support on ARM
2320
if (CMAKE_ANDROID_ARCH STREQUAL "arm64")
2421
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} --target=aarch64-linux-android${ANDROID_NATIVE_API_LEVEL}")
2522
elseif (CMAKE_ANDROID_ARCH STREQUAL "arm")
2623
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} --target=arm-linux-androideabi${ANDROID_NATIVE_API_LEVEL}")
2724
endif ()
2825

29-
3026
###############################################################################
3127
# JPEG
3228
###############################################################################
@@ -39,10 +35,10 @@ add_subdirectory(${AVNC_LIBJPEG_SRC_DIR} ${AVNC_LIBJPEG_BUILD_DIR})
3935

4036
# Set these variables so FindJPEG can find the library
4137
set(JPEG_LIBRARY ${AVNC_LIBJPEG_BUILD_DIR}/libturbojpeg.a)
42-
set(JPEG_INCLUDE_DIR ${AVNC_LIBJPEG_SRC_DIR})
43-
44-
include_directories(${AVNC_LIBJPEG_SRC_DIR} ${AVNC_LIBJPEG_BUILD_DIR})
4538

39+
# Create an interface library to manage include directories
40+
add_library(libjpeg INTERFACE)
41+
target_include_directories(libjpeg INTERFACE ${AVNC_LIBJPEG_SRC_DIR})
4642

4743
###############################################################################
4844
# SSL
@@ -63,13 +59,9 @@ add_definitions(-DOPENSSL_ALL -DOPENSSL_EXTRA -DHAVE_CRL -DHAVE_EX_DATA
6359

6460
add_subdirectory(${AVNC_LIBSSL_SRC_DIR} ${AVNC_LIBSSL_BUILD_DIR})
6561

66-
# Set these variables so FindOpenSSL can find the library
67-
set(OPENSSL_SSL_LIBRARY ${AVNC_LIBSSL_BUILD_DIR}/libwolfssl.a)
68-
set(OPENSSL_CRYPTO_LIBRARY ${AVNC_LIBSSL_BUILD_DIR}/libwolfssl.a)
69-
set(OPENSSL_INCLUDE_DIR ${AVNC_LIBSSL_SRC_DIR}/wolfssl)
70-
71-
include_directories(${AVNC_LIBSSL_SRC_DIR})
72-
62+
# Create an interface library to manage include directories
63+
add_library(libssl INTERFACE)
64+
target_include_directories(libssl INTERFACE ${AVNC_LIBSSL_SRC_DIR}/wolfssl)
7365

7466
###############################################################################
7567
# LibVNC
@@ -78,29 +70,45 @@ avnc_check_submodule(libvncserver)
7870

7971
set(AVNC_LIBVNC_SRC_DIR ${AVNC_EXTERN_DIR}/libvncserver)
8072
set(AVNC_LIBVNC_BUILD_DIR ${CMAKE_BINARY_DIR}/libvncserver)
81-
set(WITH_LIBSSH2 OFF CACHE BOOL "Find LibSSH" FORCE)
82-
83-
add_subdirectory(${AVNC_LIBVNC_SRC_DIR} ${AVNC_LIBVNC_BUILD_DIR}) # (source dir, build dir)
8473

85-
include_directories(${AVNC_LIBVNC_SRC_DIR}/include ${AVNC_LIBVNC_BUILD_DIR}/include)
74+
add_subdirectory(${AVNC_LIBVNC_SRC_DIR} ${AVNC_LIBVNC_BUILD_DIR})
8675

76+
# Create an interface library to manage include directories
77+
add_library(libvnc INTERFACE)
78+
target_include_directories(libvnc INTERFACE ${AVNC_LIBVNC_SRC_DIR}/include ${AVNC_LIBVNC_BUILD_DIR}/include)
8779

8880
###############################################################################
8981
# Native VNC
9082
#
9183
# It contains implementation of JNI native methods, some NDK scaffolding and
92-
# some helpers for OpenGL ES rendring. This is the library loaded from Java.
84+
# some helpers for OpenGL ES rendering. This is the library loaded from Java.
9385
###############################################################################
9486
set(AVNC_NATIVE_SOURCE src/main/cpp/native-vnc.cpp)
9587

9688
add_library(native-vnc SHARED ${AVNC_NATIVE_SOURCE})
9789

98-
target_link_libraries(native-vnc vncclient)
99-
90+
# Link libraries
91+
target_link_libraries(native-vnc
92+
PRIVATE
93+
libjpeg
94+
libssl
95+
libvnc
96+
vncclient
97+
)
10098

10199
# Link NDK libraries
102100
find_library(LIB_LOG log)
103-
target_link_libraries(native-vnc ${LIB_LOG})
104-
105101
find_library(LIB_GLES GLESv2)
106-
target_link_libraries(native-vnc ${LIB_GLES})
102+
103+
target_link_libraries(native-vnc
104+
PRIVATE
105+
${LIB_LOG}
106+
${LIB_GLES}
107+
)
108+
109+
###############################################################################
110+
# Termux X11
111+
#
112+
###############################################################################
113+
set(X11_EXTERN_DIR ${PROJECT_SOURCE_DIR}/src/main/cpp)
114+
add_subdirectory(${X11_EXTERN_DIR})

android/app/build.gradle

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ android {
5555
versionCode flutterVersionCode.toInteger()
5656
versionName flutterVersionName
5757

58+
buildConfigField "String", "COMMIT", "\"" + ("git rev-parse HEAD\n".execute().getText().trim() ?: (System.getenv('CURRENT_COMMIT') ?: "NO_COMMIT")) + "\""
59+
5860
javaCompileOptions {
5961
annotationProcessorOptions {
6062
arguments += ["room.schemaLocation": "$projectDir/roomSchema/".toString()]
@@ -68,10 +70,27 @@ android {
6870
// TODO: Add your own signing config for the release build.
6971
// Signing with the debug keys for now, so `flutter run --release` works.
7072
signingConfig signingConfigs.debug
73+
// remove flutter's default ShrinkResources settings at flutter\packages\flutter_tools\gradle\src\main\flutter.groovy
74+
postprocessing {
75+
removeUnusedCode true
76+
removeUnusedResources true
77+
obfuscate false
78+
optimizeCode true
79+
}
80+
}
81+
debug {
82+
signingConfig signingConfigs.debug
83+
postprocessing {
84+
removeUnusedCode true
85+
removeUnusedResources true
86+
obfuscate false
87+
optimizeCode true
88+
}
7189
}
7290
}
7391

7492
buildFeatures {
93+
aidl true
7594
dataBinding true
7695
buildConfig true
7796
}
@@ -106,6 +125,7 @@ dependencies {
106125
implementation "androidx.fragment:fragment-ktx:1.6.2"
107126
implementation "androidx.appcompat:appcompat:1.6.1"
108127
implementation "androidx.preference:preference-ktx:1.2.1"
128+
implementation "androidx.preference:preference:1.2.1"
109129
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
110130
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.2"
111131
implementation "androidx.dynamicanimation:dynamicanimation:1.0.0"
@@ -122,5 +142,65 @@ dependencies {
122142
implementation "com.google.android.material:material:1.11.0"
123143
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0"
124144
implementation "org.connectbot:sshlib:2.2.23"
145+
implementation 'com.github.tiann:FreeReflection:3.1.0'
125146

147+
compileOnly project(':shell-loader:stub')
126148
}
149+
150+
afterEvaluate {
151+
tasks.register("generatePrefs") {
152+
//noinspection UnnecessaryQualifiedReference
153+
def xml = groovy.xml.DOMBuilder.parse((new StringReader(file('src/main/res/xml/preferences.xml').text)))
154+
def preferenceNodes = xml.documentElement.getElementsByTagName("*")
155+
def preferences = []
156+
157+
for (int i = 0; i < preferenceNodes.length; i++) {
158+
def node = preferenceNodes.item(i)
159+
if (node.nodeName == 'EditTextPreference' && node.getAttribute("app:key") != "extra_keys_config")
160+
preferences << [ type: 'String', key: node.getAttribute("app:key"), default: node.getAttribute("app:defaultValue") ]
161+
else if (node.nodeName == 'SeekBarPreference')
162+
preferences << [ type: 'Int', key: node.getAttribute("app:key"), default: node.getAttribute("app:defaultValue") ]
163+
else if (node.nodeName == 'ListPreference') {
164+
def entries = node.getAttribute("app:entries")
165+
def values = node.getAttribute("app:entryValues")
166+
preferences << [type: 'List', key: node.getAttribute("app:key"), default: node.getAttribute("app:defaultValue"),
167+
entries: entries.substring(7, entries.length()), values: values.substring(7, values.length())]
168+
}
169+
else if (node.nodeName == 'SwitchPreferenceCompat')
170+
preferences << [ type: 'Boolean', key: node.getAttribute("app:key"), default: node.getAttribute("app:defaultValue") ]
171+
}
172+
173+
def out = file('build/generated/java/com/termux/x11/Prefs.java')
174+
out.getParentFile().exists() || out.getParentFile().mkdirs()
175+
out.delete()
176+
out.createNewFile()
177+
178+
out << 'package com.termux.x11;\n'
179+
out << 'import java.util.HashMap;\n'
180+
out << 'import android.content.Context;\n'
181+
out << 'import com.termux.x11.utils.TermuxX11ExtraKeys;\n'
182+
out << 'import com.example.tiny_computer.R;\n'
183+
out << '\n'
184+
out << 'public class Prefs extends LoriePreferences.PrefsProto {\n'
185+
preferences.each {
186+
if (it.type == 'Int' || it.type == 'Boolean')
187+
out << " public final ${it.type}Preference ${it.key} = new ${it.type}Preference(\"${it.key}\", ${it.default});\n"
188+
else if (it.type == 'String')
189+
out << " public final StringPreference ${it.key} = new StringPreference(\"${it.key}\", \"${it.default}\");\n"
190+
else if (it.type == 'List')
191+
out << " public final ${it.type}Preference ${it.key} = new ${it.type}Preference(\"${it.key}\", \"${it.default}\", R.array.${it.entries}, R.array.${it.values});\n"
192+
}
193+
out << ' public final StringPreference extra_keys_config = new StringPreference("extra_keys_config", TermuxX11ExtraKeys.DEFAULT_IVALUE_EXTRA_KEYS);\n'
194+
out << ' public final HashMap<String, Preference> keys = new HashMap<String, Preference>() {{\n'
195+
preferences.each { out << ' put("' + it.key + '", ' + it.key + ');\n' }
196+
out << ' put("extra_keys_config", extra_keys_config);\n'
197+
out << ' }};\n'
198+
out << '\n'
199+
out << ' public Prefs(Context ctx) {\n'
200+
out << ' super(ctx);\n'
201+
out << ' }\n'
202+
out << '}\n'
203+
}
204+
android.sourceSets.main.java.srcDirs += 'build/generated/java'
205+
preBuild.dependsOn generatePrefs
206+
}

0 commit comments

Comments
 (0)