~rakete/eidete/no-duration-fix

« back to all changes in this revision

Viewing changes to src/Widgets/keyview.vala

  • Committer: Tom Beckmann
  • Date: 2012-04-04 00:02:38 UTC
  • Revision ID: tombeckmann@online.de-20120404000238-sh18kb190cyyz0ma
Added mouse click display, background circle for mouse options

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
 
5
5
namespace Eidete.Widgets {
6
 
        
7
 
        public class Key : Label {
8
 
                
9
 
                public string key;
10
 
                public bool ctrl;
11
 
                public bool shift;
12
 
                public bool alt;
13
 
                public bool super;
14
 
                public bool iso_level3_shift;
15
 
                public int count;
16
 
                
17
 
                public Key (string key, bool ctrl, bool shift, bool alt, bool super, bool iso_level3_shift){
18
 
                        this.key = key;
19
 
                        this.ctrl = ctrl;
20
 
                        this.shift = shift;
21
 
                        this.alt = alt;
22
 
                        this.super = super;
23
 
                        this.iso_level3_shift = iso_level3_shift;
24
 
                        this.count = 1;
25
 
                }
26
 
        }
27
 
        
28
 
        
29
 
        public class KeyView : Granite.Widgets.CompositedWindow{
30
 
                
 
6
    
 
7
    public class YellowCircle : Granite.Widgets.CompositedWindow {
 
8
        
 
9
        public YellowCircle (Gdk.RGBA color) {
 
10
            this.skip_pager_hint = true;
 
11
            this.skip_taskbar_hint = true;
 
12
            this.set_keep_above (true);
 
13
            this.stick ();
 
14
            this.type_hint = Gdk.WindowTypeHint.SPLASHSCREEN;
 
15
            this.accept_focus = false;
 
16
            
 
17
            this.draw.connect ( (ctx) => {
 
18
                ctx.arc (this.get_allocated_width () / 2, this.get_allocated_height () / 2, 
 
19
                         this.get_allocated_width () / 2, 0, 6.28318);
 
20
                ctx.set_source_rgba (color.red, color.green, color.blue, color.alpha);
 
21
                ctx.fill ();
 
22
                return false;
 
23
            });
 
24
            
 
25
            this.set_size_request (70, 70);
 
26
            this.realize ();
 
27
            this.get_window ().input_shape_combine_region (new Cairo.Region.rectangle ({0, 0, 1, 1}), 0, 0);
 
28
            this.show_all ();
 
29
        }
 
30
        
 
31
        public new void move (int x, int y) {
 
32
            base.move (x - (int)(this.get_allocated_width ()/2), y - (int)(this.get_allocated_height ()/2));
 
33
        }
 
34
    }
 
35
    
 
36
    public class ClickWindow : Granite.Widgets.CompositedWindow {
 
37
        public ClickWindow (int x, int y, int button) {
 
38
            this.skip_pager_hint = true;
 
39
            this.skip_taskbar_hint = true;
 
40
            this.set_keep_above (true);
 
41
            this.stick ();
 
42
            this.type_hint = Gdk.WindowTypeHint.SPLASHSCREEN;
 
43
            this.accept_focus = false;
 
44
            
 
45
            string label = "";
 
46
            switch (button) {
 
47
                case 1:
 
48
                    label = "Left";
 
49
                    break;
 
50
                case 2:
 
51
                    label = "Middle";
 
52
                    break;
 
53
                case 3:
 
54
                    label = "Right";
 
55
                    break;
 
56
                default:
 
57
                    break;
 
58
            }
 
59
            var lbl = new Gtk.Label (label);
 
60
            lbl.attributes = new Pango.AttrList ();
 
61
            lbl.attributes.insert (new Pango.AttrFontDesc (Pango.FontDescription.from_string ("16px")));
 
62
            this.add (lbl);
 
63
            var css = new Gtk.CssProvider ();
 
64
            try {
 
65
                css.load_from_data ("*{color:#fff; text-shadow:1 1 #000;}", -1);
 
66
            } catch (Error e) { warning (e.message); }
 
67
            lbl.get_style_context ().add_provider (css, 20000);
 
68
            
 
69
            this.realize ();
 
70
            this.get_window ().input_shape_combine_region (new Cairo.Region.rectangle ({0, 0, 1, 1}), 0, 0);
 
71
            this.show_all ();
 
72
            this.move (x + 5, y + 5);
 
73
            
 
74
            Timeout.add (10, () => {
 
75
                this.opacity -= 0.007;
 
76
                if (this.opacity < 0.1) //prevent flickering
 
77
                    this.foreach ( (c) => this.remove (c) );
 
78
                if (this.opacity <= 0) {
 
79
                    this.destroy ();
 
80
                    return false;
 
81
                }
 
82
                return true;
 
83
            });
 
84
        }
 
85
    }
 
86
    
 
87
    
 
88
    public class Key : Label {
 
89
        
 
90
        public string key;
 
91
        public bool ctrl;
 
92
        public bool shift;
 
93
        public bool alt;
 
94
        public bool super;
 
95
        public bool iso_level3_shift;
 
96
        public int count;
 
97
        
 
98
        public Key (string key, bool ctrl, bool shift, bool alt, bool super, bool iso_level3_shift){
 
99
            this.key = key;
 
100
            this.ctrl = ctrl;
 
101
            this.shift = shift;
 
102
            this.alt = alt;
 
103
            this.super = super;
 
104
            this.iso_level3_shift = iso_level3_shift;
 
105
            this.count = 1;
 
106
        }
 
107
    }
 
108
    
 
109
    
 
110
    public class KeyView : Granite.Widgets.CompositedWindow {
 
111
        
31
112
                public int key_size;
32
113
                public int fade_duration;
33
114
                
43
124
                
44
125
                public Queue<Key> keys;
45
126
                
 
127
                public YellowCircle circle;
 
128
                
46
129
                public Cairo.ImageSurface key_bg;
47
130
                
48
131
                [CCode (cname = "intercept_key_thread")]
49
132
                public extern void *intercept_key_thread ();
50
133
                
51
134
                public signal void captured (string keyvalue, bool released);
52
 
                
 
135
                public signal void captured_mouse (int x, int y, int button);
 
136
                public signal void captured_move (int x, int y);
53
137
                
54
138
                public override bool draw (Cairo.Context ctx){
55
139
                        
110
194
                        this.screen_h = h;
111
195
                }
112
196
                
113
 
