Skip to content
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

Scim GTK4 immodule crashing on Wayland (incorrect code) #38

Open
hosiet opened this issue Aug 4, 2023 · 1 comment
Open

Scim GTK4 immodule crashing on Wayland (incorrect code) #38

hosiet opened this issue Aug 4, 2023 · 1 comment

Comments

@hosiet
Copy link

hosiet commented Aug 4, 2023

Forwarding comments from https://bugs.debian.org/1042759#37 :

On Mon, 31 Jul 2023 at 20:57:25 +0200, Michał Byrecki wrote:
> > (org.gnome.Nautilus:51577): GLib-GObject-WARNING **: 20:53:04.844:
> > invalid cast from 'GdkWaylandToplevel' to 'GdkX11Surface'
> > 
> > (org.gnome.Nautilus:51577): GLib-GObject-WARNING **: 20:53:04.844:
> > invalid cast from 'GdkWaylandDisplay' to 'GdkX11Display'

These warnings indicate that a component is assuming that all windows
are X11 windows, and all displays are X11 displays; and that's also the
cause of the segfault, while calling XGetWindowAttributes on something
that is not a valid X11 window (probably a null pointer dereference).

> > #1  0x00007ffff070d467 in  () at /usr/lib/x86_64-linux-gnu/gtk-4.0/4.0.0/immodules/libim-scim.so

This component seems to be the one that is making that assumption.
The bug affects multiple GTK 4 apps because it's a module that has been
loaded into GTK 4.

Looking at scim-gtk-immodule's GTK 4 code in
<https://github.com/scim-im/scim/commit/d35bf5d331d885e94914fea6eab9c56f20666c8d>,
it does things like this:

> #ifdef GDK_WINDOWING_X11
>     GdkX11Display *display = NULL;
> 
>     if (widget != NULL) {
>         display = GDK_X11_DISPLAY (gtk_widget_get_display(widget));
>     } else {
>         display = GDK_X11_DISPLAY (gdk_display_get_default ());
>     }

That's not correct code: just because the X11 windowing system is
compiled into GTK, that doesn't mean it is the one currently in use. The
GdkDisplay object might be a GdkX11Display, but equally it might be a
GdkWaylandDisplay. (That's why GDK_BACKEND=x11 is a workaround for this,
because when that environment variable is set, the X11 windowing system
*is* the one in use.)

I haven't checked what scim-gtk-immodule does for GTK 3, but if it has the
same pattern there, it would be equally problematic for GTK 3.

The correct pattern is more like this:

    GdkDisplay *display;

    if (widget != NULL) {
        display = gtk_widget_get_display (widget));
    } else {
        display = gdk_display_get_default ();
    }

#ifdef GDK_WINDOWING_X11
    if (GDK_IS_X11_DISPLAY (display) {
        GdkX11Display *x11_display = GDK_X11_DISPLAY (display);

        /* ... do X11 things with x11_display ... */
    }
#endif
#ifdef GDK_WINDOWING_WAYLAND
    if (GDK_IS_WAYLAND_DISPLAY (display) {
        GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY (display);

        /* ... do Wayland things with wayland_display ... */
    }
#endif

Until scim-gtk-immodule is fixed, the workaround would be to either set
GDK_BACKEND=x11, or use an X11 desktop environment or a desktop environment
in X11 mode (like the "GNOME (Xorg)" option for GNOME), or remove
scim-gtk-immodule and use a different input method framework such as ibus.
@tzhuan
Copy link
Member

tzhuan commented Aug 5, 2023

Thank you very much for the bug report. I have pushed a fix to the bugfix-x11-display branch. However, there are still some issues:

  • The preedit area position is incorrect for some application (e.g. gnome-terminal)
  • I don't have a gtk4 application in hand right now. I just test it for gtk3 application in the wayland environment and it works well.

I'll try to address the issues and make a new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants