~codygarver/+junk/remove-gala-using-statements

« back to all changes in this revision

Viewing changes to plugins/template/README

  • Committer: Cody Garver
  • Date: 2014-04-20 04:50:03 UTC
  • mfrom: (364.1.13 gala)
  • Revision ID: cody@elementaryos.org-20140420045003-30f1augwn8vqq5jx
Merge in trunk and revert files with conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
Note for compilition
 
3
--------------------
 
4
If you want your own plugin within this source tree
 
5
don't forget to add the new subdirectory to the plugins' Makefile.am
 
6
SUBDIRS list and add your Makefile to the list of Makefiles found at
 
7
about the end of the configure.ac file AC_CONFIG_FILES.
 
8
The API is currently internal until the API is finalized, so you have
 
9
to build it in this source tree.
 
10
 
 
11
Some more useful notes on developing plugins:
 
12
 
 
13
Modal Mode
 
14
----------
 
15
If you want to display large elements that can be toggled instead of small overlays,
 
16
you can use wm.begin_modal() to make Gala enter modal mode. In this mode, you'll be
 
17
able to receive key events and all mouse events will be delivered regardless of the
 
18
region you have set. Don't forget to call wm.end_modal() and provide an obvious way
 
19
to exit modal mode for the user, otherwise he will be stuck and can only restart
 
20
Gala.
 
21
 
 
22
Keybindings
 
23
-----------
 
24
To add keybindings, you'll need a gsettings schema. You can take a look at Gala's
 
25
schema in data/org.pantheon.desktop.gschema.xml for an example. You'll also find
 
26
how to correctly declare shortcut keys in that file. Once you got this file ready
 
27
it's pretty easy. Just enable its installation in cmake, the relevant is commented
 
28
out in this template, and call wm.get_screen().get_display().add_keybinding().
 
29
The keybinding function takes the name of the shortcut key in your 
 
30
schema, then a GSettings instance for that schema, which can be obtained with
 
31
'new GLib.Settings("org.pantheon.gala.plugins.my-plugin")', then some flags, for
 
32
which you can almost always use 0, refer to the vapi for more details, and finally
 
33
your function as arguments. Its delegate is:
 
34
 
 
35
public delegate void KeyHandlerFunc (Meta.Display display, Meta.Screen screen,
 
36
        Meta.Window? window, X.Event event, Meta.KeyBinding binding);
 
37
 
 
38
So it'd be something like
 
39
 
 
40
void initialize (Gala.WindowManager wm)
 
41
{
 
42
        [...]
 
43
        var display = wm.get_screen ().get_display ();
 
44
        var schema = new GLib.Settings ("org.pantheon.desktop.gala.plugins");
 
45
        display.add_keybinding ("my-shortcut", schema, 0, my_handler);
 
46
        [...]
 
47
}
 
48
void my_handler (Meta.Display display, Meta.Screen screen, Meta.Window? window,
 
49
        X.Event event, Meta.KeyBinding binding)
 
50
{
 
51
        print ("Shortcut hit! D:");
 
52
}
 
53
void destroy ()
 
54
{
 
55
        wm.get_screen ().get_display ().remove_keybinding ("my-shortcut");
 
56
}
 
57
 
 
58
Overriding default keybindings
 
59
------------------------------
 
60
Libmutter allows you to override exisiting shortcuts, which is a lot easier than
 
61
adding new ones. All you have to do is:
 
62
 
 
63
Keybinding.set_custom_handler ("shortcut-name", my_handler);
 
64
 
 
65
The signature for my_handler is the same as above.
 
66
 
 
67
More info
 
68
---------
 
69
A great source for exploring the possibilities of mutter's API is scrolling through
 
70
the mentioned mutter vapi. In some cases you can find documentation on particular
 
71
functions in the mutter source code. Just grep for their C names.
 
72
 
 
73
*/