Skip to content
Browse files

Converted to use of binaries.

  • Loading branch information...
1 parent 1c6e37d commit 05990f107a18bd22cca5ee3e3b6d1b9fc656fa82 vladdu committed Feb 28, 2003
View
1 lib/ex11/TODO
@@ -0,0 +1 @@
+
View
47 lib/ex11/include/ex11.hrl
@@ -347,20 +347,53 @@
-define(PRINT_ERROR(E),
error_logger:error_msg(
- "ERROR-MSG: type = ~w seqno = ~w minor_opcode = ~w major_opcode = ~w~n",
- [E#error.type,E#error.seqno,E#error.minor_opcode,E#error.major_opcode])).
+ "ERROR-MSG: type= ~w seqno= ~w minor_opcode =~w major_opcode= ~w id= ~w~n",
+ [E#error.type,E#error.seqno,E#error.minor_opcode,E#error.major_opcode,E#error.bad_resource_id])).
%% ---------------
%% EVENT MESSAGES
%% ---------------
%% Event codes
+-define(EVENT_KEYPRESS, 2).
+-define(EVENT_KEYRELEASE, 3).
+-define(EVENT_BUTTONPRESS, 4).
+-define(EVENT_BUTTONRELEASE, 5).
+-define(EVENT_MOTION_NOTIFY, 6).
+-define(EVENT_ENTER_NOTIFY, 7).
+-define(EVENT_LEAVE_NOTIFY, 8).
+-define(EVENT_FOCUS_IN, 9).
+-define(EVENT_FOCUS_OUT, 10).
+-define(EVENT_KEYMAP_NOTIFY, 11).
-define(EVENT_EXPOSE, 12).
+-define(EVENT_GRAPHICS_EXPOSURE, 13).
+-define(EVENT_NO_EXPOSURE, 14).
+-define(EVENT_VISIBILITY_NOTIFY, 15).
+-define(EVENT_CREATE_NOTIFY, 16).
+-define(EVENT_DESTROY_NOTIFY, 17).
+-define(EVENT_UNMAP_NOTIFY, 18).
-define(EVENT_MAP_NOTIFY, 19).
+-define(EVENT_MAP_REQUEST, 20).
-define(EVENT_REPARENT_NOTIFY, 21).
-define(EVENT_CONFIGURE_NOTIFY, 22).
+-define(EVENT_CONFIGURE_REQUEST, 23).
+-define(EVENT_GRAVITY_NOTIFY, 24).
+-define(EVENT_RESIZE_REQUEST, 25).
+-define(EVENT_CIRCULATE_NOTIFY, 26).
+-define(EVENT_CIRCULATE_REQUEST, 27).
+-define(EVENT_PROPERTY_NOTIFY, 28).
+-define(EVENT_SELECTION_CLEAR, 29).
+-define(EVENT_SELECTION_REQUEST, 30).
+-define(EVENT_SELECTION_NOTIFY, 31).
+-define(EVENT_COLORMAP_NOTIFY, 32).
+-define(EVENT_CLIENT_MESSAGE, 33).
+-define(EVENT_MAPPING_NOTIFY, 34).
%% Event records
+-record(key_press, {seqno}).
+
+-record(key_release, {seqno}).
+
-record(expose, {seqno, window, x, y, width, height, count}).
-record(map_notify, {seqno, event, window, override_redirect}).
@@ -371,10 +404,12 @@
width, height, border_width, override_redirect}).
%% Event guards
--define(IS_EXPOSE_EVENT(E), record(E,expose)).
--define(IS_MAP_NOTIFY_EVENT(E), record(E,map_notify)).
--define(IS_REPARENT_NOTIFY_EVENT(E), record(E,reparent_notify)).
--define(IS_CONFIGURE_NOTIFY_EVENT(E), record(E,configure_notify)).
+-define(IS_KEY_PRESS_EVENT(E), record(E, key_press)).
+-define(IS_KEY_RELEASE_EVENT(E), record(E, key_release)).
+-define(IS_EXPOSE_EVENT(E), record(E, expose)).
+-define(IS_MAP_NOTIFY_EVENT(E), record(E, map_notify)).
+-define(IS_REPARENT_NOTIFY_EVENT(E), record(E, reparent_notify)).
+-define(IS_CONFIGURE_NOTIFY_EVENT(E), record(E, configure_notify)).
%% TEMPORARY: Until all events is implemented
-record(event_nyi, {event}).
View
1 lib/ex11/src/ex11.erl
@@ -23,7 +23,6 @@
%%% Contributor(s): ______________________________________.
%%%
%%%---------------------------------------------------------------------
--vc('$Id$ ').
-export([start/1,req/2,synchronize/2,flush/1,get_display/1,set_display/2,
lock_display/1,unlock_display/1]).
View
34 lib/ex11/src/ex11_client.erl
@@ -28,7 +28,6 @@
%%% use of ex11_xauth:filename/0.
%%%
%%%---------------------------------------------------------------------
--vc('$Id$ ').
-export([start/1,req/2,synchronize/2,flush/1,lock_display/1,unlock_display/1,
set_display/2,get_display/1,new_window/2,new_pixmap/2,new_gc/2]).
%% Internal exports
@@ -176,13 +175,13 @@ loop(Dpy,Db,Out,Cont,SeqNo,Sync,Lock) ->
receive
{From,send_msg,Msg} when Sync == ?FLUSH ->
- %%io:format("SENDING REQUEST: ~p~n",[Msg]),
+ %%io:format("SENDING REQUEST: ~w~n",[binary_to_list(Msg)]),
NewSeqNo = send_request(Dpy,SeqNo,Msg),
return(From,ok),
loop(Dpy,Db,Out,Cont,NewSeqNo,Sync,Lock);
{From,send_msg,Msg} when Sync == ?BUFFER ->
- %%io:format("BUFFERING REQUEST: ~p~n",[Msg]),
+ %%io:format("BUFFERING REQUEST: ~w~n",[binary_to_list(Msg)]),
return(From,ok),
loop(Dpy,Db,queue:in(Msg,Out),Cont,SeqNo,Sync,Lock);
@@ -249,7 +248,7 @@ loop(Dpy,Db,Out,Cont,SeqNo,Sync,Lock) ->
loop(Dpy,NewDb,Out,Cont,SeqNo,Sync,Lock);
XX ->
- io:format("GOT: ~p~n",[XX]),
+ io:format("GOT: ~w~n",[XX]),
loop(Dpy,Db,Out,Cont,SeqNo,Sync,Lock)
end.
@@ -296,8 +295,10 @@ dispatch(Dpy,Db,Out,Cont,SeqNo,Sync,Lock,Data) ->
loop(Dpy,Db,Out,?NO_CONT,SeqNo,Sync,Lock)
end.
-decode(Db,?NO_CONT,Data) -> ex11_proto:decode(Db,Data);
-decode(Db,C,Data) when ?IS_CONT(C) -> ?CONTINUE(C,{Db,Data}).
+decode(Db,?NO_CONT,Data) ->
+ ex11_proto:decode(Db,Data);
+decode(Db,C,Data) when ?IS_CONT(C) ->
+ ?CONTINUE(C,{Db,Data}).
%% -----------------------------------------
%% Deliver an event to the correct process
@@ -324,26 +325,30 @@ deliver_event(Db,Id,Event) ->
%% See p.113 in the X Protocol standard X11 Rel-6.4
setup_connection(Host,Cookie) ->
- Opts = [{packet,raw}],
+ Opts = [{packet,raw},binary],
case gen_tcp:connect(Host,6000,Opts) of
{ok,Fd} ->
- gen_tcp:send(Fd,ex11_proto:setup_connection(Cookie)),
+ Res=gen_tcp:send(Fd,ex11_proto:setup_connection(Cookie)),
get_connect_reply(Fd);
Error -> exit(Error)
end.
get_connect_reply(Fd) ->
- case recv(Fd) of
- [0|Emsg] -> {error,ex11_proto:decode_error(Emsg)};
- [2|_] -> {error,"authentication required"};
- [1,_|Msg] -> ex11_proto:decode_connect_reply(Fd,Msg)
+ Rec = recv(Fd),
+ case Rec of
+ <<0, Emsg/binary>> ->
+ {error,ex11_proto:decode_error(Emsg)};
+ <<2,_/binary>> ->
+ {error,"authentication required"};
+ <<1,_,Msg/binary>> ->
+ ex11_proto:decode_connect_reply(Fd,Msg)
end.
%% ----------------------------------------------------
%% Send a request to the X-server.
send_request(Dpy,SeqNo,Msg) ->
- gen_tcp:send(Dpy#display.fd,[Msg]),
+ gen_tcp:send(Dpy#display.fd, Msg),
bump_seqno(SeqNo).
%% Also, if the request will initiate a reply from the
@@ -361,7 +366,8 @@ bump_seqno(SeqNo) -> (SeqNo + 1) rem ?MAX_SEQNO.
recv(Fd) ->
receive
- {tcp,Fd,Data} -> Data
+ {tcp,Fd,Data} ->
+ Data
end.
View
1 lib/ex11/src/ex11_db.erl
@@ -22,7 +22,6 @@
%%% Contributor(s): ______________________________________.
%%%
%%%---------------------------------------------------------------------
--vc('$Id$ ').
-export([init/0,get_display/1,set_display/2,put_window/3,put_pixmap/3,
put_gc/3,put_id/4,get_id/2,store_req/4,get_reply/2]).
View
569 lib/ex11/src/ex11_proto.erl
@@ -27,12 +27,10 @@
%%% To make it work under Windows.
%%%
%%%---------------------------------------------------------------------
--vc('$Id$ ').
-export([map_window/2,create_window/2,decode_error/1,
setup_connection/1,decode_refused_connection/1,
decode/2,decode_connect_reply/2,encode/2]).
--import(ex11_utils,[i16/1,i16/2,i32/1,i32/4,split_list/2]).
-import(error_logger,[error_msg/2]).
-include("ex11.hrl").
@@ -46,7 +44,7 @@
setup_connection([]) ->
<<?MSB_BYTEORDER:8, % Erlang byte-order
- 0:8, % unused
+ 0, % unused
11:16, % proto-major-ver
0:16, % proto-minor-ver
0:16, % proto-name-len
@@ -56,38 +54,38 @@ setup_connection(Cookie) ->
Len = length(Cookie),
Pad = add_pad(Cookie),
<<?MSB_BYTEORDER:8, % Erlang byte-order
- 0:8, % unused
+ 0, % unused
11:16, % proto-major-ver
0:16, % proto-minor-ver
18:16, % proto-name-len
Len:16, % proto-data-len
0:16, % unused
"MIT-MAGIC-COOKIE-1", % auth-proto-name
0:16, % pad
- Cookie, % auth-proto-data
- Pad>>. % pad
+ (list_to_binary(Cookie))/binary, % auth-proto-data
+ Pad/binary>>. % pad
decode_refused_connection(<<Len,ProtoMaj:16,ProtoMin:16,_TotLen:16,D/binary>>) ->
- <<ReasonB:Len/binary, _D1/binary>> = D,
+ <<ReasonB:Len/binary, _/binary>> = D,
Reason = binary_to_list(ReasonB),
#refused_connection{maj_proto=ProtoMaj,
min_proto=ProtoMin,
reason=Reason}.
-
+
decode_connect_reply(Fd,Msg) ->
<<_:32, _Len:16, RelNo:32, ResBase:32, ResMask0:32,
- MbufSz:32, VendorLen:16, MaxReqLen:16,
- Screens, Formats,
- ImOrder, BmapOrder, BmapScanU, BmapScanP,
- MinKCode, MaxKCode, _:32,
- B/binary>> = list_to_binary(Msg),
- VendorPad = bpad(VendorLen),
+ MbufSz:32, VendorLen:16, MaxReqLen:16,
+ Screens, Formats,
+ ImOrder, BmapOrder, BmapScanU, BmapScanP,
+ MinKCode, MaxKCode, _:32,
+ B/binary>> = Msg,
+ VendorPad = pad(VendorLen),
PmapFormLen = 8*Formats,
<<VendorB:VendorLen/binary,
- _:VendorPad,
- PmapForm:PmapFormLen/binary,
- PmapScreen/binary>> = B,
-
+ _:VendorPad/binary,
+ PmapForm:PmapFormLen/binary,
+ PmapScreen/binary>> = B,
+
{ResMask,ResShift} = resource_calc(ResMask0),
Vendor = binary_to_list(VendorB),
Format = decode_format(Formats,PmapForm),
@@ -112,6 +110,7 @@ decode_connect_reply(Fd,Msg) ->
nformats=Formats,
pixmap_formats=Format,
fd=Fd},
+
{ok,Display}.
%% Eh...what a hell am I doing here ? See OpenDis.c l.374
@@ -133,7 +132,7 @@ decode_format(N, <<Depth,
Format = #format{depth=Depth,
bpp=Bpp,
scanline_pad=ScanlinePad
- },
+ },
[Format | decode_format(N-1,T)].
decode_screen(0, _) -> [];
@@ -166,7 +165,7 @@ decode_screen(N, <<Window:32,
depths=Depths,
root_depth=Rd},
[Screen | decode_screen(N-1,Rest)].
-
+
decode_depth(Nd,D) -> decode_depth(Nd,D,[]).
decode_depth(0,Rest,Acc) -> {lists:reverse(Acc),Rest};
@@ -230,7 +229,7 @@ enc(_,_) -> {error,unknown_request}.
%% -----------------------
%% The Change GC request
-change_gc(X,#change_gc{opcode=Opcode, cid=Cid, value_mask=ValueMask}=R)
+change_gc(_X, #change_gc{opcode=Opcode, cid=Cid, value_mask=ValueMask}=R)
when Cid =/= undefined ->
ValueList = encode_gc_valuelist(ValueMask, R#change_gc.value_list),
Len = 3 + length(ValueList),
@@ -245,9 +244,9 @@ change_gc(X,#change_gc{opcode=Opcode, cid=Cid, value_mask=ValueMask}=R)
%% -----------------------
%% The clear area request
-clear_area(X,#clear_area{}=R) when R#clear_area.window =/= undefined,
- R#clear_area.width =/= undefined,
- R#clear_area.height =/= undefined ->
+clear_area(_X, #clear_area{}=R) when R#clear_area.window =/= undefined,
+ R#clear_area.width =/= undefined,
+ R#clear_area.height =/= undefined ->
{ok,
<<(R#clear_area.opcode),
(R#clear_area.exposures),
@@ -261,15 +260,15 @@ clear_area(X,#clear_area{}=R) when R#clear_area.window =/= undefined,
%% ----------------------
%% The copy area request
-copy_area(X,R) when R#copy_area.src =/= undefined,
- R#copy_area.dst =/= undefined,
- R#copy_area.cid =/= undefined,
- R#copy_area.src_x =/= undefined,
- R#copy_area.src_y =/= undefined,
- R#copy_area.dst_x =/= undefined,
- R#copy_area.dst_y =/= undefined,
- R#copy_area.width =/= undefined,
- R#copy_area.height =/= undefined ->
+copy_area(_X, R) when R#copy_area.src =/= undefined,
+ R#copy_area.dst =/= undefined,
+ R#copy_area.cid =/= undefined,
+ R#copy_area.src_x =/= undefined,
+ R#copy_area.src_y =/= undefined,
+ R#copy_area.dst_x =/= undefined,
+ R#copy_area.dst_y =/= undefined,
+ R#copy_area.width =/= undefined,
+ R#copy_area.height =/= undefined ->
{ok,
<<(R#copy_area.opcode),
0, % unused
@@ -287,7 +286,7 @@ copy_area(X,R) when R#copy_area.src =/= undefined,
%% ---------------------
%% The Create GC request
-create_gc(X,R) when R#create_gc.drawable =/= undefined ->
+create_gc(X, R) when R#create_gc.drawable =/= undefined ->
Cid = case R#create_gc.cid of
undefined ->
ex11:lock_display(X),
@@ -301,67 +300,92 @@ create_gc(X,R) when R#create_gc.drawable =/= undefined ->
end,
ValueMask = R#create_gc.value_mask,
ValueList = encode_gc_valuelist(ValueMask,R#create_gc.value_list),
- {ok,
- [(R#create_gc.opcode),
- 0, % unused
- i16(4 + length(ValueList)),
- i32(Cid),
- i32(R#create_gc.drawable),
- i32(ValueMask),
- ValueList],
- {ok,Cid}}.
+
+ B = <<(R#create_gc.opcode),
+ 0, % unused
+ (4 + size(ValueList) div 4):16,
+ (Cid):32,
+ (R#create_gc.drawable):32,
+ (ValueMask):32,
+ ValueList/binary>>,
+
+ {ok, B, {ok,Cid}}.
encode_gc_valuelist(ValueMask,R) when ?IS_GC_VALUES(R) ->
enc_gc_vl(ValueMask,R).
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_FUNCTION) ->
- [i32(R#gc_values.function)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FUNCTION),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FUNCTION),R),
+ <<(R#gc_values.function):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_PLANE_MASK) ->
- [i32(R#gc_values.plane_mask)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_PLANE_MASK),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_PLANE_MASK),R),
+ <<(R#gc_values.plane_mask):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_FOREGROUND) ->
- [i32(R#gc_values.foreground)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FOREGROUND),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FOREGROUND),R),
+ <<(R#gc_values.foreground):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_BACKGROUND) ->
- [i32(R#gc_values.background)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_BACKGROUND),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_BACKGROUND),R),
+ <<(R#gc_values.background):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_LINE_WIDTH) ->
- [i32(R#gc_values.line_width)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_LINE_WIDTH),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_LINE_WIDTH),R),
+ <<(R#gc_values.line_width):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_LINE_STYLE) ->
- [i32(R#gc_values.line_style)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_LINE_STYLE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_LINE_STYLE),R),
+ <<(R#gc_values.line_style):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_CAP_STYLE) ->
- [i32(R#gc_values.cap_style)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_CAP_STYLE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_CAP_STYLE),R),
+ <<(R#gc_values.cap_style):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_JOIN_STYLE) ->
- [i32(R#gc_values.join_style)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_JOIN_STYLE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_JOIN_STYLE),R),
+ <<(R#gc_values.join_style):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_FILL_STYLE) ->
- [i32(R#gc_values.fill_style)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FILL_STYLE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FILL_STYLE),R),
+ <<(R#gc_values.fill_style):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_FILL_RULE) ->
- [i32(R#gc_values.fill_rule)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FILL_RULE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FILL_RULE),R),
+ <<(R#gc_values.fill_rule):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_TILE) ->
- [i32(R#gc_values.tile)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_TILE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_TILE),R),
+ <<(R#gc_values.tile):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_STIPPLE) ->
- [i32(R#gc_values.stipple)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_STIPPLE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_STIPPLE),R),
+ <<(R#gc_values.stipple):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_TILE_STIPPLE_X) ->
- [i32(R#gc_values.tile_stipple_x)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_TILE_STIPPLE_X),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_TILE_STIPPLE_X),R),
+ <<(R#gc_values.tile_stipple_x):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_TILE_STIPPLE_Y) ->
- [i32(R#gc_values.tile_stipple_y)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_TILE_STIPPLE_Y),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_TILE_STIPPLE_Y),R),
+ <<(R#gc_values.tile_stipple_y):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_FONT) ->
- [i32(R#gc_values.font)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FONT),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_FONT),R),
+ <<(R#gc_values.font):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_SUBWIN_MODE) ->
- [i32(R#gc_values.subwin_mode)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_SUBWIN_MODE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_SUBWIN_MODE),R),
+ <<(R#gc_values.subwin_mode):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_EXPOSURES) ->
- [i32(R#gc_values.exposures)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_EXPOSURES),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_EXPOSURES),R),
+ <<(R#gc_values.exposures):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_CLIP_X) ->
- [i32(R#gc_values.clip_x)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_CLIP_X),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_CLIP_X),R),
+ <<(R#gc_values.clip_x):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_CLIP_Y) ->
- [i32(R#gc_values.clip_y)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_CLIP_Y),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_CLIP_Y),R),
+ <<(R#gc_values.clip_y):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_CLIP_MASK) ->
- [i32(R#gc_values.clip_mask)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_CLIP_MASK),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_CLIP_MASK),R),
+ <<(R#gc_values.clip_mask):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_DASH_OFFSET) ->
- [i32(R#gc_values.dash_offset)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_DASH_OFFSET),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_DASH_OFFSET),R),
+ <<(R#gc_values.dash_offset):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_DASHES) ->
- [i32(R#gc_values.dashes)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_DASHES),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_DASHES),R),
+ <<(R#gc_values.dashes):32, Rest/binary>>;
enc_gc_vl(Vm,R) when ?IS_SET(Vm,?GC_VALUEMASK_ARC_MODE) ->
- [i32(R#gc_values.arc_mode)|enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_ARC_MODE),R)];
-enc_gc_vl(_,_) -> [].
+ Rest = enc_gc_vl(?CLR(Vm,?GC_VALUEMASK_ARC_MODE),R),
+ <<(R#gc_values.arc_mode):32, Rest/binary>>;
+enc_gc_vl(_,_) ->
+ <<>>.
%% --------------------------
%% The Create Pixmap request
@@ -384,15 +408,15 @@ create_pixmap(X,R) when R#create_pixmap.drawable =/= undefined,
undefined -> ?ROOT_DEPTH(Dpy);
Depth0 -> Depth0
end,
- {ok,
- [R#create_pixmap.opcode,
- Depth,
- i16(4),
- i32(Pid),
- i32(R#create_pixmap.drawable),
- i16(R#create_pixmap.width),
- i16(R#create_pixmap.height)],
- {ok,Pid}}.
+ B = <<(R#create_pixmap.opcode),
+ Depth,
+ 4:16,
+ (Pid):32,
+ (R#create_pixmap.drawable):32,
+ (R#create_pixmap.width):16,
+ (R#create_pixmap.height):16>>,
+
+ {ok, B, {ok,Pid}}.
%% --------------------------
%% The Create Window request
@@ -422,285 +446,332 @@ create_window(X,R) ->
ValueMask = R#create_window.value_mask,
ValueList = encode_win_valuelist(ValueMask,
R#create_window.value_list),
- {ok,
- [R#create_window.opcode,
- Depth,
- i16(8+length(ValueList)),
- i32(Win),
- i32(Parent),
- i16(R#create_window.x),
- i16(R#create_window.y),
- i16(R#create_window.width),
- i16(R#create_window.height),
- i16(R#create_window.border_width),
- i16(R#create_window.class),
- i32(R#create_window.visual),
- i32(R#create_window.value_mask),
- ValueList],
- {ok,Win}}.
+ B = <<(R#create_window.opcode),
+ Depth,
+ (8+size(ValueList) div 4):16,
+ (Win):32,
+ (Parent):32,
+ (R#create_window.x):16,
+ (R#create_window.y):16,
+ (R#create_window.width):16,
+ (R#create_window.height):16,
+ (R#create_window.border_width):16,
+ (R#create_window.class):16,
+ (R#create_window.visual):32,
+ (R#create_window.value_mask):32,
+ ValueList/binary>>,
+
+ {ok, B, {ok,Win}}.
encode_win_valuelist(ValueMask,R) when ?IS_WIN_VALUES(R) ->
enc_win_vl(ValueMask,R).
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_BG_PIXMAP) ->
- [i32(R#win_values.bg_pixmap)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BG_PIXMAP),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BG_PIXMAP),R),
+ <<(R#win_values.bg_pixmap):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_BG_PIXEL) ->
- [i32(R#win_values.bg_pixel)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BG_PIXEL),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BG_PIXEL),R),
+ <<(R#win_values.bg_pixel):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_BD_PIXMAP) ->
- [i32(R#win_values.bd_pixmap)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BD_PIXMAP),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BD_PIXMAP),R),
+ <<(R#win_values.bd_pixmap):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_BD_PIXEL) ->
- [i32(R#win_values.bd_pixel)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BD_PIXEL),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BD_PIXEL),R),
+ <<(R#win_values.bd_pixel):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_BIT_GRAVITY) ->
- [i32(R#win_values.bit_gravity)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BIT_GRAVITY),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BIT_GRAVITY),R),
+ <<(R#win_values.bit_gravity):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_WIN_GRAVITY) ->
- [i32(R#win_values.win_gravity)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_WIN_GRAVITY),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_WIN_GRAVITY),R),
+ <<(R#win_values.win_gravity):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_BACKING_STORE) ->
- [i32(R#win_values.backing_store)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BACKING_STORE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BACKING_STORE),R),
+ <<(R#win_values.backing_store):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_BACKING_PLANES) ->
- [i32(R#win_values.backing_planes)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BACKING_PLANES),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BACKING_PLANES),R),
+ <<(R#win_values.backing_planes):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_BACKING_PIXEL) ->
- [i32(R#win_values.backing_pixel)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BACKING_PIXEL),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_BACKING_PIXEL),R),
+ <<(R#win_values.backing_pixel):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_OVERRIDE_REDIRECT) ->
- [i32(R#win_values.override_redirect)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_OVERRIDE_REDIRECT),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_OVERRIDE_REDIRECT),R),
+ <<(R#win_values.override_redirect):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_SAVE_UNDER) ->
- [i32(R#win_values.save_under)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_SAVE_UNDER),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_SAVE_UNDER),R),
+ <<(R#win_values.save_under):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_EVENT_MASK) ->
- [i32(R#win_values.event_mask)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_EVENT_MASK),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_EVENT_MASK),R),
+ <<(R#win_values.event_mask):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_DO_NOT_PROPAGATE) ->
- [i32(R#win_values.do_not_propagate)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_DO_NOT_PROPAGATE),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_DO_NOT_PROPAGATE),R),
+ <<(R#win_values.do_not_propagate):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_COLORMAP) ->
- [i32(R#win_values.colormap)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_COLORMAP),R)];
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_COLORMAP),R),
+ <<(R#win_values.colormap):32, Rest/binary>>;
enc_win_vl(Vm,R) when ?IS_SET(Vm,?WIN_VALUEMASK_CURSOR) ->
- [i32(R#win_values.cursor)|enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_CURSOR),R)];
-enc_win_vl(_,_) -> [].
+ Rest = enc_gc_vl(?CLR(Vm,?WIN_VALUEMASK_CURSOR),R),
+ <<(R#win_values.cursor):32, Rest/binary>>;
+enc_win_vl(_,_) ->
+ <<>>.
%% --------------------------
%% The Get Geometry request.
-get_geometry(X,R) when R#get_geometry.drawable =/= undefined ->
+get_geometry(_X,R) when R#get_geometry.drawable =/= undefined ->
{reply,
- [R#get_geometry.opcode,
+ <<(R#get_geometry.opcode),
0, % unused
- i16(R#get_geometry.len),
- i32(R#get_geometry.drawable)],
+ (R#get_geometry.len):16,
+ (R#get_geometry.drawable):32>>,
get_geometry_reply}. % Reply type
%% ------------------------
%% The Map Window request.
-map_window(X,R) ->
- {ok,[R#map_window.opcode,
+map_window(_X,R) ->
+ {ok,<<(R#map_window.opcode),
0, % unused
- i16(R#map_window.len),
- i32(R#map_window.window)]}.
+ (R#map_window.len):16,
+ (R#map_window.window):32>>}.
%% --------------------------------
%% The Poly Fill Rectangle request
-poly_fill_rectangle(X,R) when R#poly_fill_rectangle.drawable =/= undefined,
- R#poly_fill_rectangle.cid =/= undefined,
- list(R#poly_fill_rectangle.rectangles) ->
- RectangleList = encode_rectangles(R#poly_fill_rectangle.rectangles),
+poly_fill_rectangle(_X,R) when R#poly_fill_rectangle.drawable =/= undefined,
+ R#poly_fill_rectangle.cid =/= undefined,
+ list(R#poly_fill_rectangle.rectangles) ->
+ Rectangles = encode_rectangles(R#poly_fill_rectangle.rectangles),
{ok,
- [R#poly_fill_rectangle.opcode,
+ <<(R#poly_fill_rectangle.opcode),
0, % unused
- i16(3 + length(RectangleList)),
- i32(R#poly_fill_rectangle.drawable),
- i32(R#poly_fill_rectangle.cid),
- RectangleList]}.
+ (3 + size(Rectangles) div 4):16,
+ (R#poly_fill_rectangle.drawable):32,
+ (R#poly_fill_rectangle.cid):32,
+ Rectangles/binary>>}.
encode_rectangles([H|T]) when ?IS_RECTANGLE(H) ->
- [i16(H#rectangle.x) ++ i16(H#rectangle.y),
- i16(H#rectangle.width) ++ i16(H#rectangle.height)
- |encode_rectangles(T)];
-encode_rectangles([]) -> [].
+ <<(H#rectangle.x):16, (H#rectangle.y):16,
+ (H#rectangle.width):16, (H#rectangle.height):16,
+ (encode_rectangles(T))/binary>>;
+encode_rectangles([]) -> <<>>.
%% ----------------------
%% The Poly Line request
-poly_line(X,R) when R#poly_line.drawable =/= undefined,
- R#poly_line.gc =/= undefined,
- list(R#poly_line.points) ->
+poly_line(_X,R) when R#poly_line.drawable =/= undefined,
+ R#poly_line.gc =/= undefined,
+ list(R#poly_line.points) ->
PointsList = encode_points(R#poly_line.points),
{ok,
- [R#poly_line.opcode,
- R#poly_line.coord_mode,
- i16(3 + length(PointsList)),
- i32(R#poly_line.drawable),
- i32(R#poly_line.gc),
- PointsList]}.
+ <<(R#poly_line.opcode),
+ (R#poly_line.coord_mode),
+ (3 + size(PointsList) div 4):16,
+ (R#poly_line.drawable):32,
+ (R#poly_line.gc):32,
+ PointsList/binary>>}.
encode_points([H|T]) when ?IS_POINT(H) ->
- [i16(H#point.x) ++ i16(H#point.y)|encode_points(T)];
-encode_points([]) -> [].
+ <<(H#point.x):16, (H#point.y):16, (encode_points(T))/binary>>;
+encode_points([]) -> <<>>.
%% ----------------------
%% The Poly Segment request
-poly_segment(X,R) when R#poly_segment.drawable =/= undefined,
- R#poly_segment.gc =/= undefined,
- list(R#poly_segment.segments) ->
+poly_segment(_X,R) when R#poly_segment.drawable =/= undefined,
+ R#poly_segment.gc =/= undefined,
+ list(R#poly_segment.segments) ->
SegmList = encode_segments(R#poly_segment.segments),
{ok,
- [R#poly_segment.opcode,
- i16(3 + length(SegmList)),
- i32(R#poly_segment.drawable),
- i32(R#poly_segment.gc),
- SegmList]}.
+ <<(R#poly_segment.opcode),
+ (3 + size(SegmList) div 4):16,
+ (R#poly_segment.drawable):32,
+ (R#poly_segment.gc):32,
+ SegmList/binary>>}.
encode_segments([H|T]) when ?IS_SEGMENT(H) ->
- [i16(H#segment.x1) ++ i16(H#segment.y1),
- i16(H#segment.x2) ++ i16(H#segment.y2)
- |encode_segments(T)];
-encode_segments([]) -> [].
+ <<(H#segment.x1):16, (H#segment.y1):16,
+ (H#segment.x2):16, (H#segment.y2):16,
+ (encode_segments(T))/binary>>;
+encode_segments([]) ->
+ <<>>.
%% ------------------
%% DECODING MESSAGES
%% ------------------
-decode(Db,[]) -> decode_cont(Db,[]);
-decode(_,[0|Emsg]) -> decode_error(Emsg);
-decode(Db,[1|Reply]) -> decode_reply(Db,Reply);
-decode(_,Event) -> decode_event(Event).
+decode(Db,<<>>) ->
+decode_cont(Db,<<>>);
+decode(_,<<0, Emsg/binary>>) ->
+ decode_error(Emsg);
+decode(Db,<<1, Reply/binary>>) ->
+ decode_reply(Db,Reply);
+decode(_,Event) ->
+ decode_event(Event).
-decode_cont(X,Msg) ->
- #more{cont=fun({Db,More}) -> decode(Db,Msg ++ More) end}.
+decode_cont(_X, Msg) ->
+ #more{cont = fun({Db,More}) ->
+ decode(Db, <<Msg/binary, More/binary>>)
+ end}.
%% ------------------------
%% Decoding reply messages
-decode_reply(Db,[B,S1,S0|D]) ->
- SeqNo = i16(S1,S0),
+decode_reply(Db,<<_B, SeqNo:16, _D/binary>>=R) ->
case ex11_db:get_reply(Db,SeqNo) of
{ok,{Pid,ReplyType}} when pid(Pid) ->
- decode_reply_type(ReplyType,Pid,[B,S1,S0|D]);
+ decode_reply_type(ReplyType,Pid,R);
_ ->
- error_msg("unable to decode reply message: ~w~n",[[B,S1,S0|D]])
+ error_msg("unable to decode reply message: ~w~n",[R])
end.
-decode_reply_type(get_geometry_reply,Pid,[D,_,_,_,_,_,_,R3,R2,R1,R0,X1,X0,
- Y1,Y0,W1,W0,H1,H0,B1,B0|T]) ->
- {_,Rest} = split_list(10,T), % 10 unused bytes
- Reply = #get_geometry_reply{depth=D,
- root=i32(R3,R2,R1,R0),
- x=i16(X1,X0),
- y=i16(Y1,Y0),
- width=i16(W1,W0),
- height=i16(H1,H0),
- border_width=i16(B1,B0)},
+decode_reply_type(get_geometry_reply,Pid,<<Depth,_:48,Root:32,X:16,
+ Y:16,W:16,H:16,Border:16,
+ _:80, Rest/binary>>) ->
+ Reply = #get_geometry_reply{depth=Depth,
+ root=Root,
+ x=X,
+ y=Y,
+ width=W,
+ height=H,
+ border_width=Border},
{reply,{Pid,Reply},Rest}.
%% ------------------------
%% Decoding error messages
-decode_error(Emsg) when length(Emsg)<32 ->
+decode_error(Emsg) when size(Emsg)<32 ->
error_cont(Emsg);
-decode_error([?ERROR_IDCHOICE,S1,S0,R3,R2,R1,R0,Mi1,Mi0,Ma|D]) ->
- {_,Rest} = split_list(21,D), % 21 unused bytes
- E = #error{type=idchoice,
- seqno=i16(S1,S0),
- bad_resource_id=i32(R3,R2,R1,R0),
- minor_opcode=i16(Mi1,Mi0),
+decode_error(<<Error,SeqNo:16,BadRes:32,Mi:16,Ma, _:168, Rest/binary>>) ->
+ E = #error{type=err_type(Error),
+ seqno=SeqNo,
+ bad_resource_id=BadRes,
+ minor_opcode=Mi,
major_opcode=Ma},
- {error,E,Rest};
-decode_error([?ERROR_LENGTH,S1,S0,_,_,_,_,Mi1,Mi0,Ma|D]) ->
- {_,Rest} = split_list(21,D), % 21 unused bytes
- E = #error{type=idchoice,
- seqno=i16(S1,S0),
- minor_opcode=i16(Mi1,Mi0),
- major_opcode=Ma},
- {error,E,Rest};
-decode_error([?ERROR_REQUEST,S1,S0,_,_,_,_,Mi1,Mi0,Ma|D]) ->
- {_,Rest} = split_list(21,D), % 21 unused bytes
- E = #error{type=request,
- seqno=i16(S1,S0),
- minor_opcode=i16(Mi1,Mi0),
- major_opcode=Ma},
- {error,E,Rest};
-decode_error([Error|D]) ->
- io:format("decode_error(NYI): ~w , ~w ~n",[Error,D]),
- {error,#error{type=Error},[]}.
+ {error,E,Rest}.
error_cont(Emsg) ->
- #more{cont=fun(More) -> decode_error(Emsg ++ More) end}.
+ #more{cont=fun(More) ->
+ decode_error(<<Emsg/binary, More/binary>>)
+ end}.
+
+err_type(?ERROR_REQUEST) ->
+ request;
+err_type(?ERROR_VALUE) ->
+ value;
+err_type(?ERROR_WINDOW) ->
+ window;
+err_type(?ERROR_PIXMAP) ->
+ pixmap;
+err_type(?ERROR_ATOM) ->
+ atom;
+err_type(?ERROR_CURSOR) ->
+ cursor;
+err_type(?ERROR_FONT) ->
+ font;
+err_type(?ERROR_MATCH) ->
+ match;
+err_type(?ERROR_DRAWABLE) ->
+ drawable;
+err_type(?ERROR_ACCESS) ->
+ access;
+err_type(?ERROR_ALLOC) ->
+ alloc;
+err_type(?ERROR_COLORMAP) ->
+ colormap;
+err_type(?ERROR_GCONTEXT) ->
+ gcontext;
+err_type(?ERROR_IDCHOICE) ->
+ idchoice;
+err_type(?ERROR_NAME) ->
+ name;
+err_type(?ERROR_LENGTH) ->
+ length;
+err_type(?ERROR_IMPLEMENTATION) ->
+ implementation;
+err_type(_) ->
+ undefined.
%% ------------------------
%% Decoding event messages
-decode_event(Event) when length(Event)<32 ->
+decode_event(Event) when size(Event)<32 ->
event_cont(Event);
-decode_event([?EVENT_EXPOSE,_,S1,S0,W3,W2,W1,W0,
- X1,X0,Y1,Y0,Wi1,Wi0,H1,H0,C1,C0|D]) ->
- {_,Rest} = split_list(14,D), % 14 unused bytes
- E = #expose{seqno=i16(S1,S0),
- window=i32(W3,W2,W1,W0),
- x=i16(X1,X0),
- y=i16(Y1,Y0),
- width=i16(Wi1,Wi0),
- height=i16(H1,H0),
- count=i16(C1,C0)},
+decode_event(<<?EVENT_EXPOSE, _, SeqNo:16,
+ Win:32,
+ X:16, Y:16, W:16, H:16, C:16,
+ _:112, Rest/binary>>) ->
+ E = #expose{seqno=SeqNo,
+ window=Win,
+ x=X,
+ y=Y,
+ width=W,
+ height=H,
+ count=C},
{event,E,Rest};
-decode_event([?EVENT_MAP_NOTIFY,_,S1,S0,E3,E2,E1,E0,W3,W2,W1,W0,V|D]) ->
- {_,Rest} = split_list(19,D), % 19 unused bytes
- E = #map_notify{seqno=i16(S1,S0),
- event=i32(W3,W2,W1,W0),
- window=i32(W3,W2,W1,W0),
+decode_event(<<?EVENT_MAP_NOTIFY, _, SeqNo:16,
+ Event:32, Win:32, V,
+ _:152, Rest/binary>>) ->
+ E = #map_notify{seqno=SeqNo,
+ event=Event,
+ window=Win,
override_redirect=V},
{event,E,Rest};
-decode_event([?EVENT_REPARENT_NOTIFY,_,S1,S0,E3,E2,E1,E0,W3,W2,W1,W0,
- P3,P2,P1,P0,X1,X0,Y1,Y0,V|D]) ->
- {_,Rest} = split_list(11,D), % 11 unused bytes
- E = #reparent_notify{seqno=i16(S1,S0),
- event=i32(E3,E2,E1,E0),
- window=i32(W3,W2,W1,W0),
- parent=i32(P3,P2,P1,P0),
- x=i16(X1,X0),
- y=i16(Y1,Y0),
+decode_event(<<?EVENT_REPARENT_NOTIFY, _, SeqNo:16,
+ Event:32, Win:32, Parent:32,
+ X:16, Y:16, V,
+ _:88, Rest/binary>>) ->
+ E = #reparent_notify{seqno=SeqNo,
+ event=Event,
+ window=Win,
+ parent=Parent,
+ x=X,
+ y=Y,
override_redirect=V},
{event,E,Rest};
-decode_event([?EVENT_CONFIGURE_NOTIFY,_,S1,S0,E3,E2,E1,E0,W3,W2,W1,W0,
- A3,A2,A1,A0,X1,X0,Y1,Y0,Wi1,Wi0,H1,H0,B1,B0,V|D]) ->
- {_,Rest} = split_list(5,D), % 5 unused bytes
- E = #configure_notify{seqno=i16(S1,S0),
- event=i32(E3,E2,E1,E0),
- window=i32(W3,W2,W1,W0),
- above_sibling=i32(A3,A2,A1,A0),
- x=i16(X1,X0),
- y=i16(Y1,Y0),
- width=i16(Wi1,Wi0),
- height=i16(H1,H0),
- border_width=i16(B1,B0),
+decode_event(<<?EVENT_CONFIGURE_NOTIFY, _, SeqNo:16,
+ Event:32, Win:32, Above:32,
+ X:16, Y:16, W:16, H:16, Border:16, V,
+ _:40, Rest/binary>>) ->
+ E = #configure_notify{seqno=SeqNo,
+ event=Event,
+ window=Win,
+ above_sibling=Above,
+ x=X,
+ y=Y,
+ width=W,
+ height=H,
+ border_width=Border,
override_redirect=V},
{event,E,Rest};
-decode_event([Event|D]) ->
+decode_event(<<Event, D/binary>>) ->
io:format("decode_event(NYI): ~w , ~w~n",[Event,D]),
- {event,#event_nyi{event=Event},[]}.
+ {event,#event_nyi{event=Event},<<>>}.
event_cont(Event) ->
- #more{cont=fun(More) -> decode_event(Event ++ More) end}.
-
-
+ #more{cont=fun(More) ->
+ decode_event(<<Event/binary, More/binary>>)
+ end}.
%% ---------------
%% Misc routines
%% ---------------
pad(E) -> (4 - (E rem 4)) rem 4.
-bpad(E) -> pad(E)*8.
rm_pad(0,L) -> L;
-rm_pad(1,[_|L]) -> L;
-rm_pad(2,[_,_|L]) -> L;
-rm_pad(3,[_,_,_|L]) -> L;
rm_pad(1,<<_:8, L>>) -> L;
rm_pad(2,<<_:16, L>>) -> L;
rm_pad(3,<<_:24, L>>) -> L.
-add_pad(Data) -> add_pad_0(pad(length(Data))).
+add_pad(Data) when binary(Data) ->
+ add_pad_0(pad(size(Data)));
+add_pad(Data) when list(Data) ->
+ add_pad_0(pad(length(Data))).
+
+add_pad_0(0) -> <<>>;
+add_pad_0(1) -> <<0>>;
+add_pad_0(2) -> <<0,0>>;
+add_pad_0(3) -> <<0,0,0>>.
-add_pad_0(0) -> [];
-add_pad_0(1) -> [0];
-add_pad_0(2) -> [0,0];
-add_pad_0(3) -> [0,0,0].
View
1 lib/ex11/src/ex11_utils.erl
@@ -23,7 +23,6 @@
%%% Contributor(s): ______________________________________.
%%%
%%%---------------------------------------------------------------------
--vc('$Id$ ').
-export([first/2,i16/1,i16/2,i32/1,i32/4,split_list/2,get_display/0,
b16/2,b32/2,xalloc_id/1]).
View
1 lib/ex11/src/ex11_xauth.erl
@@ -27,7 +27,6 @@
%%% To make it work under Windows. Added filename/0.
%%%
%%%---------------------------------------------------------------------
--vc('$Id$ ').
-export([read/1,host2cookie/2,filename/0]).
-import(ex11_utils,[first/2,i16/2,split_list/2]).
View
1 lib/ex11/src/matrix44.erl
@@ -43,7 +43,6 @@
%% represents the given point specified by X,Y,Z .
%%
%% ---------------------------------------------------------------------
--vc('$Id$ ').
-export([start/0,multiply44/2,multiply14/2,mk_projection_matrix/1,
mk_rotate_matrix/2,mk_scale_matrix/3,mk_hcord/3,
mk_translate_matrix/3]).
View
3 lib/ex11/src/rcube.erl
@@ -17,7 +17,6 @@
%%% Transformed again to use the Erlang X11 binding.
%%%
%%% --------------------------------------------------------------------
--vc('$Id$ ').
-export([start/0, start/1,init/1,kicker/2]).
-import(matrix44,[multiply14/2,mk_rotate_matrix/2,mk_hcord/3,
@@ -47,6 +46,7 @@ init(Host) ->
Fig = figure(),
Object = draw_cube(X,Rcube,Fig),
Kicker = start_kicker(?KICK_INTERVAL),
+ timer:sleep(1000),
loop(X,Rcube,Fig,Kicker).
init_xyz() ->
@@ -277,6 +277,7 @@ mk_window(Host) ->
value_mask = Wmask,
value_list = Wval
}),
+io:format("PIX=~w~n", [Window]),
%%
%% Create the Pixmap
%%

0 comments on commit 05990f1

Please sign in to comment.
Something went wrong with that request. Please try again.