From 25edb08f683aa2760f53cb14fe9a9b60f3f33498 Mon Sep 17 00:00:00 2001 From: gambas Date: Sun, 2 May 2021 00:31:54 +0200 Subject: [PATCH] The GTK+3 GLArea control now works, by forcing the legacy mode. [GB.GTK3.OPENGL] * BUG: GLArea: Force legacy mode (OpenGL < 3.2), unless the 'GDK_GL' environment variale is already defined. * BUG: GlArea: The control can now take the focus. --- gb.gtk/src/gb.gtk.h | 5 ++++- gb.gtk/src/main.cpp | 6 ++++-- gb.gtk3/src/Makefile.am | 1 - gb.gtk3/src/gglarea.cpp | 1 - gb.gtk3/src/gglarea.h | 1 - gb.gtk3/src/main.cpp | 19 +++++-------------- gb.gtk3/src/opengl/c_glarea.c | 19 +++++++------------ gb.gtk3/src/opengl/main.c | 4 ++++ gb.gtk3/src/webview/c_webview.c | 2 +- 9 files changed, 25 insertions(+), 33 deletions(-) delete mode 120000 gb.gtk3/src/gglarea.cpp delete mode 120000 gb.gtk3/src/gglarea.h diff --git a/gb.gtk/src/gb.gtk.h b/gb.gtk/src/gb.gtk.h index 15c566ffa..ca29f301e 100644 --- a/gb.gtk/src/gb.gtk.h +++ b/gb.gtk/src/gb.gtk.h @@ -44,11 +44,14 @@ typedef void *GTK_PICTURE; +#define CCF_NONE 0 +#define CCF_HAS_INPUT_METHOD 1 + typedef struct { intptr_t version; - void (*CreateControl)(void *control, void *parent, GtkWidget *widget); + void (*CreateControl)(void *control, void *parent, GtkWidget *widget, uint flags); GtkWidget *(*CreateGLArea)(void *control, void *parent, void (*init)(GtkWidget *)); GTK_PICTURE *(*CreatePicture)(cairo_surface_t *surf, int w, int h); int (*GetDesktopScale)(void); diff --git a/gb.gtk/src/main.cpp b/gb.gtk/src/main.cpp index 89e786ef9..dfb45af71 100644 --- a/gb.gtk/src/main.cpp +++ b/gb.gtk/src/main.cpp @@ -103,7 +103,7 @@ bool MAIN_rtl = false; //------------------------------------------------------------------------- -static void GTK_CreateControl(CWIDGET *ob, void *parent, GtkWidget *widget) +static void GTK_CreateControl(CWIDGET *ob, void *parent, GtkWidget *widget, uint flags) { gControl *ctrl; bool recreate; @@ -125,7 +125,9 @@ static void GTK_CreateControl(CWIDGET *ob, void *parent, GtkWidget *widget) ctrl->widget = ctrl->border; InitControl(ctrl, ob); ctrl->realize(); - ctrl->_has_input_method = TRUE; + + if (flags & CCF_HAS_INPUT_METHOD) + ctrl->_has_input_method = TRUE; if (recreate) ctrl->updateGeometry(true); diff --git a/gb.gtk3/src/Makefile.am b/gb.gtk3/src/Makefile.am index f2d37e5a9..dae15d2c5 100644 --- a/gb.gtk3/src/Makefile.am +++ b/gb.gtk3/src/Makefile.am @@ -74,5 +74,4 @@ gb_gtk3_la_SOURCES = \ gdrag.h gdrag.cpp \ gtools.h kentities.h \ gprinter.h gprinter.cpp \ - gglarea.h gglarea.cpp \ desktop.h desktop.c diff --git a/gb.gtk3/src/gglarea.cpp b/gb.gtk3/src/gglarea.cpp deleted file mode 120000 index d8935b879..000000000 --- a/gb.gtk3/src/gglarea.cpp +++ /dev/null @@ -1 +0,0 @@ -../../gb.gtk/src/gglarea.cpp \ No newline at end of file diff --git a/gb.gtk3/src/gglarea.h b/gb.gtk3/src/gglarea.h deleted file mode 120000 index 84b0fa59f..000000000 --- a/gb.gtk3/src/gglarea.h +++ /dev/null @@ -1 +0,0 @@ -../../gb.gtk/src/gglarea.h \ No newline at end of file diff --git a/gb.gtk3/src/main.cpp b/gb.gtk3/src/main.cpp index 4e0ad5d46..6e02d16d1 100644 --- a/gb.gtk3/src/main.cpp +++ b/gb.gtk3/src/main.cpp @@ -30,7 +30,6 @@ #include "gb.image.h" #include "gb.gtk.h" #include "watcher.h" -#include "gglarea.h" #include "gkey.h" #include "desktop.h" @@ -96,8 +95,6 @@ static void hook_post(void); static int hook_loop(); static void hook_watch(int fd, int type, void *callback, intptr_t param); -static GtkWidget *GTK_CreateGLArea(void *_object, void *parent, void (*init)(GtkWidget *)); - static bool _post_check = false; static bool _must_check_quit = false; @@ -114,7 +111,7 @@ bool MAIN_platform_is_wayland = false; //------------------------------------------------------------------------- -static void GTK_CreateControl(CWIDGET *ob, void *parent, GtkWidget *widget) +static void GTK_CreateControl(CWIDGET *ob, void *parent, GtkWidget *widget, uint flags) { gControl *ctrl; bool recreate; @@ -136,20 +133,14 @@ static void GTK_CreateControl(CWIDGET *ob, void *parent, GtkWidget *widget) ctrl->widget = ctrl->border; InitControl(ctrl, ob); ctrl->realize(); - ctrl->_has_input_method = TRUE; + + if (flags & CCF_HAS_INPUT_METHOD) + ctrl->_has_input_method = TRUE; if (recreate) ctrl->updateGeometry(true); } -static GtkWidget *GTK_CreateGLArea(void *_object, void *parent, void (*init)(GtkWidget *)) -{ - gControl *ctrl = new gGLArea(CONTAINER(parent), init); - InitControl(ctrl, (CWIDGET *)_object); - //WIDGET->onExpose = Darea_Expose; - return ctrl->widget; -} - static void *GTK_CreatePicture(cairo_surface_t *surf, int w, int h) { gPicture *p = new gPicture(surf); @@ -255,7 +246,7 @@ void *GB_GTK3_1[] EXPORT = { (void *)GTK_INTERFACE_VERSION, (void *)GTK_CreateControl, - (void *)GTK_CreateGLArea, + (void *)NULL, (void *)GTK_CreatePicture, (void *)GTK_GetDesktopScale, NULL diff --git a/gb.gtk3/src/opengl/c_glarea.c b/gb.gtk3/src/opengl/c_glarea.c index cd6157b51..e3a75fd7f 100644 --- a/gb.gtk3/src/opengl/c_glarea.c +++ b/gb.gtk3/src/opengl/c_glarea.c @@ -26,12 +26,12 @@ #include #include "c_glarea.h" -//-- GLArea ----------------------------------------------------------------- - DECLARE_EVENT(EVENT_Open); DECLARE_EVENT(EVENT_Draw); DECLARE_EVENT(EVENT_Resize); +//------------------------------------------------------------------------- + static void init_control(void *_object) { if (THIS->init) @@ -64,14 +64,16 @@ static gboolean cb_render(GtkGLArea *area, GdkGLContext *context, void *_object) return TRUE; } +//------------------------------------------------------------------------- BEGIN_METHOD(GLArea_new, GB_OBJECT parent) THIS->widget = gtk_gl_area_new(); - GTK.CreateControl(THIS, VARG(parent), THIS->widget); + GTK.CreateControl(THIS, VARG(parent), THIS->widget, CCF_NONE); + gtk_widget_set_can_focus(THIS->widget, TRUE); - gtk_gl_area_set_has_alpha(WIDGET, TRUE); + //gtk_gl_area_set_has_alpha(WIDGET, TRUE); gtk_gl_area_set_has_depth_buffer(WIDGET, TRUE); gtk_gl_area_set_has_stencil_buffer(WIDGET, TRUE); @@ -87,15 +89,8 @@ GB_DESC GLAreaDesc[] = { GB_DECLARE("GLArea", sizeof(CGLAREA)), GB_INHERITS("Control"), - //GB_STATIC_METHOD("_exit", NULL, GLArea_exit, NULL), - GB_METHOD("_new", NULL, GLArea_new, "(Parent)Container;"), - //GB_METHOD("_free", NULL, GLArea_free, NULL), - //GB_METHOD("Update", NULL, GLArea_update, NULL), - //GB_METHOD("Refresh", NULL, GLArea_Refresh, NULL), - //GB_METHOD("Select", NULL, CGLAREA_select, NULL), - //GB_METHOD("Text", NULL, CGLAREA_text, "(Text)s(X)i(Y)i"), - + GB_CONSTANT("_Group", "s", "Special"), GB_EVENT("Open", NULL, NULL, &EVENT_Open), diff --git a/gb.gtk3/src/opengl/main.c b/gb.gtk3/src/opengl/main.c index c98739cdc..6c06b9bde 100644 --- a/gb.gtk3/src/opengl/main.c +++ b/gb.gtk3/src/opengl/main.c @@ -39,6 +39,10 @@ GB_DESC *GB_CLASSES[] EXPORT = int EXPORT GB_INIT(void) { + char *env = getenv("GDK_GL"); + if (!env || !*env) + putenv("GDK_GL=legacy"); + GB.GetInterface("gb.gtk3", GTK_INTERFACE_VERSION, >K); GB.GetInterface("gb.opengl", GL_INTERFACE_VERSION, &GL); diff --git a/gb.gtk3/src/webview/c_webview.c b/gb.gtk3/src/webview/c_webview.c index 87e4452bf..5d1aa3055 100644 --- a/gb.gtk3/src/webview/c_webview.c +++ b/gb.gtk3/src/webview/c_webview.c @@ -233,7 +233,7 @@ static void create_widget(void *_object, void *parent) { THIS->widget = webkit_web_view_new(); - GTK.CreateControl(THIS, parent, THIS->widget); + GTK.CreateControl(THIS, parent, THIS->widget, CCF_HAS_INPUT_METHOD); PATCH_CLASS(THIS->widget, WEBKIT_TYPE_WEB_VIEW)