Skip to content

Commit e9fe5a7

Browse files
authored
Add a workaround for Apple Silicon (#17)
2 parents 96cefba + 9fcb271 commit e9fe5a7

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# DurianSwt releases
22

33
## [Unreleased]
4+
### Added
5+
- On Mac Apple Silicon (but not x86_64), SWT Tables and Trees now have giant fat rows ([bugzilla](https://bugs.eclipse.org/bugs/show_bug.cgi?id=575696)). ([#17](https://github.com/diffplug/durian-swt/pull/17))
6+
- But if you call `setFont(null)` on them, then they have rows the same size as before.
7+
- We created a new class `SiliconFix` that does nothing on all platforms except Apple Silicon where it calls `setFont(null)`.
8+
- Wherever a `Table` or `Tree` instantiated (`SmoothTable` and `ColumnFormat`), we use `SiliconFix`.
9+
- This workaround is perfectly effective as of `4.21` and `4.22`, it may become obsolete in a future release.
410

511
## [3.5.0] - 2021-09-03
612
### Added

durian-swt/src/main/java/com/diffplug/common/swt/ColumnFormat.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 DiffPlug
2+
* Copyright (C) 2020-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -104,6 +104,7 @@ protected static Table buildTable(Composite parent, int style, boolean linesVisi
104104
SwtMisc.assertClean(parent);
105105
// create the control
106106
Table control = new Table(parent, style);
107+
SiliconFix.fix(control);
107108
control.setLinesVisible(linesVisible);
108109
control.setHeaderVisible(headerVisible);
109110

@@ -152,6 +153,7 @@ protected static Tree buildTree(Composite parent, int style, boolean linesVisibl
152153
SwtMisc.assertClean(parent);
153154
// create the control
154155
Tree control = new Tree(parent, style);
156+
SiliconFix.fix(control);
155157
control.setLinesVisible(linesVisible);
156158
control.setHeaderVisible(headerVisible);
157159

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2022 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.common.swt;
17+
18+
19+
import com.diffplug.common.swt.os.Arch;
20+
import com.diffplug.common.swt.os.OS;
21+
import org.eclipse.swt.widgets.List;
22+
import org.eclipse.swt.widgets.Table;
23+
import org.eclipse.swt.widgets.Tree;
24+
25+
/**
26+
* Call these methods whenever a `Table`, `Tree`, or `List` is instantiated and it will do nothing,
27+
* excpet on Mac Apple Silicon where it will call `setFont(null)` as a workaround for
28+
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=575696
29+
*/
30+
public class SiliconFix {
31+
private static final boolean APPLY_FIX = OS.getRunning().isMac() && Arch.getRunning() == Arch.arm64;
32+
33+
public static void fix(Table table) {
34+
if (APPLY_FIX) {
35+
table.setFont(null);
36+
}
37+
}
38+
39+
public static void fix(Tree tree) {
40+
if (APPLY_FIX) {
41+
tree.setFont(null);
42+
}
43+
}
44+
45+
public static void fix(List list) {
46+
if (APPLY_FIX) {
47+
list.setFont(null);
48+
}
49+
}
50+
}

durian-swt/src/main/java/com/diffplug/common/swt/widgets/AbstractSmoothTable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 DiffPlug
2+
* Copyright (C) 2020-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
package com.diffplug.common.swt.widgets;
1717

1818

19+
import com.diffplug.common.swt.SiliconFix;
1920
import java.util.function.DoubleConsumer;
2021
import org.eclipse.swt.SWT;
2122
import org.eclipse.swt.graphics.Point;
@@ -58,6 +59,7 @@ abstract class AbstractSmoothTable extends Composite {
5859
}
5960
// the table can't have the BORDER
6061
table = new Table(this, style & (~SWT.BORDER));
62+
SiliconFix.fix(table);
6163
this.setBackground(table.getBackground());
6264
rowHeight = table.getItemHeight();
6365
itemCount = table.getItemCount();

0 commit comments

Comments
 (0)