Skip to content

Commit

Permalink
Update to gir.core 0.5.0
Browse files Browse the repository at this point in the history
- This contains a fix for the random crashes encountered on Windows

- The Cairo.Matrix class now has a more convenient constructor

- Gdk.FileList.GetFiles() is not being generated and requires a manual binding for now, but GLib.SList methods are now generated

Fixes: #674
  • Loading branch information
cameronwhite committed May 9, 2024
1 parent 4e012fb commit 5284066
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="GirCore.Adw-1" Version="0.5.0-preview.4" />
<PackageVersion Include="GirCore.Gtk-4.0" Version="0.5.0-preview.4" />
<PackageVersion Include="GirCore.PangoCairo-1.0" Version="0.5.0-preview.4" />
<PackageVersion Include="GirCore.Adw-1" Version="0.5.0" />
<PackageVersion Include="GirCore.Gtk-4.0" Version="0.5.0" />
<PackageVersion Include="GirCore.PangoCairo-1.0" Version="0.5.0" />
<!-- Note: at least 1.4.2-alpha3 is required for fixes to uninstalling addins, from https://github.com/mono/mono-addins/pull/198 -->
<PackageVersion Include="Mono.Addins" Version="1.4.2-alpha.4" />
<PackageVersion Include="Mono.Addins.Setup" Version="1.4.2-alpha.4" />
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Core/Extensions/CairoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,15 +1434,15 @@ public static void AddColorStop (this Gradient gradient, double offset, Color co
// TODO-GTK4 (bindings) - requires improvements to struct generation (https://github.com/gircore/gir.core/issues/622)
public static Matrix CreateIdentityMatrix ()
{
var matrix = new Matrix (Cairo.Internal.MatrixManagedHandle.Create ());
var matrix = new Matrix ();
matrix.InitIdentity ();
return matrix;
}

// TODO-GTK4 (bindings) - requires improvements to struct generation (https://github.com/gircore/gir.core/issues/622)
public static Matrix CreateMatrix (double xx, double xy, double yx, double yy, double x0, double y0)
{
var matrix = new Matrix (Cairo.Internal.MatrixManagedHandle.Create ());
var matrix = new Matrix ();
matrix.Init (xx, xy, yx, yy, x0, y0);
return matrix;
}
Expand Down
23 changes: 19 additions & 4 deletions Pinta.Core/Extensions/GdkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@
// THE SOFTWARE.

using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Gdk;

namespace Pinta.Core;

public static class GdkExtensions
{
private const string GdkLibraryName = "Gdk";

static GdkExtensions ()
{
NativeImportResolver.RegisterLibrary (GdkLibraryName,
windowsLibraryName: "libgtk-4-1.dll",
linuxLibraryName: "libgtk-4.so.1",
osxLibraryName: "libgtk-4.1.dylib"
);
}
public static bool IsShiftPressed (this ModifierType m)
=> m.HasFlag (ModifierType.ShiftMask);

Expand Down Expand Up @@ -224,15 +235,19 @@ public static unsafe Cairo.ImageSurface ToSurface (this Gdk.Texture texture)
return surf;
}

// TODO-GTK4 (bindings) - struct methods are not generated (https://github.com/gircore/gir.core/issues/622)
[DllImport (GdkLibraryName, EntryPoint = "gdk_file_list_get_files")]
private static extern GLib.Internal.SListOwnedHandle FileListGetFiles (Gdk.Internal.FileListHandle fileList);

// Wrapper around Gdk.FileList.GetFiles() to return a Gio.File array rather than GLib.SList.
// TODO-GTK4 (bindings) - Gdk.FileList.GetFiles() is not generated
public static Gio.File[] GetFilesHelper (this Gdk.FileList file_list)
{
var slist = file_list.GetFiles ();
var slist = new GLib.SList (FileListGetFiles (file_list.Handle));

uint n = GLib.Internal.SList.Length (slist.Handle);
uint n = GLib.SList.Length (slist);
var result = new Gio.File[n];
for (uint i = 0; i < n; ++i) {
result[i] = new Gio.FileHelper (GLib.Internal.SList.NthData (slist.Handle, i), ownedRef: false);
result[i] = new Gio.FileHelper (GLib.SList.NthData (slist, i), ownedRef: false);
}

return result;
Expand Down

0 comments on commit 5284066

Please sign in to comment.