prefs.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* prefs.js
  2. * Copyright (C) 2023 kosmospredanie, shyzus, Shinigaminai
  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 Gtk from 'gi://Gtk';
  18. import Gio from 'gi://Gio';
  19. import Adw from 'gi://Adw';
  20. import { ExtensionPreferences } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
  21. export default class MyExtensionPreferences extends ExtensionPreferences {
  22. fillPreferencesWindow(window) {
  23. window._settings = this.getSettings();
  24. const page = new Adw.PreferencesPage();
  25. window.add(page);
  26. const orientationGroup = new Adw.PreferencesGroup();
  27. orientationGroup.set_title('Orientation Settings')
  28. page.add(orientationGroup);
  29. const debugGroup = new Adw.PreferencesGroup();
  30. debugGroup.set_title('Debug Settings');
  31. page.add(debugGroup);
  32. const invertHorizontalRow = new Adw.ActionRow({
  33. title: 'Invert horizontal rotation'
  34. });
  35. orientationGroup.add(invertHorizontalRow);
  36. const invertVerticalRow = new Adw.ActionRow({
  37. title: 'Invert vertical rotation'
  38. });
  39. orientationGroup.add(invertVerticalRow);
  40. const flipOrientationRow = new Adw.ActionRow({
  41. title: 'Flip orientation',
  42. subtitle: 'e.g: Landscape to Portrait. Default is Landscape'
  43. });
  44. orientationGroup.add(flipOrientationRow);
  45. const setOffsetRow = new Adw.ActionRow({
  46. title: 'Set orientation offset',
  47. subtitle: 'Valid offset range: 0 to 3. Default is 0\nExperiment with this in case\
  48. orientation is incorrect due to the display being mounted in a non-landscape orientation\
  49. e.g PineTab2 or GPD Pocket 3'
  50. });
  51. orientationGroup.add(setOffsetRow);
  52. const toggleLoggingRow = new Adw.ActionRow({
  53. title: 'Enable debug logging',
  54. subtitle: 'Use "journalctl /usr/bin/gnome-shell -f" to see log output.'
  55. });
  56. debugGroup.add(toggleLoggingRow);
  57. const invertHorizontalRotationSwitch = new Gtk.Switch({
  58. active: window._settings.get_boolean('invert-horizontal-rotation-direction'),
  59. valign: Gtk.Align.CENTER,
  60. });
  61. const invertVerticalRotationSwitch = new Gtk.Switch({
  62. active: window._settings.get_boolean('invert-vertical-rotation-direction'),
  63. valign: Gtk.Align.CENTER,
  64. });
  65. const flipOrientationSwitch = new Gtk.Switch({
  66. active: window._settings.get_boolean('flip-orientation'),
  67. valign: Gtk.Align.CENTER,
  68. });
  69. const setOffsetSpinButton = Gtk.SpinButton.new_with_range(0, 3, 1);
  70. setOffsetSpinButton.value = window._settings.get_int('orientation-offset');
  71. const toggleLoggingSwitch = new Gtk.Switch({
  72. active: window._settings.get_boolean('debug-logging'),
  73. valign: Gtk.Align.CENTER
  74. });
  75. window._settings.bind('invert-horizontal-rotation-direction',
  76. invertHorizontalRotationSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  77. window._settings.bind('invert-vertical-rotation-direction',
  78. invertVerticalRotationSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  79. window._settings.bind('flip-orientation',
  80. flipOrientationSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  81. window._settings.bind('orientation-offset',
  82. setOffsetSpinButton, 'value', Gio.SettingsBindFlags.DEFAULT);
  83. window._settings.bind('debug-logging',
  84. toggleLoggingSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  85. invertHorizontalRow.add_suffix(invertHorizontalRotationSwitch);
  86. invertHorizontalRow.activatable_widget = invertHorizontalRotationSwitch;
  87. invertVerticalRow.add_suffix(invertVerticalRotationSwitch);
  88. invertVerticalRow.activatable_widget = invertVerticalRotationSwitch;
  89. flipOrientationRow.add_suffix(flipOrientationSwitch);
  90. flipOrientationRow.activatable_widget = flipOrientationSwitch;
  91. setOffsetRow.add_suffix(setOffsetSpinButton);
  92. setOffsetRow.activatable_widget = setOffsetSpinButton;
  93. toggleLoggingRow.add_suffix(toggleLoggingSwitch);
  94. toggleLoggingRow.activatable_widget = toggleLoggingSwitch;
  95. }
  96. }