-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
WindowIcon.vala
43 lines (39 loc) · 1.6 KB
/
WindowIcon.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Copyright 2012 Tom Beckmann
* Copyright 2012 Rico Tzschichholz
* Copyright 2023 elementary, Inc. <https://elementary.io>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
/**
* Creates a new ClutterTexture with an icon for the window at the given size.
* This is recommended way to grab an icon for a window as this method will make
* sure the icon is updated if it becomes available at a later point.
*/
public class Gala.WindowIcon : Clutter.Actor {
public Meta.Window window { get; construct; }
public int icon_size { get; construct; }
public int scale { get; construct; }
/**
* Creates a new WindowIcon
*
* @param window The window for which to create the icon
* @param icon_size The size of the icon in pixels
* @param scale The desired scale of the icon
*/
public WindowIcon (Meta.Window window, int icon_size, int scale = 1) {
Object (window: window,
icon_size: icon_size,
scale: scale);
}
construct {
width = Gala.Utils.scale_to_int (icon_size, scale);
height = Gala.Utils.scale_to_int (icon_size, scale);
var pixbuf = Gala.Utils.get_icon_for_window (window, icon_size, (int)Math.round (scale));
try {
var image = new Clutter.Image ();
Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888);
image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride);
set_content (image);
} catch (Error e) {}
}
}