HoverDisplay is invisible
I built a custom HoverProvider and populate the HoverDisplay. When opening the window (see reproducer) and hovering a word - the virtual function populate
is called but the HoverDisplay is invisible.
It steals the focus and sometimes prevents me from closing the window. It also appears to make GNOME Shell behave erratically at times (windows overview imeditaly closes).
If you are patient and click around – it will become visible after hovering again, but it looks misplaced.
- Fedora 36 Wayland
- GtkSourceView 5.4.2 but also reproduced with master
- GTK 4.6.6
Steps to reproduce
- Open the reproducer
- Move the mouse cursor over “world”
What happens
Nothing is visible, but the focus is stolen.
What should happen
The HoverDisplay is visible
// run with $ gjs -m reproduce.js
import Gtk from "gi://Gtk?version=4.0";
import Source from "gi://GtkSource?version=5";
import GObject from "gi://GObject";
import GLib from "gi://GLib";
const mainloop = new GLib.MainLoop(null, false);
Gtk.init();
Source.init();
const builder = new Gtk.Builder();
builder.add_from_string(
`
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkWindow" id="window">
<property name="default-width">800</property>
<property name="default-height">600</property>
<child type="content">
<object class="GtkScrolledWindow">
<property name="vexpand">true</property>
<property name="hexpand">true</property>
<child>
<object class="GtkSourceView" id="source_view">
<property name="buffer">
<object class="GtkSourceBuffer">
<property name="text">
hello world
</property>
</object>
</property>
<property name="monospace">true</property>
<property name="auto-indent">true</property>
<property name="highlight-current-line">true</property>
<property name="indent-on-tab">true</property>
<property name="indent-width">2</property>
<property name="insert-spaces-instead-of-tabs">true</property>
<property name="show-line-marks">true</property>
<property name="show-line-numbers">true</property>
<property name="smart-backspace">true</property>
<property name="tab-width">2</property>
</object>
</child>
</object>
</child>
</object>
</interface>
`,
-1
);
const window = builder.get_object("window");
const source_view = builder.get_object("source_view");
const WorkbenchHoverProvider = GObject.registerClass(
{
GTypeName: "WorkbenchHoverProvider",
Implements: [Source.HoverProvider],
},
class WorkbenchHoverProvider extends GObject.Object {
vfunc_populate(context, display) {
log("populate");
try {
const box = new Gtk.Box();
box.add_css_class("osd");
box.append(
new Gtk.Label({
label: "foobar",
margin_top: 8,
margin_bottom: 8,
margin_start: 8,
margin_end: 8,
})
);
display.append(box);
} catch (err) {
logError(err);
}
return true;
}
}
);
const hover = source_view.get_hover();
hover.hover_delay = 25;
const provider = new WorkbenchHoverProvider();
hover.add_provider(provider);
window.present();
window.connect("close-request", () => {
mainloop.quit();
});
mainloop.run();
Edited by Sonny Piers