Skip to content

Commit 85e6d5e

Browse files
authored
panel: minor compatibility, RTL fixes. (#13682)
Followup to #13613. - Fix RTL swap in _calculateBoxes - Mask panel.height GObject property with a js property that prints a warning and recommends Applet._panelHeight, and returns the expected value (heightForZones). - Use get_height() internally to avoid this (also arguably faster) - Use get_width() internally, just for consistency. - Fix the menu applet (was still accessing panel.height).
1 parent 1572920 commit 85e6d5e

2 files changed

Lines changed: 50 additions & 32 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
16151615
let size;
16161616

16171617
if (this.menuCustom) {
1618-
size = Math.min(this.menuIconSize, this.panel.height);
1618+
size = Math.min(this.menuIconSize, this._panelHeight);
16191619
} else {
16201620
size = this.getPanelIconSize(icon_type);
16211621
}

js/ui/panel.js

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ function heightsUsedMonitor(monitorIndex, listofpanels) {
165165
if (listofpanels[i]) {
166166
if (listofpanels[i].monitorIndex == monitorIndex) {
167167
if (listofpanels[i].panelPosition == PanelLoc.top)
168-
toppanelHeight = listofpanels[i].actor.height;
168+
toppanelHeight = listofpanels[i].get_height();
169169
else if (listofpanels[i].panelPosition == PanelLoc.bottom)
170-
bottompanelHeight = listofpanels[i].actor.height;
170+
bottompanelHeight = listofpanels[i].get_height();
171171
}
172172
}
173173
}
@@ -225,9 +225,9 @@ function setHeightForPanel(panel) {
225225

226226
// for vertical panels use the width instead of the height
227227
if (panel.panelPosition > 1)
228-
height = panel.actor.get_width();
228+
height = panel.get_width();
229229
else
230-
height = panel.actor.get_height();
230+
height = panel.get_height();
231231

232232
if (height < 20)
233233
height = 40;
@@ -1614,6 +1614,20 @@ var Panel = GObject.registerClass({
16141614
this._onPanelZoneSizesChanged();
16151615
}
16161616

1617+
/**
1618+
* height:
1619+
*
1620+
* Deprecated: Third-party applets should use Applet._panelHeight (available since 4.0).
1621+
* For the actual actor pixel height, use panel.get_height().
1622+
*/
1623+
get height() {
1624+
global.logWarning(`panel.height should no longer be accessed. ` +
1625+
`Third-party applets should use applet._panelHeight (available since 4.0) ` +
1626+
`to get the panel size for zone/icon calculations. Use panel.get_height() ` +
1627+
`for the actual actor height.`);
1628+
return this.heightForZones;
1629+
}
1630+
16171631
/**
16181632
* updatePosition:
16191633
* @monitorIndex: integer, index of monitor
@@ -1850,8 +1864,8 @@ var Panel = GObject.registerClass({
18501864
let [x, y, whatever] = global.get_pointer();
18511865
this.sync_hover();
18521866

1853-
if (this.x < x && x < this.x + this.width &&
1854-
this.y < y && y < this.y + this.height) {
1867+
if (this.x < x && x < this.x + this.get_width() &&
1868+
this.y < y && y < this.y + this.get_height()) {
18551869
return true;
18561870
} else {
18571871
this._leavePanel();
@@ -1884,7 +1898,7 @@ var Panel = GObject.registerClass({
18841898

18851899
let noBarriers = global.settings.get_boolean("no-adjacent-panel-barriers");
18861900

1887-
if (this.height && this.width) {
1901+
if (this.get_height() && this.get_width()) {
18881902
let panelTop = 0;
18891903
let panelBottom = 0;
18901904
let panelLeft = 0;
@@ -1895,10 +1909,10 @@ var Panel = GObject.registerClass({
18951909
switch (this.panelPosition) {
18961910
case PanelLoc.top:
18971911
panelTop = this.monitor.y;
1898-
panelBottom = this.monitor.y + this.height;
1912+
panelBottom = this.monitor.y + this.get_height();
18991913
break;
19001914
case PanelLoc.bottom:
1901-
panelTop = this.monitor.y + this.monitor.height - Math.floor(this.height);
1915+
panelTop = this.monitor.y + this.monitor.height - Math.floor(this.get_height());
19021916
panelBottom = this.monitor.y + this.monitor.height -1;
19031917
break;
19041918
}
@@ -1928,10 +1942,10 @@ var Panel = GObject.registerClass({
19281942
switch (this.panelPosition) {
19291943
case PanelLoc.left:
19301944
panelLeft = this.monitor.x;
1931-
panelRight = this.monitor.x + Math.floor(this.width);
1945+
panelRight = this.monitor.x + Math.floor(this.get_width());
19321946
break;
19331947
case PanelLoc.right:
1934-
panelLeft = this.monitor.x + this.monitor.width - Math.floor(this.width);
1948+
panelLeft = this.monitor.x + this.monitor.width - Math.floor(this.get_width());
19351949
panelRight = this.monitor.x + this.monitor.width-1;
19361950
break;
19371951
default:
@@ -2155,14 +2169,14 @@ var Panel = GObject.registerClass({
21552169
: 1;
21562170
else
21572171
exposedAmount = animating ? Math.abs(this.y - offset)
2158-
: this.height;
2172+
: this.get_height();
21592173
} else {
21602174
if (hidden)
21612175
exposedAmount = animating ? Math.abs(this.x - offset) + 1
21622176
: 1;
21632177
else
21642178
exposedAmount = animating ? Math.abs(this.x - offset)
2165-
: this.width;
2179+
: this.get_width();
21662180
}
21672181

21682182
// determine offset & set clip
@@ -2177,25 +2191,25 @@ var Panel = GObject.registerClass({
21772191
if (isHorizontal) {
21782192
let clipOffsetY = 0;
21792193
if (this.panelPosition == PanelLoc.top) {
2180-
clipOffsetY = this.height - exposedAmount;
2194+
clipOffsetY = this.get_height() - exposedAmount;
21812195
} else {
21822196
if (!hidden)
21832197
clipOffsetY = this._shadowBox.y1;
21842198
}
21852199
if (!hidden)
21862200
exposedAmount += Math.abs(this._shadowBox.y1);
2187-
this.set_clip(0, clipOffsetY, this.width, exposedAmount);
2201+
this.set_clip(0, clipOffsetY, this.get_width(), exposedAmount);
21882202
} else {
21892203
let clipOffsetX = 0;
21902204
if (this.panelPosition == PanelLoc.left) {
2191-
clipOffsetX = this.width - exposedAmount;
2205+
clipOffsetX = this.get_width() - exposedAmount;
21922206
} else {
21932207
if (!hidden)
21942208
clipOffsetX = this._shadowBox.x1;
21952209
}
21962210
if (!hidden)
21972211
exposedAmount += Math.abs(this._shadowBox.x1);
2198-
this.set_clip(clipOffsetX, 0, exposedAmount, this.height);
2212+
this.set_clip(clipOffsetX, 0, exposedAmount, this.get_height());
21992213
}
22002214
// Force the layout manager to update the input region
22012215
Main.layoutManager.updateChrome()
@@ -2220,7 +2234,7 @@ var Panel = GObject.registerClass({
22202234
case PanelLoc.top:
22212235
case PanelLoc.bottom:
22222236
test_rect.x = this.x;
2223-
test_rect.width = this.width;
2237+
test_rect.width = this.get_width();
22242238
test_rect.height = this.heightForZones;
22252239

22262240
if (this.panelPosition === PanelLoc.top) {
@@ -2232,7 +2246,7 @@ var Panel = GObject.registerClass({
22322246
case PanelLoc.left:
22332247
case PanelLoc.right:
22342248
test_rect.y = this.y;
2235-
test_rect.height = this.height;
2249+
test_rect.height = this.get_height();
22362250
test_rect.width = this.heightForZones;
22372251

22382252
if (this.panelPosition === PanelLoc.left) {
@@ -2350,10 +2364,10 @@ var Panel = GObject.registerClass({
23502364

23512365
// and determine if this panel's size changed
23522366
if (horizontal_panel) {
2353-
if (this.width != newHorizPanelWidth || this.height != panelHeight)
2367+
if (this.get_width() != newHorizPanelWidth || this.get_height() != panelHeight)
23542368
panelChanged = true;
23552369
} else {
2356-
if (this.width != panelHeight || this.height != newVertPanelHeight)
2370+
if (this.get_width() != panelHeight || this.get_height() != newVertPanelHeight)
23572371
panelChanged = true;
23582372
}
23592373

@@ -2849,6 +2863,11 @@ var Panel = GObject.registerClass({
28492863
leftBoundary = Math.round(leftWidth);
28502864
rightBoundary = Math.round(allocWidth - rightWidth);
28512865

2866+
if (!isVertical && (this.get_direction() === St.TextDirection.RTL)) {
2867+
leftBoundary = Math.round(allocWidth - leftWidth);
2868+
rightBoundary = Math.round(rightWidth);
2869+
}
2870+
28522871
return [leftBoundary, rightBoundary];
28532872
}
28542873

@@ -2977,28 +2996,27 @@ var Panel = GObject.registerClass({
29772996
y = this.monitor.y;
29782997
break;
29792998
case PanelLoc.bottom:
2980-
y = this.monitor.y + this.monitor.height - this.height;
2999+
y = this.monitor.y + this.monitor.height - this.get_height();
29813000
break;
29823001
case PanelLoc.left:
29833002
x = this.monitor.x;
29843003
break;
29853004
case PanelLoc.right:
2986-
x = this.monitor.x + this.monitor.width - this.width;
3005+
x = this.monitor.x + this.monitor.width - this.get_width();
29873006
break;
29883007
default:
29893008
global.log("updatePanelVisibility - unrecognised panel position "+this.panelPosition);
29903009
}
29913010

2992-
let a = this;
2993-
let b = global.display.focus_window.get_frame_rect();
3011+
let rect = global.display.focus_window.get_frame_rect();
29943012
/* Magic to check whether the panel position overlaps with the
29953013
* current focused window */
29963014
if (this.panelPosition == PanelLoc.top || this.panelPosition == PanelLoc.bottom) {
2997-
this._shouldShow = !(Math.max(a.x, b.x) < Math.min(a.x + a.width, b.x + b.width) &&
2998-
Math.max(y, b.y) < Math.min(y + a.height, b.y + b.height));
3015+
this._shouldShow = !(Math.max(this.x, rect.x) < Math.min(this.x + this.get_width(), rect.x + rect.width) &&
3016+
Math.max(y, rect.y) < Math.min(y + this.get_height(), rect.y + rect.height));
29993017
} else {
3000-
this._shouldShow = !(Math.max(x, b.x) < Math.min(x + a.width, b.x + b.width) &&
3001-
Math.max(a.y, b.y) < Math.min(a.y + a.height, b.y + b.height));
3018+
this._shouldShow = !(Math.max(x, rect.x) < Math.min(x + this.get_width(), rect.x + rect.width) &&
3019+
Math.max(this.y, rect.y) < Math.min(this.y + this.get_height(), rect.y + rect.height));
30023020
}
30033021

30043022
} // end of switch on autohidesettings
@@ -3068,8 +3086,8 @@ var Panel = GObject.registerClass({
30683086
this.sync_hover();
30693087
const [x, y] = global.get_pointer();
30703088

3071-
return (this.x <= x && x <= this.x + this.width &&
3072-
this.y <= y && y <= this.y + this.height);
3089+
return (this.x <= x && x <= this.x + this.get_width() &&
3090+
this.y <= y && y <= this.y + this.get_height());
30733091
}
30743092

30753093
/**

0 commit comments

Comments
 (0)