0

I am using GJS, how do I get Clutter.Actor via its name. For example, if I wanted to get GNOME Shell's top panel, how do I get its Clutter.Actor via its name "panel"?

My research ended up somewhere along Clutter.Stage which is where Actor(s) can go be appended to, however by the way I see things, there can be multiple Stages setup so I might also have to find which Stage it is the Actor I am trying to find is at. For now I want to know how I can get an Actor via its name.

I have seen from a code; Main.layoutManager.panelBox to get the GNOME Shell's top panel, however that doesn't seem applicable to my case since it's a third party Actor I am trying to get, and the way I wish to get Actor(s) is via the name since I may be working with different third party Actor(s).

There is one way that I can get this that I know of; Main.layoutManager.panelBox.get_parent().get_children() and I can just get the specific Actor via its index, but I don't think this is the best way to approach this, considering how dynamic things are, secondly, I find this way kinda sloppy so..

I was able to get the name via Looking Glass (Alt + F2 -> lg -> picker). For now, the specific Actor I am trying to get is the DashtoDock's, just for info.

Thank you~ Hope someone can help.

Gelo Tress
  • 53
  • 4

1 Answers1

2

Unfortunately, it seems like what you're looking for is a searchByName() function, but you'll have to implement that yourself I think. Something like (untested):

function searchByName(topActor, name) {
    let children = topActor.get_children();

    for (let i = 0; i < children.length; i++) {
        if (child.name === name) {
            return child;
        } else if (child.get_n_children()) {
            let result = searchByName(child, name);

            if (result) {
                return result;
            }
        }
    }

    return false;
};

Then call it on Main.layoutManager.uiGroup where Dash to Dock is

const Main = imports.ui.main;

let dashToDock = searchByName(Main.layoutManager.uiGroup, "dashtodockContainer");
andy.holmes
  • 3,383
  • 17
  • 28
  • Yes, I have found out the same result yesterday night. Haven't gotten it here myself as it was already late and had to sleep, nevertheless this is what I would be expecting myself implementing as I have found no similar functions that exists. I should have read Clutter's documents much more thoroughly as well, I kept missing the object literal property "name". Thanks for your answer still. I might update to give thanks to a user that helped me out at GNOME IRC as well. – Gelo Tress Feb 05 '18 at 04:26
  • Probably is good to start from the global.state instead of the Main.layout Manager.uiGroup if what you are looking for could be outside the uiGroup and you don't know what you are looking for. – lestcape May 30 '18 at 22:51