Skip to content

Commit ac6aaea

Browse files
itzexormtwebster
authored andcommitted
menu-applet: rework vectorBox
-Rework the workaround in 1c513b2 so that the overlay box only contains the actor we want to overlay, and the overlaying actor itself. This simplifies the vectorBox calculations and positioning a bit. -Reduce code duplication by doing the calculations in a separate function. -Ignore invalid coordinates. If the mouse is outside the overlay box, then we can just destroy or not create the vectorBox. -Position the vectorBox to the same size as the categoriesBox and only change the "point". Avoids having to reposition the box every time or rely on an ActorAlign. -Some comments explaining the vectorBox. fixes #7109
1 parent 4c17a4d commit ac6aaea

File tree

1 file changed

+54
-32
lines changed
  • files/usr/share/cinnamon/applets/menu@cinnamon.org

1 file changed

+54
-32
lines changed

files/usr/share/cinnamon/applets/menu@cinnamon.org/applet.js

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,33 +2098,59 @@ MyApplet.prototype = {
20982098
}
20992099
},
21002100

2101-
makeVectorBox: function(actor) {
2102-
this.destroyVectorBox(actor);
2101+
/*
2102+
* The vectorBox overlays the the categoriesBox to aid in navigation from categories to apps
2103+
* by preventing misselections. It is set to the same size as the categoriesOverlayBox and
2104+
* categoriesBox.
2105+
*
2106+
* The actor is a quadrilateral that we turn into a triangle by setting the A and B vertices to
2107+
* the same position. The size and origin of the vectorBox are calculated in _getVectorInfo().
2108+
* Using those properties, the bounding box is sized as (w, h) and the triangle is defined as
2109+
* follows:
2110+
* _____
2111+
* | /|D
2112+
* | / | AB: (mx, my)
2113+
* | A/ | C: (w, h)
2114+
* | B\ | D: (w, 0)
2115+
* | \ |
2116+
* |____\|C
2117+
*/
2118+
2119+
_getVectorInfo: function() {
21032120
let [mx, my, mask] = global.get_pointer();
2104-
let [bx, by] = this.categoriesApplicationsBox.actor.get_transformed_position();
2105-
let [bw, bh] = this.categoriesApplicationsBox.actor.get_transformed_size();
2106-
let [appbox_x, appbox_y] = this.applicationsBox.get_transformed_position();
2121+
let [bx, by] = this.categoriesOverlayBox.get_transformed_position();
2122+
let [bw, bh] = this.categoriesOverlayBox.get_transformed_size();
21072123

2108-
let right_x = appbox_x - bx;
2109-
let xformed_mouse_x = mx-bx;
2110-
let xformed_mouse_y = my-by;
2111-
let w = Math.max(right_x-xformed_mouse_x, 0);
2124+
let xformed_mx = mx - bx;
2125+
let xformed_my = my - by;
2126+
2127+
if (xformed_mx < 0 || xformed_mx > bw || xformed_my < 0 || xformed_my > bh) {
2128+
return null;
2129+
}
21122130

2113-
let ulc_y = xformed_mouse_y + 0;
2114-
let llc_y = xformed_mouse_y + 0;
2131+
return { mx: xformed_mx,
2132+
my: xformed_my,
2133+
w: bw,
2134+
h: bh };
2135+
},
2136+
2137+
makeVectorBox: function(actor) {
2138+
this.destroyVectorBox(actor);
2139+
let vi = this._getVectorInfo();
2140+
if (!vi) {
2141+
return;
2142+
}
21152143

2116-
this.vectorBox = new St.Polygon({ debug: false, width: w, height: bh,
2117-
ulc_x: 0, ulc_y: ulc_y,
2118-
llc_x: 0, llc_y: llc_y,
2119-
urc_x: w, urc_y: 0,
2120-
lrc_x: w, lrc_y: bh });
2144+
this.vectorBox = new St.Polygon({ debug: false, width: vi.w, height: vi.h,
2145+
ulc_x: vi.mx, ulc_y: vi.my,
2146+
llc_x: vi.mx, llc_y: vi.my,
2147+
urc_x: vi.w, urc_y: 0,
2148+
lrc_x: vi.w, lrc_y: vi.h });
21212149

21222150
this.categoriesOverlayBox.add_actor(this.vectorBox);
2123-
this.vectorBox.set_position(xformed_mouse_x, 0);
21242151

21252152
this.vectorBox.show();
21262153
this.vectorBox.set_reactive(true);
2127-
this.vectorBox.raise_top();
21282154

21292155
this.vectorBox.connect("leave-event", Lang.bind(this, this.destroyVectorBox));
21302156
this.vectorBox.connect("motion-event", Lang.bind(this, this.maybeUpdateVectorBox));
@@ -2142,16 +2168,10 @@ MyApplet.prototype = {
21422168

21432169
updateVectorBox: function(actor) {
21442170
if (this.vectorBox) {
2145-
let [mx, my, mask] = global.get_pointer();
2146-
let [bx, by] = this.categoriesApplicationsBox.actor.get_transformed_position();
2147-
let xformed_mouse_x = mx-bx;
2148-
let [appbox_x, appbox_y] = this.applicationsBox.get_transformed_position();
2149-
let right_x = appbox_x - bx;
2150-
if ((right_x-xformed_mouse_x) > 0) {
2151-
this.vectorBox.width = Math.max(right_x-xformed_mouse_x, 0);
2152-
this.vectorBox.set_position(xformed_mouse_x, 0);
2153-
this.vectorBox.urc_x = this.vectorBox.width;
2154-
this.vectorBox.lrc_x = this.vectorBox.width;
2171+
let vi = this._getVectorInfo();
2172+
if (vi) {
2173+
this.vectorBox.ulc_x = vi.mx;
2174+
this.vectorBox.llc_x = vi.mx;
21552175
this.vectorBox.queue_repaint();
21562176
} else {
21572177
this.destroyVectorBox(actor);
@@ -2854,13 +2874,15 @@ MyApplet.prototype = {
28542874
this.searchEntryText.connect('key-press-event', Lang.bind(this, this._onMenuKeyPress));
28552875
this._previousSearchPattern = "";
28562876

2857-
this.categoriesOverlayBox = new Clutter.Actor();
28582877
this.categoriesApplicationsBox = new CategoriesApplicationsBox();
2859-
this.categoriesOverlayBox.add_actor(this.categoriesApplicationsBox.actor);
2860-
rightPane.add_actor(this.categoriesOverlayBox);
2878+
rightPane.add_actor(this.categoriesApplicationsBox.actor);
2879+
2880+
this.categoriesOverlayBox = new Clutter.Actor();
28612881
this.categoriesBox = new St.BoxLayout({ style_class: 'menu-categories-box',
28622882
vertical: true,
28632883
accessible_role: Atk.Role.LIST });
2884+
this.categoriesOverlayBox.add_actor(this.categoriesBox);
2885+
28642886
this.applicationsScrollBox = new St.ScrollView({ x_fill: true, y_fill: false, y_align: St.Align.START, style_class: 'vfade menu-applications-scrollbox' });
28652887

28662888
this.a11y_settings = new Gio.Settings({ schema_id: "org.cinnamon.desktop.a11y.applications" });
@@ -2887,7 +2909,7 @@ MyApplet.prototype = {
28872909
this.applicationsBox.add_style_class_name('menu-applications-box'); //this is to support old themes
28882910
this.applicationsScrollBox.add_actor(this.applicationsBox);
28892911
this.applicationsScrollBox.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
2890-
this.categoriesApplicationsBox.actor.add_actor(this.categoriesBox);
2912+
this.categoriesApplicationsBox.actor.add_actor(this.categoriesOverlayBox);
28912913
this.categoriesApplicationsBox.actor.add_actor(this.applicationsScrollBox);
28922914

28932915
let fav_obj = new FavoritesBox();

0 commit comments

Comments
 (0)