Skip to content

Commit

Permalink
Add window choice
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Apr 4, 2024
1 parent 0a1c0bd commit 4891619
Showing 1 changed file with 61 additions and 20 deletions.
81 changes: 61 additions & 20 deletions src/ScreenCast/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class ScreenCast.Dialog : Granite.Dialog {
private List<SelectionRow> window_rows;
private List<SelectionRow> monitor_rows;

private Gtk.ListBox list_box;
private Gtk.CheckButton? group = null;

public Dialog (SourceType source_types, bool allow_multiple) {
Object (source_types: source_types, allow_multiple: allow_multiple);
}
Expand All @@ -15,20 +18,13 @@ public class ScreenCast.Dialog : Granite.Dialog {
window_rows = new List<SelectionRow> ();
monitor_rows = new List<SelectionRow> ();

var list_box = new Gtk.ListBox () {
selection_mode = MULTIPLE,
list_box = new Gtk.ListBox () {
vexpand = true
};
list_box.add_css_class ("boxed-list");
list_box.add_css_class (Granite.STYLE_CLASS_RICH_LIST);
list_box.set_header_func (header_func);

Gtk.CheckButton? group = null;

if (WINDOW in source_types) {
//TODO: populate windows
}

if (MONITOR in source_types) {
var monitor_tracker = new MonitorTracker ();

Expand All @@ -37,21 +33,14 @@ public class ScreenCast.Dialog : Granite.Dialog {
monitor.display_name, null, allow_multiple ? null : group);

monitor_rows.append (row);

group = row.check_button;

list_box.append (row);

row.notify["selected"].connect (() => {
if (row.selected) {
n_selected++;
} else {
n_selected--;
}
});
setup_row (row);
}
}

if (WINDOW in source_types) {
populate_windows.begin ();
}

get_content_area ().append (list_box);

add_button (_("Cancel"), Gtk.ResponseType.CANCEL);
Expand All @@ -64,6 +53,58 @@ public class ScreenCast.Dialog : Granite.Dialog {
});
}

private async void populate_windows () {
var desktop_integration = yield Gala.DesktopIntegration.get_instance ();

if (desktop_integration == null) {
return;
}

Gala.DesktopIntegration.Window[] windows;
try {
windows = yield desktop_integration.get_windows ();
} catch (Error e) {
warning ("Failed to get windows from desktop integration: %s", e.message);
return;
}

foreach (var window in windows) {
var label = _("Unknown Window");

if ("title" in window.details) {
label = (string) window.details["title"];
}

Icon icon = new ThemedIcon ("application-x-executable");
if ("app-id" in window.details) {
var app_info = new DesktopAppInfo ((string) window.details["app-id"]);
if (app_info != null && app_info.get_icon () != null) {
icon = app_info.get_icon ();
}
}

var row = new SelectionRow (WINDOW, window.uid,
label, icon, allow_multiple ? null : group);

window_rows.append (row);
setup_row (row);
}
}

private void setup_row (SelectionRow row) {
group = row.check_button;

list_box.append (row);

row.notify["selected"].connect (() => {
if (row.selected) {
n_selected++;
} else {
n_selected--;
}
});
}

private void header_func (Gtk.ListBoxRow row, Gtk.ListBoxRow? prev) {
if (!(row is SelectionRow) && prev != null && !(prev is SelectionRow)) {
return;
Expand Down

0 comments on commit 4891619

Please sign in to comment.