Compare commits
37 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
ead863266a | |
![]() |
07a5d51c59 | |
![]() |
e64bddd156 | |
![]() |
27108bf7fd | |
![]() |
acd6474395 | |
![]() |
301045cfd1 | |
![]() |
7c85242bac | |
![]() |
ef01ddc3e6 | |
![]() |
1a171d94f5 | |
![]() |
b99487564d | |
![]() |
f6aff61e0b | |
![]() |
997be8823c | |
![]() |
32b698bf37 | |
![]() |
a31337c988 | |
![]() |
56bfa03c14 | |
![]() |
b88a5fa75e | |
![]() |
f6358ff6a1 | |
![]() |
c8e02d8e82 | |
![]() |
e5dc13f81a | |
![]() |
b2748cf993 | |
![]() |
be0061a24d | |
![]() |
840814bcab | |
![]() |
0ccefaaf30 | |
![]() |
b735367bea | |
![]() |
8aa51ac16a | |
![]() |
cd0020c8e5 | |
![]() |
fe601105d9 | |
![]() |
9b6075b2b1 | |
![]() |
d7e6f6fa71 | |
![]() |
9b5706579c | |
![]() |
e142850e49 | |
![]() |
5da6aab77c | |
![]() |
0c4ddc932f | |
![]() |
46dc1273a8 | |
![]() |
f6271a136c | |
![]() |
7950d45d26 | |
![]() |
3f9ecf8e9f |
|
@ -17,3 +17,13 @@ s/gdk_selection_property_get(requestor.window_ptr, data, _ptr, propFormat)/gdk_s
|
|||
s/\(@available(., deprecated) @inlinable\) \(public init() {\)/\1 override \2/
|
||||
s/gdk_gl_context_set_use_es(gl_context_ptr, gint(newValue))/gdk_gl_context_set_use_es(gl_context_ptr, newValue ? 1 : 0)/
|
||||
s/_ptr.pointee.state = newValue.value/_ptr.pointee.state = newValue.rawValue/
|
||||
s/\(gdk_crossing_event.*\)crossing_\(event_ptr\)/\1\2/
|
||||
s/\(gdk_button_event.*\)button_\(event_ptr\)/\1\2/
|
||||
s/\(gdk_dnd_event.*\)dnd_\(event_ptr\)/\1\2/
|
||||
s/\(gdk_focus_event.*\)focus_\(event_ptr\)/\1\2/
|
||||
s/\(gdk_grab_broken_event.*\)grab_broken_\(event_ptr\)/\1\2/
|
||||
s/\(gdk_key_event.*\)key_\(event_ptr\)/\1\2/
|
||||
s/\(gdk_pad_event.*\)pad_\(event_ptr\)/\1\2/
|
||||
s/\(gdk_scroll_event.*\)scroll_\(event_ptr\)/\1\2/
|
||||
s/\(gdk_touch.*_event.*\)touch.*_\(event_ptr\)/\1\2/
|
||||
|
|
@ -12,10 +12,10 @@ let package = Package(
|
|||
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.systemLibrary(name: "CGdk", pkgConfig: "gdk-3.0",
|
||||
.systemLibrary(name: "CGdk", pkgConfig: "gtk4",
|
||||
providers: [
|
||||
.brew(["gtk+3", "glib", "glib-networking", "gobject-introspection"]),
|
||||
.apt(["libgtk-3-dev", "libglib2.0-dev", "glib-networking", "gobject-introspection", "libgirepository1.0-dev"])
|
||||
.brew(["gtk4", "glib", "glib-networking", "gobject-introspection"]),
|
||||
.apt(["libgtk-4-dev", "libglib2.0-dev", "glib-networking", "gobject-introspection", "libgirepository1.0-dev"])
|
||||
]),
|
||||
.target(
|
||||
name: "Gdk",
|
||||
|
|
15
README.md
15
README.md
|
@ -23,18 +23,18 @@ Version 15 of gir2swift provides a Package Manager Plugin. This requires Swift
|
|||
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.45.2 Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
|
||||
Target: x86_64-apple-darwin20.3.0
|
||||
swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
|
||||
Target: x86_64-apple-macosx12.0
|
||||
|
||||
on macOS, or on Linux you should get something like:
|
||||
|
||||
$ swift --version
|
||||
Swift version 5.6.1 (swift-5.6.1-RELEASE)
|
||||
Swift version 5.7.3 (swift-5.7.3-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 and 2.72, and gdk/gtk 3.22 and 3.24 as well as 4.0, 4.2, 4.4, and 4.6 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 and 2.72, and gdk/gtk 3.22 and 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.
|
||||
|
||||
#### Linux
|
||||
|
||||
|
@ -56,7 +56,7 @@ On Fedora, you can use the gtk that comes with the distribution. Just install w
|
|||
On macOS, you can install gdk and gtk using HomeBrew (for setup instructions, see http://brew.sh). Once you have a running HomeBrew installation, you can use it to install a native version of gtk:
|
||||
|
||||
brew update
|
||||
brew install gtk+3 glib glib-networking gobject-introspection pkg-config
|
||||
brew install gtk4 glib glib-networking gobject-introspection pkg-config
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -70,7 +70,7 @@ import PackageDescription
|
|||
let package = Package(name: "MyPackage",
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/rhx/gir2swift.git", branch: "main"),
|
||||
.package(url: "https://github.com/rhx/SwiftGdk.git", branch: "gtk3"),
|
||||
.package(url: "https://github.com/rhx/SwiftGdk.git", branch: "gtk4"),
|
||||
],
|
||||
targets: [
|
||||
.target(name: "MyPackage",
|
||||
|
@ -82,7 +82,7 @@ let package = Package(name: "MyPackage",
|
|||
)
|
||||
```
|
||||
|
||||
For gtk4 replace `.branch("gtk3")` with `.branch("gtk4")`.
|
||||
For gtk3 replace `.branch("gtk4")` with `.branch("gtk3")`.
|
||||
|
||||
## Building
|
||||
|
||||
|
@ -104,7 +104,6 @@ On macOS, you can build the project using Xcode instead. To do this, you need t
|
|||
After that, use the (usual) Build and Test buttons to build/test this package.
|
||||
|
||||
## Documentation
|
||||
|
||||
You can generate documentation using the [DocC plugin](https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/). To preview documentation matching your local installation, simply run
|
||||
|
||||
swift package --disable-sandbox preview-documentation
|
||||
|
|
|
@ -1,23 +1,41 @@
|
|||
struct _GdkAppLaunchContext {};
|
||||
struct _GdkAtom {};
|
||||
struct _GdkAxisUse {};
|
||||
struct _GdkButtonEvent {};
|
||||
struct _GdkByteOrder {};
|
||||
struct _GdkCairoContext {};
|
||||
struct _GdkClipboard {};
|
||||
struct _GdkContentDeserializer {};
|
||||
struct _GdkContentFormats {};
|
||||
struct _GdkContentFormatsBuilder {};
|
||||
struct _GdkContentSerializer {};
|
||||
struct _GdkCrossingEvent {};
|
||||
struct _GdkCrossingMode {};
|
||||
struct _GdkCursor {};
|
||||
struct _GdkCursorType {};
|
||||
struct _GdkDNDEvent {};
|
||||
struct _GdkDeleteEvent {};
|
||||
struct _GdkDevice {};
|
||||
struct _GdkDeviceManager {};
|
||||
struct _GdkDeviceType {};
|
||||
struct _GdkDisplay {};
|
||||
struct _GdkDisplayManager {};
|
||||
struct _GdkDrag {};
|
||||
struct _GdkDragAction {};
|
||||
struct _GdkDragContext {};
|
||||
struct _GdkDragProtocol {};
|
||||
struct _GdkDragSurface {};
|
||||
struct _GdkDragSurfaceInterface {};
|
||||
struct _GdkDrawContext {};
|
||||
struct _GdkDrop {};
|
||||
struct _GdkEvent {};
|
||||
struct _GdkEventFunc {};
|
||||
struct _GdkEventMask {};
|
||||
struct _GdkEventSequence {};
|
||||
struct _GdkFileList {};
|
||||
struct _GdkFilterFunc {};
|
||||
struct _GdkFilterReturn {};
|
||||
struct _GdkFocusEvent {};
|
||||
struct _GdkFrameClock {};
|
||||
struct _GdkFrameClockClass {};
|
||||
struct _GdkFrameClockPhase {};
|
||||
|
@ -26,28 +44,56 @@ struct _GdkFrameTimings {};
|
|||
struct _GdkFullscreenMode {};
|
||||
struct _GdkGLContext {};
|
||||
struct _GdkGLError {};
|
||||
struct _GdkGLTexture {};
|
||||
struct _GdkGLTextureClass {};
|
||||
struct _GdkGrabBrokenEvent {};
|
||||
struct _GdkGrabOwnership {};
|
||||
struct _GdkGrabStatus {};
|
||||
struct _GdkGravity {};
|
||||
struct _GdkInputMode {};
|
||||
struct _GdkInputSource {};
|
||||
struct _GdkKeyEvent {};
|
||||
struct _GdkKeymap {};
|
||||
struct _GdkMemoryTexture {};
|
||||
struct _GdkMemoryTextureClass {};
|
||||
struct _GdkModifierIntent {};
|
||||
struct _GdkModifierType {};
|
||||
struct _GdkMotionEvent {};
|
||||
struct _GdkNotifyType {};
|
||||
struct _GdkOwnerChange {};
|
||||
struct _GdkPadEvent {};
|
||||
struct _GdkPaintable {};
|
||||
struct _GdkPixbuf {};
|
||||
struct _GdkPopup {};
|
||||
struct _GdkPopupInterface {};
|
||||
struct _GdkPopupLayout {};
|
||||
struct _GdkPropMode {};
|
||||
struct _GdkPropertyState {};
|
||||
struct _GdkProximityEvent {};
|
||||
struct _GdkRectangle {};
|
||||
struct _GdkScreen {};
|
||||
struct _GdkScrollDirection {};
|
||||
struct _GdkScrollEvent {};
|
||||
struct _GdkSettingAction {};
|
||||
struct _GdkSnapshot {};
|
||||
struct _GdkSnapshotClass {};
|
||||
struct _GdkStatus {};
|
||||
struct _GdkSurface {};
|
||||
struct _GdkSurfaceClass {};
|
||||
struct _GdkTexture {};
|
||||
struct _GdkTextureClass {};
|
||||
struct _GdkTextureDownloader {};
|
||||
struct _GdkToplevel {};
|
||||
struct _GdkToplevelInterface {};
|
||||
struct _GdkToplevelLayout {};
|
||||
struct _GdkToplevelSize {};
|
||||
struct _GdkTouchEvent {};
|
||||
struct _GdkTouchpadEvent {};
|
||||
struct _GdkTouchpadGesturePhase {};
|
||||
struct _GdkVisibilityState {};
|
||||
struct _GdkVisual {};
|
||||
struct _GdkVisualType {};
|
||||
struct _GdkVulkanContext {};
|
||||
struct _GdkWMDecoration {};
|
||||
struct _GdkWMFunction {};
|
||||
struct _GdkWindow {};
|
||||
|
@ -82,4 +128,9 @@ struct _GdkMonitorInterface {};
|
|||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkprivate.h>
|
||||
|
||||
#undef GDK_ACTION_ALL
|
||||
#define GDK_ACTION_ALL 7
|
||||
|
||||
#undef GDK_MODIFIER_MASK
|
||||
#define GDK_MODIFIER_MASK 0x1C001F0F
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module CGdk [system] {
|
||||
header "gdk_bridging.h"
|
||||
|
||||
link "gdk-3"
|
||||
link "gtk-4"
|
||||
link "pangocairo-1.0"
|
||||
link "pangoft2-1.0"
|
||||
link "fontconfig"
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
//
|
||||
// Gdk.swift
|
||||
// SwiftGdk
|
||||
//
|
||||
// Created by Rene Hexel on 3/6/16.
|
||||
// Copyright © 2016, 2018, 2021 Rene Hexel. All rights reserved.
|
||||
//
|
||||
import CGdk
|
||||
import GLib
|
||||
|
||||
/// A callback function or closure that runs on a different thread
|
||||
public typealias ThreadCallback = () -> Bool
|
||||
|
||||
/// A closure holder for a thread callback
|
||||
@usableFromInline typealias ThreadCallbackHolder = ClosureHolder<Void, Bool>
|
||||
|
||||
/// Adds a closure holder containing a closure or function
|
||||
/// to be called whenever there are no higher priority events pending.
|
||||
/// If the function returns false it is automatically removed
|
||||
/// from the list of event sources and will not be called again.
|
||||
/// - Parameters:
|
||||
/// - p: The priority to run, such as `PRIORITY_HIGH_IDLE`
|
||||
/// - data: the callback holder
|
||||
/// - handler: The handler wrapping the closure holder
|
||||
/// - Returns: The ID (greater than 0) of the event source.
|
||||
@usableFromInline func _threadsAddIdle(priority p: Int32 = PRIORITY_DEFAULT_IDLE, data: ThreadCallbackHolder, handler: @convention(c) @escaping (gpointer) -> gboolean) -> Int {
|
||||
let opaqueHolder = Unmanaged.passRetained(data).toOpaque()
|
||||
let callback = unsafeBitCast(handler, to: GSourceFunc.self)
|
||||
let rv = threadsAddIdleFull(priority: Int(p), function: callback, data: opaqueHolder, notify: {
|
||||
if let swift = $0 {
|
||||
let holder = Unmanaged<ThreadCallbackHolder>.fromOpaque(swift)
|
||||
holder.release()
|
||||
}
|
||||
})
|
||||
return rv
|
||||
}
|
||||
|
||||
/// Adds a closure or function to be called whenever there
|
||||
/// are no higher priority events pending.
|
||||
/// If the function returns false it is automatically removed
|
||||
/// from the list of event sources and will not be called again.
|
||||
/// - Parameters:
|
||||
/// - p: The priority to run, such as `PRIORITY_HIGH_IDLE`
|
||||
/// - callback: The callback function or closure to call
|
||||
/// - Returns: The ID (greater than 0) of the event source.
|
||||
@inlinable public func threadsAddIdle(priority p: Int32 = PRIORITY_DEFAULT_IDLE, callback: @escaping ThreadCallback) -> Int {
|
||||
let rv = _threadsAddIdle(data: ThreadCallbackHolder(callback)) {
|
||||
let holder = Unmanaged<ThreadCallbackHolder>.fromOpaque($0).takeUnretainedValue()
|
||||
let rv: gboolean = holder.call(()) ? 1 : 0
|
||||
return rv
|
||||
}
|
||||
return rv
|
||||
}
|
|
@ -1,31 +1,10 @@
|
|||
import XCTest
|
||||
import GLib
|
||||
@testable import Gdk
|
||||
|
||||
class GdkTests: XCTestCase {
|
||||
|
||||
func testEvent() {
|
||||
let event = Event(type: .keyPress)
|
||||
XCTAssertEqual(event.type, event.event_ptr.pointee.type)
|
||||
XCTAssertEqual(event.type, EventType.keyPress)
|
||||
// FIXME: implement gdk-4 tests
|
||||
func testEmpty() {
|
||||
}
|
||||
|
||||
func testEventType() {
|
||||
let doubleButton = EventType.doubleButtonPress
|
||||
XCTAssertEqual(doubleButton, EventType._2buttonPress)
|
||||
}
|
||||
|
||||
func testThreadsAddIdle() {
|
||||
let mainLoop = MainLoopRef(context: mainContextDefault(), isRunning: false)
|
||||
var done = false
|
||||
let id = threadsAddIdle(priority: PRIORITY_HIGH_IDLE) {
|
||||
done = true
|
||||
mainLoop.quit()
|
||||
return false
|
||||
}
|
||||
XCTAssertEqual(done, false)
|
||||
XCTAssertNotEqual(id, 0)
|
||||
mainLoop.run()
|
||||
XCTAssertEqual(done, true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
# Configuration for the module to compile, the Swift toolchain, and
|
||||
# the compiler and linker flags to use.
|
||||
#
|
||||
VER=3.0
|
||||
major=4
|
||||
VER=$major.0
|
||||
GLIB_VER=2.0
|
||||
JAZZY_VER=3.24.33
|
||||
JAZZY_VER=$major.6.2
|
||||
Mod=Gdk
|
||||
Module=${Mod}-$VER
|
||||
module=`echo "${Module}" | tr '[:upper:]' '[:lower:]'`
|
||||
|
@ -19,8 +20,8 @@ if [ -z "$BUILD_DIR" ]; then
|
|||
fi
|
||||
export PATH="${GIR2SWIFT_PATH}:${BUILD_DIR}/checkouts/gir2swift/.build/release:${BUILD_DIR}/checkouts/gir2swift/.build/debug:${PATH}:$PWD/.build/checkouts/gir2swift/.build/release:$PWD/.build/checkouts/gir2swift/.build/debug:${PATH}:/usr/local/opt/ruby/bin:`echo /usr/local/lib/ruby/gems/*/bin | tr ' ' '\n' | tail -n1`:${PATH}:`echo /var/lib/gems/*/gems/jazzy-*/bin/ | tr ' ' '\n' | tail -n1`:/usr/local/bin"
|
||||
export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig:${PKG_CONFIG_PATH}
|
||||
LINKFLAGS=`pkg-config --libs $module pangocairo pangoft2 pango gobject-$GLIB_VER gio-unix-$GLIB_VER glib-$GLIB_VER | tr ' ' '\n' | sed -e 's/^/-Xlinker /' -e 's/-Wl,//' | tr '\n' ' ' | sed -e 's/^/-Xlinker /' -e 's/-Wl,//g' -e 's/,/ -Xlinker /g' -e 's/ -pthread/ -lpthread/g' -e 's/-Xcc[ ]*-Xlinker/-Xlinker/g' -e 's/-Xlinker[ ]*-Xcc/-Xcc/g' -e 's/-Xlinker[ ]*--export-dynamic//g' -e 's/-Xlinker[ ]*-Xlinker/-Xlinker/g' -e 's/-Xcc *$//' -e 's/-Xlinker *$//'`
|
||||
CCFLAGS=`pkg-config --cflags $module pangocairo pangoft2 pango gobject-$GLIB_VER gio-unix-$GLIB_VER glib-$GLIB_VER | tr ' ' '\n' | sed 's/^/-Xcc /' | tr '\n' ' ' | sed -e 's/^/-Xlinker /' -e 's/-Wl,//g' -e 's/,/ -Xlinker /g' -e 's/ -pthread/ -lpthread/g' -e 's/-Xcc[ ]*-Xlinker/-Xlinker/g' -e 's/-Xlinker[ ]*-Xcc/-Xcc/g' -e 's/-Xlinker[ ]*--export-dynamic//g' -e 's/-Xlinker[ ]*-Xlinker/-Xlinker/g' -e 's/-Xcc *$//' -e 's/-Xlinker *$//'`
|
||||
LINKFLAGS=`pkg-config --libs gtk$major pangocairo pangoft2 pango gobject-$GLIB_VER gio-unix-$GLIB_VER glib-$GLIB_VER | tr ' ' '\n' | sed -e 's/^/-Xlinker /' -e 's/-Wl,//' | tr '\n' ' ' | sed -e 's/^/-Xlinker /' -e 's/-Wl,//g' -e 's/,/ -Xlinker /g' -e 's/ -pthread/ -lpthread/g' -e 's/-Xcc[ ]*-Xlinker/-Xlinker/g' -e 's/-Xlinker[ ]*-Xcc/-Xcc/g' -e 's/-Xlinker[ ]*--export-dynamic//g' -e 's/-Xlinker[ ]*-Xlinker/-Xlinker/g' -e 's/-Xcc *$//' -e 's/-Xlinker *$//'`
|
||||
CCFLAGS=`pkg-config --cflags gtk$major pangocairo pangoft2 pango gobject-$GLIB_VER gio-unix-$GLIB_VER glib-$GLIB_VER | tr ' ' '\n' | sed 's/^/-Xcc /' | tr '\n' ' ' | sed -e 's/^/-Xlinker /' -e 's/-Wl,//g' -e 's/,/ -Xlinker /g' -e 's/ -pthread/ -lpthread/g' -e 's/-Xcc[ ]*-Xlinker/-Xlinker/g' -e 's/-Xlinker[ ]*-Xcc/-Xcc/g' -e 's/-Xlinker[ ]*--export-dynamic//g' -e 's/-Xlinker[ ]*-Xlinker/-Xlinker/g' -e 's/-Xcc *$//' -e 's/-Xlinker *$//'`
|
||||
TAC="tail -r"
|
||||
if which tac >/dev/null 2>&1 ; then
|
||||
TAC=tac
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#
|
||||
. ./config.sh
|
||||
if [ -z "$@" ]; then
|
||||
JAZZY_ARGS="--theme fullwidth --author René Hexel --author_url https://experts.griffith.edu.au/9237-rene-hexel --github_url https://github.com/rhx/Swift$Mod --github-file-prefix https://github.com/rhx/Swift$Mod/tree/generated --root-url http://rhx.github.io/Swift$Mod/ --output docs"
|
||||
JAZZY_ARGS="--theme fullwidth --author René Hexel --author_url https://experts.griffith.edu.au/9237-rene-hexel --github_url https://github.com/rhx/Swift$Mod --github-file-prefix https://github.com/rhx/Swift$Mod/tree/gtk4-generated --root-url http://rhx.github.io/Swift$Mod/ --output docs"
|
||||
fi
|
||||
[ -e "$BUILD_DIR/build.db" ] || ./build.sh
|
||||
rm -rf .docs.old
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
version: 1
|
||||
gir-name: Gdk-3.0
|
||||
pkg-config: gdk-3.0
|
||||
gir-name: Gdk-4.0
|
||||
pkg-config: gtk4
|
||||
output-directory: Sources/Gdk
|
||||
alpha-names: true
|
||||
|
|
Loading…
Reference in New Issue