Initial commit
Added basic UI
This commit is contained in:
275
src/ui/main-window.c
Normal file
275
src/ui/main-window.c
Normal file
@@ -0,0 +1,275 @@
|
||||
#define G_LOG_DOMAIN "main-window"
|
||||
|
||||
#include "main-window.h"
|
||||
#include "panels/empty_panel.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
struct _MainWindow
|
||||
{
|
||||
AdwApplicationWindow parent;
|
||||
|
||||
AdwHeaderBar* header;
|
||||
AdwLeaflet* main_leaflet;
|
||||
// TODO LIST : CcPanelList *panel_list;
|
||||
GtkBox* sidebar_box;
|
||||
AdwWindowTitle* sidebar_title_widget;
|
||||
GtkStack* stack;
|
||||
|
||||
// GtkWidget *old_panel;
|
||||
GtkWidget* current_panel;
|
||||
char* current_panel_id;
|
||||
// GQueue *previous_panels;
|
||||
|
||||
GtkWidget* custom_titlebar;
|
||||
|
||||
// CcShellModel *store;
|
||||
|
||||
// CcPanel *active_panel;
|
||||
GSettings* settings;
|
||||
|
||||
gboolean folded;
|
||||
|
||||
// CcPanelListView previous_list_view;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(MainWindow, main_window, ADW_TYPE_APPLICATION_WINDOW)
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_ACTIVE_PANEL,
|
||||
PROP_MODEL,
|
||||
PROP_FOLDED,
|
||||
};
|
||||
|
||||
static gboolean activate_panel(MainWindow* self, Panel* panel, const gchar* id)
|
||||
{
|
||||
self->current_panel = GTK_WIDGET(panel);
|
||||
gtk_stack_add_named(self->stack, self->current_panel, id);
|
||||
gtk_stack_set_visible_child_name (self->stack, id);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override from GtkWidget
|
||||
*/
|
||||
static void
|
||||
main_window_map(GtkWidget* widget)
|
||||
{
|
||||
MainWindow* self = (MainWindow*) widget;
|
||||
GTK_WIDGET_CLASS(main_window_parent_class)->map(widget);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override from GtkWidget
|
||||
*/
|
||||
static void
|
||||
main_window_unmap(GtkWidget* widget)
|
||||
{
|
||||
MainWindow* self = GINPUT_MAIN_WINDOW(widget);
|
||||
gboolean maximized;
|
||||
gint height;
|
||||
gint width;
|
||||
|
||||
maximized = gtk_window_is_maximized(GTK_WINDOW(self));
|
||||
gtk_window_get_default_size(GTK_WINDOW(self), &width, &height);
|
||||
|
||||
g_settings_set(self->settings,
|
||||
"window-state",
|
||||
"(iib)",
|
||||
width,
|
||||
height,
|
||||
maximized);
|
||||
|
||||
GTK_WIDGET_CLASS(main_window_parent_class)->unmap(widget);
|
||||
}
|
||||
|
||||
static void
|
||||
main_window_get_property(GObject* object, guint property_id, GValue* value, GParamSpec* pspec)
|
||||
{
|
||||
MainWindow* self = GINPUT_MAIN_WINDOW(object);
|
||||
|
||||
switch(property_id)
|
||||
{
|
||||
// case PROP_ACTIVE_PANEL:
|
||||
// g_value_set_object (value, self->active_panel);
|
||||
// break;
|
||||
|
||||
// case PROP_MODEL:
|
||||
// g_value_set_object (value, self->store);
|
||||
// break;
|
||||
|
||||
case PROP_FOLDED:
|
||||
g_value_set_boolean(value, self->folded);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
main_window_set_property(GObject* object,
|
||||
guint property_id,
|
||||
const GValue* value,
|
||||
GParamSpec* pspec)
|
||||
{
|
||||
MainWindow* self = GINPUT_MAIN_WINDOW(object);
|
||||
|
||||
switch(property_id)
|
||||
{
|
||||
// case PROP_ACTIVE_PANEL:
|
||||
// set_active_panel(self, g_value_get_object(value));
|
||||
// break;
|
||||
|
||||
// case PROP_MODEL:
|
||||
// g_assert(self->store == NULL);
|
||||
// self->store = g_value_dup_object(value);
|
||||
// break;
|
||||
|
||||
case PROP_FOLDED:
|
||||
self->folded = g_value_get_boolean(value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
load_window_state(MainWindow* self)
|
||||
{
|
||||
gint current_width = -1;
|
||||
gint current_height = -1;
|
||||
gboolean maximized = FALSE;
|
||||
|
||||
g_settings_get(self->settings,
|
||||
"window-state",
|
||||
"(iib)",
|
||||
¤t_width,
|
||||
¤t_height,
|
||||
&maximized);
|
||||
|
||||
if(current_width != -1 && current_height != -1)
|
||||
gtk_window_set_default_size(GTK_WINDOW(self), current_width, current_height);
|
||||
if(maximized)
|
||||
gtk_window_maximize(GTK_WINDOW(self));
|
||||
}
|
||||
|
||||
static void
|
||||
main_window_constructed(GObject* object)
|
||||
{
|
||||
MainWindow* self = GINPUT_MAIN_WINDOW(object);
|
||||
|
||||
load_window_state(self);
|
||||
|
||||
/* Add the panels */
|
||||
// setup_model (self);
|
||||
|
||||
/* After everything is loaded, select the last used panel, if any,
|
||||
* or the first visible panel. We do that in an idle handler so we
|
||||
* have a chance to skip it when another panel has been explicitly
|
||||
* activated from commandline parameter or from DBus method */
|
||||
// g_idle_add_once ((GSourceOnceFunc) maybe_load_last_panel, self);
|
||||
|
||||
// g_signal_connect_swapped (self->panel_list,
|
||||
// "notify::view",
|
||||
// G_CALLBACK (update_headerbar_buttons),
|
||||
// self);
|
||||
|
||||
// update_headerbar_buttons (self);
|
||||
// adw_leaflet_set_visible_child (self->main_leaflet,
|
||||
// GTK_WIDGET (self->sidebar_box));
|
||||
|
||||
G_OBJECT_CLASS(main_window_parent_class)->constructed(object);
|
||||
}
|
||||
|
||||
static void
|
||||
main_window_dispose(GObject* object)
|
||||
{
|
||||
MainWindow* self = GINPUT_MAIN_WINDOW(object);
|
||||
|
||||
g_clear_pointer(&self->current_panel_id, g_free);
|
||||
// g_clear_object (&self->store);
|
||||
// g_clear_object (&self->active_panel);
|
||||
|
||||
G_OBJECT_CLASS(main_window_parent_class)->dispose(object);
|
||||
}
|
||||
|
||||
static void
|
||||
main_window_finalize(GObject* object)
|
||||
{
|
||||
MainWindow* self = GINPUT_MAIN_WINDOW(object);
|
||||
|
||||
// if (self->previous_panels)
|
||||
// {
|
||||
// g_queue_free_full (self->previous_panels, g_free);
|
||||
// self->previous_panels = NULL;
|
||||
// }
|
||||
|
||||
g_clear_object(&self->settings);
|
||||
|
||||
G_OBJECT_CLASS(main_window_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
main_window_class_init(MainWindowClass* klass)
|
||||
{
|
||||
GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass);
|
||||
GObjectClass* object_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
object_class->get_property = main_window_get_property;
|
||||
object_class->set_property = main_window_set_property;
|
||||
object_class->constructed = main_window_constructed;
|
||||
object_class->dispose = main_window_dispose;
|
||||
object_class->finalize = main_window_finalize;
|
||||
|
||||
widget_class->map = main_window_map;
|
||||
widget_class->unmap = main_window_unmap;
|
||||
|
||||
g_object_class_install_property(object_class, PROP_FOLDED,
|
||||
g_param_spec_boolean("folded", "Folded", "Whether the window is foled", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
gtk_widget_class_set_template_from_resource(widget_class, "/v/ginput/main-window.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child(widget_class, MainWindow, header);
|
||||
gtk_widget_class_bind_template_child(widget_class, MainWindow, main_leaflet);
|
||||
// gtk_widget_class_bind_template_child(widget_class, MainWindow, panel_list);
|
||||
gtk_widget_class_bind_template_child(widget_class, MainWindow, sidebar_box);
|
||||
gtk_widget_class_bind_template_child(widget_class, MainWindow, sidebar_title_widget);
|
||||
gtk_widget_class_bind_template_child(widget_class, MainWindow, stack);
|
||||
}
|
||||
|
||||
static void
|
||||
main_window_init(MainWindow* self)
|
||||
{
|
||||
gtk_widget_init_template(GTK_WIDGET(self));
|
||||
|
||||
self->settings = g_settings_new("v.ginput");
|
||||
// self->previous_panels = g_queue_new ();
|
||||
// self->previous_list_view = cc_panel_list_get_view (self->panel_list);
|
||||
|
||||
g_object_bind_property(self->main_leaflet,
|
||||
"folded",
|
||||
self,
|
||||
"folded",
|
||||
G_BINDING_SYNC_CREATE);
|
||||
|
||||
activate_panel(self, empty_panel_new(), "empty");
|
||||
}
|
||||
|
||||
// TODO use translation
|
||||
#define _(x) x
|
||||
|
||||
MainWindow*
|
||||
main_window_new(AdwApplication* application)
|
||||
{
|
||||
g_return_val_if_fail(GTK_IS_APPLICATION(application), NULL);
|
||||
|
||||
return g_object_new(main_window_get_type(),
|
||||
"application", application,
|
||||
"resizable", TRUE,
|
||||
"title", _("Input devices"),
|
||||
"icon-name", "input-devices",
|
||||
"show-menubar", FALSE,
|
||||
NULL);
|
||||
}
|
Reference in New Issue
Block a user