Skip to content

Commit

Permalink
8260528: Clean glass-gtk sizing and positioning code
Browse files Browse the repository at this point in the history
Reviewed-by: jvos, kcr
  • Loading branch information
Thiago Milczarek Sayao committed Apr 7, 2023
1 parent 2b2a7f1 commit 0c03a41
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 575 deletions.
Expand Up @@ -60,8 +60,6 @@ protected boolean _setMenubar(long ptr, long menubarPtr) {

private native void maximizeImpl(long ptr, boolean maximize, boolean wasMaximized);

private native void setBoundsImpl(long ptr, int x, int y, boolean xSet, boolean ySet, int w, int h, int cw, int ch);

private native void setVisibleImpl(long ptr, boolean visible);

@Override
Expand Down Expand Up @@ -185,27 +183,10 @@ public long getNativeWindow() {
return _getNativeWindowImpl(super.getNativeWindow());
}

private native void _setGravity(long ptr, float xGravity, float yGravity);

@Override
protected void _setBounds(long ptr, int x, int y, boolean xSet, boolean ySet, int w, int h, int cw, int ch, float xGravity, float yGravity) {
_setGravity(ptr, xGravity, yGravity);
setBoundsImpl(ptr, x, y, xSet, ySet, w, h, cw, ch);

if ((w <= 0) && (cw > 0) || (h <= 0) && (ch > 0)) {
final int[] extarr = new int[4];
getFrameExtents(ptr, extarr);

// TODO: ((w <= 0) && (cw <= 0)) || ((h <= 0) && (ch <= 0))
notifyResize(WindowEvent.RESIZE,
((w <= 0) && (cw > 0)) ? cw + extarr[0] + extarr[1]
: w,
((h <= 0) && (ch > 0)) ? ch + extarr[2] + extarr[3]
: h);
}
}

private native void getFrameExtents(long ptr, int[] extarr);
protected native void _setBounds(long ptr, int x, int y, boolean xSet, boolean ySet,
int w, int h, int cw, int ch,
float xGravity, float yGravity);

@Override
protected void _requestInput(long ptr, String text, int type, double width, double height,
Expand Down
Expand Up @@ -453,8 +453,9 @@ static void process_events(GdkEvent* event, gpointer data)
try {
switch (event->type) {
case GDK_PROPERTY_NOTIFY:
ctx->process_property_notify(&event->property);
// let gtk handle it first to prevent a glitch
gtk_main_do_event(event);
ctx->process_property_notify(&event->property);
break;
case GDK_CONFIGURE:
ctx->process_configure(&event->configure);
Expand Down Expand Up @@ -505,7 +506,6 @@ static void process_events(GdkEvent* event, gpointer data)
process_dnd_target(ctx, &event->dnd);
break;
case GDK_MAP:
ctx->process_map();
// fall-through
case GDK_UNMAP:
case GDK_CLIENT_EVENT:
Expand Down
52 changes: 9 additions & 43 deletions modules/javafx.graphics/src/main/native-glass/gtk/GlassWindow.cpp
Expand Up @@ -172,17 +172,17 @@ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow_maximizeImpl

/*
* Class: com_sun_glass_ui_gtk_GtkWindow
* Method: setBoundsImpl
* Signature: (JIIZZIIII)V
* Method: _setBounds
* Signature: (JIIZZIIIIFF)V
*/
JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow_setBoundsImpl
(JNIEnv * env, jobject obj, jlong ptr, jint x, jint y, jboolean xSet, jboolean ySet, jint w, jint h, jint cw, jint ch)
{
JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1setBounds
(JNIEnv * env, jobject obj, jlong ptr, jint x, jint y, jboolean xSet, jboolean ySet,
jint w, jint h, jint cw, jint ch, jfloat xGravity, jfloat yGravity) {
(void)env;
(void)obj;

WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
ctx->set_bounds(x, y, xSet, ySet, w, h, cw, ch);
ctx->set_bounds(x, y, xSet, ySet, w, h, cw, ch, xGravity, yGravity);
}

/*
Expand Down Expand Up @@ -428,7 +428,7 @@ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1toFront
(void)obj;

WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
ctx->restack(true);
ctx->to_front();
}

/*
Expand All @@ -443,8 +443,7 @@ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1toBack
(void)obj;

WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
ctx->restack(false);

ctx->to_back();
}

/*
Expand Down Expand Up @@ -539,6 +538,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_gtk_GtkWindow_isVisible
WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
return ctx->is_visible() ? JNI_TRUE : JNI_FALSE;
}

JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1getNativeWindowImpl
(JNIEnv * env, jobject obj, jlong ptr)
{
Expand All @@ -548,39 +548,5 @@ JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1getNativeWindowImp
WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
return GDK_WINDOW_XID(ctx->get_gdk_window());
}
/*
* Class: com_sun_glass_ui_gtk_GtkWindow
* Method: getFrameExtents
* Signature: (J[I)V
*/
JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow_getFrameExtents
(JNIEnv * env, jobject obj, jlong ptr, jintArray extarr)
{
(void)obj;

WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
WindowFrameExtents extents = ctx->get_frame_extents();

env->SetIntArrayRegion(extarr, 0, 1, &extents.left);
env->SetIntArrayRegion(extarr, 1, 1, &extents.right);
env->SetIntArrayRegion(extarr, 2, 1, &extents.top);
env->SetIntArrayRegion(extarr, 3, 1, &extents.bottom);
}

/*
* Class: com_sun_glass_ui_gtk_GtkWindow
* Method: _setGravity
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1setGravity
(JNIEnv * env, jobject obj, jlong ptr, jfloat xGravity, jfloat yGravity)
{
(void)env;
(void)obj;

WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
ctx->set_gravity(xGravity, yGravity);

}

} // extern "C"

1 comment on commit 0c03a41

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.