~and471/slickpanel/trunk

« back to all changes in this revision

Viewing changes to panel/items/windowlist/windowbutton.vala

  • Committer: Andrew Higginson
  • Date: 2014-12-29 17:48:31 UTC
  • Revision ID: at.higginson@gmail.com-20141229174831-bukedaw8kny4aq8t
updating

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
namespace SlickPanel {
 
2
 
 
3
public class WindowButton : Gtk.EventBox {
 
4
    
 
5
    public Wnck.Window window;
 
6
    public QuickLists.QuickList? quicklist;
 
7
    public new Gtk.Label label;
 
8
    
 
9
    private WindowMenu menu;
 
10
    private new bool pressed = false;
 
11
    
 
12
    public WindowButton(Wnck.Window window) {
 
13
        set_has_tooltip(true);
 
14
        set_tooltip_window(new Tooltip());
 
15
    
 
16
        this.window = window;
 
17
        this.button_press_event.connect(this.on_button_press_event);
 
18
        this.button_release_event.connect(this.on_button_release_event);
 
19
        
 
20
        var hbox = new Gtk.HBox(false, 0);
 
21
        this.label = new Gtk.Label(window.get_name());
 
22
        var pixbuf = window.get_mini_icon();
 
23
        var image = new Gtk.Image.from_pixbuf(pixbuf);
 
24
        
 
25
        var icon_alignment = new Gtk.Alignment(0.5f, 0.5f, 1.0f, 1.0f);
 
26
        icon_alignment.set_padding(6, 6, 18, 18);
 
27
        icon_alignment.add(image);
 
28
        
 
29
        label.set_padding(6, 6);
 
30
        
 
31
        label.set_ellipsize(Pango.EllipsizeMode.END);
 
32
        label.set_alignment(0.0f, 0.5f);
 
33
        
 
34
        hbox.pack_start(icon_alignment, false, false);
 
35
        
 
36
        //hbox.pack_start(label, false, false);
 
37
        this.add(hbox);
 
38
        
 
39
        hbox.show_all();
 
40
        
 
41
                
 
42
        query_tooltip.connect((x, y, keyboard, tooltip) => {
 
43
            int window_x, window_y;
 
44
            this.get_window().get_origin(out window_x, out y);
 
45
            this.get_window().get_position(out x, out window_y);
 
46
            
 
47
            (get_tooltip_window() as Tooltip).set_label(window.get_name());
 
48
            //get_tooltip_window().move(window_x, 0);
 
49
            
 
50
            
 
51
            return true;
 
52
        });
 
53
        
 
54
        try {
 
55
            this.quicklist = new QuickLists.QuickList.from_window(window);
 
56
        } catch (QuickLists.Error e) {
 
57
            this.quicklist = null;
 
58
        }
 
59
        
 
60
        this.menu = new WindowMenu(this.window, this.quicklist);
 
61
    }
 
62
    
 
63
    private bool on_button_press_event(Gdk.EventButton event) {
 
64
        this.pressed = true;
 
65
        return false;
 
66
    }
 
67
    
 
68
    private bool on_button_release_event(Gdk.EventButton event) {
 
69
        if (this.pressed) {
 
70
            this.on_click_event(event);
 
71
        }
 
72
        this.pressed = false;
 
73
        return false;
 
74
    }
 
75
    
 
76
    private void on_click_event(Gdk.EventButton event) {
 
77
        if (Gdk.ModifierType.BUTTON1_MASK in event.state) {
 
78
            if (screen.get_active_window() == this.window) {
 
79
                this.window.minimize();
 
80
            } else {
 
81
                this.window.activate(event.time);
 
82
            }
 
83
        } else if (Gdk.ModifierType.BUTTON3_MASK in event.state) {
 
84
            this.menu.popup(null, null, null, event.button, event.time);
 
85
        }
 
86
    }
 
87
    
 
88
    private class Tooltip : Gtk.Window {
 
89
        
 
90
        private Gtk.Label label;
 
91
        
 
92
        public Tooltip() {
 
93
            set_type_hint(Gdk.WindowTypeHint.TOOLTIP);
 
94
            skip_pager_hint = true;
 
95
            skip_taskbar_hint = true;
 
96
            decorated = false;
 
97
            app_paintable = true;
 
98
            accept_focus = false;
 
99
            
 
100
            label = new Gtk.Label(null);
 
101
            add(label);   
 
102
            
 
103
            label.set_padding(12, 12);  
 
104
                    
 
105
            get_style_context().add_class("window-tooltip");
 
106
            var css = new Gtk.CssProvider();
 
107
            css.load_from_path(Paths.build({Paths.datadir, "panel.css"}));
 
108
            this.get_style_context().add_provider_for_screen(Gdk.Screen.get_default(), css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
 
109
        }
 
110
        
 
111
        public void set_label(string label) {
 
112
            this.label.set_text(label);
 
113
            this.label.show();
 
114
        }
 
115
    }
 
116
}
 
117
}