overview.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import Meta from 'gi://Meta';
  2. import * as Main from 'resource:///org/gnome/shell/ui/main.js';
  3. import { WorkspaceAnimationController } from 'resource:///org/gnome/shell/ui/workspaceAnimation.js';
  4. const wac_proto = WorkspaceAnimationController.prototype;
  5. import { Pipeline } from '../conveniences/pipeline.js';
  6. const OVERVIEW_COMPONENTS_STYLE = [
  7. "overview-components-light",
  8. "overview-components-dark",
  9. "overview-components-transparent"
  10. ];
  11. export const OverviewBlur = class OverviewBlur {
  12. constructor(connections, settings, effects_manager) {
  13. this.connections = connections;
  14. this.settings = settings;
  15. this.effects_manager = effects_manager;
  16. this.overview_background_managers = [];
  17. this.overview_background_group = new Meta.BackgroundGroup(
  18. { name: 'bms-overview-backgroundgroup' }
  19. );
  20. this.animation_background_managers = [];
  21. this.animation_background_group = new Meta.BackgroundGroup(
  22. { name: 'bms-animation-backgroundgroup' }
  23. );
  24. this.enabled = false;
  25. this.proto_patched = false;
  26. }
  27. enable() {
  28. this._log("blurring overview");
  29. // add css class name for workspace-switch background
  30. Main.uiGroup.add_style_class_name("blurred-overview");
  31. // add css class name to make components semi-transparent if wanted
  32. this.update_components_classname();
  33. // update backgrounds when the component is enabled
  34. this.update_backgrounds();
  35. // connect to monitors change
  36. this.connections.connect(Main.layoutManager, 'monitors-changed',
  37. _ => this.update_backgrounds()
  38. );
  39. // part for the workspace animation switch
  40. // make sure not to do this part if the functions were patched prior, as
  41. // the functions would call themselves and cause infinite recursion
  42. if (!this.proto_patched) {
  43. // store original workspace switching methods for restoring them on
  44. // disable()
  45. this._original_PrepareSwitch = wac_proto._prepareWorkspaceSwitch;
  46. this._original_FinishSwitch = wac_proto._finishWorkspaceSwitch;
  47. const w_m = global.workspace_manager;
  48. const outer_this = this;
  49. // create a blurred background actor for each monitor during a
  50. // workspace switch
  51. wac_proto._prepareWorkspaceSwitch = function (...params) {
  52. outer_this._log("prepare workspace switch");
  53. outer_this._original_PrepareSwitch.apply(this, params);
  54. // this permits to show the blur behind windows that are on
  55. // workspaces on the left and right
  56. if (
  57. outer_this.settings.applications.BLUR
  58. ) {
  59. let ws_index = w_m.get_active_workspace_index();
  60. [ws_index - 1, ws_index + 1].forEach(
  61. i => w_m.get_workspace_by_index(i)?.list_windows().forEach(
  62. window => window.get_compositor_private().show()
  63. )
  64. );
  65. }
  66. Main.uiGroup.insert_child_above(
  67. outer_this.animation_background_group,
  68. global.window_group
  69. );
  70. outer_this.animation_background_managers.forEach(bg_manager => {
  71. if (bg_manager._bms_pipeline.actor)
  72. if (
  73. Meta.prefs_get_workspaces_only_on_primary() &&
  74. bg_manager._monitorIndex !== Main.layoutManager.primaryMonitor.index
  75. )
  76. bg_manager._bms_pipeline.actor.visible = false;
  77. else
  78. bg_manager._bms_pipeline.actor.visible = true;
  79. });
  80. };
  81. // remove the workspace-switch actors when the switch is done
  82. wac_proto._finishWorkspaceSwitch = function (...params) {
  83. outer_this._log("finish workspace switch");
  84. outer_this._original_FinishSwitch.apply(this, params);
  85. // this hides windows that are not on the current workspace
  86. if (
  87. outer_this.settings.applications.BLUR
  88. )
  89. for (let i = 0; i < w_m.get_n_workspaces(); i++) {
  90. if (i != w_m.get_active_workspace_index())
  91. w_m.get_workspace_by_index(i)?.list_windows().forEach(
  92. window => window.get_compositor_private().hide()
  93. );
  94. }
  95. Main.uiGroup.remove_child(outer_this.animation_background_group);
  96. };
  97. this.proto_patched = true;
  98. }
  99. this.enabled = true;
  100. }
  101. update_backgrounds() {
  102. // remove every old background
  103. this.remove_background_actors();
  104. // create new backgrounds for the overview and the animation
  105. for (let i = 0; i < Main.layoutManager.monitors.length; i++) {
  106. const pipeline_overview = new Pipeline(
  107. this.effects_manager,
  108. global.blur_my_shell._pipelines_manager,
  109. this.settings.overview.PIPELINE
  110. );
  111. pipeline_overview.create_background_with_effects(
  112. i, this.overview_background_managers,
  113. this.overview_background_group, 'bms-overview-blurred-widget'
  114. );
  115. const pipeline_animation = new Pipeline(
  116. this.effects_manager,
  117. global.blur_my_shell._pipelines_manager,
  118. this.settings.overview.PIPELINE
  119. );
  120. pipeline_animation.create_background_with_effects(
  121. i, this.animation_background_managers,
  122. this.animation_background_group, 'bms-animation-blurred-widget'
  123. );
  124. }
  125. // add the container widget for the overview only to the overview group
  126. Main.layoutManager.overviewGroup.insert_child_at_index(this.overview_background_group, 0);
  127. // make sure it stays below
  128. this.connections.connect(Main.layoutManager.overviewGroup, "child-added", (_, child) => {
  129. if (child !== this.overview_background_group) {
  130. if (this.overview_background_group.get_parent())
  131. Main.layoutManager.overviewGroup.remove_child(this.overview_background_group);
  132. Main.layoutManager.overviewGroup.insert_child_at_index(this.overview_background_group, 0);
  133. }
  134. });
  135. }
  136. /// Updates the classname to style overview components with semi-transparent
  137. /// backgrounds.
  138. update_components_classname() {
  139. OVERVIEW_COMPONENTS_STYLE.forEach(
  140. style => Main.uiGroup.remove_style_class_name(style)
  141. );
  142. if (this.settings.overview.STYLE_COMPONENTS > 0)
  143. Main.uiGroup.add_style_class_name(
  144. OVERVIEW_COMPONENTS_STYLE[this.settings.overview.STYLE_COMPONENTS - 1]
  145. );
  146. }
  147. remove_background_actors() {
  148. this.overview_background_group.remove_all_children();
  149. this.animation_background_group.remove_all_children();
  150. this.connections.disconnect_all_for(Main.layoutManager.overviewGroup);
  151. if (this.overview_background_group.get_parent())
  152. Main.layoutManager.overviewGroup.remove_child(this.overview_background_group);
  153. this.overview_background_managers.forEach(background_manager => {
  154. background_manager._bms_pipeline.destroy();
  155. background_manager.destroy();
  156. });
  157. this.animation_background_managers.forEach(background_manager => {
  158. background_manager._bms_pipeline.destroy();
  159. background_manager.destroy();
  160. });
  161. this.overview_background_managers = [];
  162. this.animation_background_managers = [];
  163. }
  164. disable() {
  165. this._log("removing blur from overview");
  166. this.remove_background_actors();
  167. Main.uiGroup.remove_style_class_name("blurred-overview");
  168. OVERVIEW_COMPONENTS_STYLE.forEach(
  169. style => Main.uiGroup.remove_style_class_name(style)
  170. );
  171. this.connections.disconnect_all();
  172. this.enabled = false;
  173. }
  174. restore_patched_proto() {
  175. if (this.proto_patched) {
  176. if (this._original_PrepareSwitch)
  177. wac_proto._prepareWorkspaceSwitch = this._original_PrepareSwitch;
  178. if (this._original_FinishSwitch)
  179. wac_proto._finishWorkspaceSwitch = this._original_FinishSwitch;
  180. this.proto_patched = false;
  181. }
  182. }
  183. _log(str) {
  184. if (this.settings.DEBUG)
  185. console.log(`[Blur my Shell > overview] ${str}`);
  186. }
  187. _warn(str) {
  188. console.warn(`[Blur my Shell > overview] ${str}`);
  189. }
  190. };