extension.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
  2. import * as ExtensionTheme from './theme.js';
  3. import {TileWindowManager} from './tileWindowManager.js';
  4. import KeybindingHandler from './settingsHandlers/keybindingHandler.js';
  5. import SwitchHandler from './settingsHandlers/switchHandler.js';
  6. import SpinHandler from './settingsHandlers/spinHandler.js';
  7. import ComboRowHandler from './settingsHandlers/comboRowHandler.js';
  8. import {Tile} from './tile.js';
  9. import {destroyController} from './keybindingController.js';
  10. import {loadExecutables, destroy as unloadExecutables} from './autocomplete.js';
  11. import GLib from 'gi://GLib';
  12. export default class Grimble extends Extension {
  13. _tileWindowManager = null;
  14. _settings = null;
  15. _keybindingHandler = null;
  16. _switchHandler = null;
  17. _spinHandler = null;
  18. _comboHandler = null;
  19. _timeoutId = null;
  20. enable() {
  21. this._settings = this.getSettings();
  22. ExtensionTheme.enableWindowTheme();
  23. Tile.padding = this._settings.get_int('tile-padding');
  24. /**
  25. * When we unlock the session (after a lock, not when starting the system),
  26. * there is a period of time during which the Gnome settings used for the
  27. * extension are not set. If we don't wait, it leads the windows to be
  28. * organized in an undefined way when using multiple monitors (because
  29. * of the workspaces-only-on-primary setting). In order to fix it we
  30. * wait 2 seconds to be sure everything is set up. It is applied ONLY when using
  31. * multiple monitors.
  32. * -> Could problably be improved by waiting for the setting changed signal.
  33. */
  34. if (global.display.get_n_monitors() > 1 && TileWindowManager.locked) {
  35. this._timeoutId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 2, () => {
  36. this._tileWindowManager = new TileWindowManager(this);
  37. this._keybindingHandler = new KeybindingHandler(this._tileWindowManager, this);
  38. this._switchHandler = new SwitchHandler(this._tileWindowManager, this);
  39. this._spinHandler = new SpinHandler(this._tileWindowManager, this);
  40. this._comboHandler = new ComboRowHandler(this._tileWindowManager, this);
  41. return GLib.SOURCE_REMOVE;
  42. });
  43. } else {
  44. this._tileWindowManager = new TileWindowManager(this);
  45. this._keybindingHandler = new KeybindingHandler(this._tileWindowManager, this);
  46. this._switchHandler = new SwitchHandler(this._tileWindowManager, this);
  47. this._spinHandler = new SpinHandler(this._tileWindowManager, this);
  48. this._comboHandler = new ComboRowHandler(this._tileWindowManager, this);
  49. }
  50. loadExecutables();
  51. }
  52. disable() {
  53. unloadExecutables();
  54. this._tileWindowManager?._saveBeforeSessionLock();
  55. // Restore theme
  56. ExtensionTheme.disableWindowTheme();
  57. if (this._timeoutId) {
  58. GLib.Source.remove(this._timeoutId);
  59. this._timeoutId = null;
  60. }
  61. destroyController();
  62. this._tileWindowManager?.destroy();
  63. this._tileWindowManager = null;
  64. this._keybindingHandler?.destroy();
  65. this._keybindingHandler = null;
  66. this._spinHandler = null;
  67. this._switchHandler = null;
  68. this._comboHandler = null;
  69. this._settings = null;
  70. }
  71. }