OpenSource For You

Try Your Hand at GNOME Shell Extensions

One of the most popular features of GNOME is that it enables users to build extensions for their shell to increase its basic functional­ity. You can think of these extensions as add-ons to the GNOME shell. Here’s more on developing GNOME shell extensions.

-

One of the many choices available to a Linux user is that of the desktop environmen­t. Among the many available, GNOME stands out as one of the most prominent. The GNOME shell has a very user friendly interface, which makes it popular amongst users.

)LUsW WhLnJs fiUsW. GN2M( HxWHnsLRns DUH wULWWHn Ln gavascript. This is actually Mozilla's special version of gavascript, which is based on Spidermonk­ey and is widely known as GgS. A working knowledge of regular gavascript is enough to begin extension developmen­t.

Let us have a look at what the components of a GNOME extension are. Metadata.json: ThLs fiOH FRnWDLns GDWD DERuW WhH extension— details like the extension name, descriptio­n, LGHnWLfiHU DnG FRmSDWLELO­LWy LniRUmDWLR­n (whLFh YHUsLRns of the GNOME shell are compatible with the extension). Extension.js: ThLs Ls WhH GN2M(--DYDsFULSW(G-S) fiOH, which will store the logic that controls the extension. This fiOH musW FRnWDLn WhH iROORwLnJ WhUHH iunFWLRns. • Init (metadata) – This is called to initialise the extension. The metadata argument is the data stored in the metadata.json fiOH, DORnJ wLWh sRmH DGGLWLRnDO details like the absolute path to your extension. enable – This is called when the extension is enabled. This function stores the actions to be performed when the extension is enabled, and this generally is the function in which the logic for extensions is placed. disable – This is called when the extension is disabled. It generally contains code, related to clean up activities, which stops whatever actions the extensions perform and restores the system to a state such as when the extension was never there. There is also an optional stylesheet. css file, which is used to style various attributes of the extension, like buttons or displays.

Creating an extension

:hHn yRu wULWH yRuU HxWHnsLRn, WhH fiOHs UHODWHG WR WhH extension should be placed in the ~/.local/share/gnome-shell/ extensions directory. In the same directory, you will be able to see various other extensions that exist on your system, and it may be a good idea to look at some of them to get a better understand­ing of how they work. You will also see that the already existing extensions will have the above mentioned fiOHs ( extension.js, stylesheet.css, metadata.json) .

Now, let us start building our extension. Although it is not mandatory (you can write the extension from scratch),

gnome-shell-extension-tool --create-extension

When you run the above command, you will be prompted to enter the following metadata. Name – Name of the extension. Descriptio­n – Descriptio­n of the extension. UUID – ThLs Ls D unLTuH LGHnWLfiHU iRU WhH HxWHnsLRn. ,W should be in an email address format, like foo@bar.com. In general, as long as the UUID can be used to create a subdirecto­ry, it will be regarded as a valid UUID. Now, you will be told that your extension has been created and the path to it will also be displayed. You are free to make the required changes to your extension. Next, activate the extension by using the GNOME tweak-tool (if you have not already installed it, you can download and install it from your distro's software manager). Under the tweak tool, go to shell extensions and turn on your extension there. If you cannot see it, restart your GNOME shell (Alt + F2 and type 'r', and then press ‘Enter’) to force load all the extensions.

You will see a new icon in the GNOME tray (top right corner of your screen) in the shape of gears. If you click on it, your extension will display ‘Hello world’.

This is the default extension, created by the GNOME shell HxWHnsLRn WRRO. :H musW mRGLiy WhH fiOHs ORFDWHG Ln ~/.local/ share/gnome-shell/extensions, in the folder with the same name as the UUID you entered earlier.

Understand­ing the code

Let’s look at the code that the GNOME shell extension-tool FUHDWHG, Ey fiUsW HxDmLnLnJ WhH extension.js fiOH: GNOME 3 has a bash command that helps create new extensions. Let’s use the following command to create a draft of our extension:

 ??  ??

Newspapers in English

Newspapers from India