16
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
23
namespace Slingshot.Widgets {
25
public class AppEntry : Button {
27
public Label app_label;
31
public string exec_name;
32
public string app_name;
33
public string desktop_id;
35
public string desktop_path;
37
public signal void app_launched ();
39
private double alpha = 1.0;
40
private bool dragging = false; //prevent launching
42
private Backend.App application;
44
public AppEntry (Backend.App app) {
45
TargetEntry dnd = {"text/uri-list", 0, 0};
46
Gtk.drag_source_set (this, Gdk.ModifierType.BUTTON1_MASK, {dnd},
50
set_visual (get_screen ().get_rgba_visual());
51
set_size_request (130, 130);
52
desktop_id = app.desktop_id;
53
desktop_path = app.desktop_path;
57
tooltip_text = app.description;
59
icon_size = Slingshot.settings.icon_size;
62
get_style_context ().add_class ("app");
64
app_label = new Label (app_name);
65
app_label.halign = Align.CENTER;
66
app_label.justify = Justification.CENTER;
67
app_label.set_line_wrap (true); // Need a smarter way
68
app_label.set_single_line_mode (false);
69
app_label.set_ellipsize (Pango.EllipsizeMode.END);
71
layout = new Box (Orientation.VERTICAL, 0);
72
layout.homogeneous = false;
74
layout.pack_start (app_label, false, true, 0);
76
add (Utils.set_padding (layout, 78, 5, 5, 5));
78
this.clicked.connect (launch_app);
80
this.button_press_event.connect ((e) => {return e.button == 3;});
82
this.drag_begin.connect ( (ctx) => {
84
Gtk.drag_set_icon_pixbuf (ctx, icon, 0, 0);
86
this.drag_end.connect ( () => {
87
this.dragging = false;
89
this.drag_data_get.connect ( (ctx, sel, info, time) => {
90
sel.set_uris ({File.new_for_path (desktop_path).get_uri ()});
93
app.icon_changed.connect (queue_draw);
97
protected override bool draw (Context cr) {
101
get_allocation (out size);
106
Gdk.cairo_set_source_pixbuf (cr, icon, (icon.width - size.width) / -2.0, 10);
107
cr.paint_with_alpha (alpha);
113
public void fade_out () {
115
Timeout.add (20, () => {
130
public void fade_in () {
132
Timeout.add (20, () => {
147
public void launch_app () {
148
application.launch ();
19
public class Slingshot.Widgets.AppEntry : Gtk.Button {
21
public Gtk.Label app_label;
22
private Gdk.Pixbuf icon;
23
private Gtk.Box layout;
25
public string exec_name;
26
public string app_name;
27
public string desktop_id;
29
public string desktop_path;
31
public signal void app_launched ();
33
private double alpha = 1.0;
34
private bool dragging = false; //prevent launching
36
private Backend.App application;
38
public AppEntry (Backend.App app) {
39
Gtk.TargetEntry dnd = {"text/uri-list", 0, 0};
40
Gtk.drag_source_set (this, Gdk.ModifierType.BUTTON1_MASK, {dnd},
44
set_visual (get_screen ().get_rgba_visual());
45
set_size_request (130, 130);
46
desktop_id = app.desktop_id;
47
desktop_path = app.desktop_path;
51
tooltip_text = app.description;
53
icon_size = Slingshot.settings.icon_size;
56
get_style_context ().add_class ("app");
58
app_label = new Gtk.Label (app_name);
59
app_label.halign = Gtk.Align.CENTER;
60
app_label.justify = Gtk.Justification.CENTER;
61
app_label.set_line_wrap (true); // Need a smarter way
62
app_label.set_single_line_mode (false);
63
app_label.set_ellipsize (Pango.EllipsizeMode.END);
65
layout = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
66
layout.homogeneous = false;
68
layout.pack_start (app_label, false, true, 0);
70
add (Utils.set_padding (layout, 78, 5, 5, 5));
72
this.clicked.connect (launch_app);
74
this.button_press_event.connect ((e) => {return e.button == 3;});
76
this.drag_begin.connect ( (ctx) => {
78
Gtk.drag_set_icon_pixbuf (ctx, icon, 0, 0);
80
this.drag_end.connect ( () => {
81
this.dragging = false;
83
this.drag_data_get.connect ( (ctx, sel, info, time) => {
84
sel.set_uris ({File.new_for_path (desktop_path).get_uri ()});
87
app.icon_changed.connect (queue_draw);
91
protected override bool draw (Cairo.Context cr) {
95
get_allocation (out size);
100
Gdk.cairo_set_source_pixbuf (cr, icon, (icon.width - size.width) / -2.0, 10);
101
cr.paint_with_alpha (alpha);
107
public void fade_out () {
109
Timeout.add (20, () => {
124
public void fade_in () {
126
Timeout.add (20, () => {
141
public void launch_app () {
142
application.launch ();