prefs.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 skipInitRotationRow = new Adw.ActionRow({
  64. title: 'Skip initial rotation',
  65. subtitle: 'Skip initial rotation on extension startup ensures the' +
  66. ' last known orientation is loaded on startup and the' +
  67. ' overview screen is not skipped.'
  68. });
  69. orientationGroup.add(skipInitRotationRow);
  70. const enableManualFlipRow = new Adw.ActionRow({
  71. title: 'Enable manual flip',
  72. subtitle: 'Enable a toggle in the GNOME Shell System Menu to manually flip between landscape and portrait.'
  73. });
  74. shellMenuGroup.add(enableManualFlipRow);
  75. const hideLockRotateRow = new Adw.ActionRow({
  76. title: 'Hide the "Auto Rotate" quick toggle'
  77. });
  78. shellMenuGroup.add(hideLockRotateRow);
  79. const landscapeOskRow = new Adw.ActionRow({
  80. title: 'Show OSK in landscape orientation'
  81. });
  82. oskSettingsGroup.add(landscapeOskRow);
  83. const portraitRightOskRow = new Adw.ActionRow({
  84. title: 'Show OSK in portrait (right) orientation'
  85. });
  86. oskSettingsGroup.add(portraitRightOskRow);
  87. const landscapeFlippedOskRow = new Adw.ActionRow({
  88. title: 'Show OSK in landscape (flipped) orientation'
  89. });
  90. oskSettingsGroup.add(landscapeFlippedOskRow);
  91. const portraitLeftOskRow = new Adw.ActionRow({
  92. title: 'Show OSK in portrait (left) orientation'
  93. });
  94. oskSettingsGroup.add(portraitLeftOskRow);
  95. const toggleLoggingRow = new Adw.ActionRow({
  96. title: 'Enable debug logging',
  97. subtitle: 'Use "journalctl /usr/bin/gnome-shell -f" to see log output.'
  98. });
  99. debugGroup.add(toggleLoggingRow);
  100. const invertHorizontalRotationSwitch = new Gtk.Switch({
  101. active: window._settings.get_boolean('invert-horizontal-rotation-direction'),
  102. valign: Gtk.Align.CENTER,
  103. });
  104. const invertVerticalRotationSwitch = new Gtk.Switch({
  105. active: window._settings.get_boolean('invert-vertical-rotation-direction'),
  106. valign: Gtk.Align.CENTER,
  107. });
  108. const flipOrientationSwitch = new Gtk.Switch({
  109. active: window._settings.get_boolean('flip-orientation'),
  110. valign: Gtk.Align.CENTER,
  111. });
  112. const setOffsetSpinButton = Gtk.SpinButton.new_with_range(0, 3, 1);
  113. setOffsetSpinButton.value = window._settings.get_int('orientation-offset');
  114. const skipInitRotationButton = new Gtk.Switch({
  115. active: window._settings.get_boolean('skip-initial-rotation'),
  116. valign: Gtk.Align.CENTER
  117. });
  118. const manualFlipSwitch = new Gtk.Switch({
  119. active: window._settings.get_boolean('manual-flip'),
  120. valign: Gtk.Align.CENTER,
  121. });
  122. const hideLockRotateSwitch = new Gtk.Switch({
  123. active: window._settings.get_boolean('hide-lock-rotate'),
  124. valign: Gtk.Align.CENTER,
  125. });
  126. const landscapeOskCheckButton = new Gtk.CheckButton({
  127. active: window._settings.get_boolean('landscape-osk'),
  128. valign: Gtk.Align.CENTER
  129. });
  130. const portraitRightOskCheckButton = new Gtk.CheckButton({
  131. active: window._settings.get_boolean('portrait-right-osk'),
  132. valign: Gtk.Align.CENTER
  133. });
  134. const portraitLeftOskCheckButton = new Gtk.CheckButton({
  135. active: window._settings.get_boolean('portrait-left-osk'),
  136. valign: Gtk.Align.CENTER
  137. });
  138. const landscapeFlippedOskCheckButton = new Gtk.CheckButton({
  139. active: window._settings.get_boolean('landscape-flipped-osk'),
  140. valign: Gtk.Align.CENTER
  141. });
  142. const dorNotebook = new Gtk.Notebook();
  143. const dorKeyboardPage = new Gtk.ListBox();
  144. dorKeyboardPage.set_visible(false); // Keep hidden until feature can be implemented.
  145. dorKeyboardPage.set_selection_mode(Gtk.SelectionMode.NONE);
  146. for (let orientation in Orientation) {
  147. let actionRowTitle = undefined;
  148. let checkButtonBoolId = undefined;
  149. switch (orientation) {
  150. case 'normal':
  151. actionRowTitle = "Landscape";
  152. checkButtonBoolId = "dor-keyboard-landscape";
  153. break;
  154. case 'left-up':
  155. actionRowTitle = "Portrait (Left)";
  156. checkButtonBoolId = "dor-keyboard-portrait-left";
  157. break;
  158. case 'bottom-up':
  159. actionRowTitle = "Landscape Flipped";
  160. checkButtonBoolId = "dor-keyboard-landscape-flipped";
  161. break;
  162. case 'right-up':
  163. actionRowTitle = "Portrait (Right)";
  164. checkButtonBoolId = "dor-keyboard-portrait-right";
  165. break;
  166. }
  167. const dorActionRow = new Adw.ActionRow({
  168. title: actionRowTitle
  169. });
  170. const dorCheckButton = new Gtk.CheckButton({
  171. active: window._settings.get_boolean(checkButtonBoolId),
  172. valign: Gtk.Align.CENTER
  173. });
  174. window._settings.bind(checkButtonBoolId,
  175. dorCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  176. dorActionRow.add_suffix(dorCheckButton);
  177. dorActionRow.activatable_widget = dorCheckButton;
  178. dorKeyboardPage.append(dorActionRow);
  179. }
  180. const dorTouchpadPage = new Gtk.ListBox();
  181. dorTouchpadPage.set_selection_mode(Gtk.SelectionMode.NONE);
  182. for (let orientation in Orientation) {
  183. let actionRowTitle = undefined;
  184. let checkButtonBoolId = undefined;
  185. switch (orientation) {
  186. case 'normal':
  187. actionRowTitle = "Landscape";
  188. checkButtonBoolId = "dor-touchpad-landscape";
  189. break;
  190. case 'left-up':
  191. actionRowTitle = "Portrait (Left)";
  192. checkButtonBoolId = "dor-touchpad-portrait-left";
  193. break;
  194. case 'bottom-up':
  195. actionRowTitle = "Landscape Flipped";
  196. checkButtonBoolId = "dor-touchpad-landscape-flipped";
  197. break;
  198. case 'right-up':
  199. actionRowTitle = "Portrait (Right)";
  200. checkButtonBoolId = "dor-touchpad-portrait-right";
  201. break;
  202. }
  203. const dorActionRow = new Adw.ActionRow({
  204. title: actionRowTitle
  205. });
  206. const dorCheckButton = new Gtk.CheckButton({
  207. active: window._settings.get_boolean(checkButtonBoolId),
  208. valign: Gtk.Align.CENTER
  209. });
  210. window._settings.bind(checkButtonBoolId,
  211. dorCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  212. dorActionRow.add_suffix(dorCheckButton);
  213. dorActionRow.activatable_widget = dorCheckButton;
  214. dorTouchpadPage.append(dorActionRow);
  215. }
  216. const dorKeyboardLabel = Gtk.Label.new('Keyboard');
  217. dorNotebook.append_page(dorKeyboardPage, dorKeyboardLabel);
  218. const dorTouchpadLabel = Gtk.Label.new('Touchpad');
  219. dorNotebook.append_page(dorTouchpadPage, dorTouchpadLabel)
  220. disableOnRotateGroup.add(dorNotebook);
  221. const toggleLoggingSwitch = new Gtk.Switch({
  222. active: window._settings.get_boolean('debug-logging'),
  223. valign: Gtk.Align.CENTER
  224. });
  225. window._settings.bind('invert-horizontal-rotation-direction',
  226. invertHorizontalRotationSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  227. window._settings.bind('invert-vertical-rotation-direction',
  228. invertVerticalRotationSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  229. window._settings.bind('flip-orientation',
  230. flipOrientationSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  231. window._settings.bind('orientation-offset',
  232. setOffsetSpinButton, 'value', Gio.SettingsBindFlags.DEFAULT);
  233. window._settings.bind('skip-initial-rotation',
  234. skipInitRotationButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  235. window._settings.bind('manual-flip',
  236. manualFlipSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  237. window._settings.bind('hide-lock-rotate',
  238. hideLockRotateSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  239. window._settings.bind('landscape-osk',
  240. landscapeOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  241. window._settings.bind('portrait-right-osk',
  242. portraitRightOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  243. window._settings.bind('portrait-left-osk',
  244. portraitLeftOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  245. window._settings.bind('landscape-flipped-osk',
  246. landscapeFlippedOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);
  247. window._settings.bind('debug-logging',
  248. toggleLoggingSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
  249. invertHorizontalRow.add_suffix(invertHorizontalRotationSwitch);
  250. invertHorizontalRow.activatable_widget = invertHorizontalRotationSwitch;
  251. invertVerticalRow.add_suffix(invertVerticalRotationSwitch);
  252. invertVerticalRow.activatable_widget = invertVerticalRotationSwitch;
  253. flipOrientationRow.add_suffix(flipOrientationSwitch);
  254. flipOrientationRow.activatable_widget = flipOrientationSwitch;
  255. setOffsetRow.add_suffix(setOffsetSpinButton);
  256. setOffsetRow.activatable_widget = setOffsetSpinButton;
  257. skipInitRotationRow.add_suffix(skipInitRotationButton);
  258. skipInitRotationRow.activatable_widget = skipInitRotationButton;
  259. enableManualFlipRow.add_suffix(manualFlipSwitch);
  260. enableManualFlipRow.activatable_widget = manualFlipSwitch;
  261. hideLockRotateRow.add_suffix(hideLockRotateSwitch);
  262. hideLockRotateRow.activatable_widget = hideLockRotateSwitch;
  263. landscapeOskRow.add_suffix(landscapeOskCheckButton);
  264. landscapeOskRow.activatable_widget = landscapeOskCheckButton;
  265. portraitRightOskRow.add_suffix(portraitRightOskCheckButton);
  266. portraitRightOskRow.activatable_widget = portraitRightOskCheckButton;
  267. portraitLeftOskRow.add_suffix(portraitLeftOskCheckButton);
  268. portraitLeftOskRow.activatable_widget = portraitLeftOskCheckButton;
  269. landscapeFlippedOskRow.add_suffix(landscapeFlippedOskCheckButton);
  270. landscapeFlippedOskRow.activatable_widget = landscapeFlippedOskCheckButton;
  271. toggleLoggingRow.add_suffix(toggleLoggingSwitch);
  272. toggleLoggingRow.activatable_widget = toggleLoggingSwitch;
  273. }
  274. }