diff --git a/src/api-impl-jni/views/android_view_View.c b/src/api-impl-jni/views/android_view_View.c index 7c718302..78b6d407 100644 --- a/src/api-impl-jni/views/android_view_View.c +++ b/src/api-impl-jni/views/android_view_View.c @@ -1,6 +1,8 @@ -#include +#include #include +#include + #include "../defines.h" #include "../util.h" @@ -51,12 +53,20 @@ static bool call_ontouch_callback(int action, double x, double y, struct touch_c } static void gdk_event_get_widget_relative_position(GdkEvent *event, GtkWidget *widget, double *x, double *y) { + int ret; + + graphene_point_t p; double off_x; double off_y; + gdk_event_get_position(event, x, y); GtkWidget *window = GTK_WIDGET(gtk_widget_get_native(widget)); gtk_native_get_surface_transform(GTK_NATIVE(window), &off_x, &off_y); - gtk_widget_translate_coordinates(window, widget, *x - off_x, *y - off_y, x, y); + ret = gtk_widget_compute_point(window, widget, &GRAPHENE_POINT_INIT(*x - off_x, *y - off_y), &p); + assert(ret); + + *x = p.x; + *y = p.y; } // TODO: find a way to reconcile this with libandroid/input.c? @@ -439,19 +449,29 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1requestLayout(JNIEnv *env, gtk_widget_queue_resize(widget); } -// FIXME: this will probably behave unfortunately if called multiple times +/* we kinda need per-widget css */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" JNIEXPORT void JNICALL Java_android_view_View_setBackgroundColor(JNIEnv *env, jobject this, jint color) { GtkWidget *widget = GTK_WIDGET(_PTR(_GET_LONG_FIELD(this, "widget"))); + GtkStyleContext *style_context = gtk_widget_get_style_context(widget); + + GtkCssProvider *old_provider = g_object_get_data(G_OBJECT(widget), "background_color_style_provider"); + if(old_provider) + gtk_style_context_remove_provider(style_context, GTK_STYLE_PROVIDER(old_provider)); + GtkCssProvider *css_provider = gtk_css_provider_new(); char *css_string = g_markup_printf_escaped("* { background-image: none; background-color: #%06x%02x; }", color & 0xFFFFFF, (color >> 24) & 0xFF); gtk_css_provider_load_from_string(css_provider, css_string); g_free(css_string); - gtk_style_context_add_provider(gtk_widget_get_style_context(widget), GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + gtk_style_context_add_provider(style_context, GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_set_data(G_OBJECT(widget), "background_color_style_provider", css_provider); } +#pragma GCC diagnostic pop JNIEXPORT void JNICALL Java_android_view_View_native_1setBackgroundDrawable(JNIEnv *env, jobject this, jlong widget_ptr, jlong paintable_ptr) { GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr)); diff --git a/src/api-impl-jni/widgets/android_widget_TextView.c b/src/api-impl-jni/widgets/android_widget_TextView.c index ebc08d9f..0081be34 100644 --- a/src/api-impl-jni/widgets/android_widget_TextView.c +++ b/src/api-impl-jni/widgets/android_widget_TextView.c @@ -47,6 +47,9 @@ JNIEXPORT void JNICALL Java_android_widget_TextView_native_1setText(JNIEnv *env, (*env)->ReleaseStringUTFChars(env, charseq, text); } +/* we kinda need per-widget css */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" JNIEXPORT void JNICALL Java_android_widget_TextView_native_1setTextColor(JNIEnv *env, jobject this, jint color) { GtkWidget *widget = GTK_WIDGET(box_get_label(env, _PTR(_GET_LONG_FIELD(this, "widget")))); @@ -66,6 +69,7 @@ JNIEXPORT void JNICALL Java_android_widget_TextView_native_1setTextColor(JNIEnv gtk_style_context_add_provider(style_context, GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_object_set_data(G_OBJECT(widget), "color_style_provider", css_provider); } +#pragma GCC diagnostic pop JNIEXPORT void JNICALL Java_android_widget_TextView_setTextSize(JNIEnv *env, jobject this, jfloat size) { diff --git a/src/libandroid/input.c b/src/libandroid/input.c index e393e1f1..828153d1 100644 --- a/src/libandroid/input.c +++ b/src/libandroid/input.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -173,8 +174,15 @@ static inline void make_touch_event(GdkEvent* event, GtkEventControllerLegacy* e // apps expect it to start at the top left of the area where child widgets get placed, so that // the top left of the window is the same as the top left of a single widget filling the entire window // while it's quite hacky, the following should realistically work for most if not all cases - if(child = gtk_window_get_child(GTK_WINDOW(window))) - gtk_widget_translate_coordinates(window, child, ainput_event->x, ainput_event->y, &ainput_event->x, &ainput_event->y); + if((child = gtk_window_get_child(GTK_WINDOW(window)))) { + int ret; + graphene_point_t p; + ret = gtk_widget_compute_point(window, child, &GRAPHENE_POINT_INIT(ainput_event->x, ainput_event->y), &p); + assert(ret); + + ainput_event->x = p.x; + ainput_event->y = p.y; + } switch(gdk_event_get_event_type(event)) { case GDK_BUTTON_PRESS: diff --git a/src/libandroid/native_window.c b/src/libandroid/native_window.c index 015ed4f1..630e2865 100644 --- a/src/libandroid/native_window.c +++ b/src/libandroid/native_window.c @@ -44,6 +44,7 @@ #define XR_USE_PLATFORM_EGL #include +#include #include #include @@ -251,8 +252,9 @@ ANativeWindow * ANativeWindow_fromSurface(JNIEnv* env, jobject surface) int width; int height; - double pos_x; - double pos_y; + int ret; + + graphene_point_t pos; double off_x; double off_y; @@ -273,14 +275,15 @@ ANativeWindow * ANativeWindow_fromSurface(JNIEnv* env, jobject surface) // get position of the SurfaceView widget wrt the toplevel window - gtk_widget_translate_coordinates(surface_view_widget, window, 0, 0, &pos_x, &pos_y); + ret = gtk_widget_compute_point(surface_view_widget, window, &GRAPHENE_POINT_INIT(0, 0), &pos); + assert(ret); // compensate for offset between the widget coordinates and the surface coordinates gtk_native_get_surface_transform(GTK_NATIVE(window), &off_x, &off_y); - pos_x += off_x; - pos_y += off_y; + pos.x += off_x; + pos.y += off_y; printf("XXXXX: SurfaceView widget: %p (%s), width: %d, height: %d\n", surface_view_widget, gtk_widget_get_name(surface_view_widget), width, height); - printf("XXXXX: SurfaceView widget: x: %lf, y: %lf\n", pos_x, pos_y); + printf("XXXXX: SurfaceView widget: x: %lf, y: %lf\n", pos.x, pos.y); printf("XXXXX: native offset: x: %lf, y: %lf\n", off_x, off_y); struct ANativeWindow *native_window = calloc(1, sizeof(struct ANativeWindow)); @@ -306,7 +309,7 @@ ANativeWindow * ANativeWindow_fromSurface(JNIEnv* env, jobject surface) struct wl_subsurface *subsurface = wl_subcompositor_get_subsurface(wl_subcompositor, wayland_surface, toplevel_surface); wl_subsurface_set_desync(subsurface); - wl_subsurface_set_position(subsurface, pos_x, pos_y); + wl_subsurface_set_position(subsurface, pos.x, pos.y); struct wl_region *empty_region = wl_compositor_create_region(wl_compositor); wl_surface_set_input_region(wayland_surface, empty_region);