Skip to content

Commit 9a1887f

Browse files
committed
feat(style): blur window
1 parent 1889396 commit 9a1887f

File tree

5 files changed

+93
-16
lines changed

5 files changed

+93
-16
lines changed

data/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ button.large {
6464
background: none;
6565
}
6666

67+
.main-box.osd {
68+
border-radius: 15px;
69+
}
70+
6771
.about .app-version{color:#fff;text-shadow:-1px -1px 0#000,1px -1px 0#000,-1px 1px 0#000,1px 1px 0#000;background:linear-gradient(150deg,#fdd81755 0,#66338b55 8.3%,#fff5 16.6%,#f4aec855 24.9%,#7bcce555 33.2%,#94551655 41.5%,#0005 49.8%,#e2201655 58.1%,#f2891755 66.4%,#efe52455 74.7%,#78b82a55 83%,#2c58a4 91.3%,#6d238055 100%);}
6872
.about .app-version:hover{background:radial-gradient(circle at 9.75% 50%,#0000 6.66%,#7902aa 6.7%,#0000 8.4%),conic-gradient(at 26.66% 50%,#0000 222.75deg,#ffd800 0 317.25deg,#0000 0),conic-gradient(at 33% 50%,#0000 222.75deg,white 0 317.25deg,#0000 0),conic-gradient(at 39% 50%,#0000 222.75deg,#ffa6b9 0 317.25deg,#0000 0),conic-gradient(at 45.66% 50%,#0000 222.75deg,#00d2ff 0 317.25deg,#0000 0),conic-gradient(at 52% 50%,#0000 222.75deg,#753000 0 317.25deg,#0000 0),conic-gradient(at 58.33% 50%,#0000 222.75deg,#000 0 317.25deg,#0000 0),linear-gradient(to bottom,#e40303,#e40303 16.67%,#ff8c00 16.67%,#ff8c00 33.33%,#ffed00 33.33%,#ffed00 50%,#008026 50%,#008026 66.67%,#004dff 66.67%,#004dff 83.33%,#750787 83.33%,#750787);}
6973
.theme-disability.about .app-version{background:linear-gradient(45deg,#59595955 0,#59595955 37.5%,#cf728055 37.5%,#cf728055 42.5%,#eede7755 42.5%,#eede7755 47.5%,#e8e8e855 47.5%,#e8e8e855 52.5%,#7bc2e055 52.5%,#7bc2e055 57.5%,#3bb07d55 57.5%,#3bb07d55 62.5%,#59595955 62.5%,#59595955 100%);}

src/Utils/Cli.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class Turntable.Utils.CLI : GLib.Object {
101101
scrobbling_manager.clear_queue ("1");
102102
foreach (var binding in cli_player_bindings) {
103103
binding.unbind ();
104+
binding.unref ();
104105
}
105106
cli_player_bindings = {};
106107

src/Views/Window.vala

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
2424
public enum Style {
2525
WINDOW,
2626
OSD,
27-
TRANSPARENT;
27+
TRANSPARENT,
28+
BLUR;
2829

2930
public string to_string () {
3031
switch (this) {
3132
case OSD: return "osd";
3233
case TRANSPARENT: return "transparent";
34+
case BLUR: return "blur";
3335
default: return "window";
3436
}
3537
}
@@ -38,6 +40,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
3840
switch (string_style.down ()) {
3941
case "osd": return OSD;
4042
case "transparent": return TRANSPARENT;
43+
case "blur": return BLUR;
4144
default: return WINDOW;
4245
}
4346
}
@@ -139,7 +142,12 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
139142
get { return _window_style; }
140143
set {
141144
if (value != _window_style) {
145+
// reset to initial state
142146
switch (_window_style) {
147+
case Style.BLUR:
148+
prog.cover = null;
149+
main_box.remove_css_class ("osd");
150+
break;
143151
case Style.WINDOW: break;
144152
case Style.TRANSPARENT:
145153
this.add_css_class ("csd");
@@ -155,6 +163,10 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
155163
string window_style_string = value.to_string ();
156164

157165
switch (_window_style) {
166+
case Style.BLUR:
167+
on_cover_changed ();
168+
main_box.add_css_class ("osd");
169+
return;
158170
case Style.WINDOW: return;
159171
case Style.TRANSPARENT:
160172
this.remove_css_class ("csd");
@@ -370,7 +382,8 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
370382

371383
main_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
372384
valign = CENTER,
373-
halign = CENTER
385+
halign = CENTER,
386+
css_classes = {"main-box"}
374387
};
375388
art_pic = new Widgets.Cover () {
376389
valign = Gtk.Align.START,
@@ -528,6 +541,14 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
528541
};
529542
click_gesture.pressed.connect (on_click);
530543
prog.add_controller (click_gesture);
544+
545+
// art_pic.bind_property ("cover", prog, "cover", SYNC_CREATE);
546+
art_pic.notify["cover"].connect (on_cover_changed);
547+
}
548+
549+
private void on_cover_changed () {
550+
if (this.window_style != Style.BLUR) return;
551+
prog.cover = art_pic.cover;
531552
}
532553

533554
private void on_click () {

src/Widgets/ControlsOverlay.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ public class Turntable.Widgets.ControlsOverlay : Adw.Bin {
221221
window_style_submenu_model.append (_("OSD"), "win.window-style('osd')");
222222
// translators: window style name
223223
window_style_submenu_model.append (_("Transparent"), "win.window-style('transparent')");
224+
// translators: window style name
225+
window_style_submenu_model.append (_("Blur"), "win.window-style('blur')");
224226
// translators: menu entry that opens a submenu
225227
style_submenu_model.append_submenu (_("Window"), window_style_submenu_model);
226228

src/Widgets/ProgressBin.vala

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,16 @@ public class Turntable.Widgets.ProgressBin : Adw.Bin {
160160
}
161161
}
162162

163-
private int32 _offset = 0;
164-
public int32 offset {
165-
get { return _offset; }
166-
set {
167-
if (_offset != value && value >= 0) {
168-
_offset = value;
169-
this.queue_draw ();
170-
}
171-
}
172-
}
163+
// private int32 _offset = 0;
164+
// public int32 offset {
165+
// get { return _offset; }
166+
// set {
167+
// if (_offset != value && value >= 0) {
168+
// _offset = value;
169+
// this.queue_draw ();
170+
// }
171+
// }
172+
// }
173173

174174
private Gtk.Orientation _orientation = Gtk.Orientation.HORIZONTAL;
175175
public Gtk.Orientation orientation {
@@ -222,14 +222,63 @@ public class Turntable.Widgets.ProgressBin : Adw.Bin {
222222
halign = Gtk.Align.END,
223223
margin_end = 6,
224224
margin_bottom = 6,
225-
icon_size = Gtk.IconSize.LARGE
225+
icon_size = Gtk.IconSize.LARGE,
226+
can_target = false
226227
};
227228

228229
overlay.add_overlay (client_icon_widget);
229230
this.child = overlay;
230231
}
231232

233+
private weak Gdk.Texture? _cover = null;
234+
public weak Gdk.Texture? cover {
235+
get { return _cover; }
236+
set {
237+
if (_cover != value) {
238+
_cover = value;
239+
this.queue_draw ();
240+
}
241+
}
242+
}
243+
232244
public override void snapshot (Gtk.Snapshot snapshot) {
245+
int height = this.get_height ();
246+
int width = this.get_width ();
247+
248+
if (_cover != null && _cover is Gdk.Texture) {
249+
snapshot.push_blur (20);
250+
double ratio = _cover.get_intrinsic_aspect_ratio ();
251+
252+
if (ratio == 0) {
253+
_cover.snapshot (snapshot, width, height);
254+
} else {
255+
double w = 0.0;
256+
double h = 0.0;
257+
double picture_ratio = (double) width / height;
258+
259+
if (ratio > picture_ratio) {
260+
w = height * ratio;
261+
h = height;
262+
} else {
263+
w = width;
264+
h = width / ratio;
265+
}
266+
267+
w = Math.ceil (w);
268+
h = Math.ceil (h);
269+
270+
double x = (width - w) / 2;
271+
double y = Math.floor (height - h) / 2;
272+
273+
snapshot.save ();
274+
snapshot.translate (Graphene.Point () { x = (float) x - 20, y = (float) y - 20 });
275+
_cover.snapshot (snapshot, w + 40, h + 40);
276+
snapshot.restore ();
277+
}
278+
279+
snapshot.pop ();
280+
}
281+
233282
if (this.enabled && this.animation.value > 0) {
234283
switch (this.orientation) {
235284
case Gtk.Orientation.VERTICAL:
@@ -241,7 +290,7 @@ public class Turntable.Widgets.ProgressBin : Adw.Bin {
241290
y = 0
242291
},
243292
size = Graphene.Size () {
244-
height = (float) ((this.get_height () - this.offset) * this.animation.value) + this.offset,
293+
height = (float) (height * this.animation.value),
245294
width = this.get_width ()
246295
}
247296
}
@@ -256,8 +305,8 @@ public class Turntable.Widgets.ProgressBin : Adw.Bin {
256305
y = 0
257306
},
258307
size = Graphene.Size () {
259-
height = this.get_height (),
260-
width = (float) ((this.get_width () - this.offset) * this.animation.value) + this.offset
308+
height = height,
309+
width = (float) (width * this.animation.value)
261310
}
262311
}
263312
);

0 commit comments

Comments
 (0)