1

I'm trying to create an editable multi-line text box by using the Clutter.Text's set_editable() method:

let label = new St.Label({ text: 'My dummy example.' });
label.clutter_text.set_editable(true);
label.clutter_text.set_activatable(true);

But it doesn't seem to work. What am I missing? Here is the simplified extension.js that uses the code above:

const St = imports.gi.St;
const Main = imports.ui.main;
const Pango = imports.gi.Pango;
const PanelMenu = imports.ui.panelMenu;

let btn;

function DummyApp() {
    this._init();
}

DummyApp.prototype = {
    __proto__: PanelMenu.Button.prototype,
    _init: function() {
        PanelMenu.Button.prototype._init.call(this, St.Align.START);

        let button = new St.Bin();
        let icon = new St.Icon({
            icon_name: 'system-run-symbolic',
            style_class: 'system-status-icon' });

        button.set_child(icon);

        this.actor.add_actor(button);

        let mainBox = new St.BoxLayout();
        let label = new St.Label({ text: 'My dummy example.' });
        label.clutter_text.set_editable(true);
        label.clutter_text.set_activatable(true);

        mainBox.add_child(label);
        this.menu.box.add(mainBox);
    },
}

function init() {}

function enable() {
    btn = new DummyApp();
    Main.panel.addToStatusArea('dummyapp_sec', btn);
}

function disable() {
    Main.panel._rightBox.remove_child(btn);
}

As a footnote, Gtk.TextView looks like just what I need, but I've not been able to figure out how to integrate it to the PopupMenu. Any idea?

Community
  • 1
  • 1
luvejo
  • 347
  • 2
  • 9

1 Answers1

2

Actors in Clutter do not react to events by default; you need to explicitly set the actor as reactive in order for it to receive events.

Additionally, you cannot use GTK widgets inside GNOME Shell extensions: GTK is a client toolkit, and you're writing an extension for the compositor and display server.

ebassi
  • 8,648
  • 27
  • 29
  • 1
    Yep, `label.clutter_text.set_reactive(true);` got it working. Thanks, ebassi! – luvejo Jun 13 '18 at 17:03
  • St is not a client toolkit too? St is not used inside the extension for the compositor and the display server? As this not convinced me, the question is what is really the limitation of prevent Gtk to be used in the shell? I know that i can embed a Gtk widget inside a Clutter actor so why not in the shell then? When Gtk4 will be arrived, use Clutter seem to be a really bad idea, because it seem to be in mantenice mode only, while Gtk seem to gain all Clutter advantage and more (except lightweight). – lestcape Oct 29 '19 at 23:46
  • 1
    Those are a lot of questions. No, St is not a client toolkit: it runs directly into the compositor. "Really", the limitation is that GTK expects to connect to the display server, consume its events, and manage its windows; this is not possible from within the compositor itself. Finally, Mutter/GNOME Shell forked Clutter and they are maintaining their internal copy, including improving its performance and behaviour. There is no plan to use GTK4 in GNOME Shell as of 2019. – ebassi Oct 30 '19 at 16:04