Skip to content

Commit

Permalink
enhancement: move screen name changing to LorieView::sendWindowChange
Browse files Browse the repository at this point in the history
  • Loading branch information
twaik committed Dec 22, 2024
1 parent 57bda47 commit 72c086c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/src/main/aidl/com/termux/x11/ICmdEntryInterface.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.termux.x11;

// This interface is used by utility on termux side.
interface ICmdEntryInterface {
void windowChanged(in Surface surface, String name);
void windowChanged(in Surface surface);
ParcelFileDescriptor getXConnection();
ParcelFileDescriptor getLogcatOutput();
}
19 changes: 8 additions & 11 deletions app/src/main/cpp/lorie/InitOutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,16 +713,6 @@ CursorForDevice(DeviceIntPtr pDev) {
return NULL;
}

Bool lorieChangeScreenName(unused ClientPtr pClient, void *closure) {
RROutputPtr output = RRFirstOutput(pScreenPtr);
memset(output->name, 0, 1024);
strncpy(output->name, closure, 1024);
output->name[1023] = '\0';
output->nameLength = strlen(output->name);
free(closure);
return TRUE;
}

Bool lorieChangeWindow(unused ClientPtr pClient, void *closure) {
jobject surface = (jobject) closure;
renderer_set_window(pvfb->env, surface, pvfb->root.buffer);
Expand All @@ -736,10 +726,17 @@ Bool lorieChangeWindow(unused ClientPtr pClient, void *closure) {
return TRUE;
}

void lorieConfigureNotify(int width, int height, int framerate) {
void lorieConfigureNotify(int width, int height, int framerate, size_t name_size, char* name) {
ScreenPtr pScreen = pScreenPtr;
RROutputPtr output = RRFirstOutput(pScreen);

if (output && name) {
memset(output->name, 0, 1024);
strncpy(output->name, name, name_size < 1024 ? name_size : 1024);
output->name[1023] = '\0';
output->nameLength = strlen(output->name);
}

if (output && width && height && (pScreen->width != width || pScreen->height != height)) {
CARD32 mmWidth, mmHeight;
RRModePtr mode = lorieCvt(width, height, framerate);
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/cpp/lorie/activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,15 @@ Java_com_termux_x11_LorieView_sendClipboardEvent(JNIEnv *env, __unused jobject t
}

JNIEXPORT void JNICALL
Java_com_termux_x11_LorieView_sendWindowChange(__unused JNIEnv* env, __unused jobject cls, jint width, jint height, jint framerate) {
Java_com_termux_x11_LorieView_sendWindowChange(__unused JNIEnv* env, __unused jobject cls, jint width, jint height, jint framerate, jstring jname) {
if (conn_fd != -1) {
lorieEvent e = { .screenSize = { .t = EVENT_SCREEN_SIZE, .width = width, .height = height, .framerate = framerate } };
const char *name = (!jname || width <= 0 || height <= 0) ? NULL : (*env)->GetStringUTFChars(env, jname, JNI_FALSE);
lorieEvent e = { .screenSize = { .t = EVENT_SCREEN_SIZE, .width = width, .height = height, .framerate = framerate, .name_size = (name ? strlen(name) : 0) } };
write(conn_fd, &e, sizeof(e));
if (name) {
write(conn_fd, name, strlen(name));
(*env)->ReleaseStringUTFChars(env, jname, name);
}
checkConnection(env);
}
}
Expand Down
18 changes: 8 additions & 10 deletions app/src/main/cpp/lorie/cmdentrypoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,16 @@ Java_com_termux_x11_CmdEntryPoint_start(JNIEnv *env, __unused jclass cls, jobjec
}

JNIEXPORT void JNICALL
Java_com_termux_x11_CmdEntryPoint_windowChanged(JNIEnv *env, __unused jobject cls, jobject surface, jstring jname) {
const char *name = !jname ? NULL : (*env)->GetStringUTFChars(env, jname, JNI_FALSE);
QueueWorkProc(lorieChangeScreenName, NULL, name ? strndup(name, 1024) : strdup("screen"));
if (name)
(*env)->ReleaseStringUTFChars(env, jname, name);

Java_com_termux_x11_CmdEntryPoint_windowChanged(JNIEnv *env, __unused jobject cls, jobject surface) {
QueueWorkProc(lorieChangeWindow, NULL, surface ? (*env)->NewGlobalRef(env, surface) : NULL);
lorieTriggerWorkingQueue();
}

static Bool sendConfigureNotify(__unused ClientPtr pClient, void *closure) {
// This must be done only on X server thread.
lorieEvent* e = closure;
__android_log_print(ANDROID_LOG_ERROR, "tx11-request", "window changed: %d %d", e->screenSize.width, e->screenSize.height);
lorieConfigureNotify(e->screenSize.width, e->screenSize.height, e->screenSize.framerate);
__android_log_print(ANDROID_LOG_ERROR, "tx11-request", "window changed: %d %d %s", e->screenSize.width, e->screenSize.height, e->screenSize.name);
lorieConfigureNotify(e->screenSize.width, e->screenSize.height, e->screenSize.framerate, e->screenSize.name_size, e->screenSize.name);
free(e);
return TRUE;
}
Expand Down Expand Up @@ -224,8 +219,11 @@ void handleLorieEvents(int fd, __unused int ready, __unused void *ignored) {
if (read(fd, &e, sizeof(e)) == sizeof(e)) {
switch(e.type) {
case EVENT_SCREEN_SIZE: {
lorieEvent *copy = calloc(1, sizeof(lorieEvent));
*copy = e;
lorieEvent *copy = calloc(1, sizeof(lorieEvent) + e.screenSize.name_size + 1);
memcpy(copy, &e, sizeof(e));
copy->screenSize.name = copy->screenSize.name_size ? (char*) (copy + 1) : NULL;
if (copy->screenSize.name_size)
read(fd, copy->screenSize.name, copy->screenSize.name_size);
QueueWorkProc(sendConfigureNotify, NULL, copy);
lorieTriggerWorkingQueue();
break;
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/cpp/lorie/lorie.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
#include "linux/input-event-codes.h"

void lorieSetVM(JavaVM* vm);
Bool lorieChangeScreenName(ClientPtr pClient, void *closure);
Bool lorieChangeWindow(ClientPtr pClient, void *closure);
void lorieConfigureNotify(int width, int height, int framerate);
void lorieConfigureNotify(int width, int height, int framerate, size_t name_size, char* name);
void lorieEnableClipboardSync(Bool enable);
void lorieSendClipboardData(const char* data);
void lorieInitClipboard(void);
Expand Down Expand Up @@ -44,6 +43,8 @@ typedef union {
struct {
uint8_t t;
uint16_t width, height, framerate;
size_t name_size;
char *name;
} screenSize;
struct {
uint8_t t;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/termux/x11/CmdEntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static Context createContext() {
}

public static native boolean start(String[] args);
public native void windowChanged(Surface surface, String name);
public native void windowChanged(Surface surface);
public native ParcelFileDescriptor getXConnection();
public native ParcelFileDescriptor getLogcatOutput();
private static native boolean connected();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/termux/x11/LorieView.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public boolean commitText(CharSequence text, int newCursorPosition) {
static native void setClipboardSyncEnabled(boolean enabled, boolean ignored);
public native void sendClipboardAnnounce();
public native void sendClipboardEvent(byte[] text);
static native void sendWindowChange(int width, int height, int framerate);
static native void sendWindowChange(int width, int height, int framerate, String name);
public native void sendMouseEvent(float x, float y, int whichButton, boolean buttonDown, boolean relative);
public native void sendTouchEvent(int action, int id, int x, int y);
public native void sendStylusEvent(float x, float y, int pressure, int tiltX, int tiltY, int orientation, int buttons, boolean eraser, boolean mouseMode);
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/termux/x11/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,22 @@ protected void onCreate(Bundle savedInstanceState) {
lorieView.setOnKeyListener(mLorieKeyListener);

lorieView.setCallback((sfc, surfaceWidth, surfaceHeight, screenWidth, screenHeight) -> {
String name;
int framerate = (int) ((lorieView.getDisplay() != null) ? lorieView.getDisplay().getRefreshRate() : 30);

mInputHandler.handleHostSizeChanged(surfaceWidth, surfaceHeight);
mInputHandler.handleClientSizeChanged(screenWidth, screenHeight);
LorieView.sendWindowChange(screenWidth, screenHeight, framerate);
if (lorieView.getDisplay() == null || lorieView.getDisplay().getDisplayId() == Display.DEFAULT_DISPLAY)
name = "Builtin Display";
else if (SamsungDexUtils.checkDeXEnabled(this))
name = "Dex Display";
else
name = "External Display";
LorieView.sendWindowChange(screenWidth, screenHeight, framerate, name);

if (service != null) {
try {
String name;
if (lorieView.getDisplay() == null || lorieView.getDisplay().getDisplayId() == Display.DEFAULT_DISPLAY)
name = "Builtin Display";
else if (SamsungDexUtils.checkDeXEnabled(this))
name = "Dex Display";
else
name = "External Display";
service.windowChanged(sfc, name);
service.windowChanged(sfc);
} catch (RemoteException e) {
Log.e("MainActivity", "failed to send windowChanged request", e);
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/termux/x11/XrActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ public void onSurfaceChanged(GL10 gl10, int w, int h) {
surface = new SurfaceTexture(texture);

runOnUiThread(() -> getLorieView().setCallback((sfc, surfaceWidth, surfaceHeight, screenWidth, screenHeight) -> {
LorieView.sendWindowChange(screenWidth, screenHeight, 60);
LorieView.sendWindowChange(screenWidth, screenHeight, 60, "OpenXR");
surface.setDefaultBufferSize(screenWidth, screenHeight);

if (service != null) {
try {
service.windowChanged(new Surface(surface), "OpenXR");
service.windowChanged(new Surface(surface));
} catch (RemoteException e) {
Log.e("XrActivity", "failed to send windowChanged request", e);
}
Expand Down

0 comments on commit 72c086c

Please sign in to comment.