mpris: rework carousel layout and fix navigation

parent 23095605
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
.widget-mpris { .widget-mpris {
padding: 0; padding: 0;
margin: 5px 10px; margin: 5px 15px;
border-radius: var(--window-radius);
box-shadow: 0px 0px 10px var(--headerbar-shade-color);
border: 1px solid var(--border-color);
background: var(--dialog-bg-color);
carouselindicatordots { carouselindicatordots {
margin: 0px; margin: 0px;
...@@ -16,15 +20,20 @@ ...@@ -16,15 +20,20 @@
padding: 0px; padding: 0px;
} }
.mpris-nav-prev {
border-radius: var(--window-radius) 0 0 var(--window-radius);
}
.mpris-nav-next {
border-radius: 0 var(--window-radius) var(--window-radius) 0;
}
.mpris-background { .mpris-background {
background: transparent; background: transparent;
} }
.widget-mpris-player { .widget-mpris-player {
margin: 0 5px; margin: 0;
border-radius: var(--window-radius);
box-shadow: 0px 0px 10px var(--headerbar-shade-color);
border: 1px solid var(--border-color);
.mpris-overlay { .mpris-overlay {
background: var(--dialog-bg-color); background: var(--dialog-bg-color);
......
...@@ -32,47 +32,47 @@ namespace XimperShellNotificationCenter.Widgets.Mpris { ...@@ -32,47 +32,47 @@ namespace XimperShellNotificationCenter.Widgets.Mpris {
set_valign (Gtk.Align.START); set_valign (Gtk.Align.START);
set_vexpand (false); set_vexpand (false);
carousel_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { carousel_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
visible = true,
};
button_prev = new Gtk.Button.from_icon_name ("go-previous") { button_prev = new Gtk.Button.from_icon_name ("go-previous") {
has_frame = false, has_frame = false,
visible = false, visible = false,
valign = Gtk.Align.FILL,
vexpand = true,
}; };
button_prev.add_css_class ("mpris-nav-prev");
button_prev.clicked.connect (() => change_carousel_position (-1)); button_prev.clicked.connect (() => change_carousel_position (-1));
button_next = new Gtk.Button.from_icon_name ("go-next") { button_next = new Gtk.Button.from_icon_name ("go-next") {
has_frame = false, has_frame = false,
visible = false, visible = false,
valign = Gtk.Align.FILL,
vexpand = true,
}; };
button_next.add_css_class ("mpris-nav-next");
button_next.clicked.connect (() => change_carousel_position (1)); button_next.clicked.connect (() => change_carousel_position (1));
carousel = new Adw.Carousel () { carousel = new Adw.Carousel ();
visible = true,
};
carousel.allow_scroll_wheel = true; carousel.allow_scroll_wheel = true;
carousel.page_changed.connect ((index) => { carousel.page_changed.connect ((index) => {
if (carousel.n_pages <= 1) { update_nav_buttons ();
button_prev.sensitive = false;
button_next.sensitive = false;
return;
}
button_prev.sensitive = true;
button_next.sensitive = true;
}); });
carousel_box.append (button_prev);
carousel_box.append (carousel);
carousel_box.append (button_next);
append (carousel_box);
carousel_dots = new Adw.CarouselIndicatorDots (); carousel_dots = new Adw.CarouselIndicatorDots ();
carousel_dots.set_carousel (carousel); carousel_dots.set_carousel (carousel);
carousel_dots.set_halign (Gtk.Align.CENTER); carousel_dots.set_halign (Gtk.Align.CENTER);
carousel_dots.set_valign (Gtk.Align.CENTER);
carousel_dots.set_visible (false); carousel_dots.set_visible (false);
append (carousel_dots);
var center_box = new Gtk.Box (
Gtk.Orientation.VERTICAL, 0);
center_box.set_hexpand (true);
center_box.append (carousel);
center_box.append (carousel_dots);
carousel_box.append (button_prev);
carousel_box.append (center_box);
carousel_box.append (button_next);
append (carousel_box);
// Config // Config
Json.Object ?config = get_config (this); Json.Object ?config = get_config (this);
...@@ -244,15 +244,25 @@ namespace XimperShellNotificationCenter.Widgets.Mpris { ...@@ -244,15 +244,25 @@ namespace XimperShellNotificationCenter.Widgets.Mpris {
players.remove (name); players.remove (name);
} }
private void update_nav_buttons () {
uint n = carousel.n_pages;
uint pos = (uint) carousel.position;
button_prev.sensitive = pos > 0;
button_next.sensitive = pos < n - 1;
}
private void change_carousel_position (int delta) { private void change_carousel_position (int delta) {
uint children_length = carousel.n_pages; uint children_length = carousel.n_pages;
if (children_length == 0) { if (children_length == 0) {
return; return;
} }
uint position; int position = (int) carousel.position + delta;
position = ((uint) carousel.position + delta) if (position < 0
% children_length; || position >= (int) children_length) {
carousel.scroll_to (carousel.get_nth_page (position), true); return;
}
carousel.scroll_to (
carousel.get_nth_page (position), true);
} }
private bool is_blacklisted (string name) { private bool is_blacklisted (string name) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment