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

Finish tinywl. #5

Draft
wants to merge 109 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 107 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
6d6e75f
Adding role to xdg_shell_surface
LambdaCalrissian Dec 13, 2020
87af175
Adding surface events
LambdaCalrissian Dec 27, 2020
e11ecb5
Work in progress filling out TinyWL
LambdaCalrissian Dec 27, 2020
1d16d8f
wlroots: Refer to implicit t in xdg_shell.surface sig.
jsoo1 Jan 3, 2021
f726517
Remove CTypes from tinywl.
jsoo1 Jan 3, 2021
1925924
Add keyboard_state field to Seat.
jsoo1 Jan 4, 2021
0d8e5d4
Rename Xdg_shell.Surface -> Xdg_shell.Xdg_surface.
jsoo1 Jan 4, 2021
c9a39be
Add surface field to Xdg_surface.
jsoo1 Jan 4, 2021
01d3222
Seat: Return option for focused_surface.
jsoo1 Jan 4, 2021
0770122
xdg_surface: Add from_surface.
jsoo1 Jan 6, 2021
aa7c61b
xdg_surface: Move into separate directory.
jsoo1 Jan 6, 2021
3ac5ce5
wlr_xdg_toplevel: Add wlr_xdg_toplevel_set_activated.
jsoo1 Jan 6, 2021
b2bdb00
[WIP] tinywl: Set previous surface to deactivated on xdg_surface.mapped.
jsoo1 Jan 6, 2021
a5f7978
Fixed type of modifiers field
LambdaCalrissian Jan 10, 2021
ddb0f28
Expose the Keyboard_modifiers module.
LambdaCalrissian Jan 10, 2021
b72fc83
Add the Keycodes type and module.
LambdaCalrissian Jan 10, 2021
ed6953d
Format Wlroots modules on new lines for better commits.
LambdaCalrissian Jan 10, 2021
eff3a34
Add Keycodes, Num_keycodes, and Modifier fields to Keyboard.
LambdaCalrissian Jan 10, 2021
f228aa0
Add keyboard_notify_enter.
jsoo1 Jan 10, 2021
97752b3
tinywl: Finish focus_view.
LambdaCalrissian Jan 10, 2021
5e1e2dc
Add keyboard, modifiers struct and keyboard, modifiers fields.
jsoo1 Jan 10, 2021
321482c
[WIP] tinywl: Notify keyboard enter in focus_view.
jsoo1 Jan 10, 2021
51e4770
Add mapped property to view.
LambdaCalrissian Jan 10, 2021
7063ea6
Make view a ref.
LambdaCalrissian Jan 10, 2021
0477c1a
Add unmap callback.
LambdaCalrissian Jan 10, 2021
2a17b40
xdg_toplevel: Creates types, interfaces, and events
LambdaCalrissian Jan 24, 2021
1a4089a
view:mutability Change from a ref to mutable on mapped.
LambdaCalrissian Jan 24, 2021
9f49b2e
tinywl: Stub out begin interactive.
LambdaCalrissian Jan 24, 2021
b8194af
tinywl:new_xdg_surface Comment about making mapped true.
LambdaCalrissian Jan 24, 2021
b4503e1
tinywl: Begin implementation of server_new_keyboard.
jsoo1 Jan 24, 2021
883195b
tinywl: Set repeat info in server_new_keyboard.
jsoo1 Feb 14, 2021
7a5efa2
keyboard: Add modifiers event, create Events module.
jsoo1 Feb 28, 2021
5c8627a
tinywl: Stub keyboard handlers.
jsoo1 Feb 28, 2021
046fa8f
seat: Add set_keyboard and seat_keyboard_notify_modifiers.
jsoo1 Feb 28, 2021
f507fba
tinwyl: Add keyboard_handle_modifiers.
jsoo1 Feb 28, 2021
0c8865c
keyboard: Add get_modifiers.
jsoo1 Feb 28, 2021
d63becb
types: Add wlr_keyboard_modifier.
jsoo1 Feb 28, 2021
b6e41ad
keyboard_modifiers: Add has_alt.
jsoo1 Feb 28, 2021
492a38e
[WIP] tinywl: Stub handle_keybinding
jsoo1 Feb 28, 2021
f812bdc
tinywl:server_new_sdg_surface Remove unneeded reference comment.
LambdaCalrissian Jan 24, 2021
16dde28
cursor: Add x & y fields
LambdaCalrissian Mar 21, 2021
9fd4ed0
[WIP] tinywl: process_cursor_motion
LambdaCalrissian Mar 21, 2021
9d30693
tinywl: Only do new_xdg_surface handling if TopLevel.
jsoo1 Mar 14, 2021
4d7409b
seat: Add keyboard_notify_key.
jsoo1 Mar 14, 2021
84e4812
Fill in handle_keybinding
jsoo1 Mar 14, 2021
6a50824
keyboard_modifiers: Fix has_alt coercions.
jsoo1 Mar 14, 2021
9bb93e0
cursor_move: Added ffi and functions.
LambdaCalrissian Mar 21, 2021
dda4e27
edges: Add module
LambdaCalrissian Mar 28, 2021
cbeb048
ffi: Add wlr_xdg_surface_get_geometry.
jsoo1 May 9, 2021
7420b87
ffi: Add wlr_xdg_toplevel_set_size.
jsoo1 May 9, 2021
26e8854
tinywl: Change Tinywl.box to Box.t.
jsoo1 May 9, 2021
3d338fc
tinywl: process_cursor_resize Added edge processing.
LambdaCalrissian Mar 28, 2021
0309baf
ffi: Add wlr_xdg_surface_surface_at
LambdaCalrissian May 9, 2021
05ad4a1
ffi: Add wlr_xcursor_manager_set_cursor_image
LambdaCalrissian May 9, 2021
0b2a5f1
ffi:seat Add wlr_seat_notify_pointer_enter
LambdaCalrissian May 16, 2021
23b8b9a
ffi:seat Add wlr_seat_pointer_clear_focus
LambdaCalrissian May 16, 2021
e0d9302
types:pointer_state Add focused_surface
LambdaCalrissian May 16, 2021
c8b571e
ffi:seat Add wlr_seat_pointer_notify_motion
LambdaCalrissian May 16, 2021
0349b37
tinywl: Finish server_cursor_motion
LambdaCalrissian May 9, 2021
757d53d
ffi: Add wlr_cursor_warp_absolute.
jsoo1 May 16, 2021
0611f49
types: Add device field to Event_pointer_motion_absolute.
jsoo1 May 16, 2021
d2d3a16
types: Add x and y fields to wlr_event_pointer_motion_absolute.
jsoo1 May 16, 2021
1ea917b
lib/event_pointer_motion_absolute: Move module out of Pointer.
jsoo1 May 16, 2021
224e614
event_pointer_motion_absolute: Add time_msec field.
jsoo1 May 16, 2021
8d07b27
tinywl: Finish server_cursor_motion_absolute.
jsoo1 May 16, 2021
88cf008
wlroots: Move Event_pointer_button to separate module.
jsoo1 May 16, 2021
17ebc7a
event_pointer_button: Add time_msec field.
jsoo1 May 16, 2021
69d547c
event_pointer_button: Add button field.
jsoo1 May 16, 2021
60301e1
types: Add Button_state.
jsoo1 May 16, 2021
80ccc9b
event_pointer_button: Add state field.
jsoo1 May 16, 2021
57e3ffa
ffi: Add wlr_seat_pointer_notify_button.
jsoo1 May 16, 2021
01cc9ba
tinywl: Finish server_cursor_button.
jsoo1 May 17, 2021
4b0c834
types: Add wlr_axis_source enum.
jsoo1 May 17, 2021
2d7deac
types: Add wlr_axis_orientation enum.
jsoo1 May 17, 2021
fefa49b
event_pointer_axis: Move Event_pointer_axis module to separate file.
jsoo1 May 17, 2021
d706005
types: Add field orientation of wlr_event_pointer_axis.
jsoo1 May 17, 2021
1dc5bb1
types: Add delta field of wlr_event_pointer_axis.
jsoo1 May 17, 2021
fc34992
types: Add delta_discrete field of wlr_event_pointer_axis.
jsoo1 May 17, 2021
743196f
types: Add source field of wlr_event_pointer_axis.
jsoo1 May 17, 2021
71d4e5a
ffi: Add wlr_seat_pointer_notify_axis.
jsoo1 May 17, 2021
d09affe
types: Add field time_msec of wlr_event_pointer_axis.
jsoo1 May 17, 2021
3010ad2
tinywl: Finish server_cursor_axis.
jsoo1 May 17, 2021
ad2500e
ffi: Add wlr_seat_pointer_notify_frame.
jsoo1 May 17, 2021
248451c
tinywl: Finish server_cursor_frame.
jsoo1 May 17, 2021
704faac
tiny: Make view.mapped = true when xdg_surface mapped event happens.
jsoo1 May 17, 2021
b95bc3c
tinywl: Create more descriptive failwiths.
jsoo1 May 17, 2021
8e3a5f0
ffi: Add wlr_output_effective_resolution.
jsoo1 May 23, 2021
a565a8f
types: Add wlr_surface_iterator_func_t.
jsoo1 May 25, 2021
0b8b28b
ffi: Add wlr_xdg_surface_for_each_surface.
jsoo1 May 25, 2021
880999f
ffi: Add wlr_surface_get_texture.
jsoo1 May 25, 2021
4b8dbf5
ffi: Add wlr_output_layout_output_coords.
jsoo1 May 25, 2021
c36922b
types: Add wlr_output.scale.
jsoo1 May 25, 2021
38a0a81
types: Define enum for wl_output_transform.
jsoo1 May 26, 2021
7504fe9
ffi: Add wlr_output_transform_invert.
jsoo1 May 26, 2021
03bd566
ffi: Add wlr_renderer_render_texture_with_matrix.
jsoo1 May 26, 2021
d8971b8
ffi: Add wlr_output_render_software_cursors.
jsoo1 May 26, 2021
41ea0e4
tinywl: Finish output_frame.
jsoo1 May 25, 2021
c0a8c27
utils: Add bitwise_enum32.
jsoo1 May 26, 2021
57bcbf9
types: Swaps Edges.t from enum to bitwise_enum32
jsoo1 May 26, 2021
55bcc65
types: Add xdg_toplevel_move_event and xdg_toplevel_resize_event.
jsoo1 May 26, 2021
935fb94
tinywl: Finish begin_interactive.
jsoo1 May 26, 2021
19f7318
tinywl: Swap out discard for ignore.
jsoo1 May 26, 2021
a27d884
tinywl: Use Module.(expr) to cleanup module noise.
jsoo1 May 26, 2021
586c96b
tinywl: Use single branched i.t.e. where applicable.
jsoo1 May 26, 2021
37f84cd
ffi: Add pixman_region32_t.
jsoo1 Jul 20, 2021
fd22f9c
ffi: Remove wl_output_transform.
jsoo1 Jul 20, 2021
a8dee0b
lib: Move Keyboard_modifiers to submodule of Keyboard.
jsoo1 Jul 20, 2021
a0568b0
common: Add Bitwise functor for bitwise enums.
jsoo1 Aug 2, 2021
a5a92a0
[WIP] bitwise_enums: Use Bitwise.Enum modules instead of functions
jsoo1 Aug 2, 2021
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
17 changes: 17 additions & 0 deletions common/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ let bitwise_enum desc =
in
view ~read ~write uint64_t

