client.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import Gio from 'gi://Gio';
  2. const bus_name = 'org.gnome.Shell';
  3. const iface_name = 'dev.aunetx.BlurMyShell';
  4. const obj_path = '/dev/aunetx/BlurMyShell';
  5. /// Call pick() from the DBus service, it will open the Inspector from
  6. /// gnome-shell to pick an actor on stage.
  7. export function pick() {
  8. Gio.DBus.session.call(
  9. bus_name,
  10. obj_path,
  11. iface_name,
  12. 'pick',
  13. null,
  14. null,
  15. Gio.DBusCallFlags.NO_AUTO_START,
  16. -1,
  17. null,
  18. null
  19. );
  20. }
  21. /// Connect to DBus 'picking' signal, which will be emitted when the inspector
  22. /// is picking a window.
  23. export function on_picking(cb) {
  24. const id = Gio.DBus.session.signal_subscribe(
  25. bus_name,
  26. iface_name,
  27. 'picking',
  28. obj_path,
  29. null,
  30. Gio.DBusSignalFlags.NONE,
  31. _ => {
  32. cb();
  33. Gio.DBus.session.signal_unsubscribe(id);
  34. }
  35. );
  36. }
  37. /// Connect to DBus 'picked' signal, which will be emitted when a window is
  38. /// picked.
  39. export function on_picked(cb) {
  40. const id = Gio.DBus.session.signal_subscribe(
  41. bus_name,
  42. iface_name,
  43. 'picked',
  44. obj_path,
  45. null,
  46. Gio.DBusSignalFlags.NONE,
  47. (conn, sender, obj_path, iface, signal, params) => {
  48. const val = params.get_child_value(0);
  49. cb(val.get_string()[0]);
  50. Gio.DBus.session.signal_unsubscribe(id);
  51. }
  52. );
  53. }