Skip to content

Commit ff0fa9c

Browse files
committed
Partially revert 87d34be
As part of this commit, the menu decorations are no longer drawn on Linux when the SHELL_TRIM style is set. The original motivation was to better handle the offsets when a menu is set. However, this now causes offset errors because all widgets are positioned relative to the top left corner of the shell, but the bounds of the shell still takes the decorations into consideration.
1 parent 95bf6bf commit ff0fa9c

File tree

9 files changed

+96
-17
lines changed

9 files changed

+96
-17
lines changed

org.eclipse.wb.os.linux/META-INF/MANIFEST.MF

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.wb.os.linux;singleton:=true
5-
Bundle-Version: 1.10.200.qualifier
5+
Bundle-Version: 1.10.300.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-RequiredExecutionEnvironment: JavaSE-21
88
Eclipse-PlatformFilter: (& (osgi.ws=gtk) (osgi.os=linux))
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.swt;bundle-version="[3.126.0,4.0.0)",
1111
org.eclipse.jface;bundle-version="[3.34.0,4.0.0)",
1212
org.eclipse.ui;bundle-version="[3.206.0,4.0.0)",
1313
org.eclipse.wb.core;bundle-version="[1.20.0,2.0.0)",
14-
org.eclipse.wb.swt;bundle-version="[1.10.100,2.0.0)"
14+
org.eclipse.wb.swt;bundle-version="[1.10.100,2.0.0)",
15+
org.eclipse.draw2d;bundle-version="[3.20.0,4.0.0)"
1516
Bundle-Activator: org.eclipse.wb.internal.os.linux.Activator
1617
Bundle-ActivationPolicy: lazy
1718
Bundle-Localization: plugin

org.eclipse.wb.os.linux/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ bin.includes = META-INF/,\
44
.,\
55
plugin.xml,\
66
os/,\
7+
icons/,\
78
plugin.properties,\
89
about.html
894 Bytes
Loading
710 Bytes
Loading
678 Bytes
Loading
594 Bytes
Loading

org.eclipse.wb.os.linux/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>org.eclipse.wb</groupId>
1313
<artifactId>org.eclipse.wb.os.linux</artifactId>
14-
<version>1.10.200-SNAPSHOT</version>
14+
<version>1.10.300-SNAPSHOT</version>
1515
<packaging>eclipse-plugin</packaging>
1616

1717
<build>

org.eclipse.wb.os.linux/src/org/eclipse/wb/internal/os/linux/OSSupportLinux.java

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
import org.eclipse.wb.internal.core.utils.check.AssertionFailedException;
1818
import org.eclipse.wb.internal.core.utils.execution.ExecutionUtils;
1919
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;
20+
import org.eclipse.wb.internal.core.utils.ui.DrawUtils;
2021
import org.eclipse.wb.internal.swt.VisualDataMockupProvider;
2122
import org.eclipse.wb.os.OSSupport;
2223

24+
import org.eclipse.draw2d.ColorConstants;
2325
import org.eclipse.swt.SWT;
26+
import org.eclipse.swt.graphics.Color;
2427
import org.eclipse.swt.graphics.Device;
28+
import org.eclipse.swt.graphics.GC;
2529
import org.eclipse.swt.graphics.Image;
2630
import org.eclipse.swt.graphics.Point;
2731
import org.eclipse.swt.graphics.Rectangle;
@@ -46,6 +50,11 @@
4650