let bitwise_enum32 desc =
let open Unsigned.UInt32 in
let open Infix in
let read i =
List.filter_map (fun (x, cst) ->
if (i land cst) <> zero then
Some x
else None
) desc
in
let write items =
List.fold_left (fun i item ->
(List.assoc item desc) lor i
) zero items
in
view ~read ~write uint32_t

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When should we use bitwise_enum32 instead of bitwise_enum?
After a quick google search it looks like it's not terribly well specified which size enums should have; that they fit in a uint32_t is probably a good conservative assumption. However enum from ctypes assumes int64 values so this is probably fine as well?

In any case I would make a choice and either get rid of bitwise_enum or of bitwise_enum32.

Copy link
Author

@jsoo1 jsoo1 Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, this was because the edges field of the wlr_xdg_toplevel_resize_event is a uint32_t here https://github.com/swaywm/wlroots/blob/84dea55b20b60c229a5e31ccd37b58c96cba611a/include/wlr/types/wlr_xdg_shell.h#L224:

struct wlr_xdg_toplevel_resize_event {
	struct wlr_xdg_surface *surface;
	struct wlr_seat_client *seat;
	uint32_t serial;
	uint32_t edges;
};

Which is used in begin_interactive in tinywl https://github.com/swaywm/wlroots/blob/475d9701e21e5047ee9d7e56909762c1eb961fcd/tinywl/tinywl.c#L723:

