Skip to content

Commit f505837

Browse files
authored
Separator cleanup (#13573)
* separator.js: Convert to GObject We only had one user of this in Cinnamon's codebase. Should be a pretty easy fix for any spice that uses it. Also removes the use of Lang.bind() * popupmenu.js: Use the standalone separator object We are duplicating the code for drawing the separator in object in menus for no real reason. Just use the the standalone separtor object instead.
1 parent b2827bb commit f505837

3 files changed

Lines changed: 16 additions & 41 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ class EventList {
796796

797797
for (let event_data of events) {
798798
if (first_row_done) {
799-
this.events_box.add_actor(new Separator.Separator().actor);
799+
this.events_box.add_actor(new Separator.Separator());
800800
}
801801

802802
let row = new EventRow(

js/ui/popupMenu.js

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Atk = imports.gi.Atk;
1414
const BoxPointer = imports.ui.boxpointer;
1515
const DND = imports.ui.dnd;
1616
const Main = imports.ui.main;
17+
const Separator = imports.ui.separator;
1718
const SignalManager = imports.misc.signalManager;
1819
const CheckBox = imports.ui.checkBox;
1920
const RadioButton = imports.ui.radioButton;
@@ -532,31 +533,9 @@ var PopupSeparatorMenuItem = class PopupSeparatorMenuItem extends PopupBaseMenuI
532533
_init () {
533534
super._init.call(this, { reactive: false });
534535

535-
this._drawingArea = new St.DrawingArea({ style_class: 'popup-separator-menu-item' });
536-
this.addActor(this._drawingArea, { span: -1, expand: true });
537-
this._signals.connect(this._drawingArea, 'repaint', Lang.bind(this, this._onRepaint));
538-
}
539-
540-
_onRepaint(area) {
541-
let cr = area.get_context();
542-
let themeNode = area.get_theme_node();
543-
let [width, height] = area.get_surface_size();
544-
let margin = themeNode.get_length('-margin-horizontal');
545-
let gradientHeight = themeNode.get_length('-gradient-height');
546-
let startColor = themeNode.get_color('-gradient-start');
547-
let endColor = themeNode.get_color('-gradient-end');
548-
549-
let gradientWidth = (width - margin * 2);
550-
let gradientOffset = (height - gradientHeight) / 2;
551-
let pattern = new Cairo.LinearGradient(margin, gradientOffset, width - margin, gradientOffset + gradientHeight);
552-
pattern.addColorStopRGBA(0, startColor.red / 255, startColor.green / 255, startColor.blue / 255, startColor.alpha / 255);
553-
pattern.addColorStopRGBA(0.5, endColor.red / 255, endColor.green / 255, endColor.blue / 255, endColor.alpha / 255);
554-
pattern.addColorStopRGBA(1, startColor.red / 255, startColor.green / 255, startColor.blue / 255, startColor.alpha / 255);
555-
cr.setSource(pattern);
556-
cr.rectangle(margin, gradientOffset, gradientWidth, gradientHeight);
557-
cr.fill();
558-
559-
cr.$dispose();
536+
let separator = new Separator.Separator();
537+
separator.set_style_class_name('popup-separator-menu-item');
538+
this.addActor(separator, { span: -1, expand: true });
560539
}
561540
}
562541

js/ui/separator.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
22

33
const Cairo = imports.cairo;
4-
const Lang = imports.lang;
4+
const GObject = imports.gi.GObject;
55
const St = imports.gi.St;
66

7-
function Separator() {
8-
this._init();
9-
}
10-
11-
Separator.prototype = {
12-
_init: function() {
13-
this.actor = new St.DrawingArea({ style_class: 'separator' });
14-
this.actor.connect('repaint', Lang.bind(this, this._onRepaint));
15-
},
7+
var Separator = GObject.registerClass(
8+
class Separator extends St.DrawingArea {
9+
_init() {
10+
super._init({ style_class: 'separator' });
11+
}
1612

17-
_onRepaint: function(area) {
18-
let cr = area.get_context();
19-
let themeNode = area.get_theme_node();
20-
let [width, height] = area.get_surface_size();
13+
vfunc_repaint() {
14+
let cr = this.get_context();
15+
let themeNode = this.get_theme_node();
16+
let [width, height] = this.get_surface_size();
2117
let margin = themeNode.get_length('-margin-horizontal');
2218
let gradientHeight = themeNode.get_length('-gradient-height');
2319
let startColor = themeNode.get_color('-gradient-start');
@@ -35,4 +31,4 @@ Separator.prototype = {
3531

3632
cr.$dispose();
3733
}
38-
};
34+
});

0 commit comments

Comments
 (0)