Skip to content

Commit

Permalink
Add brightness effect for contrast (#1811)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Dec 19, 2023
1 parent d38c8b6 commit 13fab74
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 46 deletions.
15 changes: 15 additions & 0 deletions data/gala.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,18 @@
0 3px 14px 2px alpha(#000, 0.12),
0 5px 5px -3px alpha(#000, 0.4);
}

.workspace-switcher.decoration {
border-radius: 6px;
box-shadow:
0 3px 4px alpha(#000, 0.25),
0 3px 3px -3px alpha(#000, 0.45);
}

.workspace-switcher-dnd.decoration {
border-radius: 6px;
box-shadow:
0 8px 10px 1px alpha(#000, 0.14),
0 3px 14px 2px alpha(#000, 0.12),
0 5px 5px -3px alpha(#000, 0.4);
}
104 changes: 58 additions & 46 deletions src/Widgets/IconGroup.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Gala {
public class IconGroup : Clutter.Actor {
public const int SIZE = 64;

private const int PLUS_SIZE = 8;
private const int PLUS_WIDTH = 24;
private const int PLUS_SIZE = 6;
private const int PLUS_WIDTH = 26;
private const int BACKDROP_ABSOLUTE_OPACITY = 40;

/**
Expand Down Expand Up @@ -208,6 +208,7 @@ namespace Gala {
* by relayouting in the same function, as it's only ever called when we invalidate it.
*/
private bool draw (Cairo.Context cr) {
clear_effects ();
cr.set_operator (Cairo.Operator.CLEAR);
cr.paint ();
cr.set_operator (Cairo.Operator.OVER);
Expand All @@ -225,43 +226,45 @@ namespace Gala {
// more than one => we need a folder
Drawing.Utilities.cairo_rounded_rectangle (
cr,
0.5 * scale_factor,
0.5 * scale_factor,
(int) width - InternalUtils.scale_to_int (1, scale_factor),
(int) height - InternalUtils.scale_to_int (1, scale_factor),
0,
0,
(int) width,
(int) height,
InternalUtils.scale_to_int (5, scale_factor)
);

var shadow_effect = new ShadowEffect (40) {
scale_factor = scale_factor
};

var granite_settings = Granite.Settings.get_default ();

if (granite_settings.prefers_color_scheme == DARK) {
const double BG_COLOR = 35.0 / 255.0;
if (drag_action.dragging) {
cr.set_source_rgba (BG_COLOR, BG_COLOR, BG_COLOR, 0.8);
} else {
cr.set_source_rgba (BG_COLOR , BG_COLOR , BG_COLOR , 0.5);
shadow_effect.shadow_opacity = 200;
}
} else {
if (drag_action.dragging) {
cr.set_source_rgba (255, 255, 255, 0.8);
} else {
cr.set_source_rgba (255, 255, 255, 0.3);
shadow_effect.shadow_opacity = 100;
}
}

if (drag_action.dragging) {
const double BG_COLOR = 53.0 / 255.0;
cr.set_source_rgba (BG_COLOR, BG_COLOR, BG_COLOR, 0.7);
shadow_effect.css_class = "workspace-switcher-dnd";
} else {
cr.set_source_rgba (0, 0, 0, 0.1);
shadow_effect.css_class = "workspace-switcher";
}

add_effect (shadow_effect);
cr.fill_preserve ();

cr.set_line_width (InternalUtils.scale_to_int (1, scale_factor));

var grad = new Cairo.Pattern.linear (0, 0, 0, height);
grad.add_color_stop_rgba (0.8, 0, 0, 0, 0);
grad.add_color_stop_rgba (1.0, 1, 1, 1, 0.1);

cr.set_source (grad);
cr.stroke ();

Drawing.Utilities.cairo_rounded_rectangle (
cr,
1.5 * scale_factor,
1.5 * scale_factor,
(int) width - InternalUtils.scale_to_int (3, scale_factor),
(int) height - InternalUtils.scale_to_int (3, scale_factor),
InternalUtils.scale_to_int (5, scale_factor)
);

cr.set_source_rgba (0, 0, 0, 0.3);
cr.stroke ();

// it's not safe to to call meta_workspace_index() here, we may be still animating something
// while the workspace is already gone, which would result in a crash.
unowned Meta.WorkspaceManager manager = workspace.get_display ().get_workspace_manager ();
Expand All @@ -284,27 +287,36 @@ namespace Gala {
var offset = scaled_size / 2 - InternalUtils.scale_to_int (PLUS_WIDTH, scale_factor) / 2;

buffer.context.rectangle (
InternalUtils.scale_to_int (PLUS_WIDTH / 2, scale_factor) - InternalUtils.scale_to_int (PLUS_SIZE / 2, scale_factor) + 0.5 + offset,
0.5 + offset,
InternalUtils.scale_to_int (PLUS_SIZE, scale_factor) - 1,
InternalUtils.scale_to_int (PLUS_WIDTH, scale_factor) - 1
InternalUtils.scale_to_int (PLUS_WIDTH / 2, scale_factor) - InternalUtils.scale_to_int (PLUS_SIZE / 2, scale_factor) + offset,
offset,
InternalUtils.scale_to_int (PLUS_SIZE, scale_factor),
InternalUtils.scale_to_int (PLUS_WIDTH, scale_factor)
);

buffer.context.rectangle (0.5 + offset,
InternalUtils.scale_to_int (PLUS_WIDTH / 2, scale_factor) - InternalUtils.scale_to_int (PLUS_SIZE / 2, scale_factor) + 0.5 + offset,
InternalUtils.scale_to_int (PLUS_WIDTH, scale_factor) - 1,
InternalUtils.scale_to_int (PLUS_SIZE, scale_factor) - 1
buffer.context.rectangle (offset,
InternalUtils.scale_to_int (PLUS_WIDTH / 2, scale_factor) - InternalUtils.scale_to_int (PLUS_SIZE / 2, scale_factor) + offset,
InternalUtils.scale_to_int (PLUS_WIDTH, scale_factor),
InternalUtils.scale_to_int (PLUS_SIZE, scale_factor)
);

buffer.context.set_source_rgb (0, 0, 0);
buffer.context.fill_preserve ();
buffer.exponential_blur (5);

buffer.context.set_source_rgb (1, 1, 1);
buffer.context.set_line_width (1);
buffer.context.stroke_preserve ();
if (granite_settings.prefers_color_scheme == DARK) {
buffer.context.move_to (0, 1 * scale_factor);
buffer.context.set_source_rgb (0, 0, 0);
buffer.context.fill_preserve ();
buffer.exponential_blur (2);

buffer.context.move_to (0, 0);
buffer.context.set_source_rgba (1, 1, 1, 0.95);
} else {
buffer.context.move_to (0, 1 * scale_factor);
buffer.context.set_source_rgba (1, 1, 1, 0.4);
buffer.context.fill_preserve ();
buffer.exponential_blur (1);

buffer.context.move_to (0, 0);
buffer.context.set_source_rgba (0, 0, 0, 0.7);
}

buffer.context.set_source_rgb (0.8, 0.8, 0.8);
buffer.context.fill ();

cr.set_source_surface (buffer.surface, 0, 0);
Expand Down
18 changes: 18 additions & 0 deletions src/Widgets/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ namespace Gala {
private Clutter.Actor workspaces;
private Clutter.Actor dock_clones;
private Clutter.Actor primary_monitor_container;
private Clutter.BrightnessContrastEffect brightness_effect;

private GLib.Settings gala_behavior_settings;
private Granite.Settings granite_settings;

private bool switching_workspace_with_gesture = false;
private bool switching_workspace_in_progress {
Expand All @@ -57,6 +59,7 @@ namespace Gala {

construct {
gala_behavior_settings = new GLib.Settings ("org.pantheon.desktop.gala.behavior");
granite_settings = Granite.Settings.get_default ();

visible = false;
reactive = true;
Expand All @@ -80,8 +83,13 @@ namespace Gala {

dock_clones = new Clutter.Actor ();

brightness_effect = new Clutter.BrightnessContrastEffect ();
update_brightness_effect ();

var blurred_bg = new BackgroundManager (wm, display.get_primary_monitor ());
blurred_bg.add_effect (new BlurEffect (blurred_bg, 18));
blurred_bg.add_effect (brightness_effect);

add_child (blurred_bg);

// Create a child container that will be sized to fit the primary monitor, to contain the "main"
Expand Down Expand Up @@ -141,6 +149,16 @@ namespace Gala {
return Source.REMOVE;
});
});

granite_settings.notify["prefers-color-scheme"].connect (update_brightness_effect);
}

private void update_brightness_effect () {
if (granite_settings.prefers_color_scheme == DARK) {
brightness_effect.set_brightness (-0.4f);
} else {
brightness_effect.set_brightness (0.4f);
}
}

/**
Expand Down

0 comments on commit 13fab74

Please sign in to comment.