use Activity title as window title

This commit is contained in:
Julian Winkler
2024-11-03 08:26:11 +01:00
parent e541d87fc2
commit fc0091a989
4 changed files with 22 additions and 0 deletions

View File

@@ -14,6 +14,14 @@ JNIEXPORT void JNICALL Java_android_view_Window_set_1widget_1as_1root(JNIEnv *en
} }
} }
JNIEXPORT void JNICALL Java_android_view_Window_set_1title(JNIEnv *env, jobject this, jlong window, jstring title_jstr)
{
GtkWindow *gtk_window = GTK_WINDOW(_PTR(window));
const char *title = (*env)->GetStringUTFChars(env, title_jstr, NULL);
gtk_window_set_title(gtk_window, title);
(*env)->ReleaseStringUTFChars(env, title_jstr, title);
}
// FIXME put this in a header file // FIXME put this in a header file
struct input_queue { struct input_queue {
int fd; int fd;

View File

@@ -19,6 +19,14 @@ extern "C" {
JNIEXPORT void JNICALL Java_android_view_Window_set_1widget_1as_1root JNIEXPORT void JNICALL Java_android_view_Window_set_1widget_1as_1root
(JNIEnv *, jobject, jlong, jlong); (JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_view_Window
* Method: set_title
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_android_view_Window_set_1title
(JNIEnv *, jobject, jlong, jstring);
/* /*
* Class: android_view_Window * Class: android_view_Window
* Method: take_input_queue * Method: take_input_queue

View File

@@ -168,6 +168,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
System.out.println("- onStart - yay!"); System.out.println("- onStart - yay!");
if (window.contentView != null) if (window.contentView != null)
window.setContentView(window.contentView); window.setContentView(window.contentView);
window.setTitle(title);
for (Fragment fragment : fragments) { for (Fragment fragment : fragments) {
fragment.onStart(); fragment.onStart();

View File

@@ -68,6 +68,7 @@ public class Window {
} }
private native void set_widget_as_root(long native_window, long widget); private native void set_widget_as_root(long native_window, long widget);
private native void set_title(long native_window, String title);
public native void take_input_queue(long native_window, InputQueue.Callback callback, InputQueue queue); public native void take_input_queue(long native_window, InputQueue.Callback callback, InputQueue queue);
@@ -133,4 +134,8 @@ public class Window {
public boolean hasFeature(int featureId) { public boolean hasFeature(int featureId) {
return false; return false;
} }
public void setTitle(CharSequence title) {
set_title(native_window, title != null ? title.toString() : context.getPackageName());
}
} }