-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat; use AdwToggleGroup for counterpart switcher
- Loading branch information
Showing
2 changed files
with
45 additions
and
17 deletions.
There are no files selected for viewing
25 changes: 10 additions & 15 deletions
25
data/ui/components/player/now-playing/counterpart-switcher.blp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
using Gtk 4.0; | ||
using Adw 1; | ||
|
||
template $MuzikaNPCounterpartSwitcher : Box { | ||
styles ["linked"] | ||
template $MuzikaNPCounterpartSwitcher : Adw.Bin { | ||
Adw.ToggleGroup toggle_group { | ||
Adw.Toggle { | ||
name: "song"; | ||
label: _("Song"); | ||
} | ||
|
||
ToggleButton music_counterpart { | ||
label: _("Song"); | ||
|
||
action-name: "queue.current-is-video"; | ||
action-target: "false"; | ||
} | ||
|
||
ToggleButton video_counterpart { | ||
label: _("Video"); | ||
group: music_counterpart; | ||
|
||
action-name: "queue.current-is-video"; | ||
action-target: "true"; | ||
Adw.Toggle { | ||
name: "video"; | ||
label: _("Video"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,48 @@ | ||
import GObject from "gi://GObject"; | ||
import Gtk from "gi://Gtk?version=4.0"; | ||
import Adw from "gi://Adw"; | ||
|
||
export class MuzikaNPCounterpartSwitcher extends Gtk.Box { | ||
import { get_player } from "src/application"; | ||
|
||
export class MuzikaNPCounterpartSwitcher extends Adw.Bin { | ||
static { | ||
GObject.registerClass( | ||
{ | ||
GTypeName: "MuzikaNPCounterpartSwitcher", | ||
Template: | ||
"resource:///com/vixalien/muzika/ui/components/player/now-playing/counterpart-switcher.ui", | ||
InternalChildren: ["toggle_group"], | ||
}, | ||
this, | ||
); | ||
} | ||
|
||
/// @ts-expect-error outdated types | ||
private _toggle_group: Adw.ToggleGroup; | ||
private _binding: GObject.Binding | null = null; | ||
|
||
vfunc_map(): void { | ||
super.vfunc_map(); | ||
|
||
this._binding?.unbind(); | ||
|
||
this._binding = get_player().queue.bind_property_full( | ||
"current-is-video", | ||
this._toggle_group, | ||
"active-name", | ||
GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.BIDIRECTIONAL, | ||
(_, current_is_video: boolean) => { | ||
return [true, current_is_video ? "video" : "song"]; | ||
}, | ||
(_, active_name: "song" | "video") => { | ||
return [true, active_name === "video" ? true : false]; | ||
}, | ||
); | ||
} | ||
|
||
vfunc_unmap(): void { | ||
super.vfunc_unmap(); | ||
|
||
this._binding?.unbind(); | ||
this._binding = null; | ||
} | ||
} |