Skip to content

Commit

Permalink
Update for gtk-4.14
Browse files Browse the repository at this point in the history
  • Loading branch information
rhx committed Apr 21, 2024
1 parent 85b4f82 commit 41a778a
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 31 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, 2017, 2018, 2019 Rene Hexel
Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Rene Hexel
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ After that, use the (usual) Build and Test buttons to build/test this package.
To build, download Swift from https://swift.org/download/ -- if you are using macOS, make sure you have the command line tools installed as well). Test that your compiler works using `swift --version`, which should give you something like

$ swift --version
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

on macOS, or on Linux you should get something like:

$ swift --version
Swift version 5.9 (swift-5.9-RELEASE)
Swift version 5.10 (swift-5.10-RELEASE)
Target: x86_64-unknown-linux-gnu

### Gtk 3.22 or higher

The Swift wrappers have been tested with glib-2.56, 2.58, 2.60, 2.62, 2.64, 2.66, 2.68, 2.70, 2.72, 2.74, 2.76 and 2.78, and gdk/gtk 3.22, 3.24 as well as 4.0, 4.2, 4.4, 4.6, 4.8, and 4.10 on the `gtk4` branch. They should work with higher versions, but YMMV. Also make sure you have `gobject-introspection` and its `.gir` files installed.
The Swift wrappers have been tested with glib-2.56, 2.58, 2.60, 2.62, 2.64, 2.66, 2.68, 2.70, 2.72, 2.74, 2.76, 2.78 and 2.80, and gdk/gtk 3.22, 3.24 as well as 4.0, 4.2, 4.4, 4.6, 4.8, 4.10, 4.12, and 4.14 on the `gtk4` branch. They should work with higher versions, but YMMV. Also make sure you have `gobject-introspection` and its `.gir` files installed.

#### Linux

Expand Down
16 changes: 16 additions & 0 deletions Sources/CGLib/glib_bridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <glib/gversionmacros.h>
#undef __GLIB_H_INSIDE__

struct _GAllocator {};
struct _GAsyncQueue {};
struct _GBookmarkFile {};
struct _GBinding {};
struct _GBytes {};
struct _GCache {};
struct _GChecksum {};
struct _GData {};
struct _GDatagramBased {};
Expand All @@ -21,6 +23,7 @@ struct _GMainLoop {};
struct _GMappedFile {};
struct _GMarkupParseContext {};
struct _GMatchInfo {};
struct _GMemChunk {};
struct _GMemoryMonitor {};
struct _GModule {};
struct _GMutexLocker {};
Expand All @@ -31,6 +34,7 @@ struct _GPatternSpec {};
struct _GPowerProfileMonitor {};
struct _GRand {};
struct _GRegex {};
struct _GRelation {};
struct _GSequence {};
struct _GSequenceNode {};
struct _GSequenceIter {};
Expand Down Expand Up @@ -368,3 +372,15 @@ typedef GUriParamsFlags GURIParamsFlags;
typedef GUriHideFlags GURIHideFlags;
typedef struct _GTreeNode GTreeNode;
typedef struct _GStrvBuilder GStrvBuilder;

#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 80
extern GType g_threaded_resolver_get_type(void);

struct _GThreadedResolver {};
struct _GThreadedResolverClass
{
GResolverClass parent_class;
};
typedef struct _GThreadedResolver GThreadedResolver;
typedef struct _GThreadedResolverClass GThreadedResolverClass;
#endif
184 changes: 178 additions & 6 deletions Sources/GLib/GLib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ extension LogLevelFlags: Hashable {}
/// - level: log level (defaults to `.debug`)
@inlinable public func g_log(messagePtr: UnsafePointer<CChar>?, level: LogLevelFlags = .debug) {
guard let msg = messagePtr else { return }
#if swift(<5.2)
#if swift(<5.2)
g_logv(nil, level.value, msg, CVaListPointer(_fromUnsafeMutablePointer: UnsafeMutableRawPointer(mutating: msg)))
#else
#else
guard GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 50 else {
print(String(cString: msg))
return
Expand All @@ -161,7 +161,7 @@ extension LogLevelFlags: Hashable {}
logStructuredArray(logLevel: level, fields: &fields, nFields: fields.count)
}
}
#endif
#endif
}

/// Logging function
Expand All @@ -178,9 +178,9 @@ extension LogLevelFlags: Hashable {}
withUnsafeMutableBytes(of: &buffer) {
guard let buffer = $0.baseAddress else { return }
let msg = buffer.assumingMemoryBound(to: CChar.self)
#if swift(<5.2)
#if swift(<5.2)
g_logv(domain, level.value, msg, CVaListPointer(_fromUnsafeMutablePointer: buffer))
#else
#else
guard GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 50 else {
print(message)
return
Expand All @@ -199,7 +199,7 @@ extension LogLevelFlags: Hashable {}
}
}
}
#endif
#endif
}
}
#endif
Expand All @@ -216,3 +216,175 @@ extension LogLevelFlags: Hashable {}
g_log(message, level: .warning)
}
}

