Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement screen cast portal #102

Merged
merged 26 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup
leolost2605 committed Apr 4, 2024
commit 775278efcb8710676ac8b426257b8939d1abf5f0
7 changes: 0 additions & 7 deletions src/ScreenCast/MonitorTracker/MonitorTracker.vala
Original file line number Diff line number Diff line change
@@ -79,13 +79,6 @@ public class ScreenCast.MonitorTracker : GLib.Object {
}
}

private static bool compare_monitor_with_mutter_info (ScreenCast.Monitor monitor, MutterReadMonitorInfo mutter_info) {
return monitor.connector == mutter_info.connector
&& monitor.vendor == mutter_info.vendor
&& monitor.product == mutter_info.product
&& monitor.serial == mutter_info.serial;
}

private ScreenCast.Monitor? get_monitor_by_hash (uint hash) {
foreach (var monitor in monitors) {
if (monitor.hash == hash) {
7 changes: 2 additions & 5 deletions src/ScreenCast/Portal.vala
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@ public enum ScreenCast.CursorMode {

[DBus (name = "org.freedesktop.impl.portal.ScreenCast")]
public class ScreenCast.Portal : Object {
public SourceType available_source_types { get; default = VIRTUAL; }
public CursorMode available_cursor_modes { get; default = HIDDEN; }
public SourceType available_source_types { get; default = MONITOR | VIRTUAL; }
public CursorMode available_cursor_modes { get; default = HIDDEN; } // TODO: What is GNOMEs cursor mode
public uint version { get; default = 3; }

private DBusConnection connection;
@@ -35,7 +35,6 @@ public class ScreenCast.Portal : Object {
out uint response,
out HashTable<string, Variant> results
) throws DBusError, IOError {
warning ("CREATE SESSION");
var session = new Session ();
try {
var session_register_id = connection.register_object (session_handle, session);
@@ -56,8 +55,6 @@ public class ScreenCast.Portal : Object {
response = 0;
results = new HashTable<string, Variant> (str_hash, str_equal);
results["session_id"] = Uuid.string_random ();

warning ("SESSION CREATED");
}

public async void select_sources (
32 changes: 16 additions & 16 deletions src/ScreenCast/Session.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[DBus (name = "org.gnome.Mutter.ScreenCast")]
private interface Mutter.ScreenCast : Object {
public abstract async ObjectPath create_session (HashTable<string, Variant> options);
public abstract async ObjectPath create_session (HashTable<string, Variant> options) throws DBusError, IOError;
}

[DBus (name = "org.gnome.Mutter.ScreenCast.Session")]
@@ -22,8 +22,6 @@ private interface Mutter.ScreenCastStream : Object {
public abstract HashTable<string, Variant> parameters { owned get; }

public signal void pipe_wire_stream_added (uint node_id);

public abstract async void start () throws DBusError, IOError;
}

[DBus (name = "org.freedesktop.impl.portal.Session")]
@@ -37,7 +35,7 @@ public class ScreenCast.Session : Object {

private signal void started ();

public uint version { get; default = 1; }
public uint version { get; default = 1; } // TODO: Were there already version bumps for org.freedesktop.impl.portal.Session ?

private Mutter.ScreenCastSession session;

@@ -52,22 +50,22 @@ public class ScreenCast.Session : Object {
try {
proxy = yield Bus.get_proxy (SESSION, "org.gnome.Mutter.ScreenCast", "/org/gnome/Mutter/ScreenCast");
} catch (Error e) {
critical ("Failed to get proxy: %s", e.message);
warning ("Failed to get proxy: %s", e.message);
return false;
}

string session_handle;
try {
session_handle = yield proxy.create_session (new HashTable<string, Variant> (str_hash, str_equal));
} catch (Error e) {
critical ("Failed to create session: %s", e.message);
warning ("Failed to create session: %s", e.message);
return false;
}

try {
session = yield Bus.get_proxy (SESSION, "org.gnome.Mutter.ScreenCast", session_handle);
} catch (Error e) {
critical ("Failed to get session object: %s", e.message);
warning ("Failed to get session object: %s", e.message);
return false;
}

@@ -80,17 +78,20 @@ public class ScreenCast.Session : Object {
}

internal async PipeWireStream[]? start () {
//do selection, etc.
//we want virtual
//TODO: All user interaction. I.e. permission stuff, allow multiple, which monitor, which window, etc.

if (VIRTUAL in source_types) {
//Should we fail if one fails or if all fail? Currently it's all
if (VIRTUAL in source_types && yield record_virtual ()) {
required_streams++;
yield record_virtual ();
}

if (MONITOR in source_types) {
if (MONITOR in source_types && yield select_monitor ()) {
required_streams++;
yield select_monitor ();
}

if (required_streams == 0) {
warning ("At least one source type has to be successfully setup.");
return null;
}

started.connect (() => Idle.add (() => {
@@ -121,10 +122,10 @@ public class ScreenCast.Session : Object {
return yield setup_mutter_stream (path, VIRTUAL);
}

private async void select_monitor () {
private async bool select_monitor () {
var monitor_tracker = new MonitorTracker ();
var monitor = monitor_tracker.monitors.get (0); //TODO
record_monitor (monitor.connector);
return yield record_monitor (monitor.connector);
}

private async bool record_monitor (string connector) {
@@ -179,7 +180,6 @@ public class ScreenCast.Session : Object {
}

public async void close () throws DBusError, IOError {
warning ("Session closed");
try {
yield session.stop ();
} catch (Error e) {