displayConfigState.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* displayConfigState.js
  2. *
  3. * Copyright (C) 2024 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 GLib from 'gi://GLib';
  19. import { Monitor } from './monitor.js'
  20. import { LogicalMonitor } from './logicalMonitor.js'
  21. export class DisplayConfigState {
  22. constructor(result) {
  23. let unpacked = result.unpack();
  24. this.serial = unpacked[0].unpack();
  25. this.monitors = [];
  26. let monitors = unpacked[1].unpack();
  27. monitors.forEach(monitor_packed => {
  28. let monitor = new Monitor(monitor_packed);
  29. this.monitors.push(monitor);
  30. });
  31. this.logical_monitors = [];
  32. let logical_monitors = unpacked[2].unpack();
  33. logical_monitors.forEach(lmonitor_packed => {
  34. let lmonitor = new LogicalMonitor(lmonitor_packed);
  35. this.logical_monitors.push(lmonitor);
  36. });
  37. this.properties = unpacked[3].unpack();
  38. for (let key in this.properties) {
  39. this.properties[key] = this.properties[key].unpack().unpack();
  40. }
  41. }
  42. get builtin_monitor() {
  43. for (let monitor of this.monitors) {
  44. if (monitor.is_builtin) {
  45. return monitor;
  46. }
  47. }
  48. return null;
  49. }
  50. get_monitor(connector) {
  51. for (let monitor of this.monitors) {
  52. if (monitor.connector === connector) {
  53. return monitor;
  54. }
  55. }
  56. return null;
  57. }
  58. get_logical_monitor_for(connector) {
  59. for (let log_monitor of this.logical_monitors) {
  60. for (let lm_monitor of log_monitor.monitors) {
  61. if (connector === lm_monitor[0]) {
  62. return log_monitor;
  63. }
  64. }
  65. }
  66. return null;
  67. }
  68. pack_to_apply(method) {
  69. let packing = [this.serial, method, [], {}];
  70. let logical_monitors = packing[2];
  71. let properties = packing[3];
  72. this.logical_monitors.forEach(lmonitor => {
  73. let lmonitor_pack = [
  74. lmonitor.x,
  75. lmonitor.y,
  76. lmonitor.scale,
  77. lmonitor.transform,
  78. lmonitor.primary,
  79. []
  80. ];
  81. let monitors = lmonitor_pack[5];
  82. for (let log_monitor of lmonitor.monitors) {
  83. let connector = log_monitor[0];
  84. let monitor = this.get_monitor(connector);
  85. monitors.push([
  86. connector,
  87. monitor.current_mode_id,
  88. {
  89. 'enable_underscanning': new GLib.Variant('b', monitor.is_underscanning)
  90. }
  91. ]);
  92. }
  93. logical_monitors.push(lmonitor_pack);
  94. });
  95. if ('layout-mode' in this.properties) {
  96. properties['layout-mode'] = new GLib.Variant('b', this.properties['layout-mode']);
  97. }
  98. return new GLib.Variant('(uua(iiduba(ssa{sv}))a{sv})', packing);
  99. }
  100. }