#if os(macOS) || os(Linux)
/// Change the mode oft a filesystem object.
///
/// This function is a wrapper around the `chmod()` system call,
/// changing the mode of the filesystem object pointed to by `path`.
///
/// - Parameters:
/// - path: The filesystem path of the object to query.
/// - mode: The new mode for the object.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_chmod(_ path: UnsafePointer<CChar>, _ mode: gint) -> CInt {
return chmod(path, mode_t(mode))
}

/// Create a file.
///
/// This function is a wrapper around the `creat()` system call,
/// creating a filesystem object pointed to by `path`.
///
/// - Parameters:
/// - path: The filesystem path of the object to create.
/// - mode: The new mode for the object.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_creat(_ path: UnsafePointer<CChar>, _ mode: gint) -> CInt {
return creat(path, mode_t(mode))
}

/// Open or create a buiffered stream.
///
/// This function is a wrapper around the `fopen()` system call,
/// creating a filesystem stream object pointed to by `path`.
///
/// - Parameters:
/// - path: The filesystem path of the object to open.
/// - mode: The new mode for the object when created.
/// - Returns: a pointer to the new stream object, `nil` on error.
@inlinable
public func g_fopen(_ path: UnsafePointer<CChar>, _ mode: UnsafePointer<CChar>) -> UnsafeMutablePointer<FILE>? {
return fopen(path, mode)
}

/// Repen a buiffered stream.
///
/// This function is a wrapper around the `freopen()` system call,
/// reopening a filesystem stream object pointed to by `path` and
/// associates the stream with the given file pointer.
///
/// - Parameters:
/// - path: The filesystem path of the object to open.
/// - mode: The new mode for the object when created.
/// - stream: The stream to associate with the file pointer.
/// - Returns: a pointer to the stream object, `nil` on error.
@inlinable
public func g_freopen(_ path: UnsafePointer<CChar>, _ mode: UnsafePointer<CChar>, _ stream: UnsafeMutablePointer<FILE>!) -> UnsafeMutablePointer<FILE>? {
return freopen(path, mode, stream)
}

/// Syncronize a filesystem object.
///
/// This function is a wrapper around the `fsync()` system call,
/// synchronising the files descriptor passed in.
///
/// - Parameters:
/// - fileDescriptor: The file descriptor to syncronise.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_fsync(_ fileDescriptor: CInt) -> CInt {
return fsync(fileDescriptor)
}

/// Get information about a filesystem object.
///
/// This function is a wrapper around the `lstat()` system call,
/// returning information about the file pointed to by `path`,
/// without following symbolic links.
///
/// - Parameters:
/// - path: The filesystem path of the object to query.
/// - buf: A `GStatBuf` structure to fill in with information about the file.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_lstat(_ path: UnsafePointer<CChar>, _ buf: UnsafeMutablePointer<GStatBuf>!) -> CInt {
return lstat(path, buf)
}

/// Create a directory.
///
/// This function is a wrapper around the `mkdir()` system call,
/// creating a directory pointed to by `path`.
///
/// - Parameters:
/// - path: The filesystem path of the directory to create.
/// - mode: The new mode for the directory.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_mkdir(_ path: UnsafePointer<CChar>, _ mode: gint) -> CInt {
return mkdir(path, mode_t(mode))
}

/// Open a file.
///
/// This function is a wrapper around the `open()` system call,
/// opening a filesystem object pointed to by `path`.
///
/// - Parameters:
/// - path: The filesystem path of the object to open.
/// - flags: The flags to use when opening the object.
/// - mode: The new mode for the object.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_open(_ path: UnsafePointer<CChar>, _ flags: CInt, _ mode: gint = 0) -> CInt {
return open(path, flags, mode_t(mode))
}

/// Remove a filesystem object.
///
/// This function is a wrapper around the `remove()` system call,
/// removing the filesystem object pointed to by `path`.
///
/// - Parameter path: The filesystem path of the object to remove.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_remove(_ path: UnsafePointer<CChar>) -> CInt {
return remove(path)
}

/// Rename a filesystem object.
///
/// This function is a wrapper around the `rename()` system call,
/// renaming the filesystem object pointed to by `old` to `new`.
///
/// - Parameters:
/// - old: The old filesystem path.
/// - new: The new filesystem path.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_rename(_ old: UnsafePointer<CChar>, _ new: UnsafePointer<CChar>) -> CInt {
return rename(old, new)
}

/// Get information about a filesystem object.
///
/// This function is a wrapper around the `stat()` system call,
/// returning information about the file pointed to by `path`.
///
/// - Parameters:
/// - path: The filesystem path of the object to query.
/// - buf: A `GStatBuf` structure to fill in with information about the file.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_stat(_ path: UnsafePointer<CChar>, _ buf: UnsafeMutablePointer<GStatBuf>!) -> CInt {
return stat(path, buf)
}

