Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion org.eclipse.wb.os.linux/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-24"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src_java24">
<attributes>
<attribute name="release" value="24"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions org.eclipse.wb.os.linux/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Import-Package: org.apache.commons.io;version="[2.16.1,3.0.0)",
org.apache.commons.lang3;version="[3.14.0,4.0.0)",
org.apache.commons.lang3.function;version="[3.14.0,4.0.0)",
org.eclipse.wb.os
Automatic-Module-Name: org.eclipse.wb.os.linux
Provide-Capability: wbp;type=os
Multi-Release: true
3 changes: 2 additions & 1 deletion org.eclipse.wb.os.linux/build.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source.. = src/
source.. = src/,\
src_java24/
output.. = bin/
bin.includes = META-INF/,\
.,\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.os.linux;

import java.lang.foreign.Arena;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.StructLayout;
import java.lang.foreign.ValueLayout;

/**
* A GdkRectangle data type for representing rectangles.
*
* GdkRectangle is identical to cairo_rectangle_t. Together with Cairo’s
* cairo_region_t data type, these are the central types for representing sets
* of pixels.
*
* The intersection of two rectangles can be computed with
* gdk_rectangle_intersect(); to find the union of two rectangles use
* gdk_rectangle_union().
*
* The cairo_region_t type provided by Cairo is usually used for managing
* non-rectangular clipping of graphical operations.
*
* The Graphene library has a number of other data types for regions and volumes
* in 2D and 3D.
*/
public sealed class GdkRectangle permits GtkAllocation {
private static final StructLayout LAYOUT = MemoryLayout.structLayout( //
ValueLayout.JAVA_INT.withName("x"), //
ValueLayout.JAVA_INT.withName("y"), //
ValueLayout.JAVA_INT.withName("width"), //
ValueLayout.JAVA_INT.withName("height"));

private final MemorySegment segment;

public GdkRectangle(Arena arena) {
segment = arena.allocate(LAYOUT);
}

public final int x() {
return segment.get(ValueLayout.JAVA_INT, 0);
}

public final int y() {
return segment.get(ValueLayout.JAVA_INT, 4);
}

public final int width() {
return segment.get(ValueLayout.JAVA_INT, 8);
}

public final int height() {
return segment.get(ValueLayout.JAVA_INT, 12);
}

public final MemorySegment segment() {
return segment;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.os.linux;

import java.lang.foreign.Arena;

/**
* A GtkAllocation-struct of a widget represents region which has been allocated
* to the widget by its parent. It is a subregion of its parents allocation.
*/
public final class GtkAllocation extends GdkRectangle {
public GtkAllocation(Arena arena) {
super(arena);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.os.linux;

import org.eclipse.wb.os.OSRuntimeException;

/**
* Wrapper for all exceptions thrown while accessing native code.
*/
public class GtkRuntimeException extends OSRuntimeException {
private static final long serialVersionUID = 1L;

public GtkRuntimeException(Throwable t) {
super(t);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.os.linux;

import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;

import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;

/**
* GtkWidget is the base class all widgets in GTK+ derive from. It manages the
* widget lifecycle, states and style.
*/
public record GtkWidget(long handle) {

public GtkWidget(Widget widget) {
this(getHandle(widget));
}

/**
* @return the handle value of the {@link Widget} using reflection.
*/
private static long getHandle(Widget widget) {
long widgetHandle = getHandleValue(widget, "fixedHandle");
if (widgetHandle == 0) {
// may be null, roll back to "handle"
if (widget instanceof Shell) {
widgetHandle = getHandleValue(widget, "shellHandle");
} else {
widgetHandle = getHandleValue(widget, "handle");
}
}
return widgetHandle;
}

/**
* @return the widget as native pointer for native handles. Note: returns 0 if
* handle cannot be obtained.
*/
private static long getHandleValue(Object widget, String fieldName) {
if (ReflectionUtils.getFieldObject(widget, fieldName) instanceof Long longValue) {
return longValue;
}
// field might be shadowed (e.g. in ImageBasedFrame)
return 0L;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.os.linux;

import org.apache.commons.lang3.function.FailableRunnable;
import org.apache.commons.lang3.function.FailableSupplier;

import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SymbolLookup;
import java.lang.invoke.MethodHandle;

public class Native {

protected static class NativeHolder {
private static final Linker LINKER = Linker.nativeLinker();

protected static MethodHandle createHandle(SymbolLookup sl, String name, FunctionDescriptor descriptor) {
MemorySegment symbol = sl.find(name).orElseThrow(UnsatisfiedLinkError::new);
return LINKER.downcallHandle(symbol, descriptor);
}
}

protected static Object callSafe(FailableSupplier<Object, Throwable> s) {
try {
return s.get();
} catch (Error e) {
throw e;
} catch (Throwable t) {
throw new GtkRuntimeException(t);
}
}

protected static void runSafe(FailableRunnable<Throwable> r) {
try {
r.run();
} catch (Error e) {
throw e;
} catch (Throwable t) {
throw new GtkRuntimeException(t);
}
}
}
Loading
Loading