mirror of
https://github.com/elementary/gala.git
synced 2024-12-29 12:13:20 +03:00
WindowClone: Fix shadows (#1503)
Co-authored-by: Ryan Kornheisl <ryan@skarva.tech>
This commit is contained in:
parent
d8bfa8129d
commit
223fdb0135
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Gala Developers
|
||||
* Copyright 2014 Gala Developers
|
||||
* Copyright 2022 elementary, Inc. (https://elementary.io)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -36,6 +37,14 @@
|
||||
0 10px 10px rgba(0, 0, 0, 0.22);
|
||||
}
|
||||
|
||||
.window-clone.decoration {
|
||||
border-radius: 0;
|
||||
box-shadow:
|
||||
0 0 0 1px alpha(#000, 0.3),
|
||||
0 14px 20px rgba(0, 0, 0, 0.35),
|
||||
0 10px 10px rgba(0, 0, 0, 0.22);
|
||||
}
|
||||
|
||||
.workspace.decoration {
|
||||
border-radius: 4px;
|
||||
box-shadow:
|
||||
|
@ -47,7 +47,6 @@ namespace Gala {
|
||||
}
|
||||
|
||||
public int shadow_size { get; construct; }
|
||||
public int shadow_spread { get; construct; }
|
||||
|
||||
public float scale_factor { get; set; default = 1; }
|
||||
public uint8 shadow_opacity { get; set; default = 255; }
|
||||
@ -56,8 +55,8 @@ namespace Gala {
|
||||
Cogl.Pipeline pipeline;
|
||||
string? current_key = null;
|
||||
|
||||
public ShadowEffect (int shadow_size, int shadow_spread) {
|
||||
Object (shadow_size: shadow_size, shadow_spread: shadow_spread);
|
||||
public ShadowEffect (int shadow_size) {
|
||||
Object (shadow_size: shadow_size);
|
||||
}
|
||||
|
||||
construct {
|
||||
@ -69,9 +68,9 @@ namespace Gala {
|
||||
decrement_shadow_users (current_key);
|
||||
}
|
||||
|
||||
Cogl.Texture? get_shadow (Cogl.Context context, int width, int height, int shadow_size, int shadow_spread) {
|
||||
Cogl.Texture? get_shadow (Cogl.Context context, int width, int height, int shadow_size) {
|
||||
var old_key = current_key;
|
||||
current_key = "%ix%i:%i:%i".printf (width, height, shadow_size, shadow_spread);
|
||||
current_key = "%ix%i:%i".printf (width, height, shadow_size);
|
||||
if (old_key == current_key)
|
||||
return null;
|
||||
|
||||
@ -135,7 +134,7 @@ namespace Gala {
|
||||
var width = (int) (bounding_box.x2 - bounding_box.x1);
|
||||
var height = (int) (bounding_box.y2 - bounding_box.y1);
|
||||
|
||||
var shadow = get_shadow (context.get_framebuffer ().get_context (), width, height, shadow_size, shadow_spread);
|
||||
var shadow = get_shadow (context.get_framebuffer ().get_context (), width, height, shadow_size);
|
||||
if (shadow != null)
|
||||
pipeline.set_layer_texture (0, shadow);
|
||||
|
||||
@ -161,13 +160,16 @@ namespace Gala {
|
||||
}
|
||||
|
||||
public override bool modify_paint_volume (Clutter.PaintVolume volume) {
|
||||
var size = shadow_size * scale_factor;
|
||||
volume.set_width (volume.get_width () + size * 2);
|
||||
volume.set_height (volume.get_height () + size * 2);
|
||||
var bounding_box = get_bounding_box ();
|
||||
|
||||
volume.set_width (bounding_box.get_width ());
|
||||
volume.set_height (bounding_box.get_height ());
|
||||
|
||||
float origin_x, origin_y;
|
||||
bounding_box.get_origin (out origin_x, out origin_y);
|
||||
var origin = volume.get_origin ();
|
||||
origin.x -= size;
|
||||
origin.y -= size;
|
||||
origin.x += origin_x;
|
||||
origin.y += origin_y;
|
||||
volume.set_origin (origin);
|
||||
|
||||
return true;
|
||||
|
@ -224,7 +224,7 @@ public class Gala.WindowClone : Clutter.Actor {
|
||||
|
||||
if (window.fullscreen || window.maximized_horizontally && window.maximized_vertically) {
|
||||
if (shadow_effect == null) {
|
||||
shadow_effect = new WindowShadowEffect (window, 40, 5);
|
||||
shadow_effect = new WindowShadowEffect (window, 40);
|
||||
clone.add_effect_with_name ("shadow", shadow_effect);
|
||||
}
|
||||
} else {
|
||||
@ -824,13 +824,13 @@ public class Gala.WindowClone : Clutter.Actor {
|
||||
private class WindowShadowEffect : ShadowEffect {
|
||||
public unowned Meta.Window window { get; construct; }
|
||||
|
||||
public WindowShadowEffect (Meta.Window window, int shadow_size, int shadow_spread) {
|
||||
Object (window: window, shadow_size: shadow_size, shadow_spread: shadow_spread, shadow_opacity: 255);
|
||||
public WindowShadowEffect (Meta.Window window, int shadow_size) {
|
||||
Object (window: window, shadow_size: shadow_size, css_class: "window-clone");
|
||||
}
|
||||
|
||||
public override Clutter.ActorBox get_bounding_box () {
|
||||
var scale_factor = InternalUtils.get_ui_scaling_factor ();
|
||||
var size = (shadow_size + shadow_spread) * scale_factor;
|
||||
var size = shadow_size * scale_factor;
|
||||
|
||||
var input_rect = window.get_buffer_rect ();
|
||||
var outer_rect = window.get_frame_rect ();
|
||||
|
@ -56,7 +56,7 @@ namespace Gala {
|
||||
create_components ();
|
||||
|
||||
// FIXME: Kind of abusing the style class here for a smaller shadow
|
||||
var effect = new ShadowEffect (30, 1) {
|
||||
var effect = new ShadowEffect (30) {
|
||||
shadow_opacity = 200,
|
||||
css_class = "workspace"
|
||||
};
|
||||
|
@ -39,7 +39,7 @@ namespace Gala {
|
||||
var primary = display.get_primary_monitor ();
|
||||
var monitor_geom = display.get_monitor_geometry (primary);
|
||||
|
||||
var effect = new ShadowEffect (40, 5) {
|
||||
var effect = new ShadowEffect (40) {
|
||||
css_class = "workspace"
|
||||
};
|
||||
add_effect (effect);
|
||||
|
Loading…
Reference in New Issue
Block a user