Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/Effects/ShadowEffect.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public class Gala.ShadowEffect : Clutter.Effect {
private const float INITIAL_OPACITY = 0.25f;
// Common GPU max texture size; also keeps width * height well below int overflow.
private const int MAX_TEXTURE_SIZE = 16384;

private class Shadow {
public int users;
Expand Down Expand Up @@ -114,8 +116,19 @@ public class Gala.ShadowEffect : Clutter.Effect {
var bounding_box = get_bounding_box ();
var width = (int) (bounding_box.x2 - bounding_box.x1);
var height = (int) (bounding_box.y2 - bounding_box.y1);
var scaled_shadow_size = Utils.scale_to_int (shadow_size, monitor_scale);
var scaled_border_radius = Utils.scale_to_int (border_radius, monitor_scale);

// get_shadow_texture () allocates width * height bytes and its corner loops
// assume the texture fits two full corners. A bogus actor size (e.g. from an
// invalid monitor geometry) would otherwise crash the compositor.
var min_size = 2 * (scaled_shadow_size + scaled_border_radius);
if (width < min_size || height < min_size || width > MAX_TEXTURE_SIZE || height > MAX_TEXTURE_SIZE) {
actor.continue_paint (context);
return;
}

var shadow = get_shadow (context.get_framebuffer ().get_context (), width, height, Utils.scale_to_int (shadow_size, monitor_scale), Utils.scale_to_int (border_radius, monitor_scale));
var shadow = get_shadow (context.get_framebuffer ().get_context (), width, height, scaled_shadow_size, scaled_border_radius);
if (shadow != null) {
pipeline.set_layer_texture (0, shadow);
}
Expand Down
66 changes: 41 additions & 25 deletions src/Background/BackgroundManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag
public signal void changed ();

public Meta.Display display { get; construct; }
public int monitor_index { get; construct; }
public int monitor_index { get; construct set; }
public bool control_position { get; construct; }
public bool rounded_corners { get; construct; }
public Meta.BackgroundActor newest_background_actor {
Expand All @@ -32,9 +32,44 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag
background_source = BackgroundCache.get_default ().get_background_source (display);
update_background_actor (false);

notify["monitor-index"].connect (() => update_background_actor (false));
destroy.connect (on_destroy);
}

/**
* The monitor layout can change after construction (e.g. a laptop lid being
* closed) leaving #monitor_index pointing at a monitor that no longer exists.
* Mutter then leaves the out rect uninitialized, so never use it in that case.
*/
private bool get_monitor_geometry (out Mtk.Rectangle geometry) {
if (monitor_index < 0 || monitor_index >= display.get_n_monitors ()) {
geometry = { 0, 0, 0, 0 };
return false;
}

geometry = display.get_monitor_geometry (monitor_index);
return true;
}

private void set_rounded_clip (Meta.BackgroundContent content) {
if (!rounded_corners) {
return;
}

Mtk.Rectangle monitor_geometry;
if (!get_monitor_geometry (out monitor_geometry)) {
return;
}

var clip_bounds = Graphene.Rect () {
origin = {0, 0},
size = {monitor_geometry.width, monitor_geometry.height},
};

content.set_rounded_clip_bounds (clip_bounds);
content.rounded_clip_radius = Utils.scale_to_int (6, Utils.get_ui_scaling_factor (display, monitor_index));
}

private void on_destroy () {
BackgroundCache.get_default ().release_background_source ();
background_source = null;
Expand Down Expand Up @@ -91,17 +126,7 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag
var background = new_content.background.get_data<unowned Background> ("delegate");

if (background.is_loaded) {
if (rounded_corners) {
var monitor_geometry = display.get_monitor_geometry (monitor_index);
var clip_bounds = Graphene.Rect () {
origin = {0, 0},
size = {monitor_geometry.width, monitor_geometry.height},
};

new_content.set_rounded_clip_bounds (clip_bounds);
new_content.rounded_clip_radius = Utils.scale_to_int (6, Utils.get_ui_scaling_factor (display, monitor_index));
}

set_rounded_clip (new_content);
swap_background_actor (animate);
return;
}
Expand All @@ -117,17 +142,7 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag
return;
}

if (rounded_corners) {
var monitor_geometry = display.get_monitor_geometry (monitor_index);
var clip_bounds = Graphene.Rect () {
origin = {0, 0},
size = {monitor_geometry.width, monitor_geometry.height},
};

new_content.set_rounded_clip_bounds (clip_bounds);
new_content.rounded_clip_radius = Utils.scale_to_int (6, Utils.get_ui_scaling_factor (display, monitor_index));
}

set_rounded_clip (new_content);
swap_background_actor (animate);
});
background.set_data<ulong> ("background-loaded-handler", handler);
Expand All @@ -150,7 +165,8 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag
unowned var content = (Meta.BackgroundContent) background_actor.content;
content.background = background.background;

var monitor = display.get_monitor_geometry (monitor_index);
Mtk.Rectangle monitor;
var monitor_valid = get_monitor_geometry (out monitor);

if (background_source.should_dim) {
content.vignette = true;
Expand All @@ -161,7 +177,7 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag

background_actor.set_size (monitor.width, monitor.height);

if (control_position) {
if (control_position && monitor_valid) {
background_actor.set_position (monitor.x, monitor.y);
}

Expand Down
23 changes: 22 additions & 1 deletion src/Widgets/MultitaskingView/WorkspaceClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
private class Gala.FramedBackground : BackgroundManager {
private Cogl.Pipeline pipeline;
private ShadowEffect shadow_effect;
private Cairo.ImageSurface cached_surface;
private Cairo.Context cached_context;
private Cogl.Texture2D cached_texture;
Expand All @@ -32,9 +33,29 @@ private class Gala.FramedBackground : BackgroundManager {
#endif
pipeline = new Cogl.Pipeline (ctx);

add_effect (new ShadowEffect ("workspace", Utils.get_ui_scaling_factor (display, display.get_primary_monitor ())));
shadow_effect = new ShadowEffect ("workspace", Utils.get_ui_scaling_factor (display, display.get_primary_monitor ()));
add_effect (shadow_effect);

reactive = true;

// monitor_index is captured at construction, keep following the primary
// monitor so we never look up the geometry of a monitor that is gone.
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.connect (on_monitors_changed);
}

~FramedBackground () {
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.disconnect (on_monitors_changed);
}

private void on_monitors_changed () {
var primary = display.get_primary_monitor ();
shadow_effect.monitor_scale = Utils.get_ui_scaling_factor (display, primary);

if (monitor_index != primary) {
monitor_index = primary;
}
}

public override void paint (Clutter.PaintContext context) {
Expand Down