forked from icedman/anino-dock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
124 lines (108 loc) · 2.95 KB
/
background.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const { St, Shell, GObject, Gio, GLib, Gtk, Meta, Clutter } = imports.gi;
const Main = imports.ui.main;
const Dash = imports.ui.dash.Dash;
const Point = imports.gi.Graphene.Point;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const DrawOverlay = Me.imports.apps.overlay.DrawOverlay;
const Drawing = Me.imports.drawing.Drawing;
function drawBackground(ctx) {
let w = 2;
// Drawing.draw_rect(
// ctx,
// [1, 0, 0, 1],
// w,
// w,
// this.width - w * 3,
// this.height - w * 3,
// w
// );
// Drawing.draw_rounded_rect(
// ctx,
// [1, 0, 0, 0],
// w,
// w,
// this.width - w * 3,
// this.height - w * 3,
// 2,
// 16
// )
}
var DockBackground = GObject.registerClass(
{},
class AninoDockBackground extends St.Widget {
_init(params) {
super._init({
name: 'DockBackground',
...(params || {}),
});
this.drawOverlay = new DrawOverlay(20, 20);
this.drawOverlay.onDraw = drawBackground.bind(this.drawOverlay);
this.add_child(this.drawOverlay);
}
update(params) {
let {
first,
last,
padding,
iconSize,
scaleFactor,
vertical,
position,
panel_mode,
dashContainer,
} = params;
let p1 = first.get_transformed_position();
let p2 = last.get_transformed_position();
if (!isNaN(p1[0]) && !isNaN(p1[1])) {
// bottom
this.x = p1[0] - padding;
this.y = first._fixedPosition[1] - padding; // p1[1] - padding
if (p2[1] > p1[1]) {
this.y = p2[1] - padding;
}
let width =
p2[0] -
p1[0] +
iconSize * scaleFactor * last._targetScale +
padding * 2;
let height = iconSize * scaleFactor + padding * 2;
if (!isNaN(width)) {
this.width = width;
}
if (!isNaN(width)) {
this.height = height;
}
// vertical
if (vertical) {
this.x = p1[0] - padding;
this.y = first._fixedPosition[1] - padding; // p1[1] - padding
if (position == 'right' && p2[0] > p1[0]) {
this.x = p2[0] - padding;
}
if (position == 'left' && p2[0] < p1[0]) {
this.x = p2[0] - padding;
}
this.width = iconSize * scaleFactor + padding * 2;
this.height =
p2[1] -
p1[1] +
iconSize * scaleFactor * last._targetScale +
padding * 2;
// log(`${width} ${height}`);
}
if (panel_mode) {
if (vertical) {
this.y = dashContainer.y;
this.height = dashContainer.height;
} else {
this.x = dashContainer.x;
this.width = dashContainer.width;
}
}
this.drawOverlay.resize(this.width, this.height);
this.drawOverlay.opacity = 100;
}
}
}
);