static void begin_interactive(struct tinywl_view *view,
		enum tinywl_cursor_mode mode, uint32_t edges) {
...
		double border_x = (view->x + geo_box.x) + ((edges & WLR_EDGE_RIGHT) ? geo_box.width : 0);
		double border_y = (view->y + geo_box.y) + ((edges & WLR_EDGE_BOTTOM) ? geo_box.height : 0);
...
}

static void xdg_toplevel_request_move(
		struct wl_listener *listener, void *data) {
	/* This event is raised when a client would like to begin an interactive
	 * move, typically because the user clicked on their client-side
	 * decorations. Note that a more sophisticated compositor should check the
	 * provied serial against a list of button press serials sent to this
	 * client, to prevent the client from requesting this whenever they want. */
	struct tinywl_view *view = wl_container_of(listener, view, request_move);
	begin_interactive(view, TINYWL_CURSOR_MOVE, 0);
}

static void xdg_toplevel_request_resize(
		struct wl_listener *listener, void *data) {
	/* This event is raised when a client would like to begin an interactive
	 * resize, typically because the user clicked on their client-side
	 * decorations. Note that a more sophisticated compositor should check the
	 * provied serial against a list of button press serials sent to this
	 * client, to prevent the client from requesting this whenever they want. */
	struct wlr_xdg_toplevel_resize_event *event = data;
	struct tinywl_view *view = wl_container_of(listener, view, request_resize);
	begin_interactive(view, TINYWL_CURSOR_RESIZE, event->edges);
}

