0

I am working with a gnome extension which has a toggle switch on its panel popup menu. I have bound a keyboard shortcut to the same setting, so I want to change the state of the toggle to reflect what happens with the keyboard shortcut.

the toggle comes from code like this:

let toggle = new PopupSwitchMenuItem(desc, active);

and I can save a reference to toggle so that is known to the code that handles the short cut. But I don't know how to change the state. I hoped toggle.set_state(true) might work, but whatever object toggle is, it does not support set_state()

Tim Richardson
  • 6,608
  • 6
  • 44
  • 71

1 Answers1

0

Right, well I found a the correct javascript libary. https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/popupMenu.js and from there, this works:

 toggle._switch.state = true;

EDIT: Better solution from Gnome dev Florian Müllner

ie toggle.setToggleState(bool)

It’s setToggleState(), see https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/popupMenu.js#L419

https://discourse.gnome.org/t/newbie-shell-extension-coder-how-to-i-set-the-state-of-a-switch-created-with-popupswitchmenuitem/3370?u=tim_richardson

Tim Richardson
  • 6,608
  • 6
  • 44
  • 71