Added handling for keyboard events
This commit is contained in:
parent
ca34e0c536
commit
bd8c2f596f
@ -41,7 +41,7 @@ AM_CFLAGS = -Werror -Wall -pedantic -Iinclude
|
||||
|
||||
lib_LTLIBRARIES = libguac-client-rdp.la
|
||||
|
||||
libguac_client_rdp_la_SOURCES = src/rdp_client.c src/rdp_handlers.c
|
||||
libguac_client_rdp_la_SOURCES = src/rdp_client.c src/rdp_handlers.c src/rdp_keymap.c
|
||||
|
||||
libguac_client_rdp_la_LDFLAGS = -version-info 0:0:0
|
||||
|
||||
|
@ -63,11 +63,14 @@ typedef struct rdp_guac_client_data {
|
||||
guac_rdp_color foreground;
|
||||
guac_rdp_color background;
|
||||
|
||||
const guac_layer* current_surface;
|
||||
|
||||
} rdp_guac_client_data;
|
||||
|
||||
int rdp_guac_client_free_handler(guac_client* client);
|
||||
int rdp_guac_client_handle_messages(guac_client* client);
|
||||
int rdp_guac_client_mouse_handler(guac_client* client, int x, int y, int mask);
|
||||
int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -84,5 +84,7 @@ void guac_rdp_ui_set_surface(rdpInst* inst, RD_HBITMAP surface);
|
||||
void guac_rdp_ui_destroy_surface(rdpInst* inst, RD_HBITMAP surface);
|
||||
void guac_rdp_ui_channel_data(rdpInst* inst, int chan_id, char* data, int data_size, int flags, int total_size);
|
||||
|
||||
extern const int guac_rdp_letter_scancodes[];
|
||||
|
||||
#endif
|
||||
|
||||
|
44
protocols/rdp/include/rdp_keymap.h
Normal file
44
protocols/rdp/include/rdp_keymap.h
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is libguac-client-rdp.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Michael Jumper.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _GUAC_CLIENT_RDP_KEYMAP
|
||||
#define _GUAC_CLIENT_RDP_KEYMAP
|
||||
|
||||
extern const int guac_rdp_keysym_scancode[256][256];
|
||||
|
||||
#endif
|
||||
|
@ -52,6 +52,7 @@
|
||||
|
||||
#include "rdp_handlers.h"
|
||||
#include "rdp_client.h"
|
||||
#include "rdp_keymap.h"
|
||||
|
||||
/* Client plugin arguments */
|
||||
const char* GUAC_CLIENT_ARGS[] = {
|
||||
@ -230,6 +231,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
||||
}
|
||||
guac_client_data->rdp_inst = rdp_inst;
|
||||
guac_client_data->mouse_button_mask = 0;
|
||||
guac_client_data->current_surface = GUAC_DEFAULT_LAYER;
|
||||
|
||||
/* Store client data */
|
||||
rdp_inst->param1 = client;
|
||||
@ -305,6 +307,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
||||
client->free_handler = rdp_guac_client_free_handler;
|
||||
client->handle_messages = rdp_guac_client_handle_messages;
|
||||
client->mouse_handler = rdp_guac_client_mouse_handler;
|
||||
client->key_handler = rdp_guac_client_key_handler;
|
||||
|
||||
/* Success */
|
||||
return 0;
|
||||
@ -335,3 +338,29 @@ int rdp_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) {
|
||||
guac_client_data->mouse_button_mask = mask;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
|
||||
|
||||
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
||||
rdpInst* rdp_inst = guac_client_data->rdp_inst;
|
||||
|
||||
/* If keysym can be in lookup table */
|
||||
if (keysym <= 0xFFFF) {
|
||||
|
||||
/* Look up scancode */
|
||||
int scancode =
|
||||
guac_rdp_keysym_scancode[(keysym & 0xFF00) >> 8][keysym & 0xFF];
|
||||
|
||||
/* If defined, send event */
|
||||
if (scancode != 0)
|
||||
rdp_inst->rdp_send_input(
|
||||
rdp_inst, RDP_INPUT_SCANCODE,
|
||||
pressed ? RDP_KEYPRESS : RDP_KEYRELEASE,
|
||||
scancode,
|
||||
0);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,6 @@
|
||||
#include "rdp_handlers.h"
|
||||
#include "rdp_client.h"
|
||||
|
||||
|
||||
void guac_rdp_convert_color(int depth, int color, guac_rdp_color* comp) {
|
||||
|
||||
switch (depth) {
|
||||
@ -176,6 +175,7 @@ RD_HBITMAP guac_rdp_ui_create_bitmap(rdpInst* inst, int width, int height, uint8
|
||||
|
||||
surface = cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_RGB24, width, height, stride);
|
||||
guac_send_png(io, GUAC_COMP_OVER, buffer, 0, 0, surface);
|
||||
guac_flush(io);
|
||||
|
||||
/* Free surface */
|
||||
cairo_surface_destroy(surface);
|
||||
@ -186,7 +186,75 @@ RD_HBITMAP guac_rdp_ui_create_bitmap(rdpInst* inst, int width, int height, uint8
|
||||
}
|
||||
|
||||
void guac_rdp_ui_paint_bitmap(rdpInst* inst, int x, int y, int cx, int cy, int width, int height, uint8* data) {
|
||||
guac_log_info("guac_rdp_ui_paint_bitmap: STUB\n");
|
||||
|
||||
guac_client* client = (guac_client*) inst->param1;
|
||||
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
||||
const guac_layer* current_surface = guac_client_data->current_surface;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
int dx, dy;
|
||||
int stride;
|
||||
int bpp = inst->settings->server_depth / 8;
|
||||
unsigned char* image_buffer;
|
||||
unsigned char* image_buffer_row;
|
||||
|
||||
cairo_surface_t* surface;
|
||||
|
||||
/* Init Cairo buffer */
|
||||
stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, width);
|
||||
image_buffer = malloc(height*stride);
|
||||
image_buffer_row = image_buffer;
|
||||
|
||||
/* Copy image data from image data to buffer */
|
||||
for (dy = 0; dy<height; dy++) {
|
||||
|
||||
unsigned int* image_buffer_current;
|
||||
|
||||
/* Get current buffer row, advance to next */
|
||||
image_buffer_current = (unsigned int*) image_buffer_row;
|
||||
image_buffer_row += stride;
|
||||
|
||||
for (dx = 0; dx<width; dx++) {
|
||||
|
||||
unsigned char red, green, blue;
|
||||
unsigned int v;
|
||||
|
||||
switch (bpp) {
|
||||
case 3:
|
||||
blue = *((unsigned char*) data++);
|
||||
green = *((unsigned char*) data++);
|
||||
red = *((unsigned char*) data++);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
v = *((unsigned char*) data++);
|
||||
v |= *((unsigned char*) data++) << 8;
|
||||
|
||||
red = ((v >> 8) & 0xF8) | ((v >> 13) & 0x07);
|
||||
green = ((v >> 3) & 0xFC) | ((v >> 9) & 0x03);
|
||||
blue = ((v << 3) & 0xF8) | ((v >> 2) & 0x07);
|
||||
break;
|
||||
|
||||
default: /* The Magenta of Failure */
|
||||
red = 0xFF;
|
||||
green = 0x00;
|
||||
blue = 0xFF;
|
||||
}
|
||||
|
||||
/* Output RGB */
|
||||
*(image_buffer_current++) = (red << 16) | (green << 8) | blue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
surface = cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_RGB24, width, height, stride);
|
||||
guac_send_png(io, GUAC_COMP_OVER, current_surface, x, y, surface);
|
||||
guac_flush(io);
|
||||
|
||||
/* Free surface */
|
||||
cairo_surface_destroy(surface);
|
||||
free(image_buffer);
|
||||
|
||||
}
|
||||
|
||||
void guac_rdp_ui_destroy_bitmap(rdpInst* inst, RD_HBITMAP bmp) {
|
||||
@ -204,6 +272,8 @@ void guac_rdp_ui_line(rdpInst* inst, uint8 opcode, int startx, int starty, int e
|
||||
void guac_rdp_ui_rect(rdpInst* inst, int x, int y, int cx, int cy, int color) {
|
||||
|
||||
guac_client* client = (guac_client*) inst->param1;
|
||||
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
||||
const guac_layer* current_surface = guac_client_data->current_surface;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
unsigned char red, green, blue;
|
||||
@ -228,7 +298,7 @@ void guac_rdp_ui_rect(rdpInst* inst, int x, int y, int cx, int cy, int color) {
|
||||
}
|
||||
|
||||
/* Send rectangle */
|
||||
guac_send_rect(io, GUAC_COMP_OVER, GUAC_DEFAULT_LAYER,
|
||||
guac_send_rect(io, GUAC_COMP_OVER, current_surface,
|
||||
x, y, cx, cy,
|
||||
red, green, blue, 0xFF);
|
||||
|
||||
@ -267,26 +337,27 @@ void guac_rdp_ui_draw_glyph(rdpInst* inst, int x, int y, int width, int height,
|
||||
|
||||
guac_client* client = (guac_client*) inst->param1;
|
||||
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
||||
const guac_layer* current_surface = guac_client_data->current_surface;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
/* NOTE: Originally: Stencil=SRC, FG=ATOP, BG=RATOP */
|
||||
/* Temporarily removed BG drawing... */
|
||||
|
||||
/* Stencil */
|
||||
guac_send_copy(io,
|
||||
(guac_layer*) glyph, 0, 0, width, height,
|
||||
GUAC_COMP_ROUT, GUAC_DEFAULT_LAYER, x, y);
|
||||
|
||||
/* Foreground */
|
||||
guac_send_rect(io, GUAC_COMP_RATOP, GUAC_DEFAULT_LAYER,
|
||||
x, y, width, height,
|
||||
guac_send_rect(io, GUAC_COMP_ATOP, glyph,
|
||||
0, 0, width, height,
|
||||
guac_client_data->foreground.red,
|
||||
guac_client_data->foreground.green,
|
||||
guac_client_data->foreground.blue,
|
||||
255);
|
||||
|
||||
/* Stencil */
|
||||
guac_send_copy(io,
|
||||
(guac_layer*) glyph, 0, 0, width, height,
|
||||
GUAC_COMP_OVER, current_surface, x, y);
|
||||
|
||||
/* Background */
|
||||
/*guac_send_rect(io, GUAC_COMP_RATOP, GUAC_DEFAULT_LAYER,
|
||||
/*guac_send_rect(io, GUAC_COMP_RATOP, current_surface,
|
||||
x, y, width, height,
|
||||
guac_client_data->background.red,
|
||||
guac_client_data->background.green,
|
||||
@ -317,12 +388,23 @@ void guac_rdp_ui_patblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int c
|
||||
}
|
||||
|
||||
void guac_rdp_ui_screenblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy) {
|
||||
guac_log_info("guac_rdp_ui_screenblt: STUB\n");
|
||||
|
||||
guac_client* client = (guac_client*) inst->param1;
|
||||
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
||||
const guac_layer* current_surface = guac_client_data->current_surface;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
guac_send_copy(io,
|
||||
(guac_layer*) current_surface, srcx, srcy, cx, cy,
|
||||
GUAC_COMP_OVER, current_surface, x, y);
|
||||
|
||||
}
|
||||
|
||||
void guac_rdp_ui_memblt(rdpInst* inst, uint8 opcode, int x, int y, int width, int height, RD_HBITMAP src, int srcx, int srcy) {
|
||||
|
||||
guac_client* client = (guac_client*) inst->param1;
|
||||
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
||||
const guac_layer* current_surface = guac_client_data->current_surface;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
if (opcode != 204)
|
||||
@ -331,7 +413,7 @@ void guac_rdp_ui_memblt(rdpInst* inst, uint8 opcode, int x, int y, int width, in
|
||||
|
||||
guac_send_copy(io,
|
||||
(guac_layer*) src, srcx, srcy, width, height,
|
||||
GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, x, y);
|
||||
GUAC_COMP_OVER, current_surface, x, y);
|
||||
|
||||
}
|
||||
|
||||
@ -391,6 +473,7 @@ RD_HGLYPH guac_rdp_ui_create_glyph(rdpInst* inst, int width, int height, uint8*
|
||||
|
||||
surface = cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_ARGB32, width, height, stride);
|
||||
guac_send_png(io, GUAC_COMP_SRC, glyph, 0, 0, surface);
|
||||
guac_flush(io);
|
||||
|
||||
/* Free surface */
|
||||
cairo_surface_destroy(surface);
|
||||
@ -416,18 +499,22 @@ int guac_rdp_ui_select(rdpInst* inst, int rdp_socket) {
|
||||
void guac_rdp_ui_set_clip(rdpInst* inst, int x, int y, int cx, int cy) {
|
||||
|
||||
guac_client* client = (guac_client*) inst->param1;
|
||||
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
||||
const guac_layer* current_surface = guac_client_data->current_surface;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
guac_send_clip(io, GUAC_DEFAULT_LAYER, x, y, cx, cy);
|
||||
guac_send_clip(io, current_surface, x, y, cx, cy);
|
||||
|
||||
}
|
||||
|
||||
void guac_rdp_ui_reset_clip(rdpInst* inst) {
|
||||
|
||||
guac_client* client = (guac_client*) inst->param1;
|
||||
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
||||
const guac_layer* current_surface = guac_client_data->current_surface;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
guac_send_clip(io, GUAC_DEFAULT_LAYER, 0, 0, inst->settings->width, inst->settings->height);
|
||||
guac_send_clip(io, current_surface, 0, 0, inst->settings->width, inst->settings->height);
|
||||
|
||||
}
|
||||
|
||||
@ -474,17 +561,26 @@ void guac_rdp_ui_set_colormap(rdpInst* inst, RD_HPALETTE map) {
|
||||
|
||||
RD_HBITMAP guac_rdp_ui_create_surface(rdpInst* inst, int width, int height, RD_HBITMAP old) {
|
||||
|
||||
/* Allocate and return buffer */
|
||||
/* If old provided, just return that one ... */
|
||||
if (old != NULL)
|
||||
return old;
|
||||
|
||||
/* Otherwise allocate and return new buffer */
|
||||
else {
|
||||
guac_client* client = (guac_client*) inst->param1;
|
||||
return (RD_HBITMAP) guac_client_alloc_buffer(client);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void guac_rdp_ui_set_surface(rdpInst* inst, RD_HBITMAP surface) {
|
||||
|
||||
guac_client* client = (guac_client*) inst->param1;
|
||||
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
guac_log_info("guac_rdp_ui_set_surface: %p (index=%i)\n", surface, surface != NULL ? ((guac_layer*) surface)->index : 0);
|
||||
|
||||
/* Init desktop */
|
||||
if (surface == NULL) {
|
||||
|
||||
@ -492,9 +588,11 @@ void guac_rdp_ui_set_surface(rdpInst* inst, RD_HBITMAP surface) {
|
||||
guac_send_size(io, inst->settings->width, inst->settings->height);
|
||||
guac_flush(io);
|
||||
|
||||
guac_client_data->current_surface = GUAC_DEFAULT_LAYER;
|
||||
}
|
||||
else {
|
||||
guac_client_data->current_surface = surface;
|
||||
}
|
||||
else
|
||||
guac_log_info("guac_rdp_ui_set_surface: STUB (surface=%p) ... %ix%i\n", surface, inst->settings->width, inst->settings->height);
|
||||
|
||||
}
|
||||
|
||||
|
5436
protocols/rdp/src/rdp_keymap.c
Normal file
5436
protocols/rdp/src/rdp_keymap.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user