FriendlyCaps: add sort func
All checks were successful
PostmarketOS Build / Prepare (push) Successful in 16s
PostmarketOS Build / Build for aarch64 (push) Successful in 44s
PostmarketOS Build / Build for x86_64 (push) Successful in 13s

Signed-off-by: Vasiliy Doylov <nekocwd@mainlining.org>
This commit is contained in:
Vasiliy Doylov 2025-06-21 19:15:58 +03:00
parent de67da42ea
commit e129b7581a
Signed by: NekoCWD
GPG key ID: B7BE22D44474A582
2 changed files with 11 additions and 10 deletions

View file

@ -27,17 +27,13 @@ public class EyeNeko.Gstreamer : Object {
private void set_up_caps (Gst.Device device) {
FriendlyCaps best_caps = null;
var caps = device.get_caps ();
available_caps.remove_all ();
for (uint i = 0; i < caps.get_size (); i++) {
var cap = new FriendlyCaps.with_struct (caps.get_structure (i));
available_caps.append (cap);
best_caps = (best_caps == null || cap.is_res_better (best_caps)) ? cap : best_caps;
}
uint pos;
available_caps.find (best_caps, out pos);
caps_selecton_model.set_selected (pos);
caps_selecton_model.selected = 0;
}
public class Camera : Object {
@ -133,11 +129,7 @@ public class EyeNeko.Gstreamer : Object {
}
construct {
var srt = new Gtk.SortListModel (available_caps, new Gtk.CustomSorter ((_a, _b) => {
var a = (FriendlyCaps) _a;
var b = (FriendlyCaps) _b;
return a.is_res_better (b) ? -1 : a.is_res_same (b) ? 0 : 1;
}));
var srt = new Gtk.SortListModel (available_caps, new Gtk.CustomSorter ((a, b) => FriendlyCaps.sort_func ((FriendlyCaps) a, (FriendlyCaps) b)));
caps_selecton_model.set_model (srt);
caps_selecton_model.notify["selected-item"].connect (() => start_stream_from (current_camera));
}

View file

@ -70,6 +70,15 @@ namespace EyeNeko {
return (width * height == cap.width * cap.height);
}
public static int sort_func (FriendlyCaps a, FriendlyCaps b) {
if (a.width > b.width)
return -1;
else if (a.width == b.width)
return a.height > b.height ? -1 : a.height == b.height ? a.fps > b.fps ? -1 : a.fps == b.fps ? 0 : 1 : 1;
else
return 1;
}
public Gst.Caps to_caps () {
var res = new Gst.Caps.empty ();
res.append_structure (struct.copy ());