dummy_pipeline.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import St from 'gi://St';
  2. import Clutter from 'gi://Clutter';
  3. /// A dummy `Pipeline`, for dynamic blur only.
  4. /// Instead of a pipeline id, we take the settings of the component we want to blur.
  5. export const DummyPipeline = class DummyPipeline {
  6. constructor(effects_manager, settings, actor = null) {
  7. this.effects_manager = effects_manager;
  8. this.settings = settings;
  9. this.effect = null;
  10. this.attach_effect_to_actor(actor);
  11. }
  12. create_background_with_effect(
  13. background_group,
  14. widget_name
  15. ) {
  16. // create the new actor
  17. this.actor = new St.Widget({ name: widget_name });
  18. this.attach_effect_to_actor(this.actor);
  19. // a dummy `BackgroundManager`, just to access the pipeline easily
  20. let bg_manager = new Clutter.Actor;
  21. bg_manager.backgroundActor = this.actor;
  22. bg_manager._bms_pipeline = this;
  23. background_group.insert_child_at_index(this.actor, 0);
  24. return [this.actor, bg_manager];
  25. };
  26. attach_effect_to_actor(actor) {
  27. // set the actor
  28. if (actor)
  29. this.actor = actor;
  30. else {
  31. this.remove_pipeline_from_actor();
  32. return;
  33. }
  34. // build the new effect to be added
  35. this.build_effect({
  36. unscaled_radius: 2 * this.settings.SIGMA,
  37. brightness: this.settings.BRIGHTNESS,
  38. });
  39. this.actor_destroy_id = this.actor.connect(
  40. "destroy", () => this.remove_pipeline_from_actor()
  41. );
  42. // add the effect to the actor
  43. if (this.actor)
  44. this.actor.add_effect(this.effect);
  45. else
  46. this._warn(`could not add effect to actor, actor does not exist anymore`);
  47. }
  48. remove_pipeline_from_actor() {
  49. this.remove_effect();
  50. if (this.actor && this.actor_destroy_id)
  51. this.actor.disconnect(this.actor_destroy_id);
  52. this.actor_destroy_id = null;
  53. this.actor = null;
  54. }
  55. build_effect(params) {
  56. // create the effect
  57. this.effect = this.effects_manager.new_native_dynamic_gaussian_blur_effect(params);
  58. // connect to settings changes, using the true gsettings object
  59. this._sigma_changed_id = this.settings.settings.connect(
  60. 'changed::sigma', () => this.effect.unscaled_radius = 2 * this.settings.SIGMA
  61. );
  62. this._brightness_changed_id = this.settings.settings.connect(
  63. 'changed::brightness', () => this.effect.brightness = this.settings.BRIGHTNESS
  64. );
  65. }
  66. repaint_effect() {
  67. this.effect?.queue_repaint();
  68. }
  69. /// Remove every effect from the actor it is attached to. Please note that they are not
  70. /// destroyed, but rather stored (thanks to the `EffectManager` class) to be reused later.
  71. remove_effect() {
  72. if (this.effect)
  73. this.effects_manager.remove(this.effect);
  74. this.effect = null;
  75. if (this._sigma_changed_id)
  76. this.settings.settings.disconnect(this._sigma_changed_id);
  77. if (this._brightness_changed_id)
  78. this.settings.settings.disconnect(this._brightness_changed_id);
  79. delete this._sigma_changed_id;
  80. delete this._brightness_changed_id;
  81. }
  82. /// Do nothing for this dummy pipeline.
  83. /// Note: exposed to public API.
  84. change_pipeline_to() { return; }
  85. /// Note: exposed to public API.
  86. destroy() {
  87. this.remove_effect();
  88. this.remove_pipeline_from_actor();
  89. }
  90. _warn(str) {
  91. console.warn(`[Blur my Shell > dummy pip] ${str}`);
  92. }
  93. };