Commit ba87ae2c authored by Stepan Salenikovich's avatar Stepan Salenikovich

save and restore main window size

Saves and restores the main window size in the GSettings.

The default size is updated to be 800x500. Gtk should automatically
resize it smaller if it doesn't fit on the screen.

Change-Id: Ia85f9fe870cf0695c5095cb138c2b8a61a8855a7
Tuleap: #1030
parent 5a12767d
...@@ -34,5 +34,15 @@ ...@@ -34,5 +34,15 @@
<default>true</default> <default>true</default>
<summary>Enable notifications for new chat messages.</summary> <summary>Enable notifications for new chat messages.</summary>
</key> </key>
<key name="window-width" type="i">
<default>800</default>
<summary>Main window width.</summary>
<description>Main window width.</description>
</key>
<key name="window-height" type="i">
<default>500</default>
<summary>Main window height.</summary>
<description>Main window height.</description>
</key>
</schema> </schema>
</schemalist> </schemalist>
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
#include "recentcontactsview.h" #include "recentcontactsview.h"
#include "chatview.h" #include "chatview.h"
#include "avatarmanipulation.h" #include "avatarmanipulation.h"
#include "utils/files.h"
static constexpr const char* CALL_VIEW_NAME = "calls"; static constexpr const char* CALL_VIEW_NAME = "calls";
static constexpr const char* CREATE_ACCOUNT_VIEW_NAME = "wizard"; static constexpr const char* CREATE_ACCOUNT_VIEW_NAME = "wizard";
...@@ -143,6 +144,8 @@ struct _RingMainWindowPrivate ...@@ -143,6 +144,8 @@ struct _RingMainWindowPrivate
/* fullscreen */ /* fullscreen */
gboolean is_fullscreen; gboolean is_fullscreen;
GSettings *settings;
}; };
G_DEFINE_TYPE_WITH_PRIVATE(RingMainWindow, ring_main_window, GTK_TYPE_APPLICATION_WINDOW); G_DEFINE_TYPE_WITH_PRIVATE(RingMainWindow, ring_main_window, GTK_TYPE_APPLICATION_WINDOW);
...@@ -1078,12 +1081,30 @@ history_selection_changed(GtkTreeSelection *selection, RingMainWindow *self) ...@@ -1078,12 +1081,30 @@ history_selection_changed(GtkTreeSelection *selection, RingMainWindow *self)
selection_changed(self); selection_changed(self);
} }
static gboolean
window_size_changed(GtkWidget *win, GdkEventConfigure *event, gpointer)
{
auto *priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
g_settings_set_int(priv->settings, "window-width", event->width);
g_settings_set_int(priv->settings, "window-height", event->height);
return GDK_EVENT_PROPAGATE;
}
static void static void
ring_main_window_init(RingMainWindow *win) ring_main_window_init(RingMainWindow *win)
{ {
RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
gtk_widget_init_template(GTK_WIDGET(win)); gtk_widget_init_template(GTK_WIDGET(win));
/* bind to window size settings */
priv->settings = g_settings_new_full(get_ring_schema(), nullptr, nullptr);
auto width = g_settings_get_int(priv->settings, "window-width");
auto height = g_settings_get_int(priv->settings, "window-height");
gtk_window_set_default_size(GTK_WINDOW(win), width, height);
g_signal_connect(win, "configure-event", G_CALLBACK(window_size_changed), nullptr);
/* set window icon */ /* set window icon */
GError *error = NULL; GError *error = NULL;
GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error); GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error);
...@@ -1287,6 +1308,11 @@ ring_main_window_dispose(GObject *object) ...@@ -1287,6 +1308,11 @@ ring_main_window_dispose(GObject *object)
static void static void
ring_main_window_finalize(GObject *object) ring_main_window_finalize(GObject *object)
{ {
RingMainWindow *self = RING_MAIN_WINDOW(object);
RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
g_clear_object(&priv->settings);
G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object); G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object);
} }
......
...@@ -3,10 +3,7 @@ ...@@ -3,10 +3,7 @@
<interface> <interface>
<requires lib="gtk+" version="3.10"/> <requires lib="gtk+" version="3.10"/>
<template class="RingMainWindow" parent="GtkApplicationWindow"> <template class="RingMainWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="show_menubar">False</property> <property name="show_menubar">False</property>
<property name="default-width">700</property>
<property name="default-height">450</property>
<!-- header definition --> <!-- header definition -->
<child type="titlebar"> <child type="titlebar">
<object class="GtkHeaderBar" id="header"> <object class="GtkHeaderBar" id="header">
......
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