Ejemplo n.º 1
1
static void
gm_window_init (GTypeInstance *instance,
                gpointer g_class)
{
  GmWindow *self = NULL;

  (void) g_class; /* -Wextra */

  self = GM_WINDOW (instance);
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_WINDOW_TYPE, GmWindowPrivate);
  self->priv->key = g_strdup ("");
  self->priv->hide_on_esc = TRUE;
  self->priv->hide_on_delete = TRUE;

  self->priv->accel = gtk_accel_group_new ();
  gtk_window_add_accel_group (GTK_WINDOW (self), self->priv->accel);
  gtk_accel_group_connect (self->priv->accel, GDK_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
                           g_cclosure_new_swap (G_CALLBACK (gtk_widget_hide), (gpointer) self, NULL));

  g_signal_connect (G_OBJECT (self), "delete_event",
		    G_CALLBACK (gm_window_delete_event), NULL);

  g_signal_connect (G_OBJECT (self), "show",
                    G_CALLBACK (gm_window_show), self);

  g_signal_connect (G_OBJECT (self), "hide",
                    G_CALLBACK (gm_window_hide), self);

  g_signal_connect (G_OBJECT (self), "configure-event",
                    G_CALLBACK (gm_window_configure_event), self);
}
Ejemplo n.º 2
0
static gboolean
gm_window_configure_event (GtkWidget *self,
                           GdkEventConfigure *event)
{
  gtk_window_get_position (GTK_WINDOW (self), &GM_WINDOW (self)->priv->x, &GM_WINDOW (self)->priv->y);

  GM_WINDOW (self)->priv->width = event->width;
  GM_WINDOW (self)->priv->height = event->height;

  return FALSE;
}
Ejemplo n.º 3
0
static void
gm_window_get_property (GObject *obj,
                        guint prop_id,
                        GValue *value,
                        GParamSpec *spec)
{
  GmWindow *self = NULL;

  self = GM_WINDOW (obj);
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_TYPE_WINDOW, GmWindowPrivate);

  switch (prop_id) {

  case GM_WINDOW_KEY:
    g_value_set_string (value, self->priv->key);
    break;

  case GM_HIDE_ON_ESC:
    g_value_set_boolean (value, self->priv->hide_on_esc);
    break;

  case GM_HIDE_ON_DELETE:
    g_value_set_boolean (value, self->priv->hide_on_delete);
    break;

  case GM_STAY_ON_TOP:
    g_value_set_boolean (value, self->priv->stay_on_top);
    break;

  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, spec);
    break;
  }
}
Ejemplo n.º 4
0
/* 
 * GObject stuff
 */
static void
gm_window_dispose (GObject *obj)
{
  GmWindow *window = NULL;

  window = GM_WINDOW (obj);

  parent_class->dispose (obj);
}
Ejemplo n.º 5
0
void
gm_window_set_hide_on_delete (GmWindow *window,
			      gboolean hide_on_delete)
{
  g_return_if_fail (window != NULL);
  g_return_if_fail (IS_GM_WINDOW (window));

  g_object_set (GM_WINDOW (window), "hide_on_delete", hide_on_delete, NULL);
}
Ejemplo n.º 6
0
void
gm_window_set_key (GmWindow *window,
                   const char *key)
{
  g_return_if_fail (window != NULL);
  g_return_if_fail (key != NULL);

  g_object_set (GM_WINDOW (window), "key", key, NULL);
}
Ejemplo n.º 7
0
static void
gm_window_finalize (GObject *obj)
{
  GmWindow *window = NULL;

  window = GM_WINDOW (obj);

  g_free ((gchar *) window->priv->key);

  parent_class->finalize (obj);
}
Ejemplo n.º 8
0
GtkWidget *
gm_window_new_with_key (const char *key)
{
  GtkWidget *window = NULL;

  g_return_val_if_fail (key != NULL, NULL);

  window = gm_window_new ();
  gm_window_set_key (GM_WINDOW (window), key);

  return window;
}
Ejemplo n.º 9
0
static void
window_hide_cb (GtkWidget *w,
                G_GNUC_UNUSED gpointer data)
{
  GmWindow *self = NULL;

  g_return_if_fail (w != NULL);

  self = GM_WINDOW (w);

  gm_window_save (self);
  self->priv->state_restored = FALSE;
}
Ejemplo n.º 10
0
static void
window_show_cb (GtkWidget *w,
                G_GNUC_UNUSED gpointer data)
{
  GmWindow *self = NULL;

  self = GM_WINDOW (w);

  g_return_if_fail (self);

  if (!self->priv->state_restored)
    gm_window_restore (self);
}
Ejemplo n.º 11
0
static void
window_realize_cb (GtkWidget *w,
		   G_GNUC_UNUSED gpointer data)
{
  GmWindow *self = NULL;

  self = GM_WINDOW (w);

  g_return_if_fail (self);

  gm_window_restore (self);
  self->priv->state_restored = TRUE;

  gtk_widget_realize (GTK_WIDGET (w));
}
Ejemplo n.º 12
0
/*
 * Our own stuff
 */
