Started adding GObject signals to gnome-class



Dear rustaceans!

Today I finally got off my ass and started adding GObject signals to
gnome-class.  You can see my progress here:

https://github.com/federicomenaquintero/gnome-class

So far I'm just getting familiar with the way gnome-class is
constructed.  I'm able to parse stuff like

  gobject_gen! {
      class Foo {
          ...
          signal clicked(&self);
      }
  }

and generate a completely non-functional call to g_signal_newv() inside
the generated class_init().

I'm trying to define the appropriate syntax to declare signal flags;
I'll probably base it on Vala, which uses something like this:

    [Signal (action=true, detailed=true, run=true, no_recurse=true, no_hooks=true)]
    public signal void sig_1 ();

Some things which I don't know how to do yet:

* Translate Rust types into G_TYPE_FOO equivalents, so that if there is
something like

     signal bar (x: c_uint, y: &str;) -> c_uint;

we'll generate the appropriate

     g_signal_newv(...
                   G_TYPE_UINT, // return type
                   2,           // n_params
                   G_TYPE_UINT,
                   G_TYPE_STRING);

I'd like to constrain the Rust types that get accepted to those that
are mappable to G_TYPE_*.  I have no idea how to say, "I can accept
GObjects of superclass GFooClass" - i.e. where to get the appropriate
GType value.  I also have no idea of how to declare new boxed types for
GObject, e.g. if we wanted to export a plain struct for a 
GColor{r, g, b, a} or something similar.

* How to remember the signal ids that g_signal_newv() generates, and
how to emit the signals later.  Niko has a clever mechanism so that the
generated code's internals use a number of traits and structs that are
only accessible from there.  I'd probably want to generate something
like

  struct FooClassSignalIds {
      foo_signal_id: c_uint,
      bar_signal_id: c_uint,
      ...
  }

and in class_init(), fill those out like

  ids.foo_signal_id = g_signal_newv(...);
  ids.bar_signal_id = g_signal_newv(...);

Also, as a replacement for g_signal_emitv(), which is tricky to call by
hand, maybe also have an

  impl FooSignals for FooClass {
      fn emit_foo(&self, x: c_uint, y: &str) -> c_uint {
          g_signal_emitv(...);
      }
  }

Then, the user's code would simply call

  let r = self.emit_foo(42, "hello");

or something.

Does this seem sane?

My main blocking point is how to translate Rust types into G_TYPE_* so
I can call g_signal_newv() with the type declarations it needs.

I'm also open to suggestions on how to store the signal ids and how to
use them, although if that scheme of internal traits/structs works out,
it seems like it would be nice to use.

  Federico


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