/// Set filesystem object times.
///
/// This function is a wrapper around the `utime()` system call,
/// setting time information about the file pointed to by `path`.
///
/// - Parameters:
/// - path: The filesystem path of the object to query.
/// - times: Pointer to a`utimbuf` structure with information about the file access and modification times.
/// - Returns: `0` on success, `-1` on error.
@inlinable
public func g_utime(_ path: UnsafePointer<CChar>, _ times: UnsafePointer<utimbuf>!) -> CInt {
return utime(path, times)
}
#endif

2 changes: 2 additions & 0 deletions Sources/GLibObject/GObject-2.0.exclude
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
VaClosureMarshal
SignalCVaMarshaller
signalSetVaMarshaller
IOCondition

4 changes: 4 additions & 0 deletions Sources/GModule/GModule-2.0.verbatim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODULE_IMPL_AR
MODULE_IMPL_DL
MODULE_IMPL_NONE
MODULE_IMPL_WIN32
43 changes: 22 additions & 21 deletions Sources/Gtk/Gtk-3.0.awk
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
BEGIN { depr_init = 0 ; comment = 0 ; slist = 0 ; overr = 0 ; ostock = 0 ;
no_fields = 0 ; close_comment = 0; icon_size = 0 ; grp = 0
}
/Creates a new `GtkRecentChooserMenu` widget\.$/ { overr = 1 }
/Creates a new ``RecentChooserMenu`` widget\.$/ { overr = 1 }
/a swatch representing the current selected color. When the button/ { overr = 1 }
#/Creates a new dialog box/ { overr = 1 }
/Creates a new font picker widget/ { overr = 1 }
/Creates a new toggle button/ { overr = 1 }
/Creates a new GtkModelButton/ { overr = 1 ; sub("GtkModelButton", "`GtkModelButton`") }
/Creates a new `GtkAboutDialog`\.$/ { overr = 1 }
/Creates a new `GtkCellRendererAccel`/ { overr = 1 }
/Creates a new `GtkCellRendererCombo`/ { overr = 1 }
/Creates a new `GtkCellRendererSpin`/ { overr = 1 }
/Creates a new `GtkCheckButton`/ { overr = 1 }
/Creates a new `GtkCheckMenuItem`/ { overr = 1 }
/Creates a new `GtkComboBoxText`/ { overr = 1 }
/Creates a new `GtkImageMenuItem` with an empty label/ { overr = 1 }
/Creates a new `GtkImageMenuItem` containing a label/ { overr = 1 }
/Creates a new `GtkMenuButton`/ { overr = 1 }
/Creates a new `GtkMenuToolButton`/ { overr = 1 }
/Creates a `GtkSearchEntry`/ { overr = 1 }
/Creates a new `GtkSeparatorMenuItem`/ { overr = 1 }
/Create a new `GtkSeparatorToolItem`/ { overr = 1 }
/Creates a new `GtkTearoffMenuItem`/ { overr = 1 }
/Creates a new `GtkToggleAction`/ { overr = 1 }
/Creates a new `GtkToggleButton`/ { overr = 1 }
/Creates a new `GtkToggleToolButton`/ { overr = 1 }
/Creates a new `GtkRecentAction`/ { ostock = 1 }
/Creates a new GtkModelButton/ { overr = 1 ; sub("GtkModelButton", "``ModelButton``") }
/Create a new GtkSeparatorToolItem/ { overr = 1 ; sub("GtkSeparatorToolItem", "``SeparatorToolItem``.") }
/Creates a new ``AboutDialog``\.$/ { overr = 1 }
/Creates a new ``CellRendererAccel`/ { overr = 1 }
/Creates a new ``CellRendererCombo`/ { overr = 1 }
/Creates a new ``CellRendererSpin`/ { overr = 1 }
/Creates a new ``CheckButton`/ { overr = 1 }
/Creates a new ``CheckMenuItem`/ { overr = 1 }
/Creates a new ``ComboBoxText`/ { overr = 1 }
/Creates a new ``ImageMenuItem`` with an empty label/ { overr = 1 }
/Creates a new ``ImageMenuItem`` containing a label/ { overr = 1 }
/Creates a new ``MenuButton`/ { overr = 1 }
/Creates a new ``MenuToolButton`/ { overr = 1 }
/Creates a ``SearchEntry`/ { overr = 1 }
/Creates a new ``SeparatorMenuItem`/ { overr = 1 }
/Create a new ``SeparatorToolItem`/ { overr = 1 }
/Creates a new ``TearoffMenuItem`/ { overr = 1 }
/Creates a new ``ToggleAction`/ { overr = 1 }
/Creates a new ``ToggleButton`/ { overr = 1 }
/Creates a new ``ToggleToolButton`/ { overr = 1 }
/Creates a new ``RecentAction`/ { ostock = 1 }
/ the file belongs to/ { grp = 1 }
/open .* ColorSelection/ { depr_init = 1 }
/public .* ColorSelection/ { depr_init = 1 }
Expand Down

0 comments on commit 41a778a

Please sign in to comment.