Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore SetWindowIcon calls on MacOS #237

Merged
Merged
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
10 changes: 8 additions & 2 deletions src/glfw3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ Set the window icon, where a single image may be passed or a vector of images wi
The images must be of RGBA format. Before calling this function it might be necessary to reinterpret the image
as a matrix of element type NTuple{4, UInt8} if the icons are loaded with type RGBA{N0f8}

Note that this is implemented as a no-op on MacOS since that platform does not have the concept of a window icon.

# Examples
```julia-repl
using FileIO
Expand All @@ -550,11 +552,15 @@ GLFW.PollEvents() # needs a poll events to become active
SetWindowIcon

function SetWindowIcon(window::Window, images::Vector{<:AbstractMatrix{NTuple{4,UInt8}}})
ccall((:glfwSetWindowIcon, libglfw), Cvoid, (Window, Cint, Ref{GLFWImage}), window, length(images), images)
if !Sys.isapple()
ccall((:glfwSetWindowIcon, libglfw), Cvoid, (Window, Cint, Ref{GLFWImage}), window, length(images), images)
end
end

function SetWindowIcon(window::Window, image::AbstractMatrix{NTuple{4,UInt8}})
ccall((:glfwSetWindowIcon, libglfw), Cvoid, (Window, Cint, Ref{GLFWImage}), window, 1, image)
if !Sys.isapple()
ccall((:glfwSetWindowIcon, libglfw), Cvoid, (Window, Cint, Ref{GLFWImage}), window, 1, image)
end
end

function GetWindowPos(window::Window)
Expand Down
31 changes: 21 additions & 10 deletions test/windowclose.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
using GLFW, Test

window = GLFW.CreateWindow(800, 600, "InexactError")
@test !GLFW.WindowShouldClose(window)
# If you call the julia function GLFW.SetWindowShouldClose(window,
# truefalse), then only 0 or 1 can be passed. However, at least on
# some platforms (Linux), clicking on the window's close icon can send
# other values (like 189). Make sure such values don't cause trouble for
# GLFW.WindowShouldClose.
ccall((:glfwSetWindowShouldClose, GLFW.libglfw), Cvoid, (GLFW.Window, Cint), window, 189)
@test GLFW.WindowShouldClose(window)
GLFW.DestroyWindow(window)
@testset "WindowShouldClose" begin
window = GLFW.CreateWindow(800, 600, "InexactError")
@test !GLFW.WindowShouldClose(window)
# If you call the julia function GLFW.SetWindowShouldClose(window,
# truefalse), then only 0 or 1 can be passed. However, at least on
# some platforms (Linux), clicking on the window's close icon can send
# other values (like 189). Make sure such values don't cause trouble for
# GLFW.WindowShouldClose.
ccall((:glfwSetWindowShouldClose, GLFW.libglfw), Cvoid, (GLFW.Window, Cint), window, 189)
@test GLFW.WindowShouldClose(window)
GLFW.DestroyWindow(window)
end

@testset "SetWindowIcon" begin
window = GLFW.CreateWindow(800, 600, "InexactError")
icon = reshape([repeat([(0x00, 0x00, 0x00, 0x00)], 128 * 128)...], (128,128))
# 2 methods, test both:
GLFW.SetWindowIcon(window, icon)
GLFW.SetWindowIcon(window, [icon])
GLFW.DestroyWindow(window)
end
Loading