presenter.js 1.8 KB

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