2016-03-01 05:50:00 +00:00
|
|
|
/*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
2016-03-01 05:50:00 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-03-01 05:50:00 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-03-01 05:50:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "client.h"
|
2017-11-27 21:03:21 +00:00
|
|
|
#include "common/recording.h"
|
2019-10-13 22:30:02 +00:00
|
|
|
#include "disp.h"
|
2016-03-01 05:50:00 +00:00
|
|
|
#include "input.h"
|
2016-08-14 00:33:30 +00:00
|
|
|
#include "keyboard.h"
|
2016-03-01 05:50:00 +00:00
|
|
|
#include "rdp.h"
|
|
|
|
|
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <freerdp/input.h>
|
|
|
|
#include <guacamole/client.h>
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int guac_rdp_user_mouse_handler(guac_user* user, int x, int y, int mask) {
|
|
|
|
|
|
|
|
guac_client* client = user->client;
|
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2016-03-16 04:23:19 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Skip if not yet connected */
|
2016-03-16 04:23:19 +00:00
|
|
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
2019-12-22 04:02:17 +00:00
|
|
|
if (rdp_inst == NULL)
|
2016-03-01 05:50:00 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-12-08 18:45:09 +00:00
|
|
|
/* Store current mouse location/state */
|
|
|
|
guac_common_cursor_update(rdp_client->display->cursor, user, x, y, mask);
|
2016-03-18 01:29:27 +00:00
|
|
|
|
2017-11-27 21:03:21 +00:00
|
|
|
/* Report mouse position within recording */
|
|
|
|
if (rdp_client->recording != NULL)
|
2017-12-08 18:45:09 +00:00
|
|
|
guac_common_recording_report_mouse(rdp_client->recording, x, y, mask);
|
2017-11-27 21:03:21 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* If button mask unchanged, just send move event */
|
|
|
|
if (mask == rdp_client->mouse_button_mask)
|
|
|
|
rdp_inst->input->MouseEvent(rdp_inst->input, PTR_FLAGS_MOVE, x, y);
|
|
|
|
|
|
|
|
/* Otherwise, send events describing button change */
|
|
|
|
else {
|
|
|
|
|
|
|
|
/* Mouse buttons which have JUST become released */
|
|
|
|
int released_mask = rdp_client->mouse_button_mask & ~mask;
|
|
|
|
|
|
|
|
/* Mouse buttons which have JUST become pressed */
|
|
|
|
int pressed_mask = ~rdp_client->mouse_button_mask & mask;
|
|
|
|
|
|
|
|
/* Release event */
|
|
|
|
if (released_mask & 0x07) {
|
|
|
|
|
|
|
|
/* Calculate flags */
|
|
|
|
int flags = 0;
|
|
|
|
if (released_mask & 0x01) flags |= PTR_FLAGS_BUTTON1;
|
|
|
|
if (released_mask & 0x02) flags |= PTR_FLAGS_BUTTON3;
|
|
|
|
if (released_mask & 0x04) flags |= PTR_FLAGS_BUTTON2;
|
|
|
|
|
|
|
|
rdp_inst->input->MouseEvent(rdp_inst->input, flags, x, y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Press event */
|
|
|
|
if (pressed_mask & 0x07) {
|
|
|
|
|
|
|
|
/* Calculate flags */
|
|
|
|
int flags = PTR_FLAGS_DOWN;
|
|
|
|
if (pressed_mask & 0x01) flags |= PTR_FLAGS_BUTTON1;
|
|
|
|
if (pressed_mask & 0x02) flags |= PTR_FLAGS_BUTTON3;
|
|
|
|
if (pressed_mask & 0x04) flags |= PTR_FLAGS_BUTTON2;
|
|
|
|
if (pressed_mask & 0x08) flags |= PTR_FLAGS_WHEEL | 0x78;
|
|
|
|
if (pressed_mask & 0x10) flags |= PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x88;
|
|
|
|
|
|
|
|
/* Send event */
|
|
|
|
rdp_inst->input->MouseEvent(rdp_inst->input, flags, x, y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll event */
|
|
|
|
if (pressed_mask & 0x18) {
|
|
|
|
|
|
|
|
/* Down */
|
|
|
|
if (pressed_mask & 0x08)
|
|
|
|
rdp_inst->input->MouseEvent(
|
|
|
|
rdp_inst->input,
|
|
|
|
PTR_FLAGS_WHEEL | 0x78,
|
|
|
|
x, y);
|
|
|
|
|
|
|
|
/* Up */
|
|
|
|
if (pressed_mask & 0x10)
|
|
|
|
rdp_inst->input->MouseEvent(
|
|
|
|
rdp_inst->input,
|
|
|
|
PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x88,
|
|
|
|
x, y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rdp_client->mouse_button_mask = mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int guac_rdp_user_key_handler(guac_user* user, int keysym, int pressed) {
|
|
|
|
|
|
|
|
guac_client* client = user->client;
|
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
|
|
|
|
2017-11-28 07:50:45 +00:00
|
|
|
/* Report key state within recording */
|
|
|
|
if (rdp_client->recording != NULL)
|
|
|
|
guac_common_recording_report_key(rdp_client->recording,
|
|
|
|
keysym, pressed);
|
|
|
|
|
2016-08-14 00:33:30 +00:00
|
|
|
/* Skip if keyboard not yet ready */
|
|
|
|
if (rdp_client->keyboard == NULL)
|
|
|
|
return 0;
|
2016-03-01 05:50:00 +00:00
|
|
|
|
2016-08-14 00:33:30 +00:00
|
|
|
/* Update keysym state */
|
|
|
|
return guac_rdp_keyboard_update_keysym(rdp_client->keyboard,
|
|
|
|
keysym, pressed);
|
2016-03-01 05:50:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int guac_rdp_user_size_handler(guac_user* user, int width, int height) {
|
|
|
|
|
|
|
|
guac_client* client = user->client;
|
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2016-03-16 04:23:19 +00:00
|
|
|
guac_rdp_settings* settings = rdp_client->settings;
|
2016-03-01 05:50:00 +00:00
|
|
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
|
|
|
|
|
|
|
/* Convert client pixels to remote pixels */
|
2016-03-16 04:23:19 +00:00
|
|
|
width = width * settings->resolution / user->info.optimal_resolution;
|
|
|
|
height = height * settings->resolution / user->info.optimal_resolution;
|
2016-03-01 05:50:00 +00:00
|
|
|
|
|
|
|
/* Send display update */
|
2016-03-16 04:23:19 +00:00
|
|
|
guac_rdp_disp_set_size(rdp_client->disp, settings, rdp_inst, width, height);
|
2016-03-01 05:50:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|