appfolders.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import Shell from 'gi://Shell';
  2. import Clutter from 'gi://Clutter';
  3. import * as Main from 'resource:///org/gnome/shell/ui/main.js';
  4. import { PaintSignals } from '../effects/paint_signals.js';
  5. const Tweener = imports.tweener.tweener;
  6. const transparent = Clutter.Color.from_pixel(0x00000000);
  7. const FOLDER_DIALOG_ANIMATION_TIME = 200;
  8. const DIALOGS_STYLES = [
  9. "appfolder-dialogs-transparent",
  10. "appfolder-dialogs-light",
  11. "appfolder-dialogs-dark"
  12. ];
  13. let original_zoomAndFadeIn = null;
  14. let original_zoomAndFadeOut = null;
  15. let sigma;
  16. let brightness;
  17. let _zoomAndFadeIn = function () {
  18. let [sourceX, sourceY] =
  19. this._source.get_transformed_position();
  20. let [dialogX, dialogY] =
  21. this.child.get_transformed_position();
  22. this.child.set({
  23. translation_x: sourceX - dialogX,
  24. translation_y: sourceY - dialogY,
  25. scale_x: this._source.width / this.child.width,
  26. scale_y: this._source.height / this.child.height,
  27. opacity: 0,
  28. });
  29. this.set_background_color(transparent);
  30. let blur_effect = this.get_effect("appfolder-blur");
  31. blur_effect.sigma = 0;
  32. blur_effect.brightness = 1.0;
  33. Tweener.addTween(blur_effect,
  34. {
  35. sigma: sigma,
  36. brightness: brightness,
  37. time: FOLDER_DIALOG_ANIMATION_TIME / 1000,
  38. transition: 'easeOutQuad'
  39. }
  40. );
  41. this.child.ease({
  42. translation_x: 0,
  43. translation_y: 0,
  44. scale_x: 1,
  45. scale_y: 1,
  46. opacity: 255,
  47. duration: FOLDER_DIALOG_ANIMATION_TIME,
  48. mode: Clutter.AnimationMode.EASE_OUT_QUAD,
  49. });
  50. this._needsZoomAndFade = false;
  51. if (this._sourceMappedId === 0) {
  52. this._sourceMappedId = this._source.connect(
  53. 'notify::mapped', this._zoomAndFadeOut.bind(this));
  54. }
  55. };
  56. let _zoomAndFadeOut = function () {
  57. if (!this._isOpen)
  58. return;
  59. if (!this._source.mapped) {
  60. this.hide();
  61. return;
  62. }
  63. let [sourceX, sourceY] =
  64. this._source.get_transformed_position();
  65. let [dialogX, dialogY] =
  66. this.child.get_transformed_position();
  67. this.set_background_color(transparent);
  68. let blur_effect = this.get_effect("appfolder-blur");
  69. Tweener.addTween(blur_effect,
  70. {
  71. sigma: 0,
  72. brightness: 1.0,
  73. time: FOLDER_DIALOG_ANIMATION_TIME / 1000,
  74. transition: 'easeInQuad'
  75. }
  76. );
  77. this.child.ease({
  78. translation_x: sourceX - dialogX,
  79. translation_y: sourceY - dialogY,
  80. scale_x: this._source.width / this.child.width,
  81. scale_y: this._source.height / this.child.height,
  82. opacity: 0,
  83. duration: FOLDER_DIALOG_ANIMATION_TIME,
  84. mode: Clutter.AnimationMode.EASE_OUT_QUAD,
  85. onComplete: () => {
  86. this.child.set({
  87. translation_x: 0,
  88. translation_y: 0,
  89. scale_x: 1,
  90. scale_y: 1,
  91. opacity: 255,
  92. });
  93. this.hide();
  94. this._popdownCallbacks.forEach(func => func());
  95. this._popdownCallbacks = [];
  96. },
  97. });
  98. this._needsZoomAndFade = false;
  99. };
  100. export const AppFoldersBlur = class AppFoldersBlur {
  101. constructor(connections, settings, _) {
  102. this.connections = connections;
  103. this.paint_signals = new PaintSignals(connections);
  104. this.settings = settings;
  105. }
  106. enable() {
  107. this._log("blurring appfolders");
  108. brightness = this.settings.appfolder.CUSTOMIZE
  109. ? this.settings.appfolder.BRIGHTNESS
  110. : this.settings.BRIGHTNESS;
  111. sigma = this.settings.appfolder.CUSTOMIZE
  112. ? this.settings.appfolder.SIGMA
  113. : this.settings.SIGMA;
  114. let appDisplay = Main.overview._overview.controls._appDisplay;
  115. if (appDisplay._folderIcons.length > 0) {
  116. this.blur_appfolders();
  117. }
  118. this.connections.connect(
  119. appDisplay, 'view-loaded', this.blur_appfolders.bind(this)
  120. );
  121. }
  122. blur_appfolders() {
  123. let appDisplay = Main.overview._overview.controls._appDisplay;
  124. if (this.settings.HACKS_LEVEL === 1 || this.settings.HACKS_LEVEL === 2)
  125. this._log(`appfolders hack level ${this.settings.HACKS_LEVEL}`);
  126. appDisplay._folderIcons.forEach(icon => {
  127. icon._ensureFolderDialog();
  128. if (original_zoomAndFadeIn == null) {
  129. original_zoomAndFadeIn = icon._dialog._zoomAndFadeIn;
  130. }
  131. if (original_zoomAndFadeOut == null) {
  132. original_zoomAndFadeOut = icon._dialog._zoomAndFadeOut;
  133. }
  134. let blur_effect = new Shell.BlurEffect({
  135. name: "appfolder-blur",
  136. sigma: sigma,
  137. brightness: brightness,
  138. mode: Shell.BlurMode.BACKGROUND
  139. });
  140. icon._dialog.remove_effect_by_name("appfolder-blur");
  141. icon._dialog.add_effect(blur_effect);
  142. DIALOGS_STYLES.forEach(
  143. style => icon._dialog._viewBox.remove_style_class_name(style)
  144. );
  145. if (this.settings.appfolder.STYLE_DIALOGS > 0)
  146. icon._dialog._viewBox.add_style_class_name(
  147. DIALOGS_STYLES[this.settings.appfolder.STYLE_DIALOGS - 1]
  148. );
  149. // finally override the builtin functions
  150. icon._dialog._zoomAndFadeIn = _zoomAndFadeIn;
  151. icon._dialog._zoomAndFadeOut = _zoomAndFadeOut;
  152. // HACK
  153. //
  154. //`Shell.BlurEffect` does not repaint when shadows are under it. [1]
  155. //
  156. // This does not entirely fix this bug (shadows caused by windows
  157. // still cause artifacts), but it prevents the shadows of the panel
  158. // buttons to cause artifacts on the panel itself
  159. //
  160. // [1]: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2857
  161. if (this.settings.HACKS_LEVEL === 1 || this.settings.HACKS_LEVEL === 2) {
  162. this.paint_signals.disconnect_all_for_actor(icon._dialog);
  163. this.paint_signals.connect(icon._dialog, blur_effect);
  164. } else {
  165. this.paint_signals.disconnect_all();
  166. }
  167. });
  168. };
  169. set_sigma(s) {
  170. sigma = s;
  171. if (this.settings.appfolder.BLUR)
  172. this.blur_appfolders();
  173. }
  174. set_brightness(b) {
  175. brightness = b;
  176. if (this.settings.appfolder.BLUR)
  177. this.blur_appfolders();
  178. }
  179. // not implemented for dynamic blur
  180. set_color(c) { }
  181. set_noise_amount(n) { }
  182. set_noise_lightness(l) { }
  183. disable() {
  184. this._log("removing blur from appfolders");
  185. let appDisplay = Main.overview._overview.controls._appDisplay;
  186. if (original_zoomAndFadeIn != null) {
  187. appDisplay._folderIcons.forEach(icon => {
  188. if (icon._dialog)
  189. icon._dialog._zoomAndFadeIn = original_zoomAndFadeIn;
  190. });
  191. }
  192. if (original_zoomAndFadeOut != null) {
  193. appDisplay._folderIcons.forEach(icon => {
  194. if (icon._dialog)
  195. icon._dialog._zoomAndFadeOut = original_zoomAndFadeOut;
  196. });
  197. }
  198. appDisplay._folderIcons.forEach(icon => {
  199. if (icon._dialog) {
  200. icon._dialog.remove_effect_by_name("appfolder-blur");
  201. DIALOGS_STYLES.forEach(
  202. s => icon._dialog._viewBox.remove_style_class_name(s)
  203. );
  204. }
  205. });
  206. this.connections.disconnect_all();
  207. }
  208. _log(str) {
  209. if (this.settings.DEBUG)
  210. console.log(`[Blur my Shell > appfolders] ${str}`);
  211. }
  212. };