prefs.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* prefs.js
  2. * Copyright (C) 2024 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. import { Orientation } from './orientation.js';
  22. export default class MyExtensionPreferences extends ExtensionPreferences {
  23. fillPreferencesWindow(window) {
  24. window._settings = this.getSettings();
  25. const page = new Adw.PreferencesPage();
  26. window.add(page);
  27. const orientationGroup = new Adw.PreferencesGroup();
  28. orientationGroup.set_title('Orientation Settings')
  29. page.add(orientationGroup);
  30. const shellMenuGroup = new Adw.PreferencesGroup();
  31. shellMenuGroup.set_title('GNOME Shell Menu Settings');
  32. page.add(shellMenuGroup);
  33. const oskSettingsGroup = new Adw.PreferencesGroup();
  34. oskSettingsGroup.set_title('On-Screen-Keyboard Settings');
  35. page.add(oskSettingsGroup);
  36. const disableOnRotateGroup = new Adw.PreferencesGroup();
  37. disableOnRotateGroup.set_title('Disable-On-Rotation Settings');
  38. page.add(disableOnRotateGroup);
  39. const debugGroup = new Adw.PreferencesGroup();
  40. debugGroup.set_title('Debug Settings');
  41. page.add(debugGroup);
  42. const invertHorizontalRow = new Adw.ActionRow({
  43. title: 'Invert horizontal rotation'
  44. });
  45. orientationGroup.add(invertHorizontalRow);
  46. const invertVerticalRow = new Adw.ActionRow({
  47. title: 'Invert vertical rotation'
  48. });
  49. orientationGroup.add(invertVerticalRow);
  50. const flipOrientationRow = new Adw.ActionRow({
  51. title: 'Flip orientation',
  52. subtitle: 'e.g: Landscape to Portrait. Default is Landscape'
  53. });
  54. orientationGroup.add(flipOrientationRow);
  55. const setOffsetRow = new Adw.ActionRow({
  56. title: 'Set orientation offset',
  57. subtitle: 'Valid offset range: 0 to 3. Default is 0\nExperiment with' +
  58. ' this in case orientation is incorrect due to the display' +
  59. ' being mounted in a non-landscape orientation' +
  60. ' e.g PineTab2 or GPD Pocket 3'
  61. });
  62. orientationGroup.add(setOffsetRow);
  63. const enableManualFlipRow = new Adw.ActionRow({
  64. title: 'Enable manual flip',
  65. subtitle: 'Enable a toggle in the GNOME Shell System Menu to manually flip between landscape and portrait.'
  66. });
  67. shellMenuGroup.add(enableManualFlipRow);
  68. const hideLockRotateRow = new Adw.ActionRow({
  69. title: 'Hide the "Auto Rotate" quick toggle'
  70. });
  71. shellMenuGroup.add(hideLockRotateRow);
  72. const landscapeOskRow = new Adw.ActionRow({
  73. title: 'Show OSK in landscape orientation'
  74. });
  75. oskSettingsGroup.add(landscapeOskRow);
  76. const portraitRightOskRow = new Adw.ActionRow({
  77. title: 'Show OSK in portrait (right) orientation'
  78. });
  79. oskSettingsGroup.add(portraitRightOskRow);
  80. const landscapeFlippedOskRow = new Adw.ActionRow({
  81. title: 'Show OSK in landscape (flipped) orientation'
  82. });
  83. oskSettingsGroup.add(landscapeFlippedOskRow);
  84. const portraitLeftOskRow = new Adw.ActionRow({
  85. title: 'Show OSK in portrait (left) orientation'
  86. });
  87. oskSettingsGroup.add(portraitLeftOskRow);
  88. const toggleLoggingRow = new Adw.ActionRow({
  89. title: 'Enable debug logging',
  90. subtitle: 'Use "journalctl /usr/bin/gnome-shell -f" to see log output.'
  91. });
  92. debugGroup.add(toggleLoggingRow);
  93. const invertHorizontalRotationSwitch = new Gtk.Switch({
  94. active: window._settings.get_boolean('invert-horizontal-rotation-direction'),
  95. valign: Gtk.Align.CENTER,
  96. });
  97. const invertVerticalRotationSwitch = new Gtk.Switch({
  98. active: window._settings.get_boolean('invert-vertical-rotation-direction'),
  99. valign: Gtk.Align.CENTER,
  100. });
  101. const flipOrientationSwitch = new Gtk.Switch({
  102. active: window._settings.get_boolean('flip-orientation'),
  103. valign: Gtk.Align.CENTER,
  104. });
  105. const setOffsetSpinButton = Gtk.SpinButton.new_with_range(0, 3, 1);
  106. setOffsetSpinButton.value = window._settings.get_int('orientation-offset');
  107. const manualFlipSwitch = new Gtk.Switch({
  108. active: window._settings.get_boolean('manual-flip'),
  109. valign: Gtk.Align.CENTER,
  110. });
  111. const hideLockRotateSwitch = new Gtk.Switch({
  112. active: window._settings.get_boolean('hide-lock-rotate'),
  113. valign: Gtk.Align.CENTER,
  114. });
  115. const landscapeOskCheckButton = new Gtk.CheckButton({
  116. active: window._settings.get_boolean('landscape-osk'),
  117. valign: Gtk.Align.CENTER
  118. });
  119. const portraitRightOskCheckButton = new Gtk.CheckButton({
  120. active: window._settings.get_boolean('portrait-right-osk'),
  121. valign: Gtk.Align.CENTER
  122. });
  123. const portraitLeftOskCheckButton = new Gtk.CheckButton({
  124. active: window._settings.get_boolean('portrait-left-osk'),
  125. valign: Gtk.Align.CENTER
  126. });
  127. const landscapeFlippedOskCheckButton = new Gtk.CheckButton({
  128. active: window._settings.get_boolean('landscape-flipped-osk'),
  129. valign: Gtk.Align.CENTER
  130. });
  131. const dorNotebook = new Gtk.Notebook();
  132. const dorKeyboardPage = new Gtk.ListBox();
  133. dorKeyboardPage.set_visible(false); // Keep hidden until feature can be implemented.
  134. dorKeyboardPage.set_selection_mode(Gtk.SelectionMode.NONE);
  135. for (let orientation in Orientation) {
  136. let actionRowTitle = undefined;
  137. let checkButtonBoolId = undefined;
  138. switch (orientation) {
  139. case 'normal':
  140. actionRowTitle = "Landscape";
  141. checkButtonBoolId = "dor-keyboard-landscape";
  142. break;
  143. case 'left-up':
  144. actionRowTitle = "Portrait (Left)";
  145. checkButtonBoolId = "dor-keyboard-portrait-left";
  146. break;
  147. case 'bottom-up':
  148. actionRowTitle = "Landscape Flipped";
  149. checkButtonBoolId = "dor-keyboard-landscape-flipped";
  150. break;
  151. case 'right-up':
  152. actionRowTitle = "Portrait (Right)";
  153. checkButtonBoolId = "dor-keyboard-portrait-right";
  154. break;
  155. }
  156. const dorActionRow = new Adw.ActionRow({
  157. title: actionRowTitle
  158. });
  159. const dorCheckButton = new Gtk.CheckButton({
  160. active: window._settings.get_boolean(checkButtonBoolId),
  161. valign: Gtk.Align.CENTER
  162. });
  163. window._settings.bind(checkButtonBoolId,
  164. dorCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  165. dorActionRow.add_suffix(dorCheckButton);
  166. dorActionRow.activatable_widget = dorCheckButton;
  167. dorKeyboardPage.append(dorActionRow);
  168. }
  169. const dorTouchpadPage = new Gtk.ListBox();
  170. dorTouchpadPage.set_selection_mode(Gtk.SelectionMode.NONE);
  171. for (let orientation in Orientation) {
  172. let actionRowTitle = undefined;
  173. let checkButtonBoolId = undefined;
  174. switch (orientation) {
  175. case 'normal':
  176. actionRowTitle = "Landscape";
  177. checkButtonBoolId = "dor-touchpad-landscape";
  178. break;
  179. case 'left-up':
  180. actionRowTitle = "Portrait (Left)";
  181. checkButtonBoolId = "dor-touchpad-portrait-left";
  182. break;
  183. case 'bottom-up':
  184. actionRowTitle = "Landscape Flipped";
  185. checkButtonBoolId = "dor-touchpad-landscape-flipped";
  186. break;
  187. case 'right-up':
  188. actionRowTitle = "Portrait (Right)";
  189. checkButtonBoolId = "dor-touchpad-portrait-right";
  190. break;
  191. }
  192. const dorActionRow = new Adw.ActionRow({
  193. title: actionRowTitle
  194. });
  195. const dorCheckButton = new Gtk.CheckButton({
  196. active: window._settings.get_boolean(checkButtonBoolId),
  197. valign: Gtk.Align.CENTER
  198. });
  199. window._settings.bind(checkButtonBoolId,
  200. dorCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  201. dorActionRow.add_suffix(dorCheckButton);
  202. dorActionRow.activatable_widget = dorCheckButton;
  203. dorTouchpadPage.append(dorActionRow);
  204. }
  205. const dorKeyboardLabel = Gtk.Label.new('Keyboard');
  206. dorNotebook.append_page(dorKeyboardPage, dorKeyboardLabel);
  207. const dorTouchpadLabel = Gtk.Label.new('Touchpad');
  208. dorNotebook.append_page(dorTouchpadPage, dorTouchpadLabel)
  209. disableOnRotateGroup.add(dorNotebook);
  210. const toggleLoggingSwitch = new Gtk.Switch({
  211. active: window._settings.get_boolean('debug-logging'),
  212. valign: Gtk.Align.CENTER
  213. });
  214. window._settings.bind('invert-horizontal-rotation-direction',
  215. invertHorizontalRotationSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  216. window._settings.bind('invert-vertical-rotation-direction',
  217. invertVerticalRotationSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  218. window._settings.bind('flip-orientation',
  219. flipOrientationSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  220. window._settings.bind('orientation-offset',
  221. setOffsetSpinButton, 'value', Gio.SettingsBindFlags.DEFAULT);
  222. window._settings.bind('manual-flip',
  223. manualFlipSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  224. window._settings.bind('hide-lock-rotate',
  225. hideLockRotateSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  226. window._settings.bind('landscape-osk',
  227. landscapeOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  228. window._settings.bind('portrait-right-osk',
  229. portraitRightOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  230. window._settings.bind('portrait-left-osk',
  231. portraitLeftOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  232. window._settings.bind('landscape-flipped-osk',
  233. landscapeFlippedOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  234. window._settings.bind('debug-logging',
  235. toggleLoggingSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  236. invertHorizontalRow.add_suffix(invertHorizontalRotationSwitch);
  237. invertHorizontalRow.activatable_widget = invertHorizontalRotationSwitch;
  238. invertVerticalRow.add_suffix(invertVerticalRotationSwitch);
  239. invertVerticalRow.activatable_widget = invertVerticalRotationSwitch;
  240. flipOrientationRow.add_suffix(flipOrientationSwitch);
  241. flipOrientationRow.activatable_widget = flipOrientationSwitch;
  242. setOffsetRow.add_suffix(setOffsetSpinButton);
  243. setOffsetRow.activatable_widget = setOffsetSpinButton;
  244. enableManualFlipRow.add_suffix(manualFlipSwitch);
  245. enableManualFlipRow.activatable_widget = manualFlipSwitch;
  246. hideLockRotateRow.add_suffix(hideLockRotateSwitch);
  247. hideLockRotateRow.activatable_widget = hideLockRotateSwitch;
  248. landscapeOskRow.add_suffix(landscapeOskCheckButton);
  249. landscapeOskRow.activatable_widget = landscapeOskCheckButton;
  250. portraitRightOskRow.add_suffix(portraitRightOskCheckButton);
  251. portraitRightOskRow.activatable_widget = portraitRightOskCheckButton;
  252. portraitLeftOskRow.add_suffix(portraitLeftOskCheckButton);
  253. portraitLeftOskRow.activatable_widget = portraitLeftOskCheckButton;
  254. landscapeFlippedOskRow.add_suffix(landscapeFlippedOskCheckButton);
  255. landscapeFlippedOskRow.activatable_widget = landscapeFlippedOskCheckButton;
  256. toggleLoggingRow.add_suffix(toggleLoggingSwitch);
  257. toggleLoggingRow.activatable_widget = toggleLoggingSwitch;
  258. }
  259. }