manualOrientationMenuToggle.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* manualOrientationMenuToggle.js
  2. * Copyright (C) 2024 shyzus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. import GObject from 'gi://GObject';
  18. import { QuickMenuToggle } from 'resource:///org/gnome/shell/ui/quickSettings.js';
  19. import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
  20. export const ManualOrientationMenuToggle = GObject.registerClass(
  21. class ManualOrientationMenuToggle extends QuickMenuToggle {
  22. constructor(ext) {
  23. super({
  24. title: 'Rotate',
  25. iconName: 'object-rotate-left-symbolic',
  26. menuEnabled: true,
  27. toggleMode: true,
  28. });
  29. this.menu.setHeader('object-rotate-left-symbolic', 'Screen Rotate');
  30. this._section = new PopupMenu.PopupMenuSection();
  31. this.menu.addMenuItem(this._section);
  32. this.landscapeItem = new PopupMenu.PopupMenuItem('Landscape', {
  33. reactive: true,
  34. can_focus: true,
  35. });
  36. this.portraitLeftItem = new PopupMenu.PopupMenuItem('Portrait Left', {
  37. reactive: true,
  38. can_focus: true,
  39. });
  40. this.landscapeFlipItem = new PopupMenu.PopupMenuItem('Landscape Flipped', {
  41. reactive: true,
  42. can_focus: true,
  43. });
  44. this.portraitRightItem = new PopupMenu.PopupMenuItem('Portrait Right', {
  45. reactive: true,
  46. can_focus: true,
  47. });
  48. this.landscapeItem.connect('activate', () => {
  49. this._onItemActivate(this.landscapeItem);
  50. ext.rotate_to('normal');
  51. });
  52. this.portraitLeftItem.connect('activate', () => {
  53. this._onItemActivate(this.portraitLeftItem);
  54. ext.rotate_to('left-up');
  55. });
  56. this.landscapeFlipItem.connect('activate', () => {
  57. this._onItemActivate(this.landscapeFlipItem);
  58. ext.rotate_to('bottom-up');
  59. });
  60. this.portraitRightItem.connect('activate', () => {
  61. this._onItemActivate(this.portraitRightItem);
  62. ext.rotate_to('right-up');
  63. });
  64. this._section.addMenuItem(this.landscapeItem);
  65. this._section.addMenuItem(this.portraitLeftItem);
  66. this._section.addMenuItem(this.landscapeFlipItem);
  67. this._section.addMenuItem(this.portraitRightItem);
  68. this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
  69. this.menu.addSettingsAction('Extension Settings',
  70. 'com.mattjakeman.ExtensionManager.desktop');
  71. this.connect('clicked', () => {
  72. if (this.checked === true) {
  73. ext.rotate_to('right-up');
  74. } else {
  75. ext.rotate_to('normal');
  76. }
  77. });
  78. }
  79. _onItemActivate(item) {
  80. this.landscapeItem.setOrnament(PopupMenu.Ornament.HIDDEN);
  81. this.portraitLeftItem.setOrnament(PopupMenu.Ornament.HIDDEN);
  82. this.landscapeFlipItem.setOrnament(PopupMenu.Ornament.HIDDEN);
  83. this.portraitRightItem.setOrnament(PopupMenu.Ornament.HIDDEN);
  84. item.setOrnament(PopupMenu.Ornament.CHECK);
  85. }
  86. });