Skip to content

Commit a40015b

Browse files
authored
Merge pull request #238 from jmert/linux_glfw3.4
Add new `InitHint` API and constants & use on Linux to prefer X11
2 parents 7d50716 + a500f3b commit a40015b

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = "3.4.2"
77
GLFW_jll = "0656b61e-2033-5cc2-a64a-77c0f6c09b89"
88

99
[compat]
10-
GLFW_jll = "3.3.3"
10+
GLFW_jll = "3.4"
1111
julia = "1.3.0"
1212

1313
[extras]

src/glfw3.jl

+74-13
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ end
204204
NO_WINDOW_CONTEXT = 0x0001000A # The specified window does not have an OpenGL or OpenGL ES context.
205205
end
206206

207+
# Init Hints
208+
const JOYSTICK_HAT_BUTTONS = 0x00050001
209+
const ANGLE_PLATFORM_TYPE = 0x00050002
210+
const PLATFORM = 0x00050003
211+
const COCOA_CHDIR_RESOURCES = 0x00051001
212+
const COCOA_MENUBAR = 0x00051002
213+
const X11_XCB_VULKAN_SURFACE = 0x00052001
214+
const WAYLAND_LIBDECOR = 0x00053001
215+
216+
# Window Hints
207217
const FOCUSED = 0x00020001
208218
const ICONIFIED = 0x00020002
209219
const RESIZABLE = 0x00020003
@@ -216,7 +226,17 @@ const CENTER_CURSOR = 0x00020009
216226
const TRANSPARENT_FRAMEBUFFER = 0x0002000A
217227
const HOVERED = 0x0002000B
218228
const FOCUS_ON_SHOW = 0x0002000C
219-
229+
const SCALE_TO_MONITOR = 0x0002200C
230+
const SCALE_FRAMEBUFFER = 0x0002200D
231+
const COCOA_FRAME_NAME = 0x00023002
232+
const COCOA_GRAPHICS_SWITCHING = 0x00023003
233+
const X11_CLASS_NAME = 0x00024001
234+
const X11_INSTANCE_NAME = 0x00024002
235+
const WIN32_KEYBOARD_MENU = 0x00025001
236+
const WIN32_SHOWDEFAULT = 0x00025002
237+
const WAYLAND_APP_ID = 0x00026001
238+
239+
# Framebuffer Hints
220240
const RED_BITS = 0x00021001
221241
const GREEN_BITS = 0x00021002
222242
const BLUE_BITS = 0x00021003
@@ -246,8 +266,6 @@ const CONTEXT_RELEASE_BEHAVIOR = 0x00022009
246266
const CONTEXT_NO_ERROR = 0x0002200A
247267
const CONTEXT_CREATION_API = 0x0002200B
248268

249-
const SCALE_TO_MONITOR = 0x0002200C
250-
251269
const OPENGL_API = 0x00030001
252270
const OPENGL_ES_API = 0x00030002
253271
const NO_API = 0
@@ -274,22 +292,54 @@ const RELEASE_BEHAVIOR_NONE = 0x00035002
274292

275293
const NATIVE_CONTEXT_API = 0x00036001
276294
const EGL_CONTEXT_API = 0x00036002
295+
const OSMESA_CONTEXT_API = 0x00036003
296+
297+
@enum AnglePlatform::Cint begin
298+
ANGLE_PLATFORM_TYPE_NONE = 0x00037001
299+
ANGLE_PLATFORM_TYPE_OPENGL = 0x00037002
300+
ANGLE_PLATFORM_TYPE_OPENGLES = 0x00037003
301+
ANGLE_PLATFORM_TYPE_D3D9 = 0x00037004
302+
ANGLE_PLATFORM_TYPE_D3D11 = 0x00037005
303+
ANGLE_PLATFORM_TYPE_VULKAN = 0x00037007
304+
ANGLE_PLATFORM_TYPE_METAL = 0x00037008
305+
end
306+
307+
@enum WaylandLibdecor::Cint begin
308+
WAYLAND_PREFER_LIBDECOR = 0x00038001
309+
WAYLAND_DISABLE_LIBDECOR = 0x00038002
310+
end
277311

