Skip to content

Commit

Permalink
Allow modifying dbus name with --audio-client-name
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsir911 committed Jul 14, 2024
1 parent 16fee38 commit f7fdb4a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mpris.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ static void on_name_lost(GDBusConnection *connection,
if (connection) {
UserData *ud = user_data;
pid_t pid = getpid();
char *name = g_strdup_printf("org.mpris.MediaPlayer2.mpv.instance%d", pid);
char *name = g_strdup_printf("%s.instance%d", _name, pid);
ud->bus_id = g_bus_own_name(G_BUS_TYPE_SESSION,
name,
G_BUS_NAME_OWNER_FLAGS_NONE,
Expand Down Expand Up @@ -1083,15 +1083,23 @@ int mpv_open_cplugin(mpv_handle *mpv)
ud.idle = FALSE;
ud.paused = FALSE;

char *mpv_name = mpv_get_property_string(mpv, "audio-client-name");
char *dbus_name = g_strdup_printf(
"org.mpris.MediaPlayer2.%s",
mpv_name != NULL ? mpv_name : "mpv" // fallback if get_property_string returns NULL
);
mpv_free(mpv_name); // doesn't fail on NULLs

g_main_context_push_thread_default(ctx);
ud.bus_id = g_bus_own_name(G_BUS_TYPE_SESSION,
"org.mpris.MediaPlayer2.mpv",
dbus_name,
G_BUS_NAME_OWNER_FLAGS_DO_NOT_QUEUE,
on_bus_acquired,
NULL,
on_name_lost,
&ud, NULL);
g_main_context_pop_thread_default(ctx);
g_free(dbus_name);

// Receive event for property changes
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_FLAG);
Expand Down

0 comments on commit f7fdb4a

Please sign in to comment.