Add preferences window with option to turn off maximized windows
This is very limited right now. See README.md for other options to integrate here (and throughout the app).
This commit is contained in:
parent
1cee8bf38c
commit
b2cab90dcb
@ -63,7 +63,11 @@ new_window_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|||||||
static void
|
static void
|
||||||
preferences_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
preferences_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
||||||
{
|
{
|
||||||
ag_preferences_show_dialog();
|
AgApp *app = AG_APP(user_data);
|
||||||
|
GtkWindow *window;
|
||||||
|
|
||||||
|
window = ag_app_peek_first_window(app);
|
||||||
|
ag_preferences_show_dialog(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1,43 +1,77 @@
|
|||||||
#include <glib.h>
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include "ag-settings.h"
|
#include "ag-settings.h"
|
||||||
|
#include "ag-preferences.h"
|
||||||
|
|
||||||
typedef struct {
|
static GtkWidget *prefs_dialog = NULL;
|
||||||
GtkWidget *dialog;
|
|
||||||
|
typedef struct _AgPreferencesPrivate {
|
||||||
|
GtkCheckButton *maximized;
|
||||||
AgSettings *settings;
|
AgSettings *settings;
|
||||||
} AgPreferences;
|
} AgPreferencesPrivate;
|
||||||
|
|
||||||
static AgPreferences *prefs;
|
G_DEFINE_TYPE_WITH_PRIVATE(AgPreferences, ag_preferences, GTK_TYPE_DIALOG);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ag_preferences_init(void)
|
ag_preferences_finalize(GObject *gobject)
|
||||||
{
|
{
|
||||||
GApplication *app;
|
AgPreferencesPrivate *priv;
|
||||||
|
|
||||||
if (prefs) {
|
priv = ag_preferences_get_instance_private(AG_PREFERENCES(gobject));
|
||||||
return;
|
|
||||||
|
g_clear_object(&priv->settings);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS(ag_preferences_parent_class)->finalize(gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((app = g_application_get_default()) == NULL) {
|
static void
|
||||||
g_warning("Cannot launch preferences: No default application found");
|
ag_preferences_response(GtkDialog *dlg, gint response_id)
|
||||||
|
{
|
||||||
return;
|
gtk_widget_destroy(GTK_WIDGET(dlg));
|
||||||
}
|
}
|
||||||
|
|
||||||
prefs = g_new0(AgPreferences, 1);
|
static void
|
||||||
prefs->settings = ag_settings_get();
|
ag_preferences_class_init(AgPreferencesClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
||||||
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
|
||||||
|
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS(klass);
|
||||||
|
|
||||||
|
object_class->finalize = ag_preferences_finalize;
|
||||||
|
dialog_class->response = ag_preferences_response;
|
||||||
|
|
||||||
|
gtk_widget_class_set_template_from_resource(widget_class, "/eu/polonkai/gergely/astrognome/ag-preferences.ui");
|
||||||
|
gtk_widget_class_bind_template_child_private(widget_class, AgPreferences, maximized);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ag_preferences_init(AgPreferences *prefs)
|
||||||
|
{
|
||||||
|
AgPreferencesPrivate *priv;
|
||||||
|
GSettings *settings_window;
|
||||||
|
|
||||||
|
priv = ag_preferences_get_instance_private(prefs);
|
||||||
|
gtk_widget_init_template(GTK_WIDGET(prefs));
|
||||||
|
|
||||||
|
priv->settings = ag_settings_get();
|
||||||
|
|
||||||
|
settings_window = ag_settings_peek_window_settings(priv->settings);
|
||||||
|
g_settings_bind(settings_window, "maximized", priv->maximized, "active", G_SETTINGS_BIND_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ag_preferences_show_dialog(void)
|
ag_preferences_show_dialog(GtkWindow *parent)
|
||||||
{
|
{
|
||||||
ag_preferences_init();
|
g_return_if_fail(GTK_IS_WINDOW(parent));
|
||||||
|
|
||||||
if (prefs->dialog != NULL) {
|
if (prefs_dialog == NULL) {
|
||||||
gtk_window_present(GTK_WINDOW(prefs->dialog));
|
prefs_dialog = GTK_WIDGET(g_object_new(AG_TYPE_PREFERENCES, NULL));
|
||||||
|
g_signal_connect(prefs_dialog, "destroy", G_CALLBACK(gtk_widget_destroyed), &prefs_dialog);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parent != gtk_window_get_transient_for(GTK_WINDOW(prefs_dialog))) {
|
||||||
|
gtk_window_set_transient_for(GTK_WINDOW(prefs_dialog), parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_window_present(GTK_WINDOW(prefs_dialog));
|
||||||
|
}
|
||||||
|
@ -5,9 +5,28 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
void ag_preferences_show_dialog(void);
|
#define AG_TYPE_PREFERENCES (ag_preferences_get_type())
|
||||||
|
#define AG_PREFERENCES(o) (G_TYPE_CHECK_INSTANCE_CAST((o), AG_TYPE_PREFERENCES, AgPreferences))
|
||||||
|
#define AG_PREFERENCES_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), AG_TYPE_PREFERENCES, AgPreferencesClass))
|
||||||
|
#define AG_IS_PREFERENCES(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), AG_TYPE_PREFERENCES))
|
||||||
|
#define AG_IS_PREFERENCES_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), AG_TYPE_PREFERENCES))
|
||||||
|
#define AG_PREFERENCES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), AG_TYPE_PREFERENCES, AgPreferencesClass))
|
||||||
|
|
||||||
|
typedef struct _AgPreferences AgPreferences;
|
||||||
|
typedef struct _AgPreferencesClass AgPreferencesClass;
|
||||||
|
|
||||||
|
struct _AgPreferences {
|
||||||
|
GtkDialog parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _AgPreferencesClass {
|
||||||
|
GtkDialogClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
GType ag_preferences_get_type(void);
|
||||||
|
|
||||||
|
void ag_preferences_show_dialog(GtkWindow *parent);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __AG_PREFERENCES_H__ */
|
#endif /* __AG_PREFERENCES_H__ */
|
||||||
|
|
||||||
|
59
src/ag-preferences.ui
Normal file
59
src/ag-preferences.ui
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.18.3 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.12"/>
|
||||||
|
<template class="AgPreferences" parent="GtkDialog">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="type_hint">normal</property>
|
||||||
|
<child internal-child="vbox">
|
||||||
|
<object class="GtkBox" id="dialog-vbox1">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">2</property>
|
||||||
|
<child internal-child="action_area">
|
||||||
|
<object class="GtkButtonBox" id="dialog-action_area1">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="layout_style">end</property>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid" id="grid2">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCheckButton" id="maximized">
|
||||||
|
<property name="label" translatable="yes">New windows start maximized</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="xalign">0</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</template>
|
||||||
|
</interface>
|
@ -2,5 +2,6 @@
|
|||||||
<gresources>
|
<gresources>
|
||||||
<gresource prefix="/eu/polonkai/gergely/astrognome">
|
<gresource prefix="/eu/polonkai/gergely/astrognome">
|
||||||
<file>astrognome.ui</file>
|
<file>astrognome.ui</file>
|
||||||
|
<file>ag-preferences.ui</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
Loading…
Reference in New Issue
Block a user