278312
# Standard cursor shapes
279313
@enum StandardCursorShape::Cint begin
280314
ARROW_CURSOR = 0x00036001
281315
IBEAM_CURSOR = 0x00036002
282316
CROSSHAIR_CURSOR = 0x00036003
283-
HAND_CURSOR = 0x00036004
284-
HRESIZE_CURSOR = 0x00036005
285-
VRESIZE_CURSOR = 0x00036006
286-
end
317+
POINTING_HAND_CURSOR = 0x00036004
318+
RESIZE_EW_CURSOR = 0x00036005
319+
RESIZE_NS_CURSOR = 0x00036006
320+
RESIZE_NWSE_CURSOR = 0x00036007
321+
RESIZE_NESW_CURSOR = 0x00036008
322+
RESIZE_ALL_CURSOR = 0x00036009
323+
NOT_ALLOWED_CURSOR = 0x0003600A
324+
end
325+
const HAND_CURSOR = POINTING_HAND_CURSOR
326+
const HRESIZE_CURSOR = RESIZE_EW_CURSOR
327+
const VRESIZE_CURSOR = RESIZE_NS_CURSOR
287328

288329
@enum DeviceConfigEvent::Cint begin
289330
CONNECTED = 0x00040001
290331
DISCONNECTED = 0x00040002
291332
end
292333

334+
@enum Platform::Cint begin
335+
ANY_PLATFORM = 0x00060000
336+
PLATFORM_WIN32 = 0x00060001
337+
PLATFORM_COCOA = 0x00060002
338+
PLATFORM_WAYLAND = 0x00060003
339+
PLATFORM_X11 = 0x00060004
340+
PLATFORM_NULL = 0x00060005
341+
end
342+
293343
const DONT_CARE = -1
294344

295345
#************************************************************************
@@ -444,7 +494,11 @@ const INITIALIZED = Ref(false)
444494
is_initialized() = INITIALIZED[]
445495

446496
# Initialization and version information
447-
function Init()
497+
InitHint(hint, value) = ccall((:glfwInitHint, libglfw), Cvoid, (Cint, Cint), hint, value)
498+
499+
function Init(; platform::Platform = @static Sys.islinux() ? PLATFORM_X11 : ANY_PLATFORM)
500+
# TODO: Resolve why trying Wayland backend causes errors
501+
InitHint(PLATFORM, platform)
448502
INITIALIZED[] = Bool(ccall((:glfwInit, libglfw), Cint, ())) || error("glfwInit failed")
449503
end
450504

@@ -455,6 +509,9 @@ end
455509

456510
GetVersionString() = unsafe_string(ccall((:glfwGetVersionString, libglfw), Cstring, ()))
457511

512+
GetPlatform() = ccall((:glfwGetPlatform, libglfw), Platform, ())
513+
PlatformSupported(platform::Platform) = ccall((:glfwPlatformSupported, libglfw), Cint, (Platform,), platform) == 1
514+
458515
# Error handling
459516
@callback Error(code::Cint, description::Cstring) -> (GLFWError(code, unsafe_string(description)),)
460517

@@ -538,7 +595,7 @@ Set the window icon, where a single image may be passed or a vector of images wi
538595
The images must be of RGBA format. Before calling this function it might be necessary to reinterpret the image
539596
as a matrix of element type NTuple{4, UInt8} if the icons are loaded with type RGBA{N0f8}
540597
541-
Note that this is implemented as a no-op on MacOS since that platform does not have the concept of a window icon.
598+
This is implemented as a no-op on MacOS and Wayland.
542599
543600
# Examples
544601
```julia-repl
@@ -552,15 +609,19 @@ GLFW.PollEvents() # needs a poll events to become active
552609
SetWindowIcon
553610

554611
function SetWindowIcon(window::Window, images::Vector{<:AbstractMatrix{NTuple{4,UInt8}}})
555-
if !Sys.isapple()
556-
ccall((:glfwSetWindowIcon, libglfw), Cvoid, (Window, Cint, Ref{GLFWImage}), window, length(images), images)
612+
platform = GetPlatform()
613+
if platform == PLATFORM_WAYLAND || platform == PLATFORM_COCOA
614+
return
557615
end
616+
ccall((:glfwSetWindowIcon, libglfw), Cvoid, (Window, Cint, Ref{GLFWImage}), window, length(images), images)
558617
end
559618

560619
function SetWindowIcon(window::Window, image::AbstractMatrix{NTuple{4,UInt8}})
561-
if !Sys.isapple()
562-
ccall((:glfwSetWindowIcon, libglfw), Cvoid, (Window, Cint, Ref{GLFWImage}), window, 1, image)
620+
platform = GetPlatform()
621+
if platform == PLATFORM_WAYLAND || platform == PLATFORM_COCOA
622+
return
563623
end
624+
ccall((:glfwSetWindowIcon, libglfw), Cvoid, (Window, Cint, Ref{GLFWImage}), window, 1, image)
564625
end
565626

566627
function GetWindowPos(window::Window)

0 commit comments

Comments
 (0)