Added null handling for findCustom

pull/9899/head
Max Bretschneider 2025-10-28 19:44:43 +01:00 committed by Mitchell Hashimoto
parent 7e0dc09873
commit bb246b2e0c
1 changed files with 6 additions and 5 deletions

View File

@ -2022,18 +2022,19 @@ const Action = struct {
const glist = gtk.Window.listToplevels(); const glist = gtk.Window.listToplevels();
defer glist.free(); defer glist.free();
const node = glist.findCustom(null, findActiveWindow); const node = @as(?*glib.List, glist.findCustom(null, findActiveWindow));
const target_node = switch (direction) { const target_node = if (node) |n| switch (direction) {
.next => node.f_next orelse glist, .next => n.f_next orelse glist,
.previous => node.f_prev orelse last: { .previous => n.f_prev orelse last: {
var current = glist; var current = glist;
while (current.f_next) |next| { while (current.f_next) |next| {
current = next; current = next;
} }
break :last current; break :last current;
}, },
}; } else glist;
const data = target_node.f_data orelse return false; const data = target_node.f_data orelse return false;
const gtk_window: *gtk.Window = @ptrCast(@alignCast(data)); const gtk_window: *gtk.Window = @ptrCast(@alignCast(data));
gtk.Window.present(gtk_window); gtk.Window.present(gtk_window);