                public KeyView (){
 
197
                public KeyView (bool keyboard, bool mouse, bool mouse_circle, Gdk.RGBA mouse_circle_color){
114
198
                        this.key_size = 75;
115
199
                        this.fade_duration = 2000;
116
 
 
 
200
            
117
201
                        this.stick ();
118
202
                        this.set_keep_above (true);
119
203
                        this.deletable = false;
120
204
                        this.resizable = false;
121
205
                        this.set_has_resize_grip (false);
122
206
                        this.skip_pager_hint = true;
123
 
                        this.skip_taskbar_hint = true;
124
 
 
125
 
                        this.type_hint = Gdk.WindowTypeHint.SPLASHSCREEN;
126
 
                        this.events = Gdk.EventMask.BUTTON_MOTION_MASK | Gdk.EventMask.BUTTON1_MOTION_MASK | 
127
 
                            Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK ;
128
 
 
129
 
                        this.realize();
 
207
            this.skip_taskbar_hint = true;
 
208
            this.accept_focus = false;
 
209
            
 
210
            this.type_hint = Gdk.WindowTypeHint.SPLASHSCREEN;
 
211
            this.events = Gdk.EventMask.BUTTON_MOTION_MASK | Gdk.EventMask.BUTTON1_MOTION_MASK | 
 
212
                Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK ;
 
213
            
 
214
                        this.realize ();
130
215
                        
131
216
                        Cairo.RectangleInt rect = {0, 0, 1, 1};
132
217
                        this.get_window ().input_shape_combine_region (new Cairo.Region.rectangle (rect), 0, 0);
155
240
                                return true;
156
241
                        });
157
242
                        
 
243
                        if (mouse_circle) {
 
244
                            this.circle = new YellowCircle (mouse_circle_color);
 
245
                        this.captured_move.connect ( (x, y) => {
 
246
                            this.circle.move (x, y);
 
247
                            //debug ("Moved to %i, %i\n", x, y);
 
248
                        });
 
249
                    }
 
250
                        
 
251
                        if (mouse)
 
252
                        this.captured_mouse.connect ( (x, y, button) => {
 
253
                            debug ("Button %i pressed at %i, %i ", button, x, y);
 
254
                    if (button <= 3)
 
255
                        Timeout.add (10, () => { new ClickWindow (x, y, button); return false; });
 
256
                        });
 
257
                        
 
258
                        if (keyboard)
158
259
                        this.captured.connect ( (keyvalue, released) => {
159
260
                                if (released){
160
261
                                        switch (keyvalue){