4751
public abstract class OSSupportLinux extends OSSupport {
4852
private static Version MINIMUM_VERSION = new Version(3, 126, 0);
53+
// constants
54+
private static final Color TITLE_BORDER_COLOR_DARKEST = DrawUtils.getShiftedColor(ColorConstants.titleBackground,
55+
-24);
56+
private static final Color TITLE_BORDER_COLOR_DARKER = DrawUtils.getShiftedColor(ColorConstants.titleBackground,
57+
-16);
4958

5059
static {
5160
System.loadLibrary("wbp3");
@@ -177,6 +186,8 @@ public void endShot(Object controlObject) {
177186
public void makeShots(Object controlObject) throws Exception {
178187
Shell shell = getShell(controlObject);
179188
makeShots0(shell);
189+
// check for decorations and draw if needed
190+
drawDecorations(shell, shell.getDisplay());
180191
}
181192

182193
/**
@@ -209,6 +220,80 @@ private void makeShots0(final Shell shell) throws Exception {
209220
}
210221
}
211222

223+
/**
224+
* Draws decorations if available/applicable.
225+
*/
226+
private void drawDecorations(Shell shell, final Display display) {
227+
Image shellImage = (Image) shell.getData(WBP_IMAGE);
228+
// draw title if any
229+
if (shellImage != null && (shell.getStyle() & SWT.TITLE) != 0) {
230+
Rectangle shellBounds = shell.getBounds();
231+
Rectangle imageBounds = shellImage.getBounds();
232+
Point offset = shell.toControl(shell.getLocation());
233+
offset.x = -offset.x;
234+
offset.y = -offset.y;
235+
// adjust by menu bar size
236+
if (shell.getMenuBar() != null) {
237+
offset.y -= getWidgetBounds(shell.getMenuBar()).height;
238+
}
239+
// draw
240+
Image decoratedShellImage = new Image(display, shellBounds);
241+
GC gc = new GC(decoratedShellImage);
242+
// draw background
243+
gc.setBackground(ColorConstants.titleBackground);
244+
gc.fillRectangle(0, 0, shellBounds.width, shellBounds.height);
245+
// title area gradient
246+
gc.setForeground(ColorConstants.titleGradient);
247+
gc.fillGradientRectangle(0, 0, shellBounds.width, offset.y, true);
248+
int buttonGapX = offset.x - 1;
249+
int nextPositionX;
250+
// buttons and title
251+
{
252+
// menu button
253+
Image buttonImage = Activator.getImage("decorations/button-menu-icon.png");
254+
Rectangle buttonImageBounds = buttonImage.getBounds();
255+
int buttonOffsetY = offset.y / 2 - buttonImageBounds.height / 2;
256+
gc.drawImage(buttonImage, buttonGapX, buttonOffsetY);
257+
nextPositionX = buttonGapX + buttonImageBounds.width + buttonGapX;
258+
}
259+
{
260+
// close button
261+
Image buttonImage = Activator.getImage("decorations/button-close-icon.png");
262+
Rectangle buttonImageBounds = buttonImage.getBounds();
263+
nextPositionX = shellBounds.width - buttonImageBounds.width - buttonGapX;
264+
int buttonOffsetY = offset.y / 2 - buttonImageBounds.height / 2;
265+
gc.drawImage(buttonImage, nextPositionX, buttonOffsetY);
266+
nextPositionX -= buttonGapX + buttonImageBounds.width;
267+
}
268+
{
269+
// maximize button
270+
Image buttonImage = Activator.getImage("decorations/button-max-icon.png");
271+
Rectangle buttonImageBounds = buttonImage.getBounds();
272+
int buttonOffsetY = offset.y / 2 - buttonImageBounds.height / 2;
273+
gc.drawImage(buttonImage, nextPositionX, buttonOffsetY);
274+
nextPositionX -= buttonGapX + buttonImageBounds.width;
275+
}
276+
{
277+
// minimize button
278+
Image buttonImage = Activator.getImage("decorations/button-min-icon.png");
279+
Rectangle buttonImageBounds = buttonImage.getBounds();
280+
int buttonOffsetY = offset.y / 2 - buttonImageBounds.height / 2;
281+
gc.drawImage(buttonImage, nextPositionX, buttonOffsetY);
282+
}
283+
// outline
284+
gc.setForeground(TITLE_BORDER_COLOR_DARKEST);
285+
gc.drawRectangle(offset.x - 1, offset.y - 1, imageBounds.width + 1, imageBounds.height + 1);
286+
gc.setForeground(TITLE_BORDER_COLOR_DARKER);
287+
gc.drawRectangle(offset.x - 2, offset.y - 2, imageBounds.width + 3, imageBounds.height + 3);
288+
// shell screen shot
289+
gc.drawImage(shellImage, offset.x, offset.y);
290+
// done
291+
gc.dispose();
292+
shellImage.dispose();
293+
shell.setData(WBP_IMAGE, decoratedShellImage);
294+
}
295+
}
296+
212297
private boolean bindImage(final Control control, final Image image) {
213298
return ExecutionUtils.runObject(() -> {
214299
if (control.getData(WBP_NEED_IMAGE) != null && control.getData(WBP_IMAGE) == null) {
@@ -412,7 +497,12 @@ public Image getMenuBarVisualData(Menu menu, List<Rectangle> bounds) {
412497
*/
413498
@Override
414499
public final Rectangle getMenuBarBounds(Menu menu) {
415-
return getWidgetBounds(menu);
500+
Rectangle bounds = getWidgetBounds(menu);
501+
Shell shell = menu.getShell();
502+
Point p = shell.toControl(shell.getLocation());
503+
p.x = -p.x;
504+
p.y = -p.y - bounds.height;
505+
return new Rectangle(p.x, p.y, bounds.width, bounds.height);
416506
}
417507

418508
@Override

org.eclipse.wb.swt/src/org/eclipse/wb/internal/swt/support/CoordinateUtils.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@ public static Point getDisplayLocation(Control composite) throws Exception {
6060
* @return the given location (in parent of given <code>composite</code>) in display coordinates.
6161
*/
6262
public static Point getDisplayLocation(Control composite, int x, int y) throws Exception {
63-
if (EnvironmentUtils.IS_LINUX && composite instanceof Shell shell) {
64-
// In GTK, the bounds of a shell return the top-left position of the window
65-
// manager. Because this manager is not part of the actual shell, we need to use
66-
// this little workaround to get the REAL position of the shell.
67-
// See: https://github.com/eclipse-platform/eclipse.platform.swt/issues/828
68-
Point point = composite.toDisplay(0, 0);
69-
y = point.y;
70-
Menu menuBar = shell.getMenuBar();
71-
if (menuBar != null) {
72-
var menuBounds = OSSupport.get().getMenuBarBounds(menuBar);
73-
y -= menuBounds.height;
74-
}
75-
}
7663
if (!(composite instanceof Shell)) {
7764
Composite parent = composite.getParent();
7865
if (parent != null) {

0 commit comments

Comments
 (0)