pointer_cursor.c (3002B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include "config.h" 21 22#include <cairo/cairo.h> 23#include <guacamole/client.h> 24#include <guacamole/layer.h> 25#include <guacamole/protocol.h> 26#include <guacamole/socket.h> 27#include <guacamole/user.h> 28 29/* Macros for prettying up the embedded image. */ 30#define X 0x00,0x00,0x00,0xFF 31#define O 0xFF,0xFF,0xFF,0xFF 32#define _ 0x00,0x00,0x00,0x00 33 34/* Dimensions */ 35const int guac_common_pointer_cursor_width = 11; 36const int guac_common_pointer_cursor_height = 16; 37 38/* Format */ 39const cairo_format_t guac_common_pointer_cursor_format = CAIRO_FORMAT_ARGB32; 40const int guac_common_pointer_cursor_stride = 44; 41 42/* Embedded pointer graphic */ 43unsigned char guac_common_pointer_cursor[] = { 44 45 O,_,_,_,_,_,_,_,_,_,_, 46 O,O,_,_,_,_,_,_,_,_,_, 47 O,X,O,_,_,_,_,_,_,_,_, 48 O,X,X,O,_,_,_,_,_,_,_, 49 O,X,X,X,O,_,_,_,_,_,_, 50 O,X,X,X,X,O,_,_,_,_,_, 51 O,X,X,X,X,X,O,_,_,_,_, 52 O,X,X,X,X,X,X,O,_,_,_, 53 O,X,X,X,X,X,X,X,O,_,_, 54 O,X,X,X,X,X,X,X,X,O,_, 55 O,X,X,X,X,X,O,O,O,O,O, 56 O,X,X,O,X,X,O,_,_,_,_, 57 O,X,O,_,O,X,X,O,_,_,_, 58 O,O,_,_,O,X,X,O,_,_,_, 59 O,_,_,_,_,O,X,X,O,_,_, 60 _,_,_,_,_,O,O,O,O,_,_ 61 62}; 63 64void guac_common_set_pointer_cursor(guac_user* user) { 65 66 guac_client* client = user->client; 67 guac_socket* socket = user->socket; 68 69 /* Draw to buffer */ 70 guac_layer* cursor = guac_client_alloc_buffer(client); 71 72 cairo_surface_t* graphic = cairo_image_surface_create_for_data( 73 guac_common_pointer_cursor, 74 guac_common_pointer_cursor_format, 75 guac_common_pointer_cursor_width, 76 guac_common_pointer_cursor_height, 77 guac_common_pointer_cursor_stride); 78 79 guac_user_stream_png(user, socket, GUAC_COMP_SRC, cursor, 80 0, 0, graphic); 81 cairo_surface_destroy(graphic); 82 83 /* Set cursor */ 84 guac_protocol_send_cursor(socket, 0, 0, cursor, 85 0, 0, 86 guac_common_pointer_cursor_width, 87 guac_common_pointer_cursor_height); 88 89 /* Free buffer */ 90 guac_client_free_buffer(client, cursor); 91 92 guac_client_log(client, GUAC_LOG_DEBUG, 93 "Client cursor image set to generic built-in pointer."); 94 95} 96