Skip to content

Commit 9642b0f

Browse files
committed
Bind more functions & start porting tinywl
1 parent 0e65e95 commit 9642b0f

File tree

20 files changed

+557
-3
lines changed

20 files changed

+557
-3
lines changed

common/dune

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,20 @@
22
(name wlroots_common)
33
(public_name wlroots.common)
44
(libraries ctypes))
5+
6+
;; xdg-shell-protocol.h
7+
(rule
8+
(targets "xdg-shell-protocol.h")
9+
(deps ../config/wayland-scanner-bin ../config/wayland-protocols-dir)
10+
(action (bash "$(< ../config/wayland-scanner-bin) server-header \
11+
$(< ../config/wayland-protocols-dir)/stable/xdg-shell/xdg-shell.xml \
12+
%{targets}")))
13+
14+
;; xdg-shell-protocol.c
15+
;;; this doesn't seem to be useful for now?
16+
(rule
17+
(targets "xdg-shell-protocol.c")
18+
(deps ../config/wayland-scanner-bin ../config/wayland-protocols-dir)
19+
(action (bash "$(< ../config/wayland-scanner-bin) private-code \
20+
$(< ../config/wayland-protocols-dir)/stable/xdg-shell/xdg-shell.xml \
21+
%{targets}")))

config/discover.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,19 @@ let () =
4949
package = "wlroots" };
5050

5151
] |> List.iter ~f:discover
52+
53+
let pkg_config_var ~var pkg =
54+
(* hack: this should be supported in configurator directly.
55+
see dune issue #3332 *)
56+
let cin = Unix.open_process_in
57+
(Printf.sprintf "pkg-config --variable=%s %s" var pkg) in
58+
let res = In_channel.input_all cin in
59+
let _ = Unix.close_process_in cin in
60+
res
61+
62+
let () =
63+
Out_channel.write_all "wayland-protocols-dir"
64+
~data:(pkg_config_var ~var:"pkgdatadir" "wayland-protocols");
65+
Out_channel.write_all "wayland-scanner-bin"
66+
~data:(pkg_config_var ~var:"wayland_scanner" "wayland-scanner");
67+
()

ffi/ffi.ml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ struct
8888
let wl_display_destroy = foreign "wl_display_destroy"
8989
(wl_display_p @-> returning void)
9090

91+
let wl_display_destroy_clients = foreign "wl_display_destroy_clients"
92+
(wl_display_p @-> returning void)
93+
9194
let wl_display_add_socket_auto = foreign "wl_display_add_socket_auto"
92-
(wl_display_p @-> returning string)
95+
(wl_display_p @-> returning string_opt)
9396

9497
let wl_display_init_shm = foreign "wl_display_init_shm"
9598
(wl_display_p @-> returning int)
@@ -121,6 +124,13 @@ struct
121124
let wlr_output_commit = foreign "wlr_output_commit"
122125
(wlr_output_p @-> returning bool)
123126

127+
(* wlr_output_layout *)
128+
129+
let wlr_output_layout_p = ptr Output_layout.t
130+
131+
let wlr_output_layout_create = foreign "wlr_output_layout_create"
132+
(void @-> returning wlr_output_layout_p)
133+
124134
(* wlr_box *)
125135

126136
let wlr_box_p = ptr Box.t
@@ -163,6 +173,9 @@ struct
163173
let wlr_renderer_clear = foreign "wlr_renderer_clear"
164174
(wlr_renderer_p @-> ptr float @-> returning void)
165175

176+
let wlr_renderer_init_wl_display = foreign "wlr_renderer_init_wl_display"
177+
(wlr_renderer_p @-> wl_display_p @-> returning bool)
178+
166179
(* wlr_keyboard *)
167180

168181
let wlr_keyboard_p = ptr Keyboard.t
@@ -186,13 +199,55 @@ struct
186199
let wlr_backend_destroy = foreign "wlr_backend_destroy"
187200
(wlr_backend_p @-> returning void)
188201

202+
(* wlr_data_device_manager *)
203+
204+
let wlr_data_device_manager_p = ptr Data_device_manager.t
205+
206+
let wlr_data_device_manager_create = foreign "wlr_data_device_manager_create"
207+
(wl_display_p @-> returning wlr_data_device_manager_p)
208+
189209
(* wlr_compositor *)
190210

191211
let wlr_compositor_p = ptr Compositor.t
192212

193213
let wlr_compositor_create = foreign "wlr_compositor_create"
194214
(wl_display_p @-> wlr_renderer_p @-> returning wlr_compositor_p)
195215

216+
(* wlr_xdg_shell *)
217+
218+
let wlr_xdg_shell_p = ptr Xdg_shell.t
219+
220+
let wlr_xdg_shell_create = foreign "wlr_xdg_shell_create"
221+
(wl_display_p @-> returning wlr_xdg_shell_p)
222+
223+
(* wlr_cursor *)
224+
225+
let wlr_cursor_p = ptr Cursor.t
226+
227+
let wlr_cursor_create = foreign "wlr_cursor_create"
228+
(void @-> returning wlr_cursor_p)
229+
230+
let wlr_cursor_attach_output_layout =
231+
foreign "wlr_cursor_attach_output_layout"
232+
(wlr_cursor_p @-> wlr_output_layout_p @-> returning void)
233+
234+
(* wlr_xcursor_manager *)
235+
236+
let wlr_xcursor_manager_p = ptr Xcursor_manager.t
237+
238+
let wlr_xcursor_manager_create = foreign "wlr_xcursor_manager_create"
239+
(string_opt @-> int @-> returning wlr_xcursor_manager_p)
240+
241+
let wlr_xcursor_manager_load = foreign "wlr_xcursor_manager_load"
242+
(wlr_xcursor_manager_p @-> float @-> returning int)
243+
244+
(* wlr_seat *)
245+
246+
let wlr_seat_p = ptr Seat.t
247+
248+
let wlr_seat_create = foreign "wlr_seat_create"
249+
(wl_display_p @-> string @-> returning wlr_seat_p)
250+
196251
(* wlr_log *)
197252

198253
(* TODO *)

lib/compositor.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
55
module Types = Wlroots_ffi_f.Ffi.Types
66

77
type t = Types.Compositor.t ptr
8+
include Ptr
89

910
let create dpy renderer =
1011
Bindings.wlr_compositor_create dpy renderer

lib/cursor.ml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
open Ctypes
2+
open Wlroots_common.Utils
3+
4+
module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
5+
module Types = Wlroots_ffi_f.Ffi.Types
6+
7+
type t = Types.Cursor.t ptr
8+
include Ptr
9+
10+
let create = Bindings.wlr_cursor_create
11+
let attach_output_layout = Bindings.wlr_cursor_attach_output_layout
12+
13+
let signal_motion (cursor: t) : Pointer.Event_motion.t Wl.Signal.t = {
14+
c = cursor |-> Types.Cursor.events_motion;
15+
typ = Pointer.Event_motion.t;
16+
}
17+
18+
let signal_motion_absolute (cursor: t) :
19+
Pointer.Event_motion_absolute.t Wl.Signal.t = {
20+
c = cursor |-> Types.Cursor.events_motion_absolute;
21+
typ = Pointer.Event_motion_absolute.t;
22+
}
23+
24+
let signal_button (cursor: t) : Pointer.Event_button.t Wl.Signal.t = {
25+
c = cursor |-> Types.Cursor.events_button;
26+
typ = Pointer.Event_button.t;
27+
}
28+
29+
let signal_axis (cursor: t) : Pointer.Event_axis.t Wl.Signal.t = {
30+
c = cursor |-> Types.Cursor.events_axis;
31+
typ = Pointer.Event_axis.t;
32+
}
33+
34+
let signal_frame (cursor: t) : unit Wl.Signal.t = {
35+
c = cursor |-> Types.Cursor.events_frame;
36+
typ = void;
37+
}

lib/data_device.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
open Ctypes
2+
open Wlroots_common.Utils
3+
4+
module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
5+
module Types = Wlroots_ffi_f.Ffi.Types
6+
7+
module Manager = struct
8+
type t = Types.Data_device_manager.t ptr
9+
include Ptr
10+
11+
let create = Bindings.wlr_data_device_manager_create
12+
end

lib/dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
generated_ffi
1717
wl log texture surface box matrix output
1818
keyboard pointer touch tablet_tool tablet_pad input_device
19-
backend renderer compositor)
19+
backend renderer data_device compositor xdg_shell cursor
20+
xcursor_manager seat)
2021
(c_names generated_ffi_stubs)
2122
(c_flags (:standard -Werror -pedantic -Wall -Wunused -DWLR_USE_UNSTABLE -O0) -w
2223
(:include ../config/wlroots-ccopt.sexp)

lib/output.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,10 @@ let attach_render (output : t): bool =
5959

6060
let commit (output : t): bool =
6161
Bindings.wlr_output_commit output
62+
63+
module Layout = struct
64+
type t = Types.Output_layout.t ptr
65+
include Ptr
66+
67+
let create = Bindings.wlr_output_layout_create
68+
end

lib/pointer.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,27 @@ module Types = Wlroots_ffi_f.Ffi.Types
66

77
type t = Types.Pointer.t ptr
88
include Ptr
9+
10+
module Event_motion = struct
11+
type t = Types.Event_pointer_motion.t ptr
12+
let t = ptr Types.Event_pointer_motion.t
13+
include Ptr
14+
end
15+
16+
module Event_motion_absolute = struct
17+
type t = Types.Event_pointer_motion_absolute.t ptr
18+
let t = ptr Types.Event_pointer_motion_absolute.t
19+
include Ptr
20+
end
21+
22+
module Event_button = struct
23+
type t = Types.Event_pointer_button.t ptr
24+
let t = ptr Types.Event_pointer_button.t
25+
include Ptr
26+
end
27+
28+
module Event_axis = struct
29+
type t = Types.Event_pointer_axis.t ptr
30+
let t = ptr Types.Event_pointer_axis.t
31+
include Ptr
32+
end

lib/renderer.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ let end_ (renderer : t) =
1616
let clear (renderer : t) ((c1,c2,c3,c4) : float * float * float * float) =
1717
let color_arr = CArray.of_list float [c1;c2;c3;c4] in
1818
Bindings.wlr_renderer_clear renderer (CArray.start color_arr)
19+
20+
let init_wl_display = Bindings.wlr_renderer_init_wl_display

0 commit comments

Comments
 (0)