Skip to content

Commit d6881e3

Browse files
committed
Bind a couple more functions related to output_layout
1 parent 5f49e38 commit d6881e3

File tree

8 files changed

+68
-32
lines changed

8 files changed

+68
-32
lines changed

examples/simple.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ let output_remove_notify output_handles _ _output =
5959
let new_output_notify _ output =
6060
let o = { frame = Wl.Listener.create ();
6161
destroy = Wl.Listener.create (); } in
62-
Output.set_best_mode output;
62+
begin match Output.modes output with
63+
| mode :: _ -> Output.set_mode output mode
64+
| [] -> ()
65+
end;
6366
Wl.Signal.add (Output.signal_frame output) o.frame output_frame_notify;
6467
Wl.Signal.add (Output.signal_destroy output) o.destroy
6568
(output_remove_notify o);

ffi/ffi.ml

+9
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,22 @@ struct
124124
let wlr_output_commit = foreign "wlr_output_commit"
125125
(wlr_output_p @-> returning bool)
126126

127+
let wlr_output_preferred_mode = foreign "wlr_output_preferred_mode"
128+
(wlr_output_p @-> returning wlr_output_mode_p)
129+
130+
let wlr_output_enable = foreign "wlr_output_enable"
131+
(wlr_output_p @-> bool @-> returning void)
132+
127133
(* wlr_output_layout *)
128134

129135
let wlr_output_layout_p = ptr Output_layout.t
130136

131137
let wlr_output_layout_create = foreign "wlr_output_layout_create"
132138
(void @-> returning wlr_output_layout_p)
133139

140+
let wlr_output_layout_add_auto = foreign "wlr_output_layout_add_auto"
141+
(wlr_output_layout_p @-> wlr_output_p @-> returning void)
142+
134143
(* wlr_box *)
135144

136145
let wlr_box_p = ptr Box.t

lib/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
wl log texture surface box matrix output
1818
keyboard pointer touch tablet_tool tablet_pad input_device
1919
backend renderer data_device compositor xdg_shell cursor
20-
xcursor_manager seat)
20+
xcursor_manager seat output_layout)
2121
(c_names generated_ffi_stubs)
2222
(c_flags (:standard -Werror -pedantic -Wall -Wunused -DWLR_USE_UNSTABLE -O0) -w
2323
(:include ../config/wlroots-ccopt.sexp)

lib/output.ml

+4-17
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,9 @@ let transform_matrix (output : t) : Matrix.t =
3838
let set_mode (output : t) (mode : Mode.t): unit =
3939
Bindings.wlr_output_set_mode output mode
4040

41-
let best_mode (output : t): Mode.t option =
42-
match modes output with
43-
| [] -> None
44-
| mode :: _ -> Some mode
45-
46-
let set_best_mode (output : t) =
47-
match best_mode output with
48-
| None -> ()
49-
| Some mode ->
50-
(* TODO log the mode set *)
51-
set_mode output mode |> ignore
41+
let preferred_mode output =
42+
let mode = Bindings.wlr_output_preferred_mode output in
43+
if is_null mode then None else Some mode
5244

5345
let create_global (output : t) =
5446
Bindings.wlr_output_create_global output
@@ -60,9 +52,4 @@ let attach_render (output : t): bool =
6052
let commit (output : t): bool =
6153
Bindings.wlr_output_commit output
6254

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
55+
let enable = Bindings.wlr_output_enable

lib/output_layout.ml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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.Output_layout.t ptr
8+
include Ptr
9+
10+
let create = Bindings.wlr_output_layout_create
11+
let add_auto = Bindings.wlr_output_layout_add_auto

lib/wlroots.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include Event
22

3+
module Output_layout = Output_layout
34
module Seat = Seat
45
module Xcursor_manager = Xcursor_manager
56
module Cursor = Cursor

lib/wlroots.mli

+9-8
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,24 @@ module Output : sig
100100
(* Setting an output mode *)
101101
val modes : t -> Mode.t list
102102
val set_mode : t -> Mode.t -> unit
103-
val best_mode : t -> Mode.t option
104-
val set_best_mode : t -> unit
103+
val preferred_mode : t -> Mode.t option
105104

106105
val transform_matrix : t -> Matrix.t
107106
val create_global : t -> unit
108107
val attach_render : t -> bool
109108
val commit : t -> bool
109+
val enable : t -> bool -> unit
110110

111111
val signal_frame : t -> t Wl.Signal.t
112112
val signal_destroy : t -> t Wl.Signal.t
113+
end
113114

114-
module Layout : sig
115-
type t
116-
include Comparable0 with type t := t
115+
module Output_layout : sig
116+
type t
117+
include Comparable0 with type t := t
117118

118-
val create : unit -> t
119-
end
119+
val create : unit -> t
120+
val add_auto : t -> Output.t -> unit
120121
end
121122

122123
module Keyboard : sig
@@ -258,7 +259,7 @@ module Cursor : sig
258259
include Comparable0 with type t := t
259260

260261
val create : unit -> t
261-
val attach_output_layout : t -> Output.Layout.t -> unit
262+
val attach_output_layout : t -> Output_layout.t -> unit
262263

263264
val signal_motion : t -> Pointer.Event_motion.t Wl.Signal.t
264265
val signal_motion_absolute : t -> Pointer.Event_motion_absolute.t Wl.Signal.t

tinywl/tinywl.ml

+29-5
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,45 @@ open Wlroots
22

33
type view
44

5-
type st = {
5+
type tinywl_output = {
6+
output : Output.t;
7+
8+
frame : Wl.Listener.t;
9+
}
10+
11+
type tinywl_server = {
612
display : Wl.Display.t;
713
backend : Backend.t;
814
renderer : Renderer.t;
9-
output_layout : Output.Layout.t;
10-
mutable outputs : Output.t list;
15+
output_layout : Output_layout.t;
16+
mutable outputs : tinywl_output list;
1117
mutable views : view list;
1218
mutable keyboards : Keyboard.t list;
1319

1420
new_output : Wl.Listener.t;
1521
}
1622

17-
let server_new_output _st _ _ =
23+
let output_frame _st _ _ =
1824
failwith "todo"
1925

26+
let server_new_output st _ output =
27+
let output_ok =
28+
match Output.preferred_mode output with
29+
| Some mode ->
30+
Output.set_mode output mode;
31+
Output.enable output true;
32+
Output.commit output
33+
| None -> true
34+
in
35+
if output_ok then begin
36+
let o = { output; frame = Wl.Listener.create () } in
37+
Wl.Signal.add (Output.signal_frame output) o.frame (output_frame st);
38+
st.outputs <- o :: st.outputs;
39+
40+
Output_layout.add_auto st.output_layout output;
41+
Output.create_global output;
42+
end
43+
2044
let server_new_xdg_surface _st _ _ =
2145
failwith "todo"
2246

@@ -60,7 +84,7 @@ let () =
6084
let _compositor = Compositor.create display renderer in
6185
let _data_manager = Data_device.Manager.create display in
6286

63-
let output_layout = Output.Layout.create () in
87+
let output_layout = Output_layout.create () in
6488

6589
let xdg_shell = Xdg_shell.create display in
6690

0 commit comments

Comments
 (0)