Skip to content

Commit

Permalink
Merge pull request #30 from bailuk/stage
Browse files Browse the repository at this point in the history
Release (0.5.0)
  • Loading branch information
bailuk authored Jan 21, 2024
2 parents db8c97a + 0c59e03 commit e19032e
Show file tree
Hide file tree
Showing 30 changed files with 272 additions and 156 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ nb-configuration.xml
## OS X
.DS_Store

## nix-shell
/shell.nix

# Development
todo/
/ci/qemu/
9 changes: 8 additions & 1 deletion CHANGES.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Release (0.4.0)
# Release (0.5.0)

- Add `shell.nix` as documentation
- Support JDK21
- Library: Remove dependency to libc
- CI: Update dependencies: gradle:8.5, kotlin:1.9.22

# 0.4.0

- Generator: Improve record support (structure and callbacks)
- Generator: Java doc for callback class
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ There are more demo applications in [examples/src/main/java/examples](examples/s
Compile Java library, generate JAR archive and copy JAR archive as artifact to local Maven repository (`~/.m2/repository`).

## Integration
Library and [Javadoc](https://javadoc.jitpack.io/com/github/bailuk/java-gtk/0.4.0/javadoc/) is available via [JitPack](https://jitpack.io).
Library and [Javadoc](https://javadoc.jitpack.io/com/github/bailuk/java-gtk/0.5.0/javadoc/) is available via [JitPack](https://jitpack.io).

```kotlin
// build.gradle.kts
Expand All @@ -87,7 +87,7 @@ repositories {
}

dependencies {
implementation("com.github.bailuk:java-gtk:0.4.0")
implementation("com.github.bailuk:java-gtk:0.5.0")
}

application {
Expand Down
10 changes: 1 addition & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ plugins {
/**
* https://github.com/allegro/axion-release-plugin
*
* 1. Current build version
* Current build version
* ./gradlew cV
*
* 2. Code freeze
* git tag v0.4.0-rc.1 -m "Code freeze"
* git push origin v0.4.0-rc.1
*
* 3. Release
* -> Update README.md
* git tag v0.4.0 -m "Release"
* git push origin v0.4.0
*/
id ("pl.allegro.tech.build.axion-release") version "1.15.0"
}
Expand Down
21 changes: 21 additions & 0 deletions doc/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Development environment with nix-shell
{ pkgs ? import <nixpkgs> {}
}:
pkgs.mkShell {
name="java-gtk";
buildInputs = [
pkgs.git
pkgs.jdk21_headless # Non headless is linked against gtk3 and does therefore not work
pkgs.gtk4
];
shellHook = ''
LD_LIBRARY_PATH=${pkgs.gtk4.outPath}/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.glib.out.outPath}/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.gdk-pixbuf.outPath}/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.cairo.outPath}/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.pango.out.outPath}/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.libadwaita.outPath}/lib
export LD_LIBRARY_PATH
echo "./gradlew generate && ./gradlew build && ./gradlew run"
'';
}
53 changes: 53 additions & 0 deletions examples/src/main/java/examples/dnd/DragAndDrop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package examples.dnd;

import ch.bailu.gtk.gdk.GdkConstants;
import ch.bailu.gtk.gio.ApplicationFlags;
import ch.bailu.gtk.gio.File;
import ch.bailu.gtk.gtk.Application;
import ch.bailu.gtk.gtk.ApplicationWindow;
import ch.bailu.gtk.gtk.DropTarget;
import ch.bailu.gtk.gtk.Label;
import ch.bailu.gtk.type.Str;
import ch.bailu.gtk.type.Strs;

/**
* https://docs.gtk.org/gtk4/drag-and-drop.html
*/
public class DragAndDrop {
public final static Str ID = new Str("org.gtk.example.dnd");

public static void main(String[] args) {

var app = new Application(ID, ApplicationFlags.FLAGS_NONE);
app.onActivate(() -> {
// Get and initialize application window
var window = new ApplicationWindow(app);
window.setTitle("Drag and drop demo");
window.setDefaultSize(400,300);

// Create a label to display dropped files
var label = new Label("Drop files here");
label.setHexpand(true);
label.setVexpand(true);

// Crate drop target
var target = new DropTarget(File.getTypeID(), GdkConstants.ACTION_ALL);
target.onDrop((value, x, y) -> {
System.out.println("dropped");
var file = new File(value.getObject().cast());
label.setText(file.getBasename());
return true;
});

// Make the label a drop target
label.addController(target);

// Compose and display
window.setChild(label);
window.show();
});


System.exit(app.run(args.length, new Strs(args)));
}
}
24 changes: 4 additions & 20 deletions examples/src/main/java/examples/libadwaita/demo/AdwaitaDemo.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package examples.libadwaita.demo;

import java.io.IOException;

import ch.bailu.gtk.adw.AboutWindow;
import ch.bailu.gtk.adw.Application;
import ch.bailu.gtk.gio.ApplicationFlags;
import ch.bailu.gtk.gio.Resource;
import ch.bailu.gtk.gtk.License;
import ch.bailu.gtk.gtk.Window;
import ch.bailu.gtk.lib.bridge.GResource;
import ch.bailu.gtk.lib.handler.action.ActionHandler;
import ch.bailu.gtk.lib.util.JavaResource;
import ch.bailu.gtk.type.Bytes;
import ch.bailu.gtk.type.Strs;
import ch.bailu.gtk.type.exception.AllocationError;

/**
* Almost complete port of the official demo from C to Java
* https://gitlab.gnome.org/GNOME/libadwaita/-/blob/main/demo
*
*/
public class AdwaitaDemo {
private static Strs developers = new Strs(new String[] {
private static final Strs developers = new Strs(new String[] {
"Adrien Plazas",
"Alexander Mikhaylenko",
"Andrei Lișiță",
Expand All @@ -33,13 +28,13 @@ public class AdwaitaDemo {
null
});

private static Strs designers = new Strs(new String[] {
private static final Strs designers = new Strs(new String[] {
"GNOME Design Team",
null
});

public static void main(String[] args) {
loadAndRegisterGResource("/adw_demo/adwaita-demo.gresources.gresource");
GResource.loadAndRegister("/adw_demo/adwaita-demo.gresources.gresource");

final var app = new Application("org.gnome.Adwaita1.Demo", ApplicationFlags.NON_UNIQUE);

Expand All @@ -55,17 +50,6 @@ public static void main(String[] args) {
app.unref();
}

private static void loadAndRegisterGResource(String path) {
// TODO wouldn't it be nice if resource could be loaded directly from java resources instead of .gresource?
try (var stream = (new JavaResource(path).asStream())) {
var bytes = new Bytes(stream.readAllBytes());
var resource = Resource.newFromDataResource(ch.bailu.gtk.glib.Bytes.newStaticBytes(bytes, bytes.getLength()));
resource.register();
} catch (IOException | AllocationError e) {
System.err.println("Load gresource failed for '" + path + "'");
}
}

private static void showAbout(Application app) {
final var about = new AboutWindow();
about.setTransientFor(app.getActiveWindow());
Expand Down
2 changes: 1 addition & 1 deletion generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
java

// https://kotlinlang.org/docs/gradle-configure-project.html
kotlin("jvm") version "1.8.20"
kotlin("jvm") version "1.9.22"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class JavaImpWriter(private val out: TextWriter) : CodeWriter {
_size = new Fields().size();
System.out.println("${structureModel.apiName} size: " + _size + " bytes");
}
return ch.bailu.gtk.lib.jna.CLib.allocate(_size);
return ch.bailu.gtk.type.Imp.allocate(_size);
}
@com.sun.jna.Structure.FieldOrder({${getFields(structureModel, fields)}})
Expand Down
34 changes: 34 additions & 0 deletions generator/src/main/resources/cairo-custom.gir
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,40 @@
</parameters>
</method>

<method name="select_font_face" c:identifier="cairo_select_font_face">
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
</return-value>
<parameters>
<instance-parameter name="cr" transfer-ownership="none">
<type name="Context" c:type="cairo_t*"/>
</instance-parameter>
<parameter name="utf8" transfer-ownership="none">
<type name="const char*" c:type="const char*"/>
</parameter>
<parameter name="style">
<type name="int" c:type="int"/>
</parameter>
<parameter name="weight">
<type name="int" c:type="int"/>
</parameter>
</parameters>
</method>

<method name="set_font_size" c:identifier="cairo_set_font_size">
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
</return-value>
<parameters>
<instance-parameter name="cr" transfer-ownership="none">
<type name="Context" c:type="cairo_t*"/>
</instance-parameter>
<parameter name="size">
<type name="gdouble" c:type="gdouble"/>
</parameter>
</parameters>
</method>

<method name="line_to" c:identifier="cairo_line_to">
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
19 changes: 12 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
28 changes: 28 additions & 0 deletions java-gtk/src/main/java/ch/bailu/gtk/lib/bridge/GResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ch.bailu.gtk.lib.bridge;

import java.io.IOException;

import ch.bailu.gtk.gio.Resource;
import ch.bailu.gtk.lib.util.JavaResource;
import ch.bailu.gtk.type.Bytes;
import ch.bailu.gtk.type.exception.AllocationError;

public class GResource {

/**
* Load a gresource bundle from java resources path and register it
* See {@link ch.bailu.gtk.gio.Resource} for documentation on how to generate
* gresource bundles.
*
* @param path absolute path to gresource: "/gresource/app.gresource"
*/
public static void loadAndRegister(String path) {
try (var stream = (new JavaResource(path).asStream())) {
var bytes = new Bytes(stream.readAllBytes());
var resource = Resource.newFromDataResource(ch.bailu.gtk.glib.Bytes.newStaticBytes(bytes, bytes.getLength()));
resource.register();
} catch (IOException | AllocationError e) {
System.err.println("Load gresource failed for '" + path + "'");
}
}
}
28 changes: 0 additions & 28 deletions java-gtk/src/main/java/ch/bailu/gtk/lib/jna/CLib.java

This file was deleted.

Loading

0 comments on commit e19032e

Please sign in to comment.