From da9a427b7c7950f66d8c10af2e14c4d6a4585512 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 14 Jan 2020 12:44:25 -0300 Subject: [PATCH] Creating gsettings path for window state and saving size and state to it. --- Makefile.in | 23 +++++++++++++++++++++-- configure.ac | 2 ++ schemas/Makefile.in | 6 +++++- schemas/common/window.gschema.xml.in | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ schemas/linux/application.gschema.xml.in | 42 ------------------------------------------ src/objects/window/private.h | 7 +++++++ src/objects/window/window.c | 278 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------- 7 files changed, 339 insertions(+), 122 deletions(-) create mode 100644 schemas/common/window.gschema.xml.in diff --git a/Makefile.in b/Makefile.in index 0e5abc1..0f7a4e0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -44,6 +44,10 @@ SOURCES= \ $(wildcard src/main/@OSNAME@/*.c) \ $(wildcard src/main/@OSNAME@/*.rc) +SCHEMAS= \ + $(wildcard schemas/@OSNAME@/*.gschema.xml) \ + $(wildcard schemas/common/*.gschema.xml) + #---[ Tools ]---------------------------------------------------------------------------- CC=@CC@ @@ -75,6 +79,7 @@ sysconfdir=@sysconfdir@ BASEDIR=@BASEDIR@ POTDIR=$(BASEDIR)/.pot +POTDIR=$(BASEDIR)/.schemas OBJDIR=$(BASEDIR)/.obj/$(PACKAGE_NAME) OBJDBG=$(OBJDIR)/Debug @@ -134,11 +139,11 @@ $(OBJDBG)/%.o: \ @$(WINDRES) $< -O coff -o $@ gschemas.compiled: \ - schemas/@OSNAME@/*.gschema.xml + $(foreach SCHEMA, $(notdir $(SCHEMAS)), $(OBJDIR)/schemas/$(SCHEMA)) @glib-compile-schemas \ --targetdir=$(@D) \ - $(BASEDIR)/schemas/@OSNAME@ + $(OBJDIR)/schemas #---[ Release Rules ]-------------------------------------------------------------------- @@ -184,6 +189,18 @@ $(POTDIR)/$(PACKAGE_NAME)/%.pot: \ @touch $@ +$(OBJDIR)/schemas/%.xml:\ + schemas/@OSNAME@/%.xml + + @$(MKDIR) $(@D) + @cp "$^" "$@" + +$(OBJDIR)/schemas/%.xml:\ + schemas/common/%.xml + + @$(MKDIR) $(@D) + @cp "$^" "$@" + install-%: \ %/Makefile @@ -299,12 +316,14 @@ clean: \ cleanDebug: @rm -fr $(OBJDBG) + @rm -fr $(OBJDIR)/schemas @rm -fr $(BINDBG) @rm -f gschemas.compiled cleanRelease: @rm -fr $(OBJRLS) + @rm -fr $(OBJDIR)/schemas @rm -fr $(BINRLS) @rm -fr $(POTDIR) diff --git a/configure.ac b/configure.ac index af4d686..9264dbc 100644 --- a/configure.ac +++ b/configure.ac @@ -97,6 +97,8 @@ dnl INSTALL_PACKAGES="linux-lib ${INSTALL_PACKAGES}" esac +AC_CONFIG_FILES(schemas/common/window.gschema.xml) + AC_SUBST(OSNAME,$app_cv_osname) AC_SUBST(LIBS) AC_SUBST(LOGDIR) diff --git a/schemas/Makefile.in b/schemas/Makefile.in index 000fdfe..4b7bcc7 100644 --- a/schemas/Makefile.in +++ b/schemas/Makefile.in @@ -55,6 +55,10 @@ install: @$(MKDIR) $(DESTDIR)/$(schemadir) @$(INSTALL_DATA) \ $(BASEDIR)/schemas/@OSNAME@/application.gschema.xml \ - $(DESTDIR)/$(schemadir)/$(PRODUCT_NAME).gschema.xml + $(DESTDIR)/$(schemadir)/$(PRODUCT_NAME)-application.gschema.xml + + @$(INSTALL_DATA) \ + $(BASEDIR)/schemas/common/window.gschema.xml \ + $(DESTDIR)/$(schemadir)/$(PRODUCT_NAME)-window.gschema.xml diff --git a/schemas/common/window.gschema.xml.in b/schemas/common/window.gschema.xml.in new file mode 100644 index 0000000..806cfa9 --- /dev/null +++ b/schemas/common/window.gschema.xml.in @@ -0,0 +1,103 @@ + + + + + + + + + -1 + The window width. + + + + + -1 + The window height. + + + + + false + Is the window maximized? + + + + + false + Is the window in full screen mode? + + + + + true + Enable top window subtitle + If TRUE, reserve space for a subtitle, even if none is currently set. + + + + true + The toolbar visible state + + + + + true + The menubar visible state + + + + + -1 + How to draw the toolbar. + + + + + 0 + The size of the icons in a toolbar + + + + + 'win.copy,win.paste,win.select-all,separator,win.connect,win.disconnect,separator,win.session.properties,win.file.transfer,win.print,win.close' + The toolbar action list + + + + + 'win.disconnect,win.reconnect,win.file.transfer,win.print:menu.open-menu' + The actions in the header bar + + + + + + diff --git a/schemas/linux/application.gschema.xml.in b/schemas/linux/application.gschema.xml.in index 3d431b2..80a596c 100644 --- a/schemas/linux/application.gschema.xml.in +++ b/schemas/linux/application.gschema.xml.in @@ -38,48 +38,6 @@ The ID of the current user interface style - - true - Enable top window subtitle - If TRUE, reserve space for a subtitle, even if none is currently set. - - - - -1 - How to draw the toolbar. - - - - - 0 - The size of the icons in a toolbar - - - - - true - The toolbar visible state - - - - - true - The menubar visible state - - - - - 'win.copy,win.paste,win.select-all,separator,win.connect,win.disconnect,separator,win.session.properties,win.file.transfer,win.print,app.quit' - The toolbar action list - - - - - 'win.disconnect,win.reconnect,win.file.transfer,win.print:menu.open-menu' - The actions in the header bar - - - diff --git a/src/objects/window/private.h b/src/objects/window/private.h index cebb586..e8f5f11 100644 --- a/src/objects/window/private.h +++ b/src/objects/window/private.h @@ -65,6 +65,13 @@ GtkNotebook * notebook; GtkToolbar * toolbar; + struct { + int width; ///< @brief Window width. + int height; ///< @brief Window height. + int is_maximized : 1; ///< @brief Non zero if window is maximized. + int is_fullscreen : 1; ///< @brief Non zero if window is fullscreen. + } state; + GtkWidget * popups[PW3270_APP_WINDOW_POPUP_COUNT]; }; diff --git a/src/objects/window/window.c b/src/objects/window/window.c index d93798c..be1116f 100644 --- a/src/objects/window/window.c +++ b/src/objects/window/window.c @@ -35,6 +35,7 @@ static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); + static GSettings *pw3270_application_window_settings_new(void); G_DEFINE_TYPE(pw3270ApplicationWindow, pw3270ApplicationWindow, GTK_TYPE_APPLICATION_WINDOW); @@ -60,29 +61,105 @@ } } + { + g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); + + g_settings_set_int(settings, "width", window->state.width); + g_settings_set_int(settings, "height", window->state.height); + g_settings_set_boolean(settings, "is-maximized", window->state.is_maximized); + g_settings_set_boolean(settings, "is-fullscreen", window->state.is_fullscreen); + } + GTK_WIDGET_CLASS(pw3270ApplicationWindow_parent_class)->destroy(widget); } - static void pw3270ApplicationWindow_class_init(pw3270ApplicationWindowClass *klass) { + static void size_allocate(GtkWidget *widget, GtkAllocation *allocation) { + + // https://developer.gnome.org/SaveWindowState/ + GTK_WIDGET_CLASS(pw3270ApplicationWindow_parent_class)->size_allocate(widget, allocation); - GTK_WIDGET_CLASS(klass)->destroy = destroy; + pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget); + + if(!(window->state.is_maximized || window->state.is_fullscreen)) { + gtk_window_get_size(GTK_WINDOW (widget), &window->state.width, &window->state.height); + } - GObjectClass *object_class = G_OBJECT_CLASS(klass); + } - object_class->set_property = set_property; - object_class->get_property = get_property; + static gboolean window_state_event(GtkWidget *widget, GdkEventWindowState *event) { - g_object_class_install_property( - object_class, - PROP_ACTION_NAMES, - g_param_spec_string ("action-names", - N_("Action Names"), - N_("The name of the actions in the header bar"), - NULL, - G_PARAM_WRITABLE|G_PARAM_READABLE) - ); + // https://developer.gnome.org/SaveWindowState/ + gboolean res = GDK_EVENT_PROPAGATE; + if(GTK_WIDGET_CLASS(pw3270ApplicationWindow_parent_class)->window_state_event != NULL) { + res = GTK_WIDGET_CLASS(pw3270ApplicationWindow_parent_class)->window_state_event(widget, event); + } + + { + pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget); + + window->state.is_maximized = (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) == 0 ? 0 : 1; + window->state.is_fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) == 0 ? 0 : 1; + } + + return res; + } + + static void constructed(GObject *object) { + + // https://developer.gnome.org/SaveWindowState/ + + pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(object); + + g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); + if(settings) { + + // https://developer.gnome.org/SaveWindowState/ + window->state.width = g_settings_get_int (settings, "width"); + window->state.height = g_settings_get_int (settings, "height"); + window->state.is_maximized = g_settings_get_boolean (settings, "is-maximized") ? 1 : 0; + window->state.is_fullscreen = g_settings_get_boolean (settings, "is-fullscreen") ? 1 : 0; + + } + + gtk_window_set_default_size(GTK_WINDOW (object), window->state.width, window->state.height); + + if(window->state.is_maximized) + gtk_window_maximize(GTK_WINDOW(object)); + + if(window->state.is_fullscreen) + gtk_window_fullscreen(GTK_WINDOW (object)); + + G_OBJECT_CLASS (pw3270ApplicationWindow_parent_class)->constructed (object); + } + + static void pw3270ApplicationWindow_class_init(pw3270ApplicationWindowClass *klass) { + + { + GtkWidgetClass *widget = GTK_WIDGET_CLASS(klass); + widget->destroy = destroy; + widget->window_state_event = window_state_event; + widget->size_allocate = size_allocate; + } + + { + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + object_class->set_property = set_property; + object_class->get_property = get_property; + object_class->constructed = constructed; + + g_object_class_install_property( + object_class, + PROP_ACTION_NAMES, + g_param_spec_string ("action-names", + N_("Action Names"), + N_("The name of the actions in the header bar"), + NULL, + G_PARAM_WRITABLE|G_PARAM_READABLE) + ); + } } @@ -104,6 +181,13 @@ static void pw3270ApplicationWindow_init(pw3270ApplicationWindow *widget) { + // Setup defaults + widget->state.width = 800; + widget->state.height = 500; + widget->state.is_maximized = 0; + widget->state.is_fullscreen = 0; + + // Create contents GtkBox * vBox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL,0)); widget->notebook = GTK_NOTEBOOK(gtk_notebook_new()); @@ -224,8 +308,6 @@ size_t ix; - g_autoptr(GSettings) settings = pw3270_application_get_settings(G_APPLICATION(application)); - g_return_val_if_fail(GTK_IS_APPLICATION(application), NULL); pw3270ApplicationWindow * window = g_object_new( @@ -259,88 +341,88 @@ } - if(pw3270_application_get_ui_style(G_APPLICATION(application)) == PW3270_UI_STYLE_GNOME) { + // Setup and show main window + { + g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); + + if(pw3270_application_get_ui_style(G_APPLICATION(application)) == PW3270_UI_STYLE_GNOME) { + + // Create header bar + + GtkHeaderBar * header = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_window_set_titlebar(GTK_WINDOW(window), GTK_WIDGET(header)); + gtk_header_bar_set_show_close_button(header,TRUE); - // Create header bar + gtk_header_bar_set_title(header,title); + g_settings_bind( + settings, + "has-subtitle", + header, + "has-subtitle", + G_SETTINGS_BIND_DEFAULT + ); - GtkHeaderBar * header = GTK_HEADER_BAR(gtk_header_bar_new()); - gtk_window_set_titlebar(GTK_WINDOW(window), GTK_WIDGET(header)); - gtk_header_bar_set_show_close_button(header,TRUE); + // Show the new header + gtk_widget_show_all(GTK_WIDGET(header)); + + g_settings_bind( + settings, + "header-action-names", + window, + "action-names", + G_SETTINGS_BIND_DEFAULT + ); + + } else { + + gtk_window_set_title(GTK_WINDOW(window), title); + + } - gtk_header_bar_set_title(header,title); g_settings_bind( settings, - "has-subtitle", - header, - "has-subtitle", + "menubar-visible", + window, + "show-menubar", G_SETTINGS_BIND_DEFAULT ); - // Show the new header - gtk_widget_show_all(GTK_WIDGET(header)); - - // g_autofree gchar * header_actions = g_settings_get_string(settings, "header-action-names"); - // pw3270_window_set_header_action_names(GTK_WIDGET(window), header_actions); + g_settings_bind( + settings, + "toolbar-visible", + window->toolbar, + "visible", + G_SETTINGS_BIND_DEFAULT + ); g_settings_bind( settings, - "header-action-names", - window, + "toolbar-action-names", + window->toolbar, "action-names", G_SETTINGS_BIND_DEFAULT ); - } else { + g_settings_bind( + settings, + "toolbar-style", + window->toolbar, + "style", + G_SETTINGS_BIND_DEFAULT + ); - gtk_window_set_title(GTK_WINDOW(window), title); + g_settings_bind( + settings, + "toolbar-icon-size", + window->toolbar, + "icon-size", + G_SETTINGS_BIND_DEFAULT + ); } - // Setup and show main window - g_settings_bind( - settings, - "menubar-visible", - window, - "show-menubar", - G_SETTINGS_BIND_DEFAULT - ); - - g_settings_bind( - settings, - "toolbar-visible", - window->toolbar, - "visible", - G_SETTINGS_BIND_DEFAULT - ); - - g_settings_bind( - settings, - "toolbar-action-names", - window->toolbar, - "action-names", - G_SETTINGS_BIND_DEFAULT - ); - - g_settings_bind( - settings, - "toolbar-style", - window->toolbar, - "style", - G_SETTINGS_BIND_DEFAULT - ); - - g_settings_bind( - settings, - "toolbar-icon-size", - window->toolbar, - "icon-size", - G_SETTINGS_BIND_DEFAULT - ); - - // Setup default position and size gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); - gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); // Create terminal widget GtkWidget * terminal = pw3270_application_window_new_tab(GTK_WIDGET(window), session_file); @@ -456,3 +538,45 @@ g_strfreev(actions); } + + GSettings *pw3270_application_window_settings_new() { + + // Get settings + g_autofree gchar * path = g_strconcat("/apps/" PACKAGE_NAME "/", g_get_application_name(), "/window/",NULL); + debug("path=%s",path); + +#ifdef DEBUG + + GError * error = NULL; + GSettingsSchemaSource * source = + g_settings_schema_source_new_from_directory( + ".", + NULL, + TRUE, + &error + ); + + g_assert_no_error(error); + + GSettingsSchema * schema = + g_settings_schema_source_lookup( + source, + "br.com.bb." PACKAGE_NAME ".window", + TRUE); + + debug("schema %s=%p path=%s","br.com.bb." PACKAGE_NAME ".window",schema,path); + + GSettings * settings = g_settings_new_full(schema, NULL, path); + + g_settings_schema_source_unref(source); + +#else + + GSettings * settings = g_settings_new_with_path("br.com.bb." PACKAGE_NAME, path); + +#endif // DEBUG + + return settings; + + } + -- libgit2 0.21.2