static gboolean
gm_window_delete_event_cb (GtkWidget *w,
                           G_GNUC_UNUSED gpointer data)
{
  GmWindow* self = NULL;

  self = GM_WINDOW (w);

  if (self->priv->hide_on_delete) {
    gtk_widget_hide (w);
    return TRUE;
  }

  return FALSE;
}
Ejemplo n.º 13
0
/*
 * GObject stuff
 */
static void
gm_window_finalize (GObject *obj)
{
  GmWindow *self = NULL;

  self = GM_WINDOW (obj);

  g_free (self->priv->key);
  self->priv->key = NULL;

  if (self->priv->settings)
    g_clear_object (&self->priv->settings);
  self->priv->settings = NULL;

  G_OBJECT_CLASS (gm_window_parent_class)->finalize (obj);
}
Ejemplo n.º 14
0
static void
gm_window_set_property (GObject *obj,
                        guint prop_id,
                        const GValue *value,
                        GParamSpec *spec)
{
  GmWindow *self = NULL;
  const gchar *str = NULL;

  self = GM_WINDOW (obj);
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_TYPE_WINDOW, GmWindowPrivate);

  switch (prop_id) {

  case GM_WINDOW_KEY:
    if (self->priv->key)
      g_free (self->priv->key);
    str = g_value_get_string (value);
    self->priv->key = g_strdup (str ? str : "");
    if (self->priv->settings)
      g_clear_object (&self->priv->settings);
    self->priv->settings = g_settings_new (self->priv->key);
    break;

  case GM_HIDE_ON_ESC:
    self->priv->hide_on_esc = g_value_get_boolean (value);
    if (!self->priv->hide_on_esc)
      gtk_accel_group_disconnect_key (self->priv->accel, GDK_KEY_Escape, (GdkModifierType) 0);
    else
      gtk_accel_group_connect (self->priv->accel, GDK_KEY_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
                               g_cclosure_new_swap (G_CALLBACK (gtk_widget_hide), (gpointer) self, NULL));
    break;

  case GM_HIDE_ON_DELETE:
    self->priv->hide_on_delete = g_value_get_boolean (value);
    break;

  case GM_STAY_ON_TOP:
    self->priv->stay_on_top = g_value_get_boolean (value);
    gtk_window_set_keep_above (GTK_WINDOW (self), self->priv->stay_on_top);
    break;

  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, spec);
    break;
  }
}
Ejemplo n.º 15
0
static void
gm_window_hide (GtkWidget *w,
                G_GNUC_UNUSED gpointer data)
{
  GmWindow *self = NULL;

  gchar *conf_key_size = NULL;
  gchar *conf_key_position = NULL;
  gchar *size = NULL;
  gchar *position = NULL;
  
  g_return_if_fail (w != NULL);
  
  self = GM_WINDOW (w);

  g_return_if_fail (strcmp (self->priv->key, ""));

  conf_key_position =
    g_strdup_printf ("%s/position", self->priv->key);
  conf_key_size =
    g_strdup_printf ("%s/size", self->priv->key);

  position = g_strdup_printf ("%d,%d", self->priv->x, self->priv->y);
  gm_conf_set_string (conf_key_position, position);
  g_free (position);

  if (gtk_window_get_resizable (GTK_WINDOW (w))) {

    size = g_strdup_printf ("%d,%d", self->priv->width, self->priv->height);
    gm_conf_set_string (conf_key_size, size);
    g_free (size);
  }
  
  g_free (conf_key_position);
  g_free (conf_key_size);
}
Ejemplo n.º 16
0
static void
gm_window_show (GtkWidget *w,
                G_GNUC_UNUSED gpointer data)
{
  int x = 0;
  int y = 0;

  GmWindow *self = NULL;

  gchar *conf_key_size = NULL;
  gchar *conf_key_position = NULL;
  gchar *size = NULL;
  gchar *position = NULL;
  gchar **couple = NULL;

  g_return_if_fail (w != NULL);
  
  self = GM_WINDOW (w);

  g_return_if_fail (strcmp (self->priv->key, ""));

  conf_key_position =
    g_strdup_printf ("%s/position", self->priv->key);
  conf_key_size =
    g_strdup_printf ("%s/size", self->priv->key);

  if (gtk_window_get_resizable (GTK_WINDOW (w))) {

    size = gm_conf_get_string (conf_key_size);
    if (size)
      couple = g_strsplit (size, ",", 0);

    if (couple && couple [0])
      x = atoi (couple [0]);
    if (couple && couple [1])
      y = atoi (couple [1]);

    if (x > 0 && y > 0) {
      gtk_window_resize (GTK_WINDOW (w), x, y);
    }

    g_strfreev (couple);
    g_free (size);
  }

  position = gm_conf_get_string (conf_key_position);
  if (position)
    couple = g_strsplit (position, ",", 0);

  if (couple && couple [0])
    x = atoi (couple [0]);
  if (couple && couple [1])
    y = atoi (couple [1]);

  if (x != 0 && y != 0)
    gtk_window_move (GTK_WINDOW (w), x, y);

  g_strfreev (couple);
  couple = NULL;
  g_free (position);

  gtk_widget_realize (GTK_WIDGET (w));

  g_free (conf_key_position);
  g_free (conf_key_size);
}