~paulliu/ubuntu/quantal/freerdp/fixext

« back to all changes in this revision

Viewing changes to libfreerdp-core/input.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-01-31 10:02:14 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20120131100214-zvig71djj2sqgq22
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * FreeRDP: A Remote Desktop Protocol Client
 
3
 * Input PDUs
 
4
 *
 
5
 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
 
6
 *
 
7
 * Licensed under the Apache License, Version 2.0 (the "License");
 
8
 * you may not use this file except in compliance with the License.
 
9
 * You may obtain a copy of the License at
 
10
 *
 
11
 *     http://www.apache.org/licenses/LICENSE-2.0
 
12
 *
 
13
 * Unless required by applicable law or agreed to in writing, software
 
14
 * distributed under the License is distributed on an "AS IS" BASIS,
 
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
 * See the License for the specific language governing permissions and
 
17
 * limitations under the License.
 
18
 */
 
19
 
 
20
#include "input.h"
 
21
 
 
22
void rdp_write_client_input_pdu_header(STREAM* s, uint16 number)
 
23
{
 
24
        stream_write_uint16(s, 1); /* numberEvents (2 bytes) */
 
25
        stream_write_uint16(s, 0); /* pad2Octets (2 bytes) */
 
26
}
 
27
 
 
28
void rdp_write_input_event_header(STREAM* s, uint32 time, uint16 type)
 
29
{
 
30
        stream_write_uint32(s, time); /* eventTime (4 bytes) */
 
31
        stream_write_uint16(s, type); /* messageType (2 bytes) */
 
32
}
 
33
 
 
34
STREAM* rdp_client_input_pdu_init(rdpRdp* rdp, uint16 type)
 
35
{
 
36
        STREAM* s;
 
37
        s = rdp_data_pdu_init(rdp);
 
38
        rdp_write_client_input_pdu_header(s, 1);
 
39
        rdp_write_input_event_header(s, 0, type);
 
40
        return s;
 
41
}
 
42
 
 
43
void rdp_send_client_input_pdu(rdpRdp* rdp, STREAM* s)
 
44
{
 
45
        rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_INPUT, rdp->mcs->user_id);
 
46
}
 
47
 
 
48
void input_write_synchronize_event(STREAM* s, uint32 flags)
 
49
{
 
50
        stream_write_uint16(s, 0); /* pad2Octets (2 bytes) */
 
51
        stream_write_uint32(s, flags); /* toggleFlags (4 bytes) */
 
52
}
 
53
 
 
54
void input_send_synchronize_event(rdpInput* input, uint32 flags)
 
55
{
 
56
        STREAM* s;
 
57
        rdpRdp* rdp = input->context->rdp;
 
58
 
 
59
        s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_SYNC);
 
60
        input_write_synchronize_event(s, flags);
 
61
        rdp_send_client_input_pdu(rdp, s);
 
62
}
 
63
 
 
64
void input_write_keyboard_event(STREAM* s, uint16 flags, uint16 code)
 
65
{
 
66
        stream_write_uint16(s, flags); /* keyboardFlags (2 bytes) */
 
67
        stream_write_uint16(s, code); /* keyCode (2 bytes) */
 
68
        stream_write_uint16(s, 0); /* pad2Octets (2 bytes) */
 
69
}
 
70
 
 
71
void input_send_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
 
72
{
 
73
        STREAM* s;
 
74
        rdpRdp* rdp = input->context->rdp;
 
75
 
 
76
        s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_SCANCODE);
 
77
        input_write_keyboard_event(s, flags, code);
 
78
        rdp_send_client_input_pdu(rdp, s);
 
79
}
 
80
 
 
81
void input_write_unicode_keyboard_event(STREAM* s, uint16 code)
 
82
{
 
83
        stream_write_uint16(s, 0); /* pad2OctetsA (2 bytes) */
 
84
        stream_write_uint16(s, code); /* unicodeCode (2 bytes) */
 
85
        stream_write_uint16(s, 0); /* pad2OctetsB (2 bytes) */
 
86
}
 
87
 
 
88
void input_send_unicode_keyboard_event(rdpInput* input, uint16 code)
 
89
{
 
90
        STREAM* s;
 
91
        rdpRdp* rdp = input->context->rdp;
 
92
 
 
93
        s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_UNICODE);
 
94
        input_write_unicode_keyboard_event(s, code);
 
95
        rdp_send_client_input_pdu(rdp, s);
 
96
}
 
97
 
 
98
void input_write_mouse_event(STREAM* s, uint16 flags, uint16 x, uint16 y)
 
99
{
 
100
        stream_write_uint16(s, flags); /* pointerFlags (2 bytes) */
 
101
        stream_write_uint16(s, x); /* xPos (2 bytes) */
 
102
        stream_write_uint16(s, y); /* yPos (2 bytes) */
 
103
}
 
104
 
 
105
void input_send_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
 
106
{
 
107
        STREAM* s;
 
108
        rdpRdp* rdp = input->context->rdp;
 
109
 
 
110
        s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_MOUSE);
 
111
        input_write_mouse_event(s, flags, x, y);
 
112
        rdp_send_client_input_pdu(rdp, s);
 
113
}
 
114
 
 
115
void input_write_extended_mouse_event(STREAM* s, uint16 flags, uint16 x, uint16 y)
 
