Re: Decision: instant apply window buttons



Hi,

We should at least start with known-good source code before we begin
the cut-and-paste party. ;-) Here is my suggestion, please fix it up,
then we can all copy the same code, if everyone keeps the same
function name it's relatively easy to repair the mess later.

#include <gtk/gtkwindow.h>
#include <gtk/gtkbindings.h>
#include <gdk/gdkkeysyms.h>

static void
gnome_cut_and_paste_propbox_class_init (GtkWindowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkBindingSet *binding_set;
  
  g_signal_new ("close",
                G_TYPE_FROM_CLASS (klass),
                G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                0,
                NULL, NULL,
                g_cclosure_marshal_VOID__VOID,
                G_TYPE_NONE, 0);

  binding_set = gtk_binding_set_by_class (klass);

#define add_close_binding(binding_set, keyval, mask)            \
  gtk_binding_entry_add_signal (binding_set, keyval, mask,      \
                                "close", 0)

  add_close_binding (binding_set, GDK_w, GDK_CONTROL_MASK);
  add_close_binding (binding_set, GDK_q, GDK_CONTROL_MASK);
  add_close_binding (binding_set, GDK_F4, GDK_MOD1_MASK);
}

static GtkWidget*
gnome_cut_and_paste_propbox_new (void)
{
  /* This function is cut-and-pasted everywhere. If you change
   * it, you should probably let others know to change theirs
   * too. GNOME 2.2 libraries will contain a propbox widget
   * or something.
   */
  static GType type = 0;  
  GtkWindow *window;

  if (type == 0)
    {
      static const GTypeInfo type_info =
      {
        sizeof (GtkWindowClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) gnome_cut_and_paste_propbox_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (GtkWindow),
        0,              /* n_preallocs */
        (GInstanceInitFunc) NULL
      };
      
      type = g_type_register_static (GTK_TYPE_WINDOW,
                                     /* use a name that won't conflict
                                      * with actual future library
                                     feature.
                                      */
                                     "GnomeCutAndPastePropbox",
                                     &type_info,
                                     0);
    }

  window = g_object_new (type, NULL);
  
  gtk_window_set_type_hint (window,
                            GDK_WINDOW_TYPE_HINT_DIALOG);
  gtk_window_set_position (window, GTK_WIN_POS_CENTER_ON_PARENT);

  return GTK_WIDGET (window);
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]