Skip to content

Commit f0dfd1d

Browse files
committed
refactor: Made some refactoring
chore: Improve focus window update
1 parent 8f882c3 commit f0dfd1d

File tree

1 file changed

+53
-36
lines changed

1 file changed

+53
-36
lines changed

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -117,39 +117,43 @@ class SimpleButton extends WorkspaceButton {
117117

118118

119119
class WindowGraph {
120-
constructor(workspaceGraph, metaWindow, showIcons, iconSize) {
120+
constructor(metaWindow, workspaceGraph, showIcon, iconSize) {
121121
this.workspaceGraph = workspaceGraph;
122122
this.metaWindow = metaWindow;
123-
this._showIcons = showIcons;
124-
this._iconSize = iconSize;
123+
this.showIcon = showIcon;
124+
this.iconSize = iconSize;
125125

126126
this.drawingArea = new St.DrawingArea({
127127
style_class: 'windows',
128-
important: true,
129128
width: this.workspaceGraph.width,
130129
height: this.workspaceGraph.height,
130+
important: true,
131131
});
132132

133133
this.drawingArea.connect('repaint', this.onRepaint.bind(this));
134134

135-
if (this._showIcons) {
136-
this.icon = this._getIcon();
137-
const [x, y] = this.iconPos();
135+
if (this.showIcon) {
136+
const [x, y] = this.calcIconPos();
137+
this.icon = this.getIcon();
138138
this.icon.set_x(x);
139139
this.icon.set_y(y);
140140
}
141141
}
142142

143-
iconPos(rect = undefined) {
144-
if (!rect) rect = this.intersectionRect();
145-
const x = Math.round(rect.x + rect.width / 2 - this._iconSize * global.ui_scale / 2);
146-
const y = Math.round(rect.y + rect.height / 2 - this._iconSize * global.ui_scale / 2);
143+
calcIconPos(rect = undefined) {
144+
if (!rect) {
145+
rect = this.intersectionRect();
146+
}
147+
148+
const x = Math.round(rect.x + rect.width / 2 - this.iconSize * global.ui_scale / 2);
149+
const y = Math.round(rect.y + rect.height / 2 - this.iconSize * global.ui_scale / 2);
150+
147151
return [x, y];
148152
}
149153

150154
intersectionRect() {
151-
// Intersection between the scaled window rect and the boundaries
152-
// of the workspace graph.
155+
// Intersection between the scaled window rect area and the
156+
// workspace graph area.
153157
const intersection = new Meta.Rectangle();
154158
const rect = this.scaledRect();
155159

@@ -186,39 +190,45 @@ class WindowGraph {
186190
}
187191

188192
onRepaint(area) {
189-
let windowBackgroundColor, windowBorderColor;
190-
193+
const [winBackgroundColor, winBorderColor] = this.getWinThemeColors();
191194
const rect = this.intersectionRect();
192-
const graphThemeNode = this.workspaceGraph.graphArea.get_theme_node();
193-
194-
if (this.metaWindow.has_focus()) {
195-
windowBorderColor = graphThemeNode.get_color('-active-window-border');
196-
windowBackgroundColor = graphThemeNode.get_color('-active-window-background');
197-
} else {
198-
windowBorderColor = graphThemeNode.get_color('-inactive-window-border');
199-
windowBackgroundColor = graphThemeNode.get_color('-inactive-window-background');
200-
}
201-
202195
const cr = area.get_context();
196+
203197
cr.setLineWidth(1);
204198

205-
Clutter.cairo_set_source_color(cr, windowBorderColor);
199+
Clutter.cairo_set_source_color(cr, winBorderColor);
206200
cr.rectangle(rect.x, rect.y, rect.width, rect.height);
207201

208202
cr.strokePreserve();
209203

210-
Clutter.cairo_set_source_color(cr, windowBackgroundColor);
204+
Clutter.cairo_set_source_color(cr, winBackgroundColor);
205+
211206
cr.fill();
212207
cr.$dispose();
213208

214-
if (this._showIcons) {
215-
const [x, y] = this.iconPos(rect);
209+
if (this.showIcon) {
210+
const [x, y] = this.calcIconPos(rect);
216211
this.icon.set_x(x);
217212
this.icon.set_y(y);
218213
}
219214
}
220215

221-
_getIcon() {
216+
getWinThemeColors() {
217+
const graphThemeNode = this.workspaceGraph.graphArea.get_theme_node();
218+
let windowBackgroundColor, windowBorderColor;
219+
220+
if (this.metaWindow.has_focus()) {
221+
windowBorderColor = graphThemeNode.get_color('-active-window-border');
222+
windowBackgroundColor = graphThemeNode.get_color('-active-window-background');
223+
} else {
224+
windowBorderColor = graphThemeNode.get_color('-inactive-window-border');
225+
windowBackgroundColor = graphThemeNode.get_color('-inactive-window-background');
226+
}
227+
228+
return [windowBackgroundColor, windowBorderColor];
229+
}
230+
231+
getIcon() {
222232
let iconActor = null;
223233
let app = null;
224234

@@ -231,22 +241,25 @@ class WindowGraph {
231241
}
232242

233243
if (app) {
234-
iconActor = app.create_icon_texture_for_window(this._iconSize, this.metaWindow);
244+
iconActor = app.create_icon_texture_for_window(this.iconSize, this.metaWindow);
235245
}
236246

237247
if (!iconActor) {
238248
iconActor = new St.Icon({
239249
icon_name: 'applications-other',
240250
icon_type: St.IconType.FULLCOLOR,
241-
icon_size: this._iconSize,
251+
icon_size: this.iconSize,
242252
});
243253
}
244254

245255
return iconActor;
246256
}
247257

248258
destroy() {
249-
if (this._showIcons) this.icon.destroy();
259+
if (this.showIcon) {
260+
this.icon.destroy();
261+
}
262+
250263
this.drawingArea.destroy();
251264
}
252265

@@ -257,8 +270,9 @@ class WindowGraph {
257270
show() {
258271
this.workspaceGraph.graphArea.add_child(this.drawingArea);
259272

260-
if (this._showIcons)
273+
if (this.showIcon) {
261274
this.workspaceGraph.graphArea.add_child(this.icon);
275+
}
262276
}
263277
}
264278

@@ -359,7 +373,7 @@ class WorkspaceGraph extends WorkspaceButton {
359373

360374
this.focusGraph = undefined;
361375
for (const window of windows) {
362-
const graph = new WindowGraph(this, window, showIcon, iconSize);
376+
const graph = new WindowGraph(window, this, showIcon, iconSize);
363377

364378
this.windowsGraphs.push(graph);
365379

@@ -380,7 +394,10 @@ class WorkspaceGraph extends WorkspaceButton {
380394
update(options = {}) {
381395
const signal = options.signal;
382396

383-
if (this.focusGraph && (signal == "position-changed" || signal == "size-changed")) {
397+
if ((signal == "position-changed" || signal == "size-changed") &&
398+
this.focusGraph &&
399+
this.focusGraph.metaWindow.has_focus()
400+
) {
384401
this.focusGraph.update(options);
385402
} else {
386403
this.graphArea.queue_repaint();

0 commit comments

Comments
 (0)