rotator.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* rotator.js
  2. *
  3. * Copyright (C) 2022 kosmospredanie, shyzus
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. import Gio from 'gi://Gio';
  19. import * as BusUtils from './busUtils.js';
  20. const connection = Gio.DBus.session;
  21. export function call_dbus_method(method, params = null, handler) {
  22. if (handler != undefined || handler != null) {
  23. connection.call(
  24. 'org.gnome.Mutter.DisplayConfig',
  25. '/org/gnome/Mutter/DisplayConfig',
  26. 'org.gnome.Mutter.DisplayConfig',
  27. method,
  28. params,
  29. null,
  30. Gio.DBusCallFlags.NONE,
  31. -1,
  32. null, handler);
  33. } else {
  34. connection.call(
  35. 'org.gnome.Mutter.DisplayConfig',
  36. '/org/gnome/Mutter/DisplayConfig',
  37. 'org.gnome.Mutter.DisplayConfig',
  38. method,
  39. params,
  40. null,
  41. Gio.DBusCallFlags.NONE,
  42. -1,
  43. null);
  44. }
  45. }
  46. export function get_state() {
  47. return new Promise((resolve, reject) => {
  48. call_dbus_method('GetCurrentState', null, (connection, res) => {
  49. try {
  50. let reply = connection.call_finish(res);
  51. let configState = new BusUtils.DisplayConfigState(reply)
  52. resolve(configState);
  53. } catch (err) {
  54. reject(err);
  55. }
  56. });
  57. })
  58. }
  59. export function rotate_to(transform) {
  60. this.get_state().then(state => {
  61. let builtin_monitor = state.builtin_monitor;
  62. let logical_monitor = state.get_logical_monitor_for(builtin_monitor.connector);
  63. logical_monitor.transform = transform;
  64. let variant = state.pack_to_apply(BusUtils.Methods['temporary']);
  65. call_dbus_method('ApplyMonitorsConfig', variant);
  66. }).catch(err => {
  67. console.error(err);
  68. })
  69. }