Some Seed updates
April 13th, 2009
I haven’t blogged much recently, but I put a lot of work in to Seed this weekend and thought I would discuss some of the changes.
New imports system
First I should note that the design of this is pretty much lifted from gjs, and the two implementations should be compatible. I do however think, it’s a very cool system, even if a bit unorthodox.
People who have used Seed would recognize that the two primary methods of importing things are
Seed.import_namespace("Gtk")
For importing libraries and native modules and
Seed.include("bla.js")
for importing files.
This however was pretty ridden with problems, notably:
- Importing GI namespaces had no sort of cache, so multiple files including eachother can’t all import the namespaces they need, one central file would have to import them all and the others rely on that
- No search path for native modules
- The including files, was merely evaluating the file in the context which was called, which could create a lot of scope issues, in particular when you have a lot of complex interdependencies in what files need from what.
So the new imports system works like this, and remedies most of these problems. There is a toplevel imports object, which itself has a “gi” property (the imports.gi object) which handles importing libraries handled by introspection, and has a pretty simple set of semantics, notably the first attempt to access imports.gi.NameSpace will return the module object for that library, and subsequent attempts will return the same object. You can set imports.gi.versions.Namespace to a value to force GI to require that version of the library, so importing a library might now look like.
imports.gi.Versions.Clutter = "0.8";
Clutter = imports.gi.Clutter;
Gtk = imports.gi.Gtk;
The exciting part is really the handling of native modules and files, there is an imports.searchPath property which is set to an array of directories used to search for files/modules. An attempt to access imports.name will now look for “name.*” in search path, and behave as follows:
- If the found file is a native module, import it and return the module object
- If the found file is a regular file, attempt to evaluate it as a JavaScript file in a new context, and return the global object for that context. Unless the file has already been imported, then return the global object from the last import
- If the found file is a folder, return a special object which works like the “imports” object for that folder
So, importing files is now much nicer, i.e.
BrowserView = imports.browser.BrowserView
and then you could access the toplevel contents of the file “browser/BrowserView.js”, through the BrowserView object. This has a lot of advantages, notably any file that needs anything in BrowserView can do this, without having to worry about scope, or overlap with other files that might include it.
All in all I think this is a really big improvement to the maintainability of large programs, and makes it feel like there is much more of a real module system. In addition this should make it pretty possible to port GNOME Shell to Seed, and this is something I will be looking in to.
OS module
There are a lot of low level unix functions not provided by GLib, which might still be useful under Seed, and to that account I’ve taken to reimplementing a large subset of the python “os” module, attempting to preserve semantics where it makes sense, for familiarity purposes. This should be nice for increasing the scope of where Seed is useful, but it’s really boring work…which should hopefully be finished over the next week or so.
Canvas
The canvas module has a pretty large subset of canvas implemented now, and properly handles saving/restoring state. I’m hoping to implement gradients and a few other missing things within the next few days.
DBus
I am still working on DBus bindings, this is slow work, and will be done eventually
. A lot of work got done recently though, and hopefully should be ready to go in GIT soon.
New Release
After these changes, the goal is to put out a release within the next few days, as soon as someone can find time to update documentation, all the examples, etc…
On top of this there have been all the usual bugfixes, optimizations, and small features, so I definitely encourage anyone interested and using the last release to start investigating GIT. There will be a lot more reorganization of the builtin functions (on the Seed global object) over the next few days, with the goal of eliminating (or eliminating for most code) the requirement of this object, and I suppose this will break most code out there, but I think it’s definitely necessary changes for presenting a more “mature” interface in a sense.
Geerios
March 18th, 2009
I’ve been throwing around a little code inbetween personal projects lately that I use for debugging, and maybe it will be useful for a few other people also.
Essentially it’s a few functions and macros to pretty-print enums and structs based on introspection data, and then also a few convenience things to spawn REPLs to play with objects.
Examples:
GEERIOS_PRINT_ENUM (GdkEventType, event->type)
GEERIOS_PRINT_STRUCT (GdkRectangle, rect)
repl = geerios_repl_new (ctx);
geerios_repl_add_object (repl, "button", button);
// later
geerois_repl_run (repl);
// Now you have a JavaScript REPL to play with the button object, connect signals, check properties, etc...
The code’s a mess, and probably just suited to being copy pasted around…but it’s been useful for me a few times, a nd I don’t have any intention to clean it up much in the near future. So here it is
http://rpi.edu/~carrr/geerios.tar.gz
Epiphany Seed Extensions
February 8th, 2009
Epiphany Seed extensions landed today. It’s still a pretty rough/simple API, but also exciting! Thanks to chpe, and xan for doing a lot of the clean up work.
One of the neat things about this, is all the bindings around the Epiphany API, were generated automatically by GObject-introspection, which made all of this rather easy!
For those not familiar yet, Seed is a library to embed JavaScriptCore as a scripting language, and provide automatic bindings around any (almost) GObject library.
As a quick example, I thought I’d do a small write up on how to make an Epiphany Seed extension, notably something quick that pops up a dialog when you try and close more than one tab. Thanks to Tim for writing the extension.
First, a file describing the extension is required, this can go in
~/.gnome2/epiphany/extensions
[Epiphany Extension] Name=Don't Close Multiple Tabs Description=Warns the user before closing a window containing multiple open tabs. Authors=Tim Horton Version=1 URL= [Loader] Type=seed Module=close-multiple-tabs
This is all pretty straightforward I think, now when loading the extension, epiphany will look for “close-multiple-tabs.js” in the extensions directory (or a system extension directory).
The script should be a JavaScript file that returns an object containing several hook functions (attach window, detach tab, things like this). As the last thing evaluated is returned in JavaScript, the hello world extension could look like:
extension = {
attach_window: function (window){
Seed.print("Hello World!");
}
}
With window being an EphyWindow object, which has all the useful methods from the epiphany API to write extensions. So, if we were actually trying to write our extension, we might do something like this:
function delete_event(window, event) {
var n = window.get_notebook();
if(n.get_n_pages() <= 1)
return false;
// Properties can be set in constructors with JSON synax.
var dialog = new Gtk.MessageDialog({text:"You are about to close a window with " + n.get_n_pages() + " open tabs.", message_type:Gtk.MessageType.WARNING });
dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL).grab_focus();
dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK);
dialog.set_default_response(Gtk.ResponseType.CANCEL);
var result = dialog.run();
dialog.hide();
dialog.destroy();
if(result == Gtk.ResponseType.OK)
return false;
else
return true;
}
extension = {
attach_window: function(window) {
signal = window.signal.delete_event.connect(delete_event);
}
}
This extension and one more (unlimited undo of Tab close) are available at (for now) http://racarr.me/epiphany-extensions/
Obscure GNUs Error Messages, Emacs fun.
February 6th, 2009
Hopefully for the benefit of anyone else trying to make GNUS work with
emacs-snapshot, the useful and obscure (and strangely absent from
google) error message "Invalid size: gnus-carpals" means that your emacs
is too new for your GNUs.
I’ve switched to using GNUS to read my mail now, as I am not a big fan
of the GMAIL web interface, or thunderbird/evolution (though Thunderbird
3 seems promising!), this should be an…interesting experiment to say
the least, hopefully I do a better job of keeping up on my mail now.
I’ve also started organizing a TODO list of sorts with org-mode
(http://orgmode.org/index.html). any Emacs users who like me have
significant difficulty organizing their lives, might want to look in to
this, it seems really nice so far. I’m also hoping to use it for taking
notes during classes, and the embedded LaTeX + Tagging should be nice there.
Projects for the last few days.
February 3rd, 2009
In addition to my various long term and continuing projects, I’ve picked up a few new things this week…
Epiphany. Seed extensions.
After the Seed 0.3 release there was a bit of interest in developing a Seed based extension system for Epiphany WebKit, for (I think) obvious reasons. I threw together a prototype loader and fixed a few other things, and Tim helped by helping port extensions (So far we have an Undo tab close extension, and a confirm closing of multiple tabs extension).
The early results are at:
git clone http://hortont.com/epiphany/.git
The interface could still use a bit of work, and in the repository is a patch to gir-repository to build a gir for the Epiphany functions, however this not crashing requires a patch to introspection which I’m still working on upstreaming (also in the git tree if anyone is desperate to try it. gir.patch and gi.patch).
Will put some more work in to this later in the week.
Clutter 0.9 Fun. Tetris and Same.
Tim and I are working on a project making…gratuitous use of Clutter, and so stemming from a desire to both learn the new 0.9 API, and write some Seed examples for it, so we wrote a few small games as examples last night.
Same Gnome Clone – In Seed! from Tim Horton on Vimeo.
Tetris from Robert Carr on Vimeo.
The funny part about the Tetris game is it’s actually built in Seed around a libtetris written in Vala, the client itself is only about 120 lines of Seed script. The new Clutter implicit animation API made it easy to write.
Both of these are in Seed SVN in examples/, but either working on anyone else’s machine is dependent on a Clutter patch which I’ll post to Clutter bugzilla later today. In the meantime check out the videos. Clutter is fun
Magic
After seeing the “Do-ifying” GTK post, I decided to make a GTK module (which I am calling “Magic”) that exposes the GTKUImanager hierarchies for an application over DBus. This has been interesting to work on as I’ve been using eggdbus which has in general been a pretty good experience.
I got a basic outline working (list actions, activate action by group/name), but I want to work on the interface a bit more before I post anything.
Hopefully with some extra application tracking, this could allow you to use Do to interact with your current application (with actions like “Save as”, “New tab”, or maybe your five most recent documents names, all being available as Do actions depending on your context).
I’ve been warned that I may be creating AppleScript for GTK. Oops?
GPU Life
January 26th, 2009
After a night of extreme boredom I present…GPU Life! A faast implementation of Conway’s Game of Life

It runs on the GPU as a fragment shader, and is fully capable of running at 60FPS, with 1.6 million cells using only 5% CPU on my (1.5 year old) laptop. Screensaver potential at 25 fps or so? if anyone wants to try it, you will probably have to change the WIDTH/HEIGHT defines in main.c, and in life.glsl.
Repository at
http://hortont.com/repo/life
Some mixed code and concepts from GPUlife for OSX and some various shaders around the internets.
Scrolling!
January 22nd, 2009
I posted this before, but wanted to repost it to planet. (Hi planet). I never have gotten the patches finished, because I ran in to a few problems with GDK XInput stuff, that I don’t entirely understand…however it’s something I’m going to revisit in February.
“So it hit me that I’m always complaining about look and feel, and various usability issues, but actually spend most of my time writing silly window managers, and increasingly obscure bits of JavaScript (Hey, if you ever want to write an asynchronous, GLib main loop integrated network server in JavaScript, I’ve got you covered now).
So without further ado I present:
Bad scroll:
Bad scrolling from Robert Carr on Vimeo.
Good Scroll:
Awesome scrolling from Robert Carr on Vimeo.
It’s worth noting that this isn’t like the firefox “smooth scrolling” where in fact scrolling is still in discrete steps of dozens of pixels, you can actually scroll by a pixel at a time here. Right now the code is in a somewhat adhorent state, but I’ll have it cleaned up within the next few days and post the xf86-input-synaptics patches, and the assosciated GTK patches.”
GTK+
December 23rd, 2008
I currently have 4 local branches of GTK.
Goal for the week: Get at least one on Bugzilla.
Look and Feel
December 18th, 2008
So it hit me that I’m always complaining about look and feel, and various usability issues, but actually spend most of my time writing silly window managers, and increasingly obscure bits of JavaScript (Hey, if you ever want to write an asynchronous, GLib main loop integrated network server in JavaScript, I’ve got you covered now).
So without further ado I present:
Bad scroll:
Bad scrolling from Robert Carr on Vimeo.
Good Scroll:
Awesome scrolling from Robert Carr on Vimeo.
It’s worth noting that this isn’t like the firefox “smooth scrolling” where in fact scrolling is still in discrete steps of dozens of pixels, you can actually scroll by a pixel at a time here. Right now the code is in a somewhat adhorent state, but I’ll have it cleaned up within the next few days and post the xf86-input-synaptics patches, and the assosciated GTK patches.
