diff --git a/data/cx.ring.RingGnome.gschema.xml b/data/cx.ring.RingGnome.gschema.xml index 71f5291047a96d8e5baa910065270dc304256c37..68c8e14b95648be29a8f2d6493d66f261350eabe 100644 --- a/data/cx.ring.RingGnome.gschema.xml +++ b/data/cx.ring.RingGnome.gschema.xml @@ -6,5 +6,15 @@ Start Ring on login. Start Ring on login. Only supported on XDG compliant desktop environments. + + true + Hide on close instead of quitting. + Hide the main window on close instead of quitting the application. If set to true, Ring will continue to run and be able to receive calls and messages if the main window is closed. + + + true + Bring window to foreground on incoming calls. + Bring window to foreground on incoming calls. + diff --git a/src/generalsettingsview.cpp b/src/generalsettingsview.cpp index 9e5f0167304a7c4bfa6580bf0f401088c2f335a3..95354be92a9c2394fcc5af062b3265449b43bacf 100644 --- a/src/generalsettingsview.cpp +++ b/src/generalsettingsview.cpp @@ -52,6 +52,8 @@ struct _GeneralSettingsViewPrivate /* Rint settings */ GtkWidget *checkbutton_autostart; + GtkWidget *checkbutton_hideonclose; + GtkWidget *checkbutton_bringtofront; /* history settings */ GtkWidget *adjustment_history_duration; @@ -130,10 +132,16 @@ general_settings_view_init(GeneralSettingsView *self) priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL); - /* bind auto startup option to gsettings */ + /* bind client option to gsettings */ g_settings_bind(priv->settings, "start-on-login", priv->checkbutton_autostart, "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(priv->settings, "hide-on-close", + priv->checkbutton_hideonclose, "active", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind(priv->settings, "bring-window-to-front", + priv->checkbutton_bringtofront, "active", + G_SETTINGS_BIND_DEFAULT); /* history limit */ gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_history_duration), @@ -154,6 +162,8 @@ general_settings_view_class_init(GeneralSettingsViewClass *klass) "/cx/ring/RingGnome/generalsettingsview.ui"); gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_autostart); + gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_hideonclose); + gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_bringtofront); gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, adjustment_history_duration); gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, button_clear_history); } diff --git a/src/ring_client.cpp b/src/ring_client.cpp index c411c061dfb49e5de2530b8aeedeffda6aa40326..31ea81dfdb04bc9409045d417b7723858ddf0317 100644 --- a/src/ring_client.cpp +++ b/src/ring_client.cpp @@ -185,6 +185,44 @@ autostart_toggled(GSettings *settings, G_GNUC_UNUSED gchar *key, G_GNUC_UNUSED g autostart_symlink(g_settings_get_boolean(settings, "start-on-login")); } +static gboolean +on_close_window(GtkWidget *window, G_GNUC_UNUSED GdkEvent *event, RingClient *client) +{ + g_return_val_if_fail(GTK_IS_WINDOW(window) && IS_RING_CLIENT(client), FALSE); + + RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); + + if (g_settings_get_boolean(priv->settings, "hide-on-close")) { + /* we want to simply hide the window and keep the client running */ + g_debug("hiding main window"); + gtk_widget_hide(window); + return TRUE; /* do not propogate event */ + } else { + /* we want to quit the application, so just propogate the event */ + return FALSE; + } +} + +static void +ring_client_activate(GApplication *app) +{ + RingClient *client = RING_CLIENT(app); + RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); + + if (priv->win == NULL) { + priv->win = ring_main_window_new(GTK_APPLICATION(app)); + + /* make sure win is set to NULL when the window is destroyed */ + g_object_add_weak_pointer(G_OBJECT(priv->win), (gpointer *)&priv->win); + + /* check if the window should be destoryed or not on close */ + g_signal_connect(priv->win, "delete-event", G_CALLBACK(on_close_window), client); + } + + g_debug("show window"); + gtk_window_present(GTK_WINDOW(priv->win)); +} + static void ring_client_startup(GApplication *app) { @@ -296,6 +334,16 @@ ring_client_startup(GApplication *app) } }); + /* show window on incoming calls (if the option is set)*/ + QObject::connect(CallModel::instance(), &CallModel::incomingCall, + [app] (G_GNUC_UNUSED Call *call) { + RingClient *client = RING_CLIENT(app); + RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); + if (g_settings_get_boolean(priv->settings, "bring-window-to-front")) + ring_client_activate(app); + } + ); + /* send call notifications */ ring_notify_init(); QObject::connect(CallModel::instance(), &CallModel::incomingCall, @@ -344,19 +392,6 @@ ring_client_command_line(GApplication *app, GApplicationCommandLine *cmdline) } #endif -static void -ring_client_activate(GApplication *app) -{ - RingClient *client = RING_CLIENT(app); - RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); - - if (priv->win == NULL) { - priv->win = ring_main_window_new(GTK_APPLICATION(app)); - } - - gtk_window_present(GTK_WINDOW(priv->win)); -} - static void ring_client_shutdown(GApplication *app) { diff --git a/ui/generalsettingsview.ui b/ui/generalsettingsview.ui index 5cefeeae9e8db538ae448dcbc71c1a5673e92ff0..e7e00450b65813552cd7fd4b1453744aff8afa88 100644 --- a/ui/generalsettingsview.ui +++ b/ui/generalsettingsview.ui @@ -46,7 +46,24 @@ Start Ring on login True True - False + 0 + True + + + + + Hide Ring on close instead of quitting. + True + True + 0 + True + + + + + Bring Ring to the foreground on incoming calls. + True + True 0 True