Commit bf42fc9d authored by Sébastien Blin's avatar Sébastien Blin

mainwindow: save maximized and fullscreen state

Change-Id: Ibc9f68f00b36ddbdb2d6f7dbcb8281e7999f1d83
Gitlab: #814
parent 55ba07df
......@@ -72,5 +72,13 @@
<summary>Where ring downloads files.</summary>
<description>When a contact sends a file, this file will be stored in the folder previously described.</description>
</key>
<key name="window-maximized" type="b">
<default>false</default>
<summary>If window is maximized.</summary>
</key>
<key name="window-fullscreen" type="b">
<default>false</default>
<summary>If window is fullscren.</summary>
</key>
</schema>
</schemalist>
......@@ -126,6 +126,8 @@ ring_accelerators(RingClient *client)
#if GTK_CHECK_VERSION(3,12,0)
const gchar *quit_accels[2] = {"<Ctrl>Q", NULL};
gtk_application_set_accels_for_action(GTK_APPLICATION(client), "app.quit", quit_accels);
const gchar *fullscreen_accels[2] = {"F11", NULL};
gtk_application_set_accels_for_action(GTK_APPLICATION(client), "app.toggle_fullscreen", fullscreen_accels);
const gchar *accounts_accels[2] = {"<Ctrl>J", NULL};
gtk_application_set_accels_for_action(GTK_APPLICATION(client), "app.display_account_list", accounts_accels);
......@@ -160,6 +162,8 @@ ring_accelerators(RingClient *client)
#else
gtk_application_add_accelerator(GTK_APPLICATION(client), "<Control>Q", "app.quit", NULL);
gtk_application_add_accelerator(GTK_APPLICATION(client), "F11", "app.toggle_fullscreen", NULL);
gtk_application_add_accelerator(GTK_APPLICATION(client), "<Control>J", "app.display_account_list", NULL);
......@@ -247,6 +251,8 @@ exec_action(GSimpleAction *simple,
ring_main_window_accept_call(RING_MAIN_WINDOW(priv->win));
else if (name == "decline_call")
ring_main_window_decline_call(RING_MAIN_WINDOW(priv->win));
else if (name == "toggle_fullscreen")
ring_main_window_toggle_fullscreen(RING_MAIN_WINDOW(priv->win));
else
g_warning("Missing implementation for this action: %s", name.c_str());
}
......@@ -301,6 +307,7 @@ static const GActionEntry ring_actions[] = {
{"accept_call", exec_action, NULL, NULL, NULL, {0}},
{"decline_call", exec_action, NULL, NULL, NULL, {0}},
{"show_shortcuts", action_show_shortcuts, NULL, NULL, NULL, {0}},
{"toggle_fullscreen", exec_action, NULL, NULL, NULL, {0}},
};
static void
......
......@@ -127,6 +127,7 @@ struct RingMainWindowPrivate
gulong notif_accept_call;
gulong notif_decline_call;
gboolean set_top_account_flag = true;
gboolean is_fullscreen_main_win = false;
GCancellable *cancellable;
#if USE_LIBNM
......@@ -623,6 +624,18 @@ on_tab_changed(GtkNotebook* notebook, GtkWidget* page, guint page_num, RingMainW
}
}
static gboolean
on_window_state_event(GtkWidget *widget, GdkEventWindowState *event)
{
g_return_val_if_fail(IS_RING_MAIN_WINDOW(widget), GDK_EVENT_PROPAGATE);
auto *priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(widget));
g_settings_set_boolean(priv->settings, "window-maximized", ((event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0));
g_settings_set_boolean(priv->settings, "window-fullscreen", ((event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0));
return GDK_EVENT_PROPAGATE;
}
static void
on_window_size_changed(GtkWidget *self, G_GNUC_UNUSED GdkRectangle*, G_GNUC_UNUSED gpointer)
{
......@@ -1029,6 +1042,14 @@ CppImpl::init()
auto height = g_settings_get_int(widgets->settings, "window-height");
gtk_window_set_default_size(GTK_WINDOW(self), width, height);
g_signal_connect(self, "size-allocate", G_CALLBACK(on_window_size_changed), nullptr);
g_signal_connect(self, "window-state-event", G_CALLBACK(on_window_state_event), nullptr);
if (g_settings_get_boolean(widgets->settings, "window-maximized"))
gtk_window_maximize(GTK_WINDOW(self));
widgets->is_fullscreen_main_win = g_settings_get_boolean(widgets->settings, "window-fullscreen");
if (widgets->is_fullscreen_main_win)
gtk_window_fullscreen(GTK_WINDOW(self));
update_data_transfer(lrc_->getDataTransferModel(), widgets->settings);
......@@ -1350,7 +1371,7 @@ CppImpl::leaveFullScreen()
{
if (is_fullscreen) {
gtk_widget_show(widgets->vbox_left_pane);
gtk_window_unfullscreen(GTK_WINDOW(self));
if (!widgets->is_fullscreen_main_win) gtk_window_unfullscreen(GTK_WINDOW(self));
is_fullscreen = false;
}
}
......@@ -2489,6 +2510,23 @@ ring_main_window_decline_call(RingMainWindow *win)
});
}
void
ring_main_window_toggle_fullscreen(RingMainWindow *win)
{
g_return_if_fail(IS_RING_MAIN_WINDOW(win));
auto *priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(win));
g_return_if_fail(priv && priv->cpp);
if (priv->cpp->is_fullscreen) return;
if (priv->is_fullscreen_main_win) {
gtk_window_unfullscreen(GTK_WINDOW(win));
} else {
gtk_window_fullscreen(GTK_WINDOW(win));
}
priv->is_fullscreen_main_win = !priv->is_fullscreen_main_win;
}
//==============================================================================
static void
......
......@@ -53,6 +53,7 @@ void ring_main_window_copy_contact(RingMainWindow *win);
void ring_main_window_add_contact(RingMainWindow *win);
void ring_main_window_accept_call(RingMainWindow *win);
void ring_main_window_decline_call(RingMainWindow *win);
void ring_main_window_toggle_fullscreen(RingMainWindow *win);
G_END_DECLS
......
......@@ -46,6 +46,13 @@
<property name="title" translatable="yes" context="shortcut window">Focus the list pending requests</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">true</property>
<property name="accelerator">F11</property>
<property name="title" translatable="yes" context="shortcut window">Toggle fullscreen</property>
</object>
</child>
</object>
</child>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment