Re: Gtk2::Gdk::Atom questions
- From: René Seindal <rene seindal dk>
- To: muppet <scott asofyet org>
- Cc: gtk-perl-list gnome org
- Subject: Re: Gtk2::Gdk::Atom questions
- Date: Fri, 6 Jun 2003 22:32:13 +0200
On Fri, Jun 06, 2003 at 02:19:17PM -0400, muppet wrote:
René Seindal said:
I'm rather blank when it comes to XS code, but I an see the basic type is
defined, but there are no methods.
I stumbled over this when working with dnd callbacks where there are several
possible types of data in play. The types are given by Atoms, but I cannot
even compare two to see if they are the same.
hmm. you aren't good at XS, but you know how to use Atoms.
i can churn out XS like nobody's business, but i know anothing about using Atoms.
:-)
if you'll tell me what's expected of the interface and give me some example
code to port and make work, i think we can get what you want and need. that
goes for anybody who wants to chime in.
You create an atom with:
GdkAtom gdk_atom_intern (const gchar *atom_name,
gboolean only_if_exists);
which could be mapped like
$atom = intern Gtk2::Gdk::Atom($name, $only_if_exists);
or
$atom = intern Gtk2::Gdk::Atom($name); # $only_if_exists=0
The usual terminology is intern(), but maybe there should be a new()
alias to maintain that convention. I'd prefer writing "new
Gtk2::Gdk::Atom($name)".
If you have a GdkAtom, you use
gchar *gdk_atom_name (GdkAtom atom);
to get the name. If the Gtk2::Gdk::Atom can be made as a real blessed
object, then it could be mapped as
$name = $atom->name;
An X11 atom is simply a numeric id. In Gtk2 an GdkAtom is an integer
X11 atom id cast to a pointer, using
GdkAtom atom = GDK_ATOM_TO_POINTER(numeric_atom);
The definition is:
#define GDK_ATOM_TO_POINTER(atom) (atom)
The reverse is
guint numeric_atom = GDK_POINTER_TO_ATOM(atom);
The definition is
#define GDK_POINTER_TO_ATOM(ptr) ((GdkAtom)(ptr))
If possible I think Gtk2::Gdk::Atom should have an id() method that
returns that number, since it is perfect for comparisons.
There is a number of predefined GdkAtom made with a macro
#define _GDK_MAKE_ATOM(val) ((GdkAtom)GUINT_TO_POINTER(val))
#define GDK_NONE _GDK_MAKE_ATOM (0)
...
#define GDK_SELECTION_TYPE_STRING _GDK_MAKE_ATOM (31)
I don't know if it is worth it reproducing that in gtk2-perl-xs, since
you can simply do
$type_string_atom = new Gtk2::Gdk::Atom('STRING');
though the Gdk way saves a round-trip to the X server. The numbers are
well-defined by X11. On my system the list is in
/usr/X11R6/include/X11/Xatom.h, but not all are equally interesting.
The documentation for the above is at
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Properties-and-Atoms.html
and
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Selections.html
(including predefined atoms)
Here is a small example using atoms in gtk-perl 0.78, though I think
this interface is a bit clumsier. I like the OO approach better, but I
don't know if it is possible given the way Gdk implements the GtkAtom as
an integer cast to a pointer.
Gtk-perl seems to implement the atom as a scalar with an integer value,
thus ruling out the OO approach. Gtk2-perl-xs already has the atom as a
blessed reference where the value of the reference is the numeric atom
id.
Anyway, you're the expert and you decide.
Gtk 1.2 perl code:
========================================================================
use Gtk;
init Gtk;
use Data::Dumper;
my $a = intern Gtk::Gdk::Atom('STRING');
print "Atom a is ", Gtk::Gdk::Atom->name($a), "\n";
my $b = Gtk::Gdk::Atom->intern('New Atom to be created');
print "Atom a is ", Gtk::Gdk::Atom->name($b), "\n";
print Dumper($a, $b);
========================================================================
Afterwards you can run xlsatoms(1) to verify that there is a new atom
with the name 'New Atom to be created' at the end of the list.
I hope this explains it.
--
René Seindal (rene seindal dk) http://sights.seindal.dk/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]