You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement WindowManager for composeUI popups
currently everything is created as GtkPopover which is not ideal for toplevel windows, so print a warning in that case.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class android_view_WindowManagerImpl */
|
||||
|
||||
#ifndef _Included_android_view_WindowManagerImpl
|
||||
#define _Included_android_view_WindowManagerImpl
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: android_view_WindowManagerImpl
|
||||
* Method: native_addView
|
||||
* Signature: (JIIIII)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1addView
|
||||
(JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: android_view_WindowManagerImpl
|
||||
* Method: native_updateViewLayout
|
||||
* Signature: (JIIII)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1updateViewLayout
|
||||
(JNIEnv *, jclass, jlong, jint, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: android_view_WindowManagerImpl
|
||||
* Method: native_removeView
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1removeView
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
45
src/api-impl-jni/views/android_view_WindowManagerImpl.c
Normal file
45
src/api-impl-jni/views/android_view_WindowManagerImpl.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "../defines.h"
|
||||
#include "gdk/gdk.h"
|
||||
#include "glib-object.h"
|
||||
#include "../generated_headers/android_view_WindowManagerImpl.h"
|
||||
|
||||
#define FIRST_SUB_WINDOW 1000
|
||||
#define LAST_SUB_WINDOW 1999
|
||||
|
||||
extern GtkWindow *window;
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1addView(JNIEnv *env, jclass clazz, jlong widget_ptr, jint type, jint x, jint y, jint width, jint height)
|
||||
{
|
||||
GtkWidget *widget = _PTR(widget_ptr);
|
||||
if (type < FIRST_SUB_WINDOW || type > LAST_SUB_WINDOW) {
|
||||
// TODO: handle toplevel windows properly
|
||||
printf("WARNING: non subwindow types not implemented properly in WindowManagerImpl\n");
|
||||
}
|
||||
GtkPopover *popover = GTK_POPOVER(g_object_ref(gtk_popover_new()));
|
||||
gtk_popover_set_child(popover, gtk_widget_get_parent(widget));
|
||||
printf("::: x=%d, y=%d, width=%d, height=%d\n", x, y, width, height);
|
||||
gtk_popover_set_autohide(popover, FALSE);
|
||||
gtk_popover_set_pointing_to(popover, &(GdkRectangle){.x=x, .y=y});
|
||||
gtk_widget_insert_before(GTK_WIDGET(popover), gtk_window_get_child(window), NULL);
|
||||
gtk_popover_present(popover);
|
||||
gtk_popover_popup(popover);
|
||||
gtk_widget_queue_allocate(gtk_widget_get_parent(gtk_window_get_child(window)));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1updateViewLayout(JNIEnv *env, jclass clazz, jlong widget_ptr, jint x, jint y, jint width, jint height)
|
||||
{
|
||||
GtkPopover *popover = GTK_POPOVER(gtk_widget_get_parent(gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr))))));
|
||||
printf("updateViewLayout::: x=%d, y=%d, width=%d, height=%d\n", x, y, width, height);
|
||||
gtk_popover_set_pointing_to(popover, &(GdkRectangle){.x=x, .y=y});
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1removeView(JNIEnv *env, jclass clazz, jlong widget_ptr)
|
||||
{
|
||||
GtkPopover *popover = GTK_POPOVER(gtk_widget_get_parent(gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr))))));
|
||||
gtk_popover_popdown(popover);
|
||||
gtk_widget_unparent(GTK_WIDGET(popover));
|
||||
gtk_popover_set_child(popover, NULL);
|
||||
g_object_unref(popover);
|
||||
}
|
||||
Reference in New Issue
Block a user