Skip to content

Commit

Permalink
Fix virtual input state not being correctly set
Browse files Browse the repository at this point in the history
  • Loading branch information
serenity4 committed Aug 23, 2024
1 parent 0643b7b commit bf50d11
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/testing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
Translate mouse or modifier state into the corresponding XCB value.
"""
function state_xcb(event::Event)
event.type in KEY_EVENT && return state_xcb(event.key_event.modifiers)
event.type in BUTTON_EVENT && return state_xcb(event.mouse_event.state)
event.type == POINTER_MOVED && return state_xcb(event.pointer_state)
in(event.type, KEY_EVENT) && return state_xcb(event.key_event.modifiers)
in(event.type, BUTTON_EVENT) && return state_xcb(event.mouse_event.state)
0
end

state_xcb(s::MouseButton) = UInt(s)
state_xcb(s::MouseButton) = xcb_button(s)
state_xcb(s::ModifierState) = xcb_mod_mask_t(UInt8(s))
state_xcb(s::PointerState) = (UInt16(s.state) << 8) + UInt8(s.modifiers)

"""
Translate an action into its corresponding XCB value.
Expand Down Expand Up @@ -41,15 +43,15 @@ function event_type_xcb(event::Event)
error("No event type corresponding to $(event.type)")
end

function button_xcb(button::MouseButton)
function xcb_button_index_t(button::MouseButton)
button == BUTTON_LEFT && return XCB_BUTTON_INDEX_1
button == BUTTON_MIDDLE && return XCB_BUTTON_INDEX_2
button == BUTTON_RIGHT && return XCB_BUTTON_INDEX_3
button == BUTTON_SCROLL_UP && return XCB_BUTTON_INDEX_4
button == BUTTON_SCROLL_DOWN && return XCB_BUTTON_INDEX_5
end

function detail_xcb_button(button::MouseButton)::xcb_button_t
function xcb_button(button::MouseButton)::xcb_button_t
button == BUTTON_NONE && return 0
button == BUTTON_LEFT && return 1
button == BUTTON_MIDDLE && return 2
Expand All @@ -60,8 +62,8 @@ function detail_xcb_button(button::MouseButton)::xcb_button_t
end

function detail_xcb(wm::XWindowManager, event::Event)
event.type in BUTTON_EVENT && return detail_xcb_button(event.mouse_event.button)
event.type in KEY_EVENT && return PhysicalKey(wm.keymap, event.key_event.key_name).code
in(event.type, BUTTON_EVENT) && return xcb_button(event.mouse_event.button)
in(event.type, KEY_EVENT) && return PhysicalKey(wm.keymap, event.key_event.key_name).code
event.type == POINTER_MOVED && return UInt8(XCB_MOTION_NORMAL)
event.type == POINTER_ENTERED && return XCB_ENTER_NOTIFY
event.type == POINTER_EXITED && return XCB_LEAVE_NOTIFY
Expand Down

0 comments on commit bf50d11

Please sign in to comment.