I wonder if this is an upstream issue.

Copy link
Author

@jsoo1 jsoo1 Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another related question: Should bitwise_enum be defined in terms of int64 instead of uint64_t? (due to the underspecified nature of enum sizes)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the details. Then I agree that sticking to the C api and avoiding any integer casts is best. In that case it makes sense to have both bitwise_enum and bitwise_enum32.

Copy link
Author

@jsoo1 jsoo1 Aug 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use a functor to parameterize the type of uint size of the enum members?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a WIP commit with a functor for bitwise enums. It does change uint64 to int64 where the unsigned version was used.

module Ptr = struct
let compare = ptr_compare
let hash = ptr_hash
Expand Down
108 changes: 108 additions & 0 deletions ffi/ffi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct
allocate Time_unix.Timespec.t timespec)
(ptr Time_unix.Timespec.t)

(* FIXME: The void pointer is a pixman_region32_t for which no bindings exist (yet).
This is only ok because so far, no one uses it. *)
let pixman_region32_t = ptr void

(* wl_list *)

type wl_list_p = Wl_list.t ptr
Expand Down Expand Up @@ -130,6 +134,15 @@ struct
let wlr_output_enable = foreign "wlr_output_enable"
(wlr_output_p @-> bool @-> returning void)

let wlr_output_effective_resolution = foreign "wlr_output_effective_resolution"
(wlr_output_p @-> ptr int @-> ptr int @-> returning void)

