Sunday, April 15, 2012

Gnome shell - Part 1

Geek speak alert. A lot of what you read here will be geek speak. You may experience some rolling of the eyes, sleepiness or a desire to use a spoon to scoop out your short term memory. These are all normal reactions to geek speak. You have been warned.

It's always worthwhile starting out any endeavour with a definition. I was helping someone help someone else. The kid in question, while extremely intelligent, suffers some concentration issues. We were half way through when I asked them "Have you defined the problem?". Turns out they hadn't...


What is Gnome Shell?

Up to actually seeing it and having a look at what's really going on, I thought it was simply another GUI interface. A move to make my computer look and behave like a touch screen interface (read: cellphone or tablet). I have different concerns for my desktop thus I haven't been at all enthusiastic about this whole new direction.

So here's how I would define it. Gnome shell is actually just a javascript interpreter. Don't believe me? Have a look inside /usr/share/gnome-shell/js/ui. All of those bits that I just don't like are defined in there. For example, the runDialog.js files defines internal commands - things that you can't run from the shell and are little bits of magic (i.e. you wouldn't know they were there unless you looked inside that file or read it on the Internet).

It stands that with a bit of time and working out the structure of the files in there (I would love to get rid of the overview mode for example as it doesn't really do anything for me) you should be able to replace or completely get rid of a lot of the things in there.

For now though, we can extend it with "extensions". Another creative computing term...


Getting Started

Type in at a bash prompt:

gnome-shell-extension-tool -c


This creates a folder and a few files in ~/.local/gnome-shell-extensions. Basically a HelloWorld program (for the non-programmers, the first program people write when learning to program is a "Hello World" program - basically, something that displays "Hello World" or "Hello, World").


It won't be enabled by default (at least from Gnome-shell 3.3). The easiest way to get it enabled is to use gnome-tweak-tool. I'm not sure if it's installed by default (besides which, this probably changes from distribution to distribution).


Debugging

But we'll get back to that. I'm always a little miffed that tutorials never actually start with debugging. What do you do when something goes wrong? Knowing that, you could get well ahead of any tutorial. So, here goes. I mentioned up there that runDialog defines some internal commands. To access it, hit Alt-F2. This brings up a run dialog. In there, type in "r" (without the quotes) and press enter.


This reloads gnome shell. If you're going to be making your own extension, you'll be doing this a lot. I have found that it doesn't always come up properly though I'm using a testing version of Ubuntu so it might just be that it's a case of using an unstable platform.


The other thing from the run dialog that you'll use a lot of is "lg". This stands for looking glass. I've never really used a debugger before, instead relying on console messages for my programming, so it's probably a hell of a lot more power than I think. The errors pane pretty much works as a console for me so that's all I need really.


So, in ~/.local/share/gnome-shell/extensions you'll have a folder. Go into the folder and look for the file called "extension.js". This is the code for the extension. In the function "_showHello" add a line that says:

global.log("Hello World!");


Restart gnome-shell (Alt-F2 r) and click on the little icon on the top right (probably looks like a couple of cogs). If you look at the errors pane in looking glass, you'll find a line there that says "Hello World!".

If this doesn't work, I did notice that the case changed between gnome-shell 3.3 and 3.4. So you might need to do Global.log("Hello World!"); instead.


Finding Information

I haven't been able to find a great deal of documentation but I've found that with some carefully thought out commands, I can list out most of what I need. In looking glass, in the evaluator, type in the following:

for ( var item in Main ) { global.log(item) };

This lists all of the attributes and methods for Main in the error pane. A bit of an educated guess (i.e. if it starts with get, it gets a value, set sets a value etc.) and you can figure out quite a bit. You can get more information about a particular object in there by referencing it. i.e.

for ( var item in Main.panel.actor ) { global.log(item) };


It might help to, before typing this command, to type in:

global.log("");

just to separate out the listings.

In the next gnome-shell post, I'll probably list out some of the documentation that I have found.

No comments:

Post a Comment