[gnome-notes] bjb-detached-window: Set the initial size the same as note view
- From: Isaque Galdino de Araujo <igaldino src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-notes] bjb-detached-window: Set the initial size the same as note view
- Date: Tue, 4 May 2021 13:10:20 +0000 (UTC)
commit 5b8830c83ee9ceb0a0c55c74caafaba009a91a3f
Author: Jonathan Kang <jonathankang gnome org>
Date: Tue Dec 8 17:00:20 2020 +0800
bjb-detached-window: Set the initial size the same as note view
src/bjb-detached-window.c | 76 ++++++++++++++++++++++++++++++++++++++++-------
src/bjb-detached-window.h | 7 ++++-
src/bjb-window-base.c | 9 ++++--
3 files changed, 79 insertions(+), 13 deletions(-)
---
diff --git a/src/bjb-detached-window.c b/src/bjb-detached-window.c
index 58e56b2..b643010 100644
--- a/src/bjb-detached-window.c
+++ b/src/bjb-detached-window.c
@@ -20,11 +20,15 @@
#include "bjb-note-view.h"
#include "bjb-organize-dialog.h"
#include "bjb-share.h"
+#include "bjb-window-base.h"
enum
{
PROP_0,
PROP_NOTE,
+ PROP_WIDTH,
+ PROP_HEIGHT,
+ PROP_MAIN_WIN,
NUM_PROPERTIES
};
@@ -32,7 +36,10 @@ struct _BjbDetachedWindow
{
HdyApplicationWindow parent_instance;
- BijiNoteObj *note;
+ int width;
+ int height;
+ BijiNoteObj *note;
+ BjbWindowBase *main_win;
GtkWidget *headerbar;
GtkWidget *main_box;
@@ -200,8 +207,8 @@ static void
bjb_detached_window_constructed (GObject *object)
{
gboolean is_maximized;
- int width, height;
- int pos_x, pos_y;
+ int main_win_width, main_win_height;
+ int main_win_pos_x, main_win_pos_y;
BjbNoteView *note_view;
BjbDetachedWindow *self = BJB_DETACHED_WINDOW (object);
g_autoptr(GSettings) settings;
@@ -213,17 +220,19 @@ bjb_detached_window_constructed (GObject *object)
G_N_ELEMENTS (win_entries),
self);
- settings = g_settings_new ("org.gnome.Notes");
+ gtk_window_set_default_size (GTK_WINDOW (self), self->width, self->height);
- g_settings_get (settings, "window-size", "(ii)", &width, &height);
- g_settings_get (settings, "window-position", "(ii)", &pos_x, &pos_y);
- gtk_window_set_default_size (GTK_WINDOW (self), width, height);
+ gtk_window_get_size (GTK_WINDOW (self->main_win), &main_win_width, &main_win_height);
+ gtk_window_get_position (GTK_WINDOW (self->main_win), &main_win_pos_x, &main_win_pos_y);
+ settings = g_settings_new ("org.gnome.Notes");
is_maximized = g_settings_get_boolean (settings, "window-maximized");
if (is_maximized)
gtk_window_maximize (GTK_WINDOW (self));
- else if (pos_x >= 0)
- gtk_window_move (GTK_WINDOW (self), pos_x, pos_y);
+ else if (main_win_pos_x >= 0)
+ gtk_window_move (GTK_WINDOW (self),
+ main_win_pos_x + main_win_width - self->width,
+ main_win_pos_y);
on_note_renamed (BIJI_ITEM (self->note), self);
g_signal_connect (self->note, "renamed", G_CALLBACK (on_note_renamed), self);
@@ -259,6 +268,15 @@ bjb_detached_window_get_property (GObject *object,
case PROP_NOTE:
g_value_set_object (value, self->note);
break;
+ case PROP_WIDTH:
+ g_value_set_int (value, self->width);
+ break;
+ case PROP_HEIGHT:
+ g_value_set_int (value, self->height);
+ break;
+ case PROP_MAIN_WIN:
+ g_value_set_object (value, self->main_win);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -278,6 +296,15 @@ bjb_detached_window_set_property (GObject *object,
case PROP_NOTE:
self->note = g_value_dup_object (value);
break;
+ case PROP_WIDTH:
+ self->width = g_value_get_int (value);
+ break;
+ case PROP_HEIGHT:
+ self->height = g_value_get_int (value);
+ break;
+ case PROP_MAIN_WIN:
+ self->main_win = g_value_get_object (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -302,6 +329,29 @@ bjb_detached_window_class_init (BjbDetachedWindowClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
+ properties[PROP_WIDTH] = g_param_spec_int ("width",
+ "Width",
+ "Initial width of the detached window",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY);
+ properties[PROP_HEIGHT] = g_param_spec_int ("height",
+ "Height",
+ "Initial height of the detached window",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY);
+ properties[PROP_MAIN_WIN] = g_param_spec_object ("window-base",
+ "Main window",
+ "The main note window",
+ BJB_TYPE_WINDOW_BASE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
@@ -320,10 +370,16 @@ bjb_detached_window_init (BjbDetachedWindow *self)
}
BjbDetachedWindow *
-bjb_detached_window_new (BijiNoteObj *note)
+bjb_detached_window_new (BijiNoteObj *note,
+ int width,
+ int height,
+ BjbWindowBase *main_win)
{
return g_object_new (BJB_TYPE_DETACHED_WINDOW,
"application", g_application_get_default (),
"note", note,
+ "width", width,
+ "height", height,
+ "window-base", main_win,
NULL);
}
diff --git a/src/bjb-detached-window.h b/src/bjb-detached-window.h
index e56c555..08243b5 100644
--- a/src/bjb-detached-window.h
+++ b/src/bjb-detached-window.h
@@ -22,12 +22,17 @@
#include <handy.h>
#include <libbiji/libbiji.h>
+#include "bjb-window-base.h"
+
G_BEGIN_DECLS
#define BJB_TYPE_DETACHED_WINDOW (bjb_detached_window_get_type ())
G_DECLARE_FINAL_TYPE (BjbDetachedWindow, bjb_detached_window, BJB, DETACHED_WINDOW, HdyApplicationWindow)
-BjbDetachedWindow *bjb_detached_window_new (BijiNoteObj *note);
+BjbDetachedWindow *bjb_detached_window_new (BijiNoteObj *note,
+ int width,
+ int height,
+ BjbWindowBase *main_win);
G_END_DECLS
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index ae3cfc3..de427e7 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -287,6 +287,7 @@ on_detach_window_cb (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
+ int width, height;
BjbDetachedWindow *detached_window;
BjbWindowBase *self = BJB_WINDOW_BASE (user_data);
BijiNoteObj *note = bjb_window_base_get_note (self);
@@ -294,12 +295,16 @@ on_detach_window_cb (GSimpleAction *action,
if (!note)
return;
+ /* Width and height of the detached window. */
+ width = gtk_widget_get_allocated_width (GTK_WIDGET (self->note_view));
+ gtk_window_get_size (GTK_WINDOW (self), NULL, &height);
+
if (biji_note_obj_is_trashed (note))
bjb_window_base_switch_to (self, BJB_WINDOW_BASE_ARCHIVE_VIEW);
else
bjb_window_base_switch_to (self, BJB_WINDOW_BASE_MAIN_VIEW);
- detached_window = bjb_detached_window_new (note);
+ detached_window = bjb_detached_window_new (note, width, height, self);
gtk_widget_show_all (GTK_WIDGET (detached_window));
}
@@ -474,7 +479,7 @@ bjb_window_base_constructed (GObject *obj)
self->settings = bjb_app_get_settings ((gpointer) g_application_get_default ());
- gtk_window_set_position (GTK_WINDOW (self),GTK_WIN_POS_CENTER);
+ gtk_window_set_position (GTK_WINDOW (self), GTK_WIN_POS_CENTER);
gtk_window_set_title (GTK_WINDOW (self), _(BIJIBEN_MAIN_WIN_TITLE));
bjb_window_base_load_geometry (self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]