let wlr_output_transform_invert = foreign "wlr_output_transform_invert"
(Wl_output_transform.t @-> returning Wl_output_transform.t)

let wlr_output_render_software_cursors = foreign "wlr_output_render_software_cursors"
(wlr_output_p @-> pixman_region32_t @-> returning void)

(* wlr_output_layout *)

let wlr_output_layout_p = ptr Output_layout.t
Expand All @@ -140,6 +153,9 @@ struct
let wlr_output_layout_add_auto = foreign "wlr_output_layout_add_auto"
(wlr_output_layout_p @-> wlr_output_p @-> returning void)

let wlr_output_layout_output_coords = foreign "wlr_output_layout_output_coords"
(wlr_output_layout_p @-> wlr_output_p @-> ptr double @-> ptr double @-> returning void)

(* wlr_box *)

let wlr_box_p = ptr Box.t
Expand Down Expand Up @@ -169,6 +185,9 @@ struct
let wlr_surface_send_frame_done = foreign "wlr_surface_send_frame_done"
(wlr_surface_p @-> time @-> returning void)

let wlr_surface_get_texture = foreign "wlr_surface_get_texture"
(wlr_surface_p @-> returning wlr_texture_p)

(* wlr_renderer *)

let wlr_renderer_p = ptr Renderer.t
Expand All @@ -185,13 +204,24 @@ struct
let wlr_renderer_init_wl_display = foreign "wlr_renderer_init_wl_display"
(wlr_renderer_p @-> wl_display_p @-> returning bool)

let wlr_render_texture_with_matrix = foreign "wlr_render_texture_with_matrix"
(wlr_renderer_p @-> wlr_texture_p @-> ptr double @-> double @-> returning bool)

(* wlr_keyboard *)

let wlr_keyboard_p = ptr Keyboard.t

let wlr_keyboard_set_keymap = foreign "wlr_keyboard_set_keymap"
(wlr_keyboard_p @-> Xkbcommon.Keymap.t @-> returning bool)

let wlr_keyboard_modifiers_p = ptr Keyboard_modifiers.t

let wlr_keyboard_set_repeat_info = foreign "wlr_keyboard_set_repeat_info"
(wlr_keyboard_p @-> int32_t @-> int32_t @-> returning void)

let wlr_keyboard_get_modifiers = foreign "wlr_keyboard_get_modifiers"
(wlr_keyboard_p @-> returning uint32_t)

(* wlr_backend *)

let wlr_backend_p = ptr Backend.t
Expand Down Expand Up @@ -229,6 +259,33 @@ struct
let wlr_xdg_shell_create = foreign "wlr_xdg_shell_create"
(wl_display_p @-> returning wlr_xdg_shell_p)

(* wlr_xdg_surface *)

let wlr_xdg_surface_p = ptr Xdg_surface.t

let wlr_surface_is_xdg_surface = foreign "wlr_surface_is_xdg_surface"
(wlr_surface_p @-> returning bool)

let wlr_xdg_surface_from_wlr_surface = foreign "wlr_xdg_surface_from_wlr_surface"
(wlr_surface_p @-> returning wlr_xdg_surface_p)

let wlr_xdg_surface_get_geometry = foreign "wlr_xdg_surface_get_geometry"
(wlr_xdg_surface_p @-> wlr_box_p @-> returning void)

let wlr_xdg_surface_surface_at = foreign "wlr_xdg_surface_surface_at"
(wlr_xdg_surface_p @-> double @-> double @-> ptr double @-> ptr double @-> returning wlr_surface_p)

