Search code examples
gnome-shell-extensionsgjs

GJS: global.window_manager.get_workspaces() is undefined


I have a code like this for my extension

for (let i = 0; i < screen.get_n_workspaces(); ++i) { let w = screen.get_workspace_by_index(i); //Do something }

Since gjs maps c functions to javascript, meta_screen_get_n_workspaces become get_n_workspaces. However when I try this for meta_screen_get_workspaces

screen.get_workspaces().forEach(w => { //Do someting })

it says 'get_workspaces is not a function'. What is the problem here?


Solution

  • Most likely you are relying on an API that was recently changed in libmutter. If you are using an older version of libmutter or newer version than the date of the change, you made need to do a check for the global variable.

    You can probably figure out from the diff in Gnome Shell how your code needs to be adjusted.

    Generally, workspaces are now handled by MetaWorkspaceManager, which is available in Gnome Shell as global.workspace_manager and you can call get_n_workspaces() on that. The related upstream file in libmutter is workspace_manager.h. Before that I believe they were accessed through global.screen.