~gala-dev/gala/windowswitcher-fade-opacity

« back to all changes in this revision

Viewing changes to plugins/template/Main.vala

  • Committer: RabbitBot
  • Author(s): Tom Beckmann, Rico Tzschichholz, Cody Garver
  • Date: 2014-04-06 18:30:23 UTC
  • mfrom: (368.1.21 plugins)
  • Revision ID: rabbitbot-20140406183023-0v1juolllz5u2fht
Add plugin support, move zoom functionality into a plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  
 
2
//  Copyright (C) 2014 Tom Beckmann
 
3
// 
 
4
//  This program is free software: you can redistribute it and/or modify
 
5
//  it under the terms of the GNU General Public License as published by
 
6
//  the Free Software Foundation, either version 3 of the License, or
 
7
//  (at your option) any later version.
 
8
// 
 
9
//  This program is distributed in the hope that it will be useful,
 
10
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
//  GNU General Public License for more details.
 
13
// 
 
14
//  You should have received a copy of the GNU General Public License
 
15
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
// 
 
17
 
 
18
/*
 
19
  This is a template class showing some of the things that can be done
 
20
  with a gala plugin and how to do them.
 
21
*/
 
22
 
 
23
namespace Gala.Plugins.Template
 
24
{
 
25
        public class Main : Gala.Plugin
 
26
        {
 
27
                const int PADDING = 50;
 
28
 
 
29
                Gala.WindowManager? wm = null;
 
30
                Clutter.Actor red_box;
 
31
 
 
32
                // This function is called as soon as Gala has started and gives you
 
33
                // an instance of the GalaWindowManager class.
 
34
                public override void initialize (Gala.WindowManager wm)
 
35
                {
 
36
                        // we will save the instance to our wm property so we can use it later again
 
37
                        // especially helpful when you have larger plugins with more functions,
 
38
                        // we won't need it here
 
39
                        this.wm = wm;
 
40
 
 
41
                        // for demonstration purposes we'll add a red quad to the stage which will
 
42
                        // turn green when clicked
 
43
                        red_box = new Clutter.Actor ();
 
44
                        red_box.set_size (100, 100);
 
45
                        red_box.background_color = { 255, 0, 0, 255 };
 
46
                        red_box.reactive = true;
 
47
                        red_box.button_press_event.connect (turn_green);
 
48
 
 
49
                        // we want to place it in the lower right of the primary monitor with a bit
 
50
                        // of padding. refer to vapi/libmutter.vapi in gala's source for something
 
51
                        // remotely similar to a documentation
 
52
                        var screen = wm.get_screen ();
 
53
                        var rect = screen.get_monitor_geometry (screen.get_primary_monitor ());
 
54
 
 
55
                        red_box.x = rect.x + rect.width - red_box.width - PADDING;
 
56
                        red_box.y = rect.y + rect.height - red_box.height - PADDING;
 
57
 
 
58
                        // to order Gala to deliver mouse events to our box instead of the underlying
 
59
                        // windows, we need to mark the region where the quad is located.
 
60
                        // The plugin class offers an utility function for this purpose, the track_actor
 
61
                        // function. It will update the region with the allocation of the actor
 
62
                        // whenever its allocation changes. Make sure to set freeze_track to 
 
63
                        // true while animating the actor to not make gala update the region
 
64
                        // every single frame.
 
65
                        // You can also handle the region manually by setting the custom_region
 
66
                        // property. The tracked actors and custom regions will be merged by
 
67
                        // the plugin.
 
68
                        track_actor (red_box);
 
69
 
 
70
                        // now we'll add our box into the ui_group. This is where all the shell
 
71
                        // elements and also the windows and backgrouds are located.
 
72
                        wm.ui_group.add_child (red_box);
 
73
                }
 
74
 
 
75
                bool turn_green (Clutter.ButtonEvent event)
 
76
                {
 
77
                        red_box.background_color = { 0, 255, 0, 255 };
 
78
                        return true;
 
79
                }
 
80
 
 
81
                // This function is actually not even called by Gala at the moment,
 
82
                // still it might be a good idea to implement it anyway to make sure
 
83
                // your plugin is compatible in case we'd add disabling specific plugins
 
84
                // in the future
 
85
                public override void destroy ()
 
86
                {
 
87
                        // here you would destroy actors you added to the stage or remove
 
88
                        // keybindings
 
89
 
 
90
                        red_box.destroy ();
 
91
                }
 
92
        }
 
93
}
 
94
 
 
95
// this little function just tells Gala which class of those you may have in
 
96
// your plugin is the one you want to start with and delivers some additional
 
97
// details about your plugin. It also gives you the option to choose a specific
 
98
// function which your plugin fulfils. Gala will then make sure that there is
 
99
// no duplicate functionality.
 
100
public Gala.PluginInfo register_plugin ()
 
101
{
 
102
        return {
 
103
                "template-plugin",                    // the plugin's name
 
104
                "Tom Beckmann <tomjonabc@gmail.com>", // you, the author
 
105
                typeof (Gala.Plugins.Template.Main),  // the type of your plugin class
 
106
 
 
107
                Gala.PluginFunction.ADDITION,         // the function which your plugin
 
108
                                                      // fulfils, ADDITION means nothing 
 
109
                                                      // specific
 
110
 
 
111
                Gala.LoadPriority.IMMEDIATE           // indicates whether your plugin's
 
112
                                                      // start can be delayed until gala
 
113
                                                      // has loaded the important stuff or
 
114
                                                      // if you want your plugin to start
 
115
                                                      // right away. False means wait.
 
116
        };
 
117
}
 
118