Skip to content

Commit baadaa0

Browse files
committed
Fix incorrect button detail for virtual events
1 parent 79a7aff commit baadaa0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/testing.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,18 @@ function button_xcb(button::MouseButton)
4949
button == BUTTON_SCROLL_DOWN && return XCB_BUTTON_INDEX_5
5050
end
5151

52+
function detail_xcb_button(button::MouseButton)::xcb_button_t
53+
button == BUTTON_NONE && return 0
54+
button == BUTTON_LEFT && return 1
55+
button == BUTTON_MIDDLE && return 2
56+
button == BUTTON_RIGHT && return 3
57+
button == BUTTON_SCROLL_UP && return 4
58+
button == BUTTON_SCROLL_DOWN && return 5
59+
error("Unknown button $button")
60+
end
61+
5262
function detail_xcb(wm::XWindowManager, event::Event)
53-
event.type in BUTTON_EVENT && return xcb_button_t(iszero(event.mouse_event.button) ? 0 : log2(Int(event.mouse_event.button)))
63+
event.type in BUTTON_EVENT && return detail_xcb_button(event.mouse_event.button)
5464
event.type in KEY_EVENT && return PhysicalKey(wm.keymap, event.key_event.key_name).code
5565
event.type == POINTER_MOVED && return UInt8(XCB_MOTION_NORMAL)
5666
event.type == POINTER_ENTERED && return XCB_ENTER_NOTIFY
@@ -82,11 +92,11 @@ end
8292

8393
hex(x) = "0x$(string(x, base=16))"
8494

85-
function send_event(wm::XWindowManager, win::XCBWindow, event_type::EventType, data = nothing; location = (0.0, 0.0))
86-
send_event(wm, Event(event_type, data, location, floor(time()), win))
95+
function send_event(wm::XWindowManager, win::XCBWindow, event_type::EventType, data = nothing; location = (0.0, 0.0), time = time())
96+
send_event(wm, Event(event_type, data, location, time, win))
8797
end
8898

89-
send_event(wm::XWindowManager, win::XCBWindow) = (event_type, data = nothing; location = (0.0, 0.0)) -> send_event(wm, win, event_type, data; location)
99+
send_event(wm::XWindowManager, win::XCBWindow) = (event_type, data = nothing; location = (0.0, 0.0), time = time()) -> send_event(wm, win, event_type, data; location, time)
90100

91101
struct WindowRef <: AbstractWindow
92102
number::Int64

src/window_manager.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ function Base.close(wm::XWindowManager, win::XCBWindow)
2525
delete!(wm.windows, win.id)
2626
finalize(win)
2727
end
28+
29+
function Base.show(io::IO, wm::XWindowManager)
30+
n = length(wm.windows)
31+
number = iszero(n) ? "no" : n
32+
print(io, XWindowManager, '(', wm.conn, ", ", n, " active window", n == 1 ? "" : "s", ')')
33+
end

0 commit comments

Comments
 (0)