2

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?

Aiono
  • 389
  • 2
  • 10

1 Answers1

4

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.

andy.holmes
  • 3,383
  • 17
  • 28
  • Thanks that helped me. However I rely on `MetaScreen`'s 'size-changed' signal in my extension. What is the equivalent of this thing on newer versions if it will be removed completely? – Aiono Oct 04 '18 at 08:54
  • 1
    I think in this case you should just use Gdk's Screen and Display objects. `Gdk.Screen.get_default().connect('size-changed', () => {})`. I believe `global.screen` was just a convenience for that anyways. – andy.holmes Oct 04 '18 at 23:40