presenter.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-FileCopyrightText: GSConnect Developers https://github.com/GSConnect
  2. //
  3. // SPDX-License-Identifier: GPL-2.0-or-later
  4. 'use strict';
  5. const GObject = imports.gi.GObject;
  6. const Components = imports.service.components;
  7. const PluginBase = imports.service.plugin;
  8. var Metadata = {
  9. label: _('Presentation'),
  10. description: _('Use the paired device as a presenter'),
  11. id: 'org.gnome.Shell.Extensions.GSConnect.Plugin.Presenter',
  12. incomingCapabilities: ['kdeconnect.presenter'],
  13. outgoingCapabilities: [],
  14. actions: {},
  15. };
  16. /**
  17. * Presenter Plugin
  18. * https://github.com/KDE/kdeconnect-kde/tree/master/plugins/presenter
  19. * https://github.com/KDE/kdeconnect-android/tree/master/src/org/kde/kdeconnect/Plugins/PresenterPlugin/
  20. */
  21. var Plugin = GObject.registerClass({
  22. GTypeName: 'GSConnectPresenterPlugin',
  23. }, class Plugin extends PluginBase.Plugin {
  24. _init(device) {
  25. super._init(device, 'presenter');
  26. if (!globalThis.HAVE_GNOME)
  27. this._input = Components.acquire('ydotool');
  28. else
  29. this._input = Components.acquire('input');
  30. }
  31. handlePacket(packet) {
  32. if (packet.body.hasOwnProperty('dx')) {
  33. this._input.movePointer(
  34. packet.body.dx * 1000,
  35. packet.body.dy * 1000
  36. );
  37. } else if (packet.body.stop) {
  38. // Currently unsupported and unnecessary as we just re-use the mouse
  39. // pointer instead of showing an arbitrary window.
  40. }
  41. }
  42. destroy() {
  43. if (this._input !== undefined) {
  44. if (!globalThis.HAVE_GNOME)
  45. this._input = Components.release('ydotool');
  46. else
  47. this._input = Components.release('input');
  48. }
  49. super.destroy();
  50. }
  51. });