Skip to content

8354943: [Linux] Simplify and update glass gtk backend: window sizing, positioning, and state management issues #1789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package com.sun.glass.ui.gtk;

import com.sun.glass.events.ViewEvent;
import com.sun.glass.ui.Pixels;
import com.sun.glass.ui.View;

Expand Down Expand Up @@ -98,8 +99,18 @@ protected void _uploadPixels(long ptr, Pixels pixels) {
private native void _uploadPixelsByteArray(long viewPtr, byte[] pixels, int offset, int width, int height);
private native void _uploadPixelsIntArray(long viewPtr, int[] pixels, int offset, int width, int height);

protected native void enterFullscreenImpl(long ptr, boolean animate, boolean keepRatio, boolean hideCursor);

@Override
protected native boolean _enterFullscreen(long ptr, boolean animate, boolean keepRatio, boolean hideCursor);
protected boolean _enterFullscreen(long ptr, boolean animate, boolean keepRatio, boolean hideCursor) {
enterFullscreenImpl(ptr, animate, keepRatio, hideCursor);

if (getWindow() != null && !getWindow().isVisible()) {
notifyView(ViewEvent.FULLSCREEN_ENTER);
}

return true;
}

@Override
protected native void _exitFullscreen(long ptr, boolean animate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ protected boolean _setMenubar(long ptr, long menubarPtr) {
protected native void _setLevel(long ptr, int level);

@Override
protected native void _setAlpha(long ptr, float alpha);
protected void _setAlpha(long ptr, float alpha) {
// Not supported
}

@Override
protected native boolean _setBackground(long ptr, float r, float g, float b);
protected boolean _setBackground(long ptr, float r, float g, float b) {
//Not supported
return false;
}

@Override
protected native void _setEnabled(long ptr, boolean enabled);
Expand Down Expand Up @@ -128,16 +133,24 @@ protected boolean _setVisible(long ptr, boolean visible) {
@Override
protected boolean _minimize(long ptr, boolean minimize) {
minimizeImpl(ptr, minimize);
notifyStateChanged(WindowEvent.MINIMIZE);
return minimize;

if (!isVisible()) {
notifyStateChanged(WindowEvent.MINIMIZE);
}

return isMinimized();
}

@Override
protected boolean _maximize(long ptr, boolean maximize,
boolean wasMaximized) {
maximizeImpl(ptr, maximize, wasMaximized);
notifyStateChanged(WindowEvent.MAXIMIZE);
return maximize;

if (!isVisible()) {
notifyStateChanged(WindowEvent.MAXIMIZE);
}

return isMaximized();
}

protected void notifyStateChanged(final int state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,12 @@ static void process_events(GdkEvent* event, gpointer data)
try {
switch (event->type) {
case GDK_PROPERTY_NOTIFY:
// let gtk handle it first to prevent a glitch
gtk_main_do_event(event);
ctx->process_property_notify(&event->property);
gtk_main_do_event(event);
break;
case GDK_CONFIGURE:
ctx->process_configure(&event->configure);
gtk_main_do_event(event);
ctx->process_configure(&event->configure);
break;
case GDK_FOCUS_CHANGE:
ctx->process_focus(&event->focus_change);
Expand All @@ -503,11 +502,12 @@ static void process_events(GdkEvent* event, gpointer data)
break;
case GDK_EXPOSE:
case GDK_DAMAGE:
ctx->process_expose(&event->expose);
ctx->notify_repaint(&event->expose.area);
break;
case GDK_WINDOW_STATE:
ctx->process_state(&event->window_state);
// Let gtk handle it first, so state functions are updated
gtk_main_do_event(event);
ctx->process_state(&event->window_state);
break;
case GDK_BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
Expand Down Expand Up @@ -535,7 +535,8 @@ static void process_events(GdkEvent* event, gpointer data)
process_dnd_target(ctx, &event->dnd);
break;
case GDK_MAP:
// fall-through
ctx->process_map();
break;
case GDK_UNMAP:
case GDK_CLIENT_EVENT:
case GDK_VISIBILITY_NOTIFY:
Expand All @@ -550,6 +551,7 @@ static void process_events(GdkEvent* event, gpointer data)
}
} else {

//FIXME: Those do not work anymore
if (window == gdk_screen_get_root_window(gdk_screen_get_default())) {
if (event->any.type == GDK_PROPERTY_NOTIFY) {
if (event->property.atom == gdk_atom_intern_static_string("_NET_WORKAREA")
Expand Down
15 changes: 4 additions & 11 deletions modules/javafx.graphics/src/main/native-glass/gtk/GlassView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,19 @@ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkView__1uploadPixelsByteArray

/*
* Class: com_sun_glass_ui_gtk_GtkView
* Method: _enterFullscreen
* Signature: (JZZZ)Z
* Method: enterFullscreenImpl
* Signature: (JZZZ)V
*/
JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_gtk_GtkView__1enterFullscreen
(JNIEnv * env, jobject obj, jlong ptr, jboolean animate, jboolean keepRation, jboolean hideCursor)
{
JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkView_enterFullscreenImpl
(JNIEnv * env, jobject obj, jlong ptr, jboolean animate, jboolean keepRation, jboolean hideCursor) {
(void)animate;
(void)keepRation;
(void)hideCursor;

GlassView* view = JLONG_TO_GLASSVIEW(ptr);
if (view->current_window) {
view->current_window->enter_fullscreen();
env->CallVoidMethod(obj, jViewNotifyView, com_sun_glass_events_ViewEvent_FULLSCREEN_ENTER);
CHECK_JNI_EXCEPTION_RET(env, JNI_FALSE)
}
return JNI_TRUE;
}

/*
Expand All @@ -307,10 +303,7 @@ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkView__1exitFullscreen
} else {
view->current_window->exit_fullscreen();
}
env->CallVoidMethod(obj, jViewNotifyView, com_sun_glass_events_ViewEvent_FULLSCREEN_EXIT);
CHECK_JNI_EXCEPTION(env)
}

}

} // extern "C"
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1createWindow

WindowContext* parent = JLONG_TO_WINDOW_CTX(owner);

WindowContext* ctx = new WindowContextTop(obj,
WindowContext* ctx = new WindowContext(obj,
parent,
screen,
glass_mask_to_window_frame_type(mask),
Expand Down Expand Up @@ -312,37 +312,6 @@ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1setLevel
ctx->set_level(level);
}

/*
* Class: com_sun_glass_ui_gtk_GtkWindow
* Method: _setAlpha
* Signature: (JF)V
*/
JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1setAlpha
(JNIEnv * env, jobject obj, jlong ptr, jfloat alpha)
{
(void)env;
(void)obj;

WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
ctx->set_alpha(alpha);
}

/*
* Class: com_sun_glass_ui_gtk_GtkWindow
* Method: _setBackground
* Signature: (JFFF)Z
*/
JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1setBackground
(JNIEnv * env, jobject obj, jlong ptr, jfloat r, jfloat g, jfloat b)
{
(void)env;
(void)obj;

WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
ctx->set_background(r, g, b);
return JNI_TRUE;
}

/*
* Class: com_sun_glass_ui_gtk_GtkWindow
* Method: _setEnabled
Expand Down Expand Up @@ -388,8 +357,6 @@ JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1setMaximumSize

WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
if (w == 0 || h == 0) return JNI_FALSE;
if (w == -1) w = G_MAXSHORT;
if (h == -1) h = G_MAXSHORT;

ctx->set_maximum_size(w, h);
return JNI_TRUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ jmethodID jWindowNotifyDelegatePtr;
jfieldID jWindowPtr;
jfieldID jCursorPtr;

jmethodID jGtkWindowNotifyStateChanged;

jmethodID jClipboardContentChanged;

jmethodID jSizeInit;
Expand Down Expand Up @@ -269,9 +267,6 @@ JNI_OnLoad(JavaVM *jvm, void *reserved)

clazz = env->FindClass("com/sun/glass/ui/gtk/GtkWindow");
if (env->ExceptionCheck()) return JNI_ERR;
jGtkWindowNotifyStateChanged =
env->GetMethodID(clazz, "notifyStateChanged", "(I)V");
if (env->ExceptionCheck()) return JNI_ERR;

clazz = env->FindClass("com/sun/glass/ui/Clipboard");
if (env->ExceptionCheck()) return JNI_ERR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ struct jni_exception: public std::exception {
extern jfieldID jWindowPtr; // com.sun.glass.ui.Window#ptr
extern jfieldID jCursorPtr; // com.sun.glass.ui.Cursor#ptr

extern jmethodID jGtkWindowNotifyStateChanged; // com.sun.glass.ui.GtkWindow#notifyStateChanged (I)V

extern jmethodID jClipboardContentChanged; // com.sun.glass.ui.Clipboard#contentChanged ()V

extern jmethodID jSizeInit; // com.sun.class.ui.Size#<init> ()V
Expand Down Expand Up @@ -249,6 +247,8 @@ struct jni_exception: public std::exception {
#define LOG3(msg, param1, param2, param3) {printf(msg, param1, param2, param3);fflush(stdout);}
#define LOG4(msg, param1, param2, param3, param4) {printf(msg, param1, param2, param3, param4);fflush(stdout);}
#define LOG5(msg, param1, param2, param3, param4, param5) {printf(msg, param1, param2, param3, param4, param5);fflush(stdout);}
#define LOG10(msg, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10) \
{printf(msg, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10);fflush(stdout);}

#define LOG_STRING_ARRAY(env, array) dump_jstring_array(env, array);

Expand All @@ -264,6 +264,7 @@ struct jni_exception: public std::exception {
#define LOG3(msg, param1, param2, param3)
#define LOG4(msg, param1, param2, param3, param4)
#define LOG5(msg, param1, param2, param3, param4, param5)
#define LOG10(msg, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10)

#define LOG_STRING_ARRAY(env, array)

Expand Down
Loading