Skip to content

Commit

Permalink
clapper-app: Support creating multiple windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafostar committed May 11, 2024
1 parent 5ffeb0b commit b16b5ab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/bin/clapper-app/clapper-app-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ clapper_app_application_command_line (GApplication *app, GApplicationCommandLine
{
ClapperAppApplication *self = CLAPPER_APP_APPLICATION_CAST (app);
struct ClapperAppOptions app_opts = { 0, };
GtkWindow *window;
GtkWindow *window = NULL;
GVariantDict *options;
GFile **files = NULL;
gint n_files = 0;
Expand All @@ -403,9 +403,13 @@ clapper_app_application_command_line (GApplication *app, GApplicationCommandLine

options = g_application_command_line_get_options_dict (cmd_line);

/* Enqueue only makes sense from remote invocation */
if (g_application_command_line_get_is_remote (cmd_line))
/* Some options only make sense from remote invocation */
if (g_application_command_line_get_is_remote (cmd_line)) {
if (g_variant_dict_contains (options, "new-window"))
window = GTK_WINDOW (clapper_app_window_new (GTK_APPLICATION (app)));

g_variant_dict_lookup (options, "enqueue", "b", &app_opts.enqueue);
}

if (!g_variant_dict_lookup (options, "volume", "d", &app_opts.volume))
app_opts.volume = -1;
Expand All @@ -425,9 +429,10 @@ clapper_app_application_command_line (GApplication *app, GApplicationCommandLine
g_application_activate (app);
}

window = gtk_application_get_active_window (GTK_APPLICATION (app));
_apply_settings_to_window (self, CLAPPER_APP_WINDOW_CAST (window), &app_opts);
if (!window)
window = gtk_application_get_active_window (GTK_APPLICATION (app));

_apply_settings_to_window (self, CLAPPER_APP_WINDOW_CAST (window), &app_opts);
_app_opts_free_content (&app_opts);

return EXIT_SUCCESS;
Expand Down Expand Up @@ -602,6 +607,7 @@ clapper_app_application_constructed (GObject *object)
guint i;

const GOptionEntry app_options[] = {
{ "new-window", 0, 0, G_OPTION_ARG_NONE, NULL, _("Create a new window"), NULL },
{ "enqueue", 0, 0, G_OPTION_ARG_NONE, NULL, _("Append media to queue in primary application instance"), NULL },
{ "volume", 0, 0, G_OPTION_ARG_DOUBLE, NULL, _("Audio volume to set at startup"), NULL },
{ "speed", 0, 0, G_OPTION_ARG_DOUBLE, NULL, _("Playback speed to set at startup"), NULL },
Expand Down
10 changes: 8 additions & 2 deletions src/bin/clapper-app/clapper-app-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ struct _ClapperAppWindow
#define parent_class clapper_app_window_parent_class
G_DEFINE_TYPE (ClapperAppWindow, clapper_app_window, GTK_TYPE_APPLICATION_WINDOW)

static guint16 instance_count = 0;

static void
_media_item_title_changed_cb (ClapperMediaItem *item,
GParamSpec *pspec G_GNUC_UNUSED, ClapperAppWindow *self)
Expand Down Expand Up @@ -1008,14 +1010,18 @@ clapper_app_window_constructed (GObject *object)
#if (CLAPPER_HAVE_MPRIS || CLAPPER_HAVE_SERVER || CLAPPER_HAVE_DISCOVERER)
ClapperFeature *feature = NULL;
#endif
#if CLAPPER_HAVE_MPRIS
gchar mpris_name[45];
g_snprintf (mpris_name, sizeof (mpris_name),
"org.mpris.MediaPlayer2.Clapper.instance%u", instance_count++);
#endif

self->settings = g_settings_new (CLAPPER_APP_ID);
self->last_volume = PERCENTAGE_ROUND (g_settings_get_double (self->settings, "volume"));

#if CLAPPER_HAVE_MPRIS
feature = CLAPPER_FEATURE (clapper_mpris_new (
"org.mpris.MediaPlayer2.Clapper",
"Clapper", CLAPPER_APP_ID));
mpris_name, CLAPPER_APP_NAME, CLAPPER_APP_ID));
clapper_mpris_set_queue_controllable (CLAPPER_MPRIS (feature), TRUE);
clapper_player_add_feature (player, feature);
gst_object_unref (feature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ Type=Application
Keywords=Video;Movie;Film;Clip;Series;Player;Playlist;DVD;TV;Disc;Album;Music;GNOME;Clapper;
# Translators: Do NOT translate or transliterate this text (these are enum types)!
X-Purism-FormFactor=Workstation;Mobile;
Actions=new-window;

[Desktop Action new-window]
Name=New Window
Exec=clapper --new-window

0 comments on commit b16b5ab

Please sign in to comment.