- /* Misc, helpers */
- site_setup(self);
- time_setup(self);
-
- /* Connect signals */
- gtk_builder_connect_signals(self->builder, self);
- g_signal_connect(self, "key-press-event",
- G_CALLBACK(on_gui_key_press), self);
- g_signal_connect_swapped(self->world, "offline",
- G_CALLBACK(gtk_toggle_action_set_active),
- aweather_gui_get_object(self, "offline"));
-
- /* Preferences */
- gchar *filename = g_build_filename(g_get_user_config_dir(),
- "aweather", "config.ini", NULL);
- self->prefs = g_key_file_new();
- g_key_file_load_from_file(self->prefs, filename, G_KEY_FILE_KEEP_COMMENTS, &error);
-}
-static GObject *aweather_gui_constructor(GType gtype, guint n_properties,
- GObjectConstructParam *properties)
-{
- g_debug("aweather_gui: constructor");
- GObjectClass *parent_class = G_OBJECT_CLASS(aweather_gui_parent_class);
- return parent_class->constructor(gtype, n_properties, properties);
-}
-static void aweather_gui_dispose(GObject *_self)
-{
- g_debug("AWeatherGui: dispose");
- AWeatherGui *self = AWEATHER_GUI(_self);
- if (self->builder) {
- /* Reparent to avoid double unrefs */
- GtkWidget *body = aweather_gui_get_widget(self, "body");
- GtkWidget *window = aweather_gui_get_widget(self, "main_window");
- gtk_widget_reparent(body, window);
- g_object_unref(self->builder);
- self->builder = NULL;
- }
- if (self->world) {
- g_object_unref(self->world);
- self->world = NULL;
- }
- if (self->view) {
- g_object_unref(self->view);
- self->view = NULL;
- }
- if (self->opengl) {
- g_object_unref(self->opengl);
- self->opengl = NULL;
- }
- if (self->plugins) {
- g_list_foreach(self->plugins, (GFunc)g_object_unref, NULL);
- g_list_free(self->plugins);
- self->plugins = NULL;
- }
- if (self->prefs) {
- gchar *filename = g_build_filename(g_get_user_config_dir(),
- "aweather", "config.ini", NULL);
- gsize length;
- g_mkdir_with_parents(g_path_get_dirname(filename), 0755);
- gchar *data = g_key_file_to_data(self->prefs, &length, NULL);
- g_file_set_contents(filename, data, length, NULL);
- g_key_file_free(self->prefs);
- self->prefs = NULL;
- }
- G_OBJECT_CLASS(aweather_gui_parent_class)->dispose(_self);
+#include "aweather-gui.h"
+#include "aweather-location.h"
+
+/* Autohide */
+typedef struct {
+ GtkWidget *widget;
+ GtkWidget *window;
+ GtkPositionType position;
+ gulong handler;
+} GtkAutohideData;
+static gboolean _gtk_widget_autohide_cb(GtkWidget *win,
+ GdkEventMotion *event, GtkAutohideData *data)
+{
+ GtkAllocation alloc;
+ gtk_widget_get_allocation(data->window, &alloc);
+ if (data->position == GTK_POS_BOTTOM)
+ g_debug("GtkWidget: autohide_cb - y=%lf, h=%d", event->y, alloc.height);
+ gint position = -1;
+ if (event->x < 20) position = GTK_POS_LEFT;
+ if (event->y < 20) position = GTK_POS_TOP;
+ if (event->x > alloc.width - 20) position = GTK_POS_RIGHT;
+ if (event->y > alloc.height - 20) position = GTK_POS_BOTTOM;
+ if (position == data->position)
+ gtk_widget_show(data->widget);
+ else
+ gtk_widget_hide(data->widget);
+ return FALSE;