116
{
 
117
        stream_write_uint16(s, flags); /* pointerFlags (2 bytes) */
 
118
        stream_write_uint16(s, x); /* xPos (2 bytes) */
 
119
        stream_write_uint16(s, y); /* yPos (2 bytes) */
 
120
}
 
121
 
 
122
void input_send_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
 
123
{
 
124
        STREAM* s;
 
125
        rdpRdp* rdp = input->context->rdp;
 
126
 
 
127
        s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_MOUSEX);
 
128
        input_write_extended_mouse_event(s, flags, x, y);
 
129
        rdp_send_client_input_pdu(rdp, s);
 
130
}
 
131
 
 
132
void input_send_fastpath_synchronize_event(rdpInput* input, uint32 flags)
 
133
{
 
134
        STREAM* s;
 
135
        rdpRdp* rdp = input->context->rdp;
 
136
 
 
137
        /* The FastPath Synchronization eventFlags has identical values as SlowPath */
 
138
        s = fastpath_input_pdu_init(rdp->fastpath, (uint8) flags, FASTPATH_INPUT_EVENT_SYNC);
 
139
        fastpath_send_input_pdu(rdp->fastpath, s);
 
140
}
 
141
 
 
142
void input_send_fastpath_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
 
143
{
 
144
        STREAM* s;
 
145
        uint8 eventFlags = 0;
 
146
        rdpRdp* rdp = input->context->rdp;
 
147
 
 
148
        eventFlags |= (flags & KBD_FLAGS_RELEASE) ? FASTPATH_INPUT_KBDFLAGS_RELEASE : 0;
 
149
        eventFlags |= (flags & KBD_FLAGS_EXTENDED) ? FASTPATH_INPUT_KBDFLAGS_EXTENDED : 0;
 
150
        s = fastpath_input_pdu_init(rdp->fastpath, eventFlags, FASTPATH_INPUT_EVENT_SCANCODE);
 
151
        stream_write_uint8(s, code); /* keyCode (1 byte) */
 
152
        fastpath_send_input_pdu(rdp->fastpath, s);
 
153
}
 
154
 
 
155
void input_send_fastpath_unicode_keyboard_event(rdpInput* input, uint16 code)
 
156
{
 
157
        STREAM* s;
 
158
        rdpRdp* rdp = input->context->rdp;
 
159
 
 
160
        s = fastpath_input_pdu_init(rdp->fastpath, 0, FASTPATH_INPUT_EVENT_UNICODE);
 
161
        stream_write_uint16(s, code); /* unicodeCode (2 bytes) */
 
162
        fastpath_send_input_pdu(rdp->fastpath, s);
 
163
}
 
164
 
 
165
void input_send_fastpath_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
 
166
{
 
167
        STREAM* s;
 
168
        rdpRdp* rdp = input->context->rdp;
 
169
 
 
170
        s = fastpath_input_pdu_init(rdp->fastpath, 0, FASTPATH_INPUT_EVENT_MOUSE);
 
171
        input_write_mouse_event(s, flags, x, y);
 
172
        fastpath_send_input_pdu(rdp->fastpath, s);
 
173
}
 
174
 
 
175
void input_send_fastpath_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
 
176
{
 
177
        STREAM* s;
 
178
        rdpRdp* rdp = input->context->rdp;
 
179
 
 
180
        s = fastpath_input_pdu_init(rdp->fastpath, 0, FASTPATH_INPUT_EVENT_MOUSEX);
 
181
        input_write_extended_mouse_event(s, flags, x, y);
 
182
        fastpath_send_input_pdu(rdp->fastpath, s);
 
183
}
 
184
 
 
185
void input_register_client_callbacks(rdpInput* input)
 
186
{
 
187
        rdpRdp* rdp = input->context->rdp;
 
188
 
 
189
        if (rdp->settings->fastpath_input)
 
190
        {
 
191
                input->SynchronizeEvent = input_send_fastpath_synchronize_event;
 
192
                input->KeyboardEvent = input_send_fastpath_keyboard_event;
 
193
                input->UnicodeKeyboardEvent = input_send_fastpath_unicode_keyboard_event;
 
194
                input->MouseEvent = input_send_fastpath_mouse_event;
 
195
                input->ExtendedMouseEvent = input_send_fastpath_extended_mouse_event;
 
196
        }
 
197
        else
 
198
        {
 
199
                input->SynchronizeEvent = input_send_synchronize_event;
 
200
                input->KeyboardEvent = input_send_keyboard_event;
 
201
                input->UnicodeKeyboardEvent = input_send_unicode_keyboard_event;
 
202
                input->MouseEvent = input_send_mouse_event;
 
203
                input->ExtendedMouseEvent = input_send_extended_mouse_event;
 
204
        }
 
205
}
 
206
 
 
207
rdpInput* input_new(rdpRdp* rdp)
 
208
{
 
209
        rdpInput* input;
 
210
 
 
211
        input = (rdpInput*) xzalloc(sizeof(rdpInput));
 
212
 
 
213
        if (input != NULL)
 
214
        {
 
215
 
 
216
        }
 
217
 
 
218
        return input;
 
219
}
 
220
 
 
221
void input_free(rdpInput* input)
 
222
{
 
223
        if (input != NULL)
 
224
        {
 
225
                xfree(input);
 
226
        }
 
227
}
 
228