这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
[submodule "app/src/main/jni/wayland"]
path = app/src/main/jni/wayland
url = https://gitlab.freedesktop.org/wayland/wayland
[submodule "x11-client-experimental/src/main/cpp/libxcb"]
path = x11-client-experimental/src/main/cpp/libxcb
url = https://gitlab.freedesktop.org/xorg/lib/libxcb
[submodule "x11-client-experimental/src/main/cpp/xorgproto"]
path = x11-client-experimental/src/main/cpp/xorgproto
url = https://gitlab.freedesktop.org/xorg/proto/xorgproto
[submodule "x11-client-experimental/src/main/cpp/xcbproto"]
path = x11-client-experimental/src/main/cpp/xcbproto
url = https://gitlab.freedesktop.org/xorg/proto/xcbproto
[submodule "x11-client-experimental/src/main/cpp/libXau"]
path = x11-client-experimental/src/main/cpp/libXau
url = https://gitlab.freedesktop.org/xorg/lib/libxau
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ dependencies {
//noinspection GradleDependency
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':common')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.termux.x11.common;
package com.termux.x11;

// This interface is used by utility on termux side.
interface ITermuxX11Internal {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.termux.x11.starter;
package com.termux.x11;

import android.annotation.SuppressLint;
import android.app.AppOpsManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
Expand All @@ -17,11 +16,12 @@
import java.io.PrintStream;
import java.util.Objects;

import com.termux.x11.common.ITermuxX11Internal;
import com.termux.x11.starter.ActivityManager;
import com.termux.x11.starter.Compat;

@SuppressLint("UnsafeDynamicallyLoadedCode")
@SuppressWarnings({"unused", "RedundantThrows", "SameParameterValue", "FieldCanBeLocal"})
public class Starter {
public class CmdEntryPoint {
@SuppressLint("SdCardPath")
private final String XwaylandPath = "/data/data/com.termux/files/usr/bin/Xwayland";
private final ComponentName TermuxX11Component =
Expand All @@ -39,7 +39,7 @@ public static void main(String[] args) {
try {
(new Thread(() -> {
try {
(new Starter()).onRun(args);
(new CmdEntryPoint()).onRun(args);
} catch (Throwable e) {
e.printStackTrace();
}
Expand All @@ -60,7 +60,7 @@ public static void main(String[] args) {
};

public void onRun(String[] args) throws Throwable {
Starter.this.args = args;
CmdEntryPoint.this.args = args;
checkXdgRuntimeDir();
prepareLogFD();
if (!Compat.havePermission(AppOpsManager.OPSTR_SYSTEM_ALERT_WINDOW)) {
Expand Down Expand Up @@ -187,15 +187,15 @@ private void startXwayland(String[] args) throws IOException {
class Service extends ITermuxX11Internal.Stub {
@Override
public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws RemoteException {
Starter.this.onTransact(code, data, reply, flags);
CmdEntryPoint.this.onTransact(code, data, reply, flags);
return super.onTransact(code, data, reply, flags);
}

@Override
public ParcelFileDescriptor getWaylandFD() throws RemoteException {
System.err.println("Got getWaylandFD");
try {
return Starter.this.getWaylandFD();
return CmdEntryPoint.this.getWaylandFD();
} catch (Throwable e) {
throw new RemoteException(e.getMessage());
}
Expand All @@ -211,7 +211,7 @@ public ParcelFileDescriptor getLogFD() throws RemoteException {
@Override
public void finish() throws RemoteException {
System.err.println("Got finish request");
handler.postDelayed(Starter.this::onFinish, 10);
handler.postDelayed(CmdEntryPoint.this::onFinish, 10);
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/termux/x11/LorieService.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@ public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
@SuppressWarnings("unused")
// It is used in native code
void setRendererVisibility(boolean visible) {
act.runOnUiThread(()-> act.findViewById(R.id.stub).setVisibility(visible?View.INVISIBLE:View.VISIBLE));
act.runOnUiThread(()-> {
act.findViewById(R.id.stub).setVisibility(visible?View.INVISIBLE:View.VISIBLE);
act.findViewById(R.id.lorieView).setVisibility(visible?View.VISIBLE:View.INVISIBLE);
});
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import androidx.annotation.Nullable;
import androidx.core.hardware.display.DisplayManagerCompat;

import com.termux.x11.common.ITermuxX11Internal;

public class TermuxX11StarterReceiver extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/termux/x11/starter/Compat.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.lang.reflect.InvocationTargetException;

public class Compat {
static final String callingPackage = "com.termux";
static int startActivity(Intent i) {
public static final String callingPackage = "com.termux";
public static int startActivity(Intent i) {
try {
if (Build.VERSION.SDK_INT >= 30) {
IActivityTaskManager taskManager = ActivityTaskManager.getService();
Expand All @@ -46,7 +46,7 @@ static int startActivity(Intent i) {

@SuppressWarnings({"JavaReflectionMemberAccess", "SameParameterValue"})
@SuppressLint("PrivateApi")
static boolean havePermission(String permission) {
public static boolean havePermission(String permission) {
try {
// We do not need Context to use checkOpNoThrow/unsafeCheckOpNoThrow so it can be null
IBinder binder = ServiceManager.getService("appops");
Expand Down
43 changes: 36 additions & 7 deletions app/src/main/jni/lorie/android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ lorie_compositor::lorie_compositor(jobject thiz): lorie_compositor() {
env->CallVoidMethod(thiz, set_renderer_visibility_id, visible);
};

set_cursor_visibility = [=](bool visible) {
env->CallVoidMethod(thiz, set_cursor_visibility_id, visible);
if (!visible)
set_cursor_position = [=](int, int) {};
set_cursor_visibility = [=](JNIEnv* jenv, bool visible) {
jenv->CallVoidMethod(thiz, set_cursor_visibility_id, visible);
if (!visible || !screen.sfc)
set_cursor_position = [=](JNIEnv*, int, int) {};
else
set_cursor_position = [=](int x, int y) {
auto b = cursor.sfc ? any_cast<surface_data*>(cursor.sfc->user_data())->buffer : nullptr;
set_cursor_position = [=](JNIEnv* jenv, int x, int y) {
auto data = cursor.sfc ? any_cast<surface_data*>(cursor.sfc->user_data()) : nullptr;
auto b = data->buffer ?: nullptr;
int sx = x - cursor.hotspot_x;
int sy = y - cursor.hotspot_y;
int w = b ? b->shm_width() : 0;
int h = b ? b->shm_height() : 0;
env->CallVoidMethod(thiz, set_cursor_rect_id, sx, sy, w, h);
jenv->CallVoidMethod(thiz, set_cursor_rect_id, sx, sy, w, h);
};
};

Expand Down Expand Up @@ -228,16 +229,44 @@ JNI_DECLARE(LorieService, windowChanged)(JNIEnv *env, jobject thiz, jobject surf
extern "C" JNIEXPORT void JNICALL
JNI_DECLARE(LorieService, pointerMotion)(JNIEnv *env, jobject thiz, jint x, jint y) {
queue<&lorie_compositor::pointer_motion>(env, thiz, x, y);
if (lorie_compositor::compositor_field_id) {
auto native =
lorie_compositor::compositor_field_id ?
reinterpret_cast<lorie_compositor *>(env->GetLongField(thiz,lorie_compositor::compositor_field_id)):
nullptr;
if (native) {
native->set_cursor_visibility(env, true);
native->set_cursor_position(env, x, y);
}
}
}

extern "C" JNIEXPORT void JNICALL
JNI_DECLARE(LorieService, pointerScroll)(JNIEnv *env, jobject thiz, jint axis, jfloat value) {
queue<&lorie_compositor::pointer_scroll>(env, thiz, axis, value);
if (lorie_compositor::compositor_field_id) {
auto native =
lorie_compositor::compositor_field_id ?
reinterpret_cast<lorie_compositor *>(env->GetLongField(thiz,lorie_compositor::compositor_field_id)):
nullptr;
if (native) {
native->set_cursor_visibility(env, true);
}
}
}

extern "C" JNIEXPORT void JNICALL
JNI_DECLARE(LorieService, pointerButton)(JNIEnv *env, jobject thiz, jint button, jint type) {
queue<&lorie_compositor::pointer_button>(env, thiz, uint32_t(button), uint32_t(type));
if (lorie_compositor::compositor_field_id) {
auto native =
lorie_compositor::compositor_field_id ?
reinterpret_cast<lorie_compositor *>(env->GetLongField(thiz,lorie_compositor::compositor_field_id)):
nullptr;
if (native) {
native->set_cursor_visibility(env, true);
}
}
}

extern "C" void get_character_data(char** layout, int *shift, int *ec, char *ch);
Expand Down
30 changes: 20 additions & 10 deletions app/src/main/jni/lorie/compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,28 @@ lorie_compositor::lorie_compositor() {
};
compositor->on_create_surface = [=](surface_t* surface) {
auto data = new surface_data;
data->id = surface->id(); // For debugging purposes
surface->user_data() = data;
surface->on_attach = [=](buffer_t* b, int32_t, int32_t) {
data->buffer = b;
};
surface->on_damage = [=](int32_t, int32_t, int32_t, int32_t) {
data->damaged = true;
};
surface->on_damage_buffer = [=](int32_t, int32_t, int32_t, int32_t) {
data->damaged = true;
};
surface->on_frame = [=] (callback_t* cb) {
data->frame_callback = cb;
};
surface->on_commit = [=] {
redraw();
data->buffer->release();
data->frame_callback->done(resource_t::timestamp());
if (data->buffer)
data->buffer->release();
if (data->frame_callback) {
data->frame_callback->done(resource_t::timestamp());
data->frame_callback = nullptr;
}
};
surface->on__destroy = [=] {
surface->destroy();
Expand Down Expand Up @@ -147,17 +155,20 @@ lorie_compositor::lorie_compositor() {
};
};
global_xdg_wm_base.on_bind = [=, this](client_t* client, xdg_wm_base_t* wm_base) {
auto data = any_cast<client_data*>(client->user_data());
wm_base->on_get_xdg_surface = [=, this](xdg_surface_t* xdg_surface, surface_t* sfc) {
xdg_surface->on_get_toplevel = [=, this](xdg_toplevel_t*) {
auto data = any_cast<client_data*>(screen.sfc->client()->user_data());
wl_array keys{};
wl_array_init(&keys);
screen.sfc = sfc;
redraw();
set_renderer_visibility(sfc != nullptr);

if (data->pointer)
data->pointer->enter(next_serial(),sfc, 0, 0);
if (data->kbd)

if(data->kbd)
data->kbd->enter(next_serial(), sfc, &keys);
redraw();
};
};
wm_base->on__destroy = [=]() { wm_base->destroy(); };
Expand All @@ -174,13 +185,17 @@ void lorie_compositor::redraw(bool force) {
bool damaged = (data && data->damaged) || force;
if (damaged)
blit(screen.win, screen.sfc);
if (data)
data->damaged = false;
}

if (cursor.win) {
auto data = cursor.sfc ? any_cast<surface_data *>(cursor.sfc->user_data()) : nullptr;
bool damaged = (data && data->damaged) || force;
if (damaged)
blit(cursor.win, cursor.sfc);
if (data)
data->damaged = false;
}
}

Expand Down Expand Up @@ -220,9 +235,6 @@ void lorie_compositor::pointer_motion(int x, int y) {

data->pointer->motion(resource_t::timestamp(), double(x), double(y));
data->pointer->frame();

set_cursor_visibility(true);
set_cursor_position(x, y);
}

void lorie_compositor::pointer_scroll(int axis, float value) {
Expand All @@ -235,7 +247,6 @@ void lorie_compositor::pointer_scroll(int axis, float value) {
data->pointer->axis_discrete(pointer_axis(axis), (value >= 0) ? 1 : -1);
data->pointer->axis(resource_t::timestamp(), pointer_axis(axis), value);
data->pointer->frame();
set_cursor_visibility(true);
}

void lorie_compositor::pointer_button(int button, int state) {
Expand All @@ -248,7 +259,6 @@ void lorie_compositor::pointer_button(int button, int state) {
LOGI("pointer button: %d %d", button, state);
data->pointer->button(next_serial(), resource_t::timestamp(), button, pointer_button_state(state));
data->pointer->frame();
set_cursor_visibility(true);
}

void lorie_compositor::keyboard_key(uint32_t key, keyboard_key_state state) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/jni/lorie/include/lorie_compositor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class lorie_compositor: public wayland::display_t {
};

struct surface_data {
uint32_t x{}, y{};
uint32_t x{}, y{}, id{};
bool damaged{};
wayland::buffer_t *buffer{};
wayland::callback_t *frame_callback{};
Expand All @@ -60,8 +60,8 @@ class lorie_compositor: public wayland::display_t {
} cursor{};
static void blit(EGLNativeWindowType win, wayland::surface_t* sfc);
std::function<void(bool)> set_renderer_visibility = [](bool){};
std::function<void(bool)> set_cursor_visibility = [](bool){};
std::function<void(int, int)> set_cursor_position = [](int, int){};
std::function<void(JNIEnv*, bool)> set_cursor_visibility = [](JNIEnv*, bool){};
std::function<void(JNIEnv*, int, int)> set_cursor_position = [](JNIEnv*, int, int){};

// backend features
void get_keymap(int *fd, int *size);
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/jni/lorie/lorie_wayland_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ namespace wayland {
return userdata;
}

inline int id() {
return wl_resource_get_id(*this);
}

inline void destroy() {
wl_resource_destroy(*this);
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/jni/starter/starter.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int socket_action(int* fd, char* path,
}

JNIEXPORT void JNICALL
Java_com_termux_x11_starter_Starter_checkXdgRuntimeDir(unused JNIEnv *env, unused jobject thiz) {
Java_com_termux_x11_CmdEntryPoint_checkXdgRuntimeDir(unused JNIEnv *env, unused jobject thiz) {
char* XDG_RUNTIME_DIR = getenv("XDG_RUNTIME_DIR");
if (!XDG_RUNTIME_DIR || strlen(XDG_RUNTIME_DIR) == 0) {
printf("$XDG_RUNTIME_DIR is unset.\n");
Expand Down Expand Up @@ -71,7 +71,7 @@ static const char *getWaylandSocketPath() {
}

JNIEXPORT jboolean JNICALL
Java_com_termux_x11_starter_Starter_checkWaylandSocket(unused JNIEnv *env, unused jobject thiz) {
Java_com_termux_x11_CmdEntryPoint_checkWaylandSocket(unused JNIEnv *env, unused jobject thiz) {
int fd;
errno = 0;

Expand All @@ -84,7 +84,7 @@ Java_com_termux_x11_starter_Starter_checkWaylandSocket(unused JNIEnv *env, unuse
}

JNIEXPORT jint JNICALL
Java_com_termux_x11_starter_Starter_createWaylandSocket(unused JNIEnv *env, unused jobject thiz) {
Java_com_termux_x11_CmdEntryPoint_createWaylandSocket(unused JNIEnv *env, unused jobject thiz) {
int fd;
errno = 0;

Expand All @@ -100,7 +100,7 @@ Java_com_termux_x11_starter_Starter_createWaylandSocket(unused JNIEnv *env, unus
#pragma clang diagnostic push
#pragma ide diagnostic ignored "hicpp-signed-bitwise"
JNIEXPORT jint JNICALL
Java_com_termux_x11_starter_Starter_openLogFD(unused JNIEnv *env, unused jobject thiz) {
Java_com_termux_x11_CmdEntryPoint_openLogFD(unused JNIEnv *env, unused jobject thiz) {
const char* TERMUX_X11_LOG_FILE = getenv("TERMUX_X11_LOG_FILE");
int sv[2]; /* the pair of socket descriptors */
if (TERMUX_X11_LOG_FILE == NULL || strlen(TERMUX_X11_LOG_FILE) == 0)
Expand Down Expand Up @@ -157,7 +157,7 @@ Java_com_termux_x11_starter_Starter_openLogFD(unused JNIEnv *env, unused jobject
}

JNIEXPORT void JNICALL
Java_com_termux_x11_starter_Starter_exec(JNIEnv *env, jclass clazz, jstring jpath, jobjectArray jargv) {
Java_com_termux_x11_CmdEntryPoint_exec(JNIEnv *env, jclass clazz, jstring jpath, jobjectArray jargv) {
// execv's argv array is a bit incompatible with Java's String[], so we do some converting here...
int argc = (*env)->GetArrayLength(env, jargv) + 2; // Leading executable path and terminating NULL
char *argv[argc];
Expand Down
Loading