let wlr_xdg_surface_for_each_surface = foreign "wlr_xdg_surface_for_each_surface"
(wlr_xdg_surface_p @-> Surface.wlr_surface_iterator_func_t @-> ptr void @-> returning void)

(* wlr_xdg_toplevel *)

let wlr_xdg_toplevel_set_activated = foreign "wlr_xdg_toplevel_set_activated"
(wlr_xdg_surface_p @-> bool @-> returning uint32_t)

let wlr_xdg_toplevel_set_size = foreign "wlr_xdg_toplevel_set_size"
(wlr_xdg_surface_p @-> int @-> int @-> returning uint32_t)

(* wlr_input_device *)

let wlr_input_device_p = ptr Input_device.t
Expand All @@ -252,6 +309,13 @@ struct
foreign "wlr_cursor_set_surface"
(wlr_cursor_p @-> wlr_surface_p @-> int @-> int @-> returning void)

let wlr_cursor_move =
foreign "wlr_cursor_move"
(wlr_cursor_p @-> wlr_input_device_p @-> double @-> double @-> returning void)

let wlr_cursor_warp_absolute = foreign "wlr_cursor_warp_absolute"
(wlr_cursor_p @-> wlr_input_device_p @-> double @-> double @-> returning void)

(* wlr_xcursor_manager *)

let wlr_xcursor_manager_p = ptr Xcursor_manager.t
Expand All @@ -262,6 +326,9 @@ struct
let wlr_xcursor_manager_load = foreign "wlr_xcursor_manager_load"
(wlr_xcursor_manager_p @-> float @-> returning int)

let wlr_xcursor_manager_set_cursor_image = foreign "wlr_xcursor_manager_set_cursor_image"
(wlr_xcursor_manager_p @-> string @-> wlr_cursor_p @-> returning void)

(* wlr_seat *)

let wlr_seat_p = ptr Seat.t
Expand All @@ -272,6 +339,47 @@ struct
let wlr_seat_set_capabilities = foreign "wlr_seat_set_capabilities"
(wlr_seat_p @-> Wl_seat_capability.t @-> returning void)

let wlr_seat_set_keyboard = foreign "wlr_seat_set_keyboard"
(wlr_seat_p @-> wlr_input_device_p @-> returning void)

let wlr_seat_keyboard_notify_modifiers = foreign "wlr_seat_keyboard_notify_modifiers"
(wlr_seat_p @-> wlr_keyboard_modifiers_p @-> returning void)

let wlr_seat_keyboard_notify_enter = foreign "wlr_seat_keyboard_notify_enter"
(wlr_seat_p
@-> wlr_surface_p
@-> Keycodes.t
@-> size_t
@-> wlr_keyboard_modifiers_p
@-> returning void)

let wlr_seat_keyboard_notify_key = foreign "wlr_seat_keyboard_notify_key"
(wlr_seat_p @-> uint32_t @-> uint32_t @-> uint32_t @-> returning void)

let wlr_seat_pointer_notify_enter = foreign "wlr_seat_pointer_notify_enter"
(wlr_seat_p @-> wlr_surface_p @-> double @-> double @-> returning void)

let wlr_seat_pointer_clear_focus = foreign "wlr_seat_pointer_clear_focus"
(wlr_seat_p @-> returning void)

let wlr_seat_pointer_notify_motion = foreign "wlr_seat_pointer_notify_motion"
(wlr_seat_p @-> uint32_t @-> double @-> double @-> returning void)

let wlr_seat_pointer_notify_button = foreign "wlr_seat_pointer_notify_button"
(wlr_seat_p @-> uint32_t @-> uint32_t @-> Button_state.t @-> returning uint32_t)

let wlr_seat_pointer_notify_axis = foreign "wlr_seat_pointer_notify_axis"
(wlr_seat_p
@-> uint32_t
@-> Axis_orientation.t
@-> double
@-> int32_t
@-> Axis_source.t
@-> returning void)

let wlr_seat_pointer_notify_frame = foreign "wlr_seat_pointer_notify_frame"
(wlr_seat_p @-> returning void)

(* wlr_log *)

(* TODO *)
Expand Down
23 changes: 15 additions & 8 deletions lib/cursor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,40 @@ module Types = Wlroots_ffi_f.Ffi.Types
type t = Types.Cursor.t ptr
include Ptr

let x = getfield Types.Cursor.x
let y = getfield Types.Cursor.y


let create = Bindings.wlr_cursor_create
let attach_output_layout = Bindings.wlr_cursor_attach_output_layout
let attach_input_device = Bindings.wlr_cursor_attach_input_device
let set_surface = Bindings.wlr_cursor_set_surface
let move = Bindings.wlr_cursor_move

let signal_motion (cursor: t) : Pointer.Event_motion.t Wl.Signal.t = {
let signal_motion (cursor: t) : Event_pointer_motion.t Wl.Signal.t = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move these to external modules? The naming convention I was trying to follow (and that also appears with Keyboard.Event_key for example) is that if there's a wlr_foo.h, then wlr_event_foo_bar gets mapped to Foo.Event_bar.
Did that naming scheme not work here? Otherwise I'd prefer to stick to it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we did this because we were struggling to learn the module system. We can definitely use a different convention.

I was kind of hoping to move events to submodules as a convention, like Pointer.Event.motion for instance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in any case each event type needs to have its own module (so it can include its compare/hash function for example), so it would have to be Pointer.Event.Motion.t.
I think having an Event submodule would be useful if we had functions that worked on all events, so that we could put them there (Pointer.Event.foo). However I IIRC don't think we have such functions currently, so for now I would just stick with the Pointer.Event_foo naming scheme.

c = cursor |-> Types.Cursor.events_motion;
typ = Pointer.Event_motion.t;
typ = Event_pointer_motion.t;
}

let signal_motion_absolute (cursor: t) :
Pointer.Event_motion_absolute.t Wl.Signal.t = {
Event_pointer_motion_absolute.t Wl.Signal.t = {
c = cursor |-> Types.Cursor.events_motion_absolute;
typ = Pointer.Event_motion_absolute.t;
typ = Event_pointer_motion_absolute.t;
}

let signal_button (cursor: t) : Pointer.Event_button.t Wl.Signal.t = {
let signal_button (cursor: t) : Event_pointer_button.t Wl.Signal.t = {
c = cursor |-> Types.Cursor.events_button;
typ = Pointer.Event_button.t;
typ = Event_pointer_button.t;
}

let signal_axis (cursor: t) : Pointer.Event_axis.t Wl.Signal.t = {
let signal_axis (cursor: t) : Event_pointer_axis.t Wl.Signal.t = {
c = cursor |-> Types.Cursor.events_axis;
typ = Pointer.Event_axis.t;
typ = Event_pointer_axis.t;
}

let signal_frame (cursor: t) : unit Wl.Signal.t = {
c = cursor |-> Types.Cursor.events_frame;
typ = void;
}

let warp_absolute = Bindings.wlr_cursor_warp_absolute
34 changes: 30 additions & 4 deletions lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,36 @@
(public_name wlroots)
(modules wlroots
generated_ffi
wl log texture surface box matrix output
keyboard pointer touch tablet_tool tablet_pad input_device
backend renderer data_device compositor xdg_shell cursor
xcursor_manager seat output_layout)
wl
log
texture
surface
box
matrix
output
keyboard
pointer
event_pointer_button
event_pointer_motion
event_pointer_motion_absolute
event_pointer_axis
edges
touch
tablet_tool
tablet_pad
input_device
keycodes
backend
renderer
data_device
compositor
xdg_shell
xdg_surface
xdg_toplevel
cursor
xcursor_manager
seat
output_layout)
(c_names generated_ffi_stubs)
(c_flags (:standard -Werror -pedantic -Wall -Wunused -DWLR_USE_UNSTABLE -O0) -w
(:include ../config/wlroots-ccopt.sexp)
Expand Down
18 changes: 18 additions & 0 deletions lib/edges.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
open Ctypes
open Wlroots_common.Utils

module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
module Types = Wlroots_ffi_f.Ffi.Types

type edges = None | Top | Bottom | Left | Right
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be edge

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but we wanted to stick to the names from wlroots. I think it is defined as wlr_edges in https://github.com/swaywm/wlroots/blob/475d9701e21e5047ee9d7e56909762c1eb961fcd/include/wlr/util/edges.h#L19:

enum wlr_edges {
	WLR_EDGE_NONE = 0,
	WLR_EDGE_TOP = 1 << 0,
	WLR_EDGE_BOTTOM = 1 << 1,
	WLR_EDGE_LEFT = 1 << 2,
	WLR_EDGE_RIGHT = 1 << 3,
};

Copy link
Collaborator

@Armael Armael Jul 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I still think that in ocaml it would be more natural to have the type named edge. In C it makes sense because an element of wlr_edges is going to be used as a bit-field and thus indeed corresponds to a set of edges ; but this is not the case for an inhabitant of the ocaml sum type.

type t = edges list
include Poly

let t : edges list typ =
bitwise_enum32 Types.Edges.([
None, _WLR_EDGE_NONE;
Top, _WLR_EDGE_TOP;
Bottom, _WLR_EDGE_BOTTOM;
Right, _WLR_EDGE_RIGHT;
Left, _WLR_EDGE_LEFT;
])
15 changes: 15 additions & 0 deletions lib/event_pointer_axis.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
open Ctypes
open Wlroots_common.Utils

module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
module Types = Wlroots_ffi_f.Ffi.Types

type t = Types.Event_pointer_axis.t ptr
let t = ptr Types.Event_pointer_axis.t
include Ptr

let time_msec = getfield Types.Event_pointer_axis.time_msec
let orientation = getfield Types.Event_pointer_axis.orientation
let delta = getfield Types.Event_pointer_axis.delta
let delta_discrete = getfield Types.Event_pointer_axis.delta_discrete
let source = getfield Types.Event_pointer_axis.source
13 changes: 13 additions & 0 deletions lib/event_pointer_button.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
open Ctypes
open Wlroots_common.Utils

module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
module Types = Wlroots_ffi_f.Ffi.Types

type t = Types.Event_pointer_button.t ptr
let t = ptr Types.Event_pointer_button.t
include Ptr

let time_msec = getfield Types.Event_pointer_button.time_msec
let button = getfield Types.Event_pointer_button.button
let state = getfield Types.Event_pointer_button.state
14 changes: 14 additions & 0 deletions lib/event_pointer_motion.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Ctypes
open Wlroots_common.Utils

module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
module Types = Wlroots_ffi_f.Ffi.Types

type t = Types.Event_pointer_motion.t ptr
let t = ptr Types.Event_pointer_motion.t
include Ptr

let device = getfield Types.Event_pointer_motion.device
let time_msec = getfield Types.Event_pointer_motion.time_msec
let delta_x = getfield Types.Event_pointer_motion.delta_x
let delta_y = getfield Types.Event_pointer_motion.delta_y
14 changes: 14 additions & 0 deletions lib/event_pointer_motion_absolute.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Ctypes
open Wlroots_common.Utils

module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
module Types = Wlroots_ffi_f.Ffi.Types

type t = Types.Event_pointer_motion_absolute.t ptr
let t = ptr Types.Event_pointer_motion_absolute.t
include Ptr

let device = getfield Types.Event_pointer_motion_absolute.device
let x = getfield Types.Event_pointer_motion_absolute.x
let y = getfield Types.Event_pointer_motion_absolute.y
let time_msec = getfield Types.Event_pointer_motion_absolute.time_msec
Loading