Packages

Native desktop GUI framework for Gleam, powered by Iced

Current section

Files

Jump to
plushie_gleam src plushie@protocol@decode.erl
Raw

src/plushie@protocol@decode.erl

-module(plushie@protocol@decode).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/plushie/protocol/decode.gleam").
-export([split_scoped_id/1, decode_message/2]).
-export_type([inbound_message/0, prop_value/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Decode inbound wire messages into typed Gleam values.\n"
"\n"
" Supports both MessagePack and JSON wire formats. The Rust binary sends\n"
" three top-level message types: \"hello\" (handshake), \"event\" (user\n"
" interaction dispatched by family), and \"effect_response\" (platform\n"
" result). Additionally, \"op_query_response\" messages carry system\n"
" query results.\n"
).
-type inbound_message() :: {hello,
integer(),
binary(),
binary(),
binary(),
list(binary()),
binary()} |
{event_message, plushie@event:event()}.
-type prop_value() :: {p_string, binary()} |
{p_int, integer()} |
{p_float, float()} |
{p_bool, boolean()} |
p_null |
{p_list, list(prop_value())} |
{p_map, gleam@dict:dict(binary(), prop_value())}.
-file("src/plushie/protocol/decode.gleam", 92).
?DOC(
" Split a scoped wire ID into (local_id, scope_list).\n"
"\n"
" Named containers scope their children with \"/\" separators. The scope\n"
" list is reversed so the nearest container is first.\n"
"\n"
" split_scoped_id(\"form/email\")\n"
" // -> #(\"email\", [\"form\"])\n"
"\n"
" split_scoped_id(\"sidebar/form/email\")\n"
" // -> #(\"email\", [\"form\", \"sidebar\"])\n"
"\n"
" split_scoped_id(\"button\")\n"
" // -> #(\"button\", [])\n"
).
-spec split_scoped_id(binary()) -> {binary(), list(binary())}.
split_scoped_id(Wire_id) ->
case gleam@string:split(Wire_id, <<"/"/utf8>>) of
[Local] ->
{Local, []};
Parts ->
case lists:reverse(Parts) of
[Local@1 | Scope] ->
{Local@1, Scope};
[] ->
{<<""/utf8>>, []}
end
end.
-file("src/plushie/protocol/decode.gleam", 187).
-spec dynamic_to_prop(gleam@dynamic:dynamic_()) -> prop_value().
dynamic_to_prop(Dyn) ->
case gleam@dynamic@decode:run(
Dyn,
{decoder, fun gleam@dynamic@decode:decode_string/1}
) of
{ok, S} ->
{p_string, S};
{error, _} ->
case gleam@dynamic@decode:run(
Dyn,
{decoder, fun gleam@dynamic@decode:decode_bool/1}
) of
{ok, B} ->
{p_bool, B};
{error, _} ->
case gleam@dynamic@decode:run(
Dyn,
{decoder, fun gleam@dynamic@decode:decode_int/1}
) of
{ok, N} ->
{p_int, N};
{error, _} ->
case gleam@dynamic@decode:run(
Dyn,
{decoder,
fun gleam@dynamic@decode:decode_float/1}
) of
{ok, F} ->
{p_float, F};
{error, _} ->
case gleam@dynamic@decode:run(
Dyn,
gleam@dynamic@decode:list(
{decoder,
fun gleam@dynamic@decode:decode_dynamic/1}
)
) of
{ok, Items} ->
{p_list,
gleam@list:map(
Items,
fun dynamic_to_prop/1
)};
{error, _} ->
case gleam@dynamic@decode:run(
Dyn,
gleam@dynamic@decode:dict(
{decoder,
fun gleam@dynamic@decode:decode_string/1},
{decoder,
fun gleam@dynamic@decode:decode_dynamic/1}
)
) of
{ok, Entries} ->
{p_map,
gleam@dict:map_values(
Entries,
fun(_, V) ->
dynamic_to_prop(
V
)
end
)};
{error, _} ->
p_null
end
end
end
end
end
end.
-file("src/plushie/protocol/decode.gleam", 132).
-spec deserialize_json(bitstring()) -> {ok,
gleam@dict:dict(binary(), prop_value())} |
{error, plushie@protocol:decode_error()}.
deserialize_json(Data) ->
case gleam@bit_array:to_string(Data) of
{error, _} ->
{error, {deserialization_failed, <<"invalid UTF-8"/utf8>>}};
{ok, Text} ->
Text@1 = gleam@string:trim_end(Text),
case gleam@json:parse(
Text@1,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1}
) of
{ok, Dyn} ->
case dynamic_to_prop(Dyn) of
{p_map, Map} ->
{ok, Map};
_ ->
{error,
{deserialization_failed,
<<"top-level value is not a map"/utf8>>}}
end;
{error, _} ->
{error, {deserialization_failed, <<"invalid JSON"/utf8>>}}
end
end.
-file("src/plushie/protocol/decode.gleam", 232).
-spec get_string(gleam@dict:dict(binary(), prop_value()), binary()) -> {ok,
binary()} |
{error, plushie@protocol:decode_error()}.
get_string(Map, Key) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_string, S}} ->
{ok, S};
{ok, _} ->
{error,
{malformed_event,
<<<<"expected string for \""/utf8, Key/binary>>/binary,
"\""/utf8>>}};
{error, _} ->
{error,
{malformed_event,
<<<<"missing field \""/utf8, Key/binary>>/binary,
"\""/utf8>>}}
end.
-file("src/plushie/protocol/decode.gleam", 245).
-spec get_int(gleam@dict:dict(binary(), prop_value()), binary()) -> {ok,
integer()} |
{error, plushie@protocol:decode_error()}.
get_int(Map, Key) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_int, N}} ->
{ok, N};
{ok, {p_float, F}} ->
{ok, erlang:trunc(F)};
{ok, _} ->
{error,
{malformed_event,
<<<<"expected int for \""/utf8, Key/binary>>/binary,
"\""/utf8>>}};
{error, _} ->
{error,
{malformed_event,
<<<<"missing field \""/utf8, Key/binary>>/binary,
"\""/utf8>>}}
end.
-file("src/plushie/protocol/decode.gleam", 259).
-spec get_float(gleam@dict:dict(binary(), prop_value()), binary()) -> {ok,
float()} |
{error, plushie@protocol:decode_error()}.
get_float(Map, Key) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_float, F}} ->
{ok, F};
{ok, {p_int, N}} ->
{ok, erlang:float(N)};
{ok, _} ->
{error,
{malformed_event,
<<<<"expected float for \""/utf8, Key/binary>>/binary,
"\""/utf8>>}};
{error, _} ->
{error,
{malformed_event,
<<<<"missing field \""/utf8, Key/binary>>/binary,
"\""/utf8>>}}
end.
-file("src/plushie/protocol/decode.gleam", 273).
-spec get_bool(gleam@dict:dict(binary(), prop_value()), binary()) -> {ok,
boolean()} |
{error, plushie@protocol:decode_error()}.
get_bool(Map, Key) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_bool, B}} ->
{ok, B};
{ok, _} ->
{error,
{malformed_event,
<<<<"expected bool for \""/utf8, Key/binary>>/binary,
"\""/utf8>>}};
{error, _} ->
{error,
{malformed_event,
<<<<"missing field \""/utf8, Key/binary>>/binary,
"\""/utf8>>}}
end.
-file("src/plushie/protocol/decode.gleam", 286).
-spec get_optional_string(gleam@dict:dict(binary(), prop_value()), binary()) -> gleam@option:option(binary()).
get_optional_string(Map, Key) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_string, S}} ->
{some, S};
_ ->
none
end.
-file("src/plushie/protocol/decode.gleam", 296).
-spec get_optional_float(gleam@dict:dict(binary(), prop_value()), binary()) -> gleam@option:option(float()).
get_optional_float(Map, Key) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_float, F}} ->
{some, F};
{ok, {p_int, N}} ->
{some, erlang:float(N)};
_ ->
none
end.
-file("src/plushie/protocol/decode.gleam", 307).
-spec get_string_or(gleam@dict:dict(binary(), prop_value()), binary(), binary()) -> binary().
get_string_or(Map, Key, Default) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_string, S}} ->
S;
_ ->
Default
end.
-file("src/plushie/protocol/decode.gleam", 318).
-spec get_bool_or(gleam@dict:dict(binary(), prop_value()), binary(), boolean()) -> boolean().
get_bool_or(Map, Key, Default) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_bool, B}} ->
B;
_ ->
Default
end.
-file("src/plushie/protocol/decode.gleam", 325).
-spec get_float_or(gleam@dict:dict(binary(), prop_value()), binary(), float()) -> float().
get_float_or(Map, Key, Default) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_float, F}} ->
F;
{ok, {p_int, N}} ->
erlang:float(N);
_ ->
Default
end.
-file("src/plushie/protocol/decode.gleam", 337).
-spec get_int_or(gleam@dict:dict(binary(), prop_value()), binary(), integer()) -> integer().
get_int_or(Map, Key, Default) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_int, N}} ->
N;
{ok, {p_float, F}} ->
erlang:trunc(F);
_ ->
Default
end.
-file("src/plushie/protocol/decode.gleam", 345).
-spec get_map(gleam@dict:dict(binary(), prop_value()), binary()) -> gleam@dict:dict(binary(), prop_value()).
get_map(Map, Key) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_map, M}} ->
M;
_ ->
maps:new()
end.
-file("src/plushie/protocol/decode.gleam", 352).
-spec get_string_list(gleam@dict:dict(binary(), prop_value()), binary()) -> list(binary()).
get_string_list(Map, Key) ->
case gleam_stdlib:map_get(Map, Key) of
{ok, {p_list, Items}} ->
gleam@list:filter_map(Items, fun(Item) -> case Item of
{p_string, S} ->
{ok, S};
_ ->
{error, nil}
end end);
_ ->
[]
end.
-file("src/plushie/protocol/decode.gleam", 365).
-spec prop_to_dynamic(prop_value()) -> gleam@dynamic:dynamic_().
prop_to_dynamic(Value) ->
case Value of
{p_string, S} ->
gleam_stdlib:identity(S);
{p_int, N} ->
gleam_stdlib:identity(N);
{p_float, F} ->
gleam_stdlib:identity(F);
{p_bool, B} ->
gleam_stdlib:identity(B);
p_null ->
gleam@dynamic:nil();
{p_list, Items} ->
gleam_stdlib:identity(gleam@list:map(Items, fun prop_to_dynamic/1));
{p_map, Entries} ->
gleam@dynamic:properties(
begin
_pipe = maps:to_list(Entries),
gleam@list:map(
_pipe,
fun(Pair) ->
{gleam_stdlib:identity(erlang:element(1, Pair)),
prop_to_dynamic(erlang:element(2, Pair))}
end
)
end
)
end.
-file("src/plushie/protocol/decode.gleam", 404).
-spec decode_hello(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_hello(Map) ->
gleam@result:'try'(
get_int(Map, <<"protocol"/utf8>>),
fun(Proto) ->
gleam@result:'try'(
get_string(Map, <<"version"/utf8>>),
fun(Version) ->
gleam@result:'try'(
get_string(Map, <<"name"/utf8>>),
fun(Name) ->
Backend = get_string_or(
Map,
<<"backend"/utf8>>,
<<"unknown"/utf8>>
),
Extensions = get_string_list(
Map,
<<"extensions"/utf8>>
),
Transport = get_string_or(
Map,
<<"transport"/utf8>>,
<<"stdio"/utf8>>
),
{ok,
{hello,
Proto,
Version,
Name,
Backend,
Extensions,
Transport}}
end
)
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 420).
-spec decode_effect_response(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_effect_response(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Request_id) ->
gleam@result:'try'(
get_string(Map, <<"status"/utf8>>),
fun(Status) ->
Result_val = case Status of
<<"ok"/utf8>> ->
R = case gleam_stdlib:map_get(
Map,
<<"result"/utf8>>
) of
{ok, V} ->
prop_to_dynamic(V);
{error, _} ->
gleam@dynamic:nil()
end,
{effect_ok, R};
<<"cancelled"/utf8>> ->
effect_cancelled;
<<"error"/utf8>> ->
R@1 = case gleam_stdlib:map_get(
Map,
<<"error"/utf8>>
) of
{ok, V@1} ->
prop_to_dynamic(V@1);
{error, _} ->
gleam@dynamic:nil()
end,
{effect_error, R@1};
_ ->
{effect_error,
gleam_stdlib:identity(
<<"unknown status: "/utf8, Status/binary>>
)}
end,
{ok,
{event_message,
{effect_response, Request_id, Result_val}}}
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 450).
-spec decode_op_query_response(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_op_query_response(Map) ->
gleam@result:'try'(
get_string(Map, <<"kind"/utf8>>),
fun(Kind) ->
Tag = get_string_or(Map, <<"tag"/utf8>>, <<""/utf8>>),
Data_val = case gleam_stdlib:map_get(Map, <<"data"/utf8>>) of
{ok, V} ->
prop_to_dynamic(V);
{error, _} ->
gleam@dynamic:nil()
end,
Evt = case Kind of
<<"system_info"/utf8>> ->
{system_info, Tag, Data_val};
<<"system_theme"/utf8>> ->
Theme = case gleam_stdlib:map_get(Map, <<"data"/utf8>>) of
{ok, {p_string, S}} ->
S;
_ ->
<<"unknown"/utf8>>
end,
{system_theme, Tag, Theme};
<<"list_images"/utf8>> ->
{image_list,
Tag,
get_string_list(
get_map(Map, <<"data"/utf8>>),
<<"handles"/utf8>>
)};
<<"tree_hash"/utf8>> ->
Data_map = get_map(Map, <<"data"/utf8>>),
Hash = get_string_or(Data_map, <<"hash"/utf8>>, <<""/utf8>>),
{tree_hash, Tag, Hash};
<<"find_focused"/utf8>> ->
Data_map@1 = get_map(Map, <<"data"/utf8>>),
Widget_id = get_optional_string(
Data_map@1,
<<"focused"/utf8>>
),
{focused_widget, Tag, Widget_id};
_ ->
{system_info, Tag, Data_val}
end,
{ok, {event_message, Evt}}
end
).
-file("src/plushie/protocol/decode.gleam", 613).
-spec parse_modifiers(gleam@dict:dict(binary(), prop_value())) -> plushie@event:modifiers().
parse_modifiers(Map) ->
Mods = get_map(Map, <<"modifiers"/utf8>>),
{modifiers,
get_bool_or(Mods, <<"shift"/utf8>>, false),
get_bool_or(Mods, <<"ctrl"/utf8>>, false),
get_bool_or(Mods, <<"alt"/utf8>>, false),
get_bool_or(Mods, <<"logo"/utf8>>, false),
get_bool_or(Mods, <<"command"/utf8>>, false)}.
-file("src/plushie/protocol/decode.gleam", 624).
-spec parse_key_location(binary()) -> plushie@event:key_location().
parse_key_location(Loc) ->
case Loc of
<<"left"/utf8>> ->
left_side;
<<"right"/utf8>> ->
right_side;
<<"numpad"/utf8>> ->
numpad;
_ ->
standard
end.
-file("src/plushie/protocol/decode.gleam", 633).
-spec parse_mouse_button(binary()) -> plushie@event:mouse_button().
parse_mouse_button(Value) ->
case Value of
<<"left"/utf8>> ->
left_button;
<<"right"/utf8>> ->
right_button;
<<"middle"/utf8>> ->
middle_button;
<<"back"/utf8>> ->
back_button;
<<"forward"/utf8>> ->
forward_button;
Other ->
{other_button, Other}
end.
-file("src/plushie/protocol/decode.gleam", 644).
-spec parse_scroll_unit(binary()) -> plushie@event:scroll_unit().
parse_scroll_unit(Value) ->
case Value of
<<"pixel"/utf8>> ->
pixel;
<<"pixels"/utf8>> ->
pixel;
_ ->
line
end.
-file("src/plushie/protocol/decode.gleam", 655).
-spec decode_widget_click(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_widget_click(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, {widget_click, Local, Scope}}}
end
).
-file("src/plushie/protocol/decode.gleam", 663).
-spec decode_widget_string_value(
gleam@dict:dict(binary(), prop_value()),
fun((binary(), list(binary()), binary()) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_widget_string_value(Map, Constructor) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
gleam@result:'try'(
get_string(Map, <<"value"/utf8>>),
fun(Value) ->
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, Constructor(Local, Scope, Value)}}
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 673).
-spec decode_widget_toggle(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_widget_toggle(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
gleam@result:'try'(
get_bool(Map, <<"value"/utf8>>),
fun(Value) ->
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, {widget_toggle, Local, Scope, Value}}}
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 682).
-spec decode_widget_float_value(
gleam@dict:dict(binary(), prop_value()),
fun((binary(), list(binary()), float()) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_widget_float_value(Map, Constructor) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
gleam@result:'try'(
get_float(Map, <<"value"/utf8>>),
fun(Value) ->
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, Constructor(Local, Scope, Value)}}
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 692).
-spec decode_widget_no_value(
gleam@dict:dict(binary(), prop_value()),
fun((binary(), list(binary())) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_widget_no_value(Map, Constructor) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, Constructor(Local, Scope)}}
end
).
-file("src/plushie/protocol/decode.gleam", 701).
-spec decode_widget_sort(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_widget_sort(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Column = get_string_or(Data, <<"column"/utf8>>, <<""/utf8>>),
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, {widget_sort, Local, Scope, Column}}}
end
).
-file("src/plushie/protocol/decode.gleam", 711).
-spec decode_widget_key_binding(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_widget_key_binding(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Binding = case gleam_stdlib:map_get(Data, <<"binding"/utf8>>) of
{ok, {p_string, S}} ->
S;
_ ->
case gleam_stdlib:map_get(Map, <<"data"/utf8>>) of
{ok, {p_string, S@1}} ->
S@1;
_ ->
<<""/utf8>>
end
end,
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, {widget_key_binding, Local, Scope, Binding}}}
end
).
-file("src/plushie/protocol/decode.gleam", 728).
-spec decode_widget_scroll(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_widget_scroll(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
{Local, Scope} = split_scoped_id(Id),
Scroll_data = {scroll_data,
get_float_or(Data, <<"absolute_x"/utf8>>, +0.0),
get_float_or(Data, <<"absolute_y"/utf8>>, +0.0),
get_float_or(Data, <<"relative_x"/utf8>>, +0.0),
get_float_or(Data, <<"relative_y"/utf8>>, +0.0),
get_float_or(Data, <<"bounds_width"/utf8>>, +0.0),
get_float_or(Data, <<"bounds_height"/utf8>>, +0.0),
get_float_or(Data, <<"content_width"/utf8>>, +0.0),
get_float_or(Data, <<"content_height"/utf8>>, +0.0)},
{ok, {event_message, {widget_scroll, Local, Scope, Scroll_data}}}
end
).
-file("src/plushie/protocol/decode.gleam", 748).
-spec decode_generic_widget_event(
gleam@dict:dict(binary(), prop_value()),
binary()
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_generic_widget_event(Map, Family) ->
Id = get_string_or(Map, <<"id"/utf8>>, <<""/utf8>>),
{Local, Scope} = split_scoped_id(Id),
Value = case gleam_stdlib:map_get(Map, <<"value"/utf8>>) of
{ok, V} ->
prop_to_dynamic(V);
{error, _} ->
gleam@dynamic:nil()
end,
Data = case gleam_stdlib:map_get(Map, <<"data"/utf8>>) of
{ok, V@1} ->
prop_to_dynamic(V@1);
{error, _} ->
gleam@dynamic:nil()
end,
{ok, {event_message, {widget_event, Family, Local, Scope, Value, Data}}}.
-file("src/plushie/protocol/decode.gleam", 777).
-spec decode_key_press(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_key_press(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
Key = get_string_or(Data, <<"key"/utf8>>, <<""/utf8>>),
Modified_key = get_string_or(Data, <<"modified_key"/utf8>>, Key),
Modifiers = parse_modifiers(Map),
Physical_key = get_optional_string(Data, <<"physical_key"/utf8>>),
Location = parse_key_location(
get_string_or(Data, <<"location"/utf8>>, <<"standard"/utf8>>)
),
Text = get_optional_string(Data, <<"text"/utf8>>),
Repeat = get_bool_or(Data, <<"repeat"/utf8>>, false),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok,
{event_message,
{key_press,
Key,
Modified_key,
Modifiers,
Physical_key,
Location,
Text,
Repeat,
Captured}}}.
-file("src/plushie/protocol/decode.gleam", 803).
-spec decode_key_release(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_key_release(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
Key = get_string_or(Data, <<"key"/utf8>>, <<""/utf8>>),
Modified_key = get_string_or(Data, <<"modified_key"/utf8>>, Key),
Modifiers = parse_modifiers(Map),
Physical_key = get_optional_string(Data, <<"physical_key"/utf8>>),
Location = parse_key_location(
get_string_or(Data, <<"location"/utf8>>, <<"standard"/utf8>>)
),
Text = get_optional_string(Data, <<"text"/utf8>>),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok,
{event_message,
{key_release,
Key,
Modified_key,
Modifiers,
Physical_key,
Location,
Text,
Captured}}}.
-file("src/plushie/protocol/decode.gleam", 827).
-spec decode_modifiers_changed(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_modifiers_changed(Map) ->
Modifiers = parse_modifiers(Map),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok, {event_message, {modifiers_changed, Modifiers, Captured}}}.
-file("src/plushie/protocol/decode.gleam", 839).
-spec decode_window_opened(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_window_opened(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_string(Data, <<"window_id"/utf8>>),
fun(Window_id) ->
gleam@result:'try'(
get_float(Data, <<"width"/utf8>>),
fun(Width) ->
gleam@result:'try'(
get_float(Data, <<"height"/utf8>>),
fun(Height) ->
{Px, Py} = case gleam_stdlib:map_get(
Data,
<<"position"/utf8>>
) of
{ok, {p_map, Pos}} ->
{get_optional_float(Pos, <<"x"/utf8>>),
get_optional_float(Pos, <<"y"/utf8>>)};
_ ->
{get_optional_float(Data, <<"x"/utf8>>),
get_optional_float(Data, <<"y"/utf8>>)}
end,
Scale_factor = get_float_or(
Data,
<<"scale_factor"/utf8>>,
1.0
),
{ok,
{event_message,
{window_opened,
Window_id,
Width,
Height,
Px,
Py,
Scale_factor}}}
end
)
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 868).
-spec decode_window_id_event(
gleam@dict:dict(binary(), prop_value()),
fun((binary()) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_window_id_event(Map, Constructor) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_string(Data, <<"window_id"/utf8>>),
fun(Window_id) -> {ok, {event_message, Constructor(Window_id)}} end
).
-file("src/plushie/protocol/decode.gleam", 877).
-spec decode_window_resized(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_window_resized(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_string(Data, <<"window_id"/utf8>>),
fun(Window_id) ->
gleam@result:'try'(
get_float(Data, <<"width"/utf8>>),
fun(Width) ->
gleam@result:'try'(
get_float(Data, <<"height"/utf8>>),
fun(Height) ->
{ok,
{event_message,
{window_resized, Window_id, Width, Height}}}
end
)
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 887).
-spec decode_window_moved(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_window_moved(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_string(Data, <<"window_id"/utf8>>),
fun(Window_id) ->
gleam@result:'try'(
get_float(Data, <<"x"/utf8>>),
fun(X) ->
gleam@result:'try'(
get_float(Data, <<"y"/utf8>>),
fun(Y) ->
{ok,
{event_message, {window_moved, Window_id, X, Y}}}
end
)
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 897).
-spec decode_window_rescaled(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_window_rescaled(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_string(Data, <<"window_id"/utf8>>),
fun(Window_id) ->
gleam@result:'try'(
get_float(Data, <<"scale_factor"/utf8>>),
fun(Scale_factor) ->
{ok,
{event_message,
{window_rescaled, Window_id, Scale_factor}}}
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 906).
-spec decode_window_file(
gleam@dict:dict(binary(), prop_value()),
fun((binary(), binary()) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_window_file(Map, Constructor) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_string(Data, <<"window_id"/utf8>>),
fun(Window_id) ->
gleam@result:'try'(
get_string(Data, <<"path"/utf8>>),
fun(Path) ->
{ok, {event_message, Constructor(Window_id, Path)}}
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 920).
-spec decode_cursor_moved(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_cursor_moved(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_float(Data, <<"x"/utf8>>),
fun(X) ->
gleam@result:'try'(
get_float(Data, <<"y"/utf8>>),
fun(Y) ->
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok, {event_message, {mouse_moved, X, Y, Captured}}}
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 930).
-spec decode_cursor_entered(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_cursor_entered(Map) ->
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok, {event_message, {mouse_entered, Captured}}}.
-file("src/plushie/protocol/decode.gleam", 937).
-spec decode_cursor_left(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_cursor_left(Map) ->
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok, {event_message, {mouse_left, Captured}}}.
-file("src/plushie/protocol/decode.gleam", 944).
-spec decode_mouse_button(
gleam@dict:dict(binary(), prop_value()),
fun((plushie@event:mouse_button(), boolean()) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_mouse_button(Map, Constructor) ->
Button_str = get_string_or(Map, <<"value"/utf8>>, <<"left"/utf8>>),
Button = parse_mouse_button(Button_str),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok, {event_message, Constructor(Button, Captured)}}.
-file("src/plushie/protocol/decode.gleam", 954).
-spec decode_wheel_scrolled(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_wheel_scrolled(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_float(Data, <<"delta_x"/utf8>>),
fun(Delta_x) ->
gleam@result:'try'(
get_float(Data, <<"delta_y"/utf8>>),
fun(Delta_y) ->
Unit = parse_scroll_unit(
get_string_or(Data, <<"unit"/utf8>>, <<"line"/utf8>>)
),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok,
{event_message,
{mouse_wheel_scrolled,
Delta_x,
Delta_y,
Unit,
Captured}}}
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 971).
-spec decode_touch(
gleam@dict:dict(binary(), prop_value()),
fun((integer(), float(), float(), boolean()) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_touch(Map, Constructor) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_int(Data, <<"id"/utf8>>),
fun(Finger_id) ->
gleam@result:'try'(
get_float(Data, <<"x"/utf8>>),
fun(X) ->
gleam@result:'try'(
get_float(Data, <<"y"/utf8>>),
fun(Y) ->
Captured = get_bool_or(
Map,
<<"captured"/utf8>>,
false
),
{ok,
{event_message,
Constructor(Finger_id, X, Y, Captured)}}
end
)
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 987).
-spec decode_ime_opened(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_ime_opened(Map) ->
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok, {event_message, {ime_opened, Captured}}}.
-file("src/plushie/protocol/decode.gleam", 994).
-spec decode_ime_preedit(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_ime_preedit(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
Text = get_string_or(Data, <<"text"/utf8>>, <<""/utf8>>),
Cursor = case gleam_stdlib:map_get(Data, <<"cursor"/utf8>>) of
{ok, {p_map, C}} ->
Start = get_int_or(C, <<"start"/utf8>>, 0),
End = get_int_or(C, <<"end"/utf8>>, 0),
{some, {Start, End}};
_ ->
none
end,
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok, {event_message, {ime_preedit, Text, Cursor, Captured}}}.
-file("src/plushie/protocol/decode.gleam", 1011).
-spec decode_ime_commit(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_ime_commit(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
Text = get_string_or(Data, <<"text"/utf8>>, <<""/utf8>>),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok, {event_message, {ime_commit, Text, Captured}}}.
-file("src/plushie/protocol/decode.gleam", 1020).
-spec decode_ime_closed(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_ime_closed(Map) ->
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{ok, {event_message, {ime_closed, Captured}}}.
-file("src/plushie/protocol/decode.gleam", 1031).
-spec decode_sensor_resize(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_sensor_resize(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_float(Data, <<"width"/utf8>>),
fun(Width) ->
gleam@result:'try'(
get_float(Data, <<"height"/utf8>>),
fun(Height) ->
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{sensor_resize, Local, Scope, Width, Height}}}
end
)
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 1046).
-spec decode_mouse_area_no_coords(
gleam@dict:dict(binary(), prop_value()),
fun((binary(), list(binary())) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_mouse_area_no_coords(Map, Constructor) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, Constructor(Local, Scope)}}
end
).
-file("src/plushie/protocol/decode.gleam", 1055).
-spec decode_mouse_area_move(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_mouse_area_move(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_float(Data, <<"x"/utf8>>),
fun(X) ->
gleam@result:'try'(
get_float(Data, <<"y"/utf8>>),
fun(Y) ->
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{mouse_area_move, Local, Scope, X, Y}}}
end
)
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 1066).
-spec decode_mouse_area_scroll(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_mouse_area_scroll(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_float(Data, <<"delta_x"/utf8>>),
fun(Delta_x) ->
gleam@result:'try'(
get_float(Data, <<"delta_y"/utf8>>),
fun(Delta_y) ->
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{mouse_area_scroll,
Local,
Scope,
Delta_x,
Delta_y}}}
end
)
end
)
end
).
-file("src/plushie/protocol/decode.gleam", 1081).
-spec decode_canvas_button(
gleam@dict:dict(binary(), prop_value()),
fun((binary(), list(binary()), float(), float(), binary()) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_canvas_button(Map, Constructor) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
X = get_float_or(Data, <<"x"/utf8>>, +0.0),
Y = get_float_or(Data, <<"y"/utf8>>, +0.0),
Button = get_string_or(Data, <<"button"/utf8>>, <<"left"/utf8>>),
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, Constructor(Local, Scope, X, Y, Button)}}
end
).
-file("src/plushie/protocol/decode.gleam", 1094).
-spec decode_canvas_move(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_canvas_move(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
X = get_float_or(Data, <<"x"/utf8>>, +0.0),
Y = get_float_or(Data, <<"y"/utf8>>, +0.0),
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, {canvas_move, Local, Scope, X, Y}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1105).
-spec decode_canvas_scroll(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_canvas_scroll(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
X = get_float_or(Data, <<"x"/utf8>>, +0.0),
Y = get_float_or(Data, <<"y"/utf8>>, +0.0),
Delta_x = get_float_or(Data, <<"delta_x"/utf8>>, +0.0),
Delta_y = get_float_or(Data, <<"delta_y"/utf8>>, +0.0),
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{canvas_scroll, Local, Scope, X, Y, Delta_x, Delta_y}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1131).
-spec decode_canvas_shape_enter(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_canvas_shape_enter(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Shape_id = get_string_or(Data, <<"shape_id"/utf8>>, <<""/utf8>>),
X = get_float_or(Data, <<"x"/utf8>>, +0.0),
Y = get_float_or(Data, <<"y"/utf8>>, +0.0),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{canvas_shape_enter, Local, Scope, Shape_id, X, Y, Captured}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1153).
-spec decode_canvas_shape_leave(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_canvas_shape_leave(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Shape_id = get_string_or(Data, <<"shape_id"/utf8>>, <<""/utf8>>),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{canvas_shape_leave, Local, Scope, Shape_id, Captured}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1166).
-spec decode_canvas_shape_click(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_canvas_shape_click(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Shape_id = get_string_or(Data, <<"shape_id"/utf8>>, <<""/utf8>>),
X = get_float_or(Data, <<"x"/utf8>>, +0.0),
Y = get_float_or(Data, <<"y"/utf8>>, +0.0),
Button = get_string_or(Data, <<"button"/utf8>>, <<"left"/utf8>>),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{canvas_shape_click,
Local,
Scope,
Shape_id,
X,
Y,
Button,
Captured}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1190).
-spec decode_canvas_shape_drag(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_canvas_shape_drag(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Shape_id = get_string_or(Data, <<"shape_id"/utf8>>, <<""/utf8>>),
X = get_float_or(Data, <<"x"/utf8>>, +0.0),
Y = get_float_or(Data, <<"y"/utf8>>, +0.0),
Delta_x = get_float_or(Data, <<"delta_x"/utf8>>, +0.0),
Delta_y = get_float_or(Data, <<"delta_y"/utf8>>, +0.0),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{canvas_shape_drag,
Local,
Scope,
Shape_id,
X,
Y,
Delta_x,
Delta_y,
Captured}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1216).
-spec decode_canvas_shape_drag_end(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_canvas_shape_drag_end(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Shape_id = get_string_or(Data, <<"shape_id"/utf8>>, <<""/utf8>>),
X = get_float_or(Data, <<"x"/utf8>>, +0.0),
Y = get_float_or(Data, <<"y"/utf8>>, +0.0),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{canvas_shape_drag_end,
Local,
Scope,
Shape_id,
X,
Y,
Captured}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1238).
-spec decode_canvas_shape_focused(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_canvas_shape_focused(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Shape_id = get_string_or(Data, <<"shape_id"/utf8>>, <<""/utf8>>),
Captured = get_bool_or(Map, <<"captured"/utf8>>, false),
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{canvas_shape_focused, Local, Scope, Shape_id, Captured}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1260).
-spec decode_pane_resized(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_pane_resized(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Split = case gleam_stdlib:map_get(Data, <<"split"/utf8>>) of
{ok, V} ->
prop_to_dynamic(V);
{error, _} ->
gleam@dynamic:nil()
end,
Ratio = get_float_or(Data, <<"ratio"/utf8>>, 0.5),
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, {pane_resized, Local, Scope, Split, Ratio}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1274).
-spec decode_pane_dragged(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_pane_dragged(Map) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Pane = case gleam_stdlib:map_get(Data, <<"pane"/utf8>>) of
{ok, V} ->
prop_to_dynamic(V);
{error, _} ->
gleam@dynamic:nil()
end,
Target = case gleam_stdlib:map_get(Data, <<"target"/utf8>>) of
{ok, V@1} ->
prop_to_dynamic(V@1);
{error, _} ->
gleam@dynamic:nil()
end,
Action = get_string_or(Data, <<"action"/utf8>>, <<""/utf8>>),
Region = get_optional_string(Data, <<"region"/utf8>>),
Edge = get_optional_string(Data, <<"edge"/utf8>>),
{Local, Scope} = split_scoped_id(Id),
{ok,
{event_message,
{pane_dragged,
Local,
Scope,
Pane,
Target,
Action,
Region,
Edge}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1304).
-spec decode_pane_simple(
gleam@dict:dict(binary(), prop_value()),
fun((binary(), list(binary()), gleam@dynamic:dynamic_()) -> plushie@event:event())
) -> {ok, inbound_message()} | {error, plushie@protocol:decode_error()}.
decode_pane_simple(Map, Constructor) ->
gleam@result:'try'(
get_string(Map, <<"id"/utf8>>),
fun(Id) ->
Data = get_map(Map, <<"data"/utf8>>),
Pane = case gleam_stdlib:map_get(Data, <<"pane"/utf8>>) of
{ok, V} ->
prop_to_dynamic(V);
{error, _} ->
gleam@dynamic:nil()
end,
{Local, Scope} = split_scoped_id(Id),
{ok, {event_message, Constructor(Local, Scope, Pane)}}
end
).
-file("src/plushie/protocol/decode.gleam", 1322).
-spec decode_animation_frame(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_animation_frame(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
gleam@result:'try'(
get_int(Data, <<"timestamp"/utf8>>),
fun(Timestamp) ->
{ok, {event_message, {animation_frame, Timestamp}}}
end
).
-file("src/plushie/protocol/decode.gleam", 1330).
-spec decode_theme_changed(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_theme_changed(Map) ->
gleam@result:'try'(
get_string(Map, <<"value"/utf8>>),
fun(Theme) -> {ok, {event_message, {theme_changed, Theme}}} end
).
-file("src/plushie/protocol/decode.gleam", 1341).
-spec decode_announce(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_announce(Map) ->
Data = get_map(Map, <<"data"/utf8>>),
Text = get_string_or(Data, <<"text"/utf8>>, <<""/utf8>>),
{ok, {event_message, {announce, Text}}}.
-file("src/plushie/protocol/decode.gleam", 1353).
-spec decode_error_event(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_error_event(Map) ->
Error_id = get_string_or(Map, <<"id"/utf8>>, <<""/utf8>>),
case Error_id of
<<"duplicate_node_ids"/utf8>> ->
Details = case gleam_stdlib:map_get(Map, <<"data"/utf8>>) of
{ok, V} ->
prop_to_dynamic(V);
{error, _} ->
gleam@dynamic:nil()
end,
{ok, {event_message, {duplicate_node_ids, Details}}};
_ ->
decode_generic_widget_event(Map, <<"error"/utf8>>)
end.
-file("src/plushie/protocol/decode.gleam", 492).
-spec decode_event(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_event(Map) ->
gleam@result:'try'(
get_string(Map, <<"family"/utf8>>),
fun(Family) -> case Family of
<<"click"/utf8>> ->
decode_widget_click(Map);
<<"input"/utf8>> ->
decode_widget_string_value(
Map,
fun(Field@0, Field@1, Field@2) -> {widget_input, Field@0, Field@1, Field@2} end
);
<<"submit"/utf8>> ->
decode_widget_string_value(
Map,
fun(Field@0, Field@1, Field@2) -> {widget_submit, Field@0, Field@1, Field@2} end
);
<<"toggle"/utf8>> ->
decode_widget_toggle(Map);
<<"select"/utf8>> ->
decode_widget_string_value(
Map,
fun(Field@0, Field@1, Field@2) -> {widget_select, Field@0, Field@1, Field@2} end
);
<<"slide"/utf8>> ->
decode_widget_float_value(
Map,
fun(Field@0, Field@1, Field@2) -> {widget_slide, Field@0, Field@1, Field@2} end
);
<<"slide_release"/utf8>> ->
decode_widget_float_value(
Map,
fun(Field@0, Field@1, Field@2) -> {widget_slide_release, Field@0, Field@1, Field@2} end
);
<<"paste"/utf8>> ->
decode_widget_string_value(
Map,
fun(Field@0, Field@1, Field@2) -> {widget_paste, Field@0, Field@1, Field@2} end
);
<<"open"/utf8>> ->
decode_widget_no_value(
Map,
fun(Field@0, Field@1) -> {widget_open, Field@0, Field@1} end
);
<<"close"/utf8>> ->
decode_widget_no_value(
Map,
fun(Field@0, Field@1) -> {widget_close, Field@0, Field@1} end
);
<<"option_hovered"/utf8>> ->
decode_widget_string_value(
Map,
fun(Field@0, Field@1, Field@2) -> {widget_option_hovered, Field@0, Field@1, Field@2} end
);
<<"sort"/utf8>> ->
decode_widget_sort(Map);
<<"key_binding"/utf8>> ->
decode_widget_key_binding(Map);
<<"scroll"/utf8>> ->
decode_widget_scroll(Map);
<<"key_press"/utf8>> ->
decode_key_press(Map);
<<"key_release"/utf8>> ->
decode_key_release(Map);
<<"modifiers_changed"/utf8>> ->
decode_modifiers_changed(Map);
<<"window_opened"/utf8>> ->
decode_window_opened(Map);
<<"window_closed"/utf8>> ->
decode_window_id_event(
Map,
fun(Field@0) -> {window_closed, Field@0} end
);
<<"window_close_requested"/utf8>> ->
decode_window_id_event(
Map,
fun(Field@0) -> {window_close_requested, Field@0} end
);
<<"window_resized"/utf8>> ->
decode_window_resized(Map);
<<"window_moved"/utf8>> ->
decode_window_moved(Map);
<<"window_focused"/utf8>> ->
decode_window_id_event(
Map,
fun(Field@0) -> {window_focused, Field@0} end
);
<<"window_unfocused"/utf8>> ->
decode_window_id_event(
Map,
fun(Field@0) -> {window_unfocused, Field@0} end
);
<<"window_rescaled"/utf8>> ->
decode_window_rescaled(Map);
<<"file_hovered"/utf8>> ->
decode_window_file(
Map,
fun(Field@0, Field@1) -> {window_file_hovered, Field@0, Field@1} end
);
<<"file_dropped"/utf8>> ->
decode_window_file(
Map,
fun(Field@0, Field@1) -> {window_file_dropped, Field@0, Field@1} end
);
<<"files_hovered_left"/utf8>> ->
decode_window_id_event(
Map,
fun(Field@0) -> {window_files_hovered_left, Field@0} end
);
<<"cursor_moved"/utf8>> ->
decode_cursor_moved(Map);
<<"cursor_entered"/utf8>> ->
decode_cursor_entered(Map);
<<"cursor_left"/utf8>> ->
decode_cursor_left(Map);
<<"button_pressed"/utf8>> ->
decode_mouse_button(
Map,
fun(Field@0, Field@1) -> {mouse_button_pressed, Field@0, Field@1} end
);
<<"button_released"/utf8>> ->
decode_mouse_button(
Map,
fun(Field@0, Field@1) -> {mouse_button_released, Field@0, Field@1} end
);
<<"wheel_scrolled"/utf8>> ->
decode_wheel_scrolled(Map);
<<"finger_pressed"/utf8>> ->
decode_touch(
Map,
fun(Field@0, Field@1, Field@2, Field@3) -> {touch_pressed, Field@0, Field@1, Field@2, Field@3} end
);
<<"finger_moved"/utf8>> ->
decode_touch(
Map,
fun(Field@0, Field@1, Field@2, Field@3) -> {touch_moved, Field@0, Field@1, Field@2, Field@3} end
);
<<"finger_lifted"/utf8>> ->
decode_touch(
Map,
fun(Field@0, Field@1, Field@2, Field@3) -> {touch_lifted, Field@0, Field@1, Field@2, Field@3} end
);
<<"finger_lost"/utf8>> ->
decode_touch(
Map,
fun(Field@0, Field@1, Field@2, Field@3) -> {touch_lost, Field@0, Field@1, Field@2, Field@3} end
);
<<"ime_opened"/utf8>> ->
decode_ime_opened(Map);
<<"ime_preedit"/utf8>> ->
decode_ime_preedit(Map);
<<"ime_commit"/utf8>> ->
decode_ime_commit(Map);
<<"ime_closed"/utf8>> ->
decode_ime_closed(Map);
<<"sensor_resize"/utf8>> ->
decode_sensor_resize(Map);
<<"mouse_right_press"/utf8>> ->
decode_mouse_area_no_coords(
Map,
fun(Field@0, Field@1) -> {mouse_area_right_press, Field@0, Field@1} end
);
<<"mouse_right_release"/utf8>> ->
decode_mouse_area_no_coords(
Map,
fun(Field@0, Field@1) -> {mouse_area_right_release, Field@0, Field@1} end
);
<<"mouse_middle_press"/utf8>> ->
decode_mouse_area_no_coords(
Map,
fun(Field@0, Field@1) -> {mouse_area_middle_press, Field@0, Field@1} end
);
<<"mouse_middle_release"/utf8>> ->
decode_mouse_area_no_coords(
Map,
fun(Field@0, Field@1) -> {mouse_area_middle_release, Field@0, Field@1} end
);
<<"mouse_double_click"/utf8>> ->
decode_mouse_area_no_coords(
Map,
fun(Field@0, Field@1) -> {mouse_area_double_click, Field@0, Field@1} end
);
<<"mouse_enter"/utf8>> ->
decode_widget_no_value(
Map,
fun(Field@0, Field@1) -> {mouse_area_enter, Field@0, Field@1} end
);
<<"mouse_exit"/utf8>> ->
decode_widget_no_value(
Map,
fun(Field@0, Field@1) -> {mouse_area_exit, Field@0, Field@1} end
);
<<"mouse_move"/utf8>> ->
decode_mouse_area_move(Map);
<<"mouse_scroll"/utf8>> ->
decode_mouse_area_scroll(Map);
<<"canvas_press"/utf8>> ->
decode_canvas_button(
Map,
fun(Field@0, Field@1, Field@2, Field@3, Field@4) -> {canvas_press, Field@0, Field@1, Field@2, Field@3, Field@4} end
);
<<"canvas_release"/utf8>> ->
decode_canvas_button(
Map,
fun(Field@0, Field@1, Field@2, Field@3, Field@4) -> {canvas_release, Field@0, Field@1, Field@2, Field@3, Field@4} end
);
<<"canvas_move"/utf8>> ->
decode_canvas_move(Map);
<<"canvas_scroll"/utf8>> ->
decode_canvas_scroll(Map);
<<"canvas_shape_enter"/utf8>> ->
decode_canvas_shape_enter(Map);
<<"canvas_shape_leave"/utf8>> ->
decode_canvas_shape_leave(Map);
<<"canvas_shape_click"/utf8>> ->
decode_canvas_shape_click(Map);
<<"canvas_shape_drag"/utf8>> ->
decode_canvas_shape_drag(Map);
<<"canvas_shape_drag_end"/utf8>> ->
decode_canvas_shape_drag_end(Map);
<<"canvas_shape_focused"/utf8>> ->
decode_canvas_shape_focused(Map);
<<"pane_resized"/utf8>> ->
decode_pane_resized(Map);
<<"pane_dragged"/utf8>> ->
decode_pane_dragged(Map);
<<"pane_clicked"/utf8>> ->
decode_pane_simple(
Map,
fun(Field@0, Field@1, Field@2) -> {pane_clicked, Field@0, Field@1, Field@2} end
);
<<"pane_focus_cycle"/utf8>> ->
decode_pane_simple(
Map,
fun(Field@0, Field@1, Field@2) -> {pane_focus_cycle, Field@0, Field@1, Field@2} end
);
<<"animation_frame"/utf8>> ->
decode_animation_frame(Map);
<<"theme_changed"/utf8>> ->
decode_theme_changed(Map);
<<"all_windows_closed"/utf8>> ->
{ok, {event_message, all_windows_closed}};
<<"announce"/utf8>> ->
decode_announce(Map);
<<"error"/utf8>> ->
decode_error_event(Map);
_ ->
decode_generic_widget_event(Map, Family)
end end
).
-file("src/plushie/protocol/decode.gleam", 387).
-spec dispatch(gleam@dict:dict(binary(), prop_value())) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
dispatch(Map) ->
gleam@result:'try'(
get_string(Map, <<"type"/utf8>>),
fun(Msg_type) -> case Msg_type of
<<"hello"/utf8>> ->
decode_hello(Map);
<<"event"/utf8>> ->
decode_event(Map);
<<"effect_response"/utf8>> ->
decode_effect_response(Map);
<<"op_query_response"/utf8>> ->
decode_op_query_response(Map);
_ ->
{error, {unknown_message_type, Msg_type}}
end end
).
-file("src/plushie/protocol/decode.gleam", 172).
-spec msgpack_map_to_string_dict(
gleam@dict:dict(glepack@data:value(), glepack@data:value())
) -> gleam@dict:dict(binary(), prop_value()).
msgpack_map_to_string_dict(Entries) ->
gleam@dict:fold(Entries, maps:new(), fun(Acc, Key, Value) -> case Key of
{string, K} ->
gleam@dict:insert(Acc, K, msgpack_to_prop(Value));
_ ->
Acc
end end).
-file("src/plushie/protocol/decode.gleam", 158).
-spec msgpack_to_prop(glepack@data:value()) -> prop_value().
msgpack_to_prop(Value) ->
case Value of
nil ->
p_null;
{boolean, B} ->
{p_bool, B};
{integer, N} ->
{p_int, N};
{float, F} ->
{p_float, F};
{string, S} ->
{p_string, S};
{binary, B@1} ->
{p_string, gleam_stdlib:base64_encode(B@1, true)};
{array, Items} ->
{p_list, gleam@list:map(Items, fun msgpack_to_prop/1)};
{map, Entries} ->
{p_map, msgpack_map_to_string_dict(Entries)};
{extension, _, _} ->
p_null
end.
-file("src/plushie/protocol/decode.gleam", 117).
-spec deserialize_msgpack(bitstring()) -> {ok,
gleam@dict:dict(binary(), prop_value())} |
{error, plushie@protocol:decode_error()}.
deserialize_msgpack(Data) ->
case glepack:unpack_exact(Data) of
{ok, Value} ->
case msgpack_to_prop(Value) of
{p_map, Map} ->
{ok, Map};
_ ->
{error,
{deserialization_failed,
<<"top-level value is not a map"/utf8>>}}
end;
{error, E} ->
{error, {deserialization_failed, glepack@error:to_string(E)}}
end.
-file("src/plushie/protocol/decode.gleam", 107).
-spec deserialize(bitstring(), plushie@protocol:format()) -> {ok,
gleam@dict:dict(binary(), prop_value())} |
{error, plushie@protocol:decode_error()}.
deserialize(Data, Format) ->
case Format of
msgpack ->
deserialize_msgpack(Data);
json ->
deserialize_json(Data)
end.
-file("src/plushie/protocol/decode.gleam", 70).
?DOC(" Decode raw wire bytes into an InboundMessage.\n").
-spec decode_message(bitstring(), plushie@protocol:format()) -> {ok,
inbound_message()} |
{error, plushie@protocol:decode_error()}.
decode_message(Data, Format) ->
gleam@result:'try'(deserialize(Data, Format), fun(Map) -> dispatch(Map) end).