Extending a gjs class that's not based on GObject

I’m getting started with my first gnome shell extension. I want to add and display titles to workspaces. My instinct is to extend the workspace class in ui/workspace.js. However, this class isn’t based on GObject. When I look at other gnome-shell extensions, any class that they extend is based on GObject. Without an example or documentation to follow, I’m unsure how to properly extend this class.

Again, my goal is to create a simple extension that adds and displays titles to workspaces. Am I going about this the right way?Is it possible to extend this class?

First: Welcome to the community :smile:

Non-GObject classes are regular ES6 classes, so any “normal” documentation applies:

class MySubclass extends BaseClass {
    constructor() {
        // important: the "this" pointer is initialized by chaining up to the base Object class
        super();

        // your custom code goes here
    }
}

The tricky bit here isn’t about extending the workspaces class, but about making sure that the shell uses your subclass instead of the original one.

This extension does add labels to workspaces, feel free to copy the relevant bits.

This was super helpful. Thank you so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.