dot_cursor.c (2543B)
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_dot_cursor_width = 5; 36const int guac_common_dot_cursor_height = 5; 37 38/* Format */ 39const cairo_format_t guac_common_dot_cursor_format = CAIRO_FORMAT_ARGB32; 40const int guac_common_dot_cursor_stride = 20; 41 42/* Embedded pointer graphic */ 43unsigned char guac_common_dot_cursor[] = { 44 45 _,O,O,O,_, 46 O,X,X,X,O, 47 O,X,X,X,O, 48 O,X,X,X,O, 49 _,O,O,O,_ 50 51}; 52 53void guac_common_set_dot_cursor(guac_user* user) { 54 55 guac_client* client = user->client; 56 guac_socket* socket = user->socket; 57 58 /* Draw to buffer */ 59 guac_layer* cursor = guac_client_alloc_buffer(client); 60 61 cairo_surface_t* graphic = cairo_image_surface_create_for_data( 62 guac_common_dot_cursor, 63 guac_common_dot_cursor_format, 64 guac_common_dot_cursor_width, 65 guac_common_dot_cursor_height, 66 guac_common_dot_cursor_stride); 67 68 guac_user_stream_png(user, socket, GUAC_COMP_SRC, cursor, 69 0, 0, graphic); 70 cairo_surface_destroy(graphic); 71 72 /* Set cursor */ 73 guac_protocol_send_cursor(socket, 2, 2, cursor, 74 0, 0, 75 guac_common_dot_cursor_width, 76 guac_common_dot_cursor_height); 77 78 /* Free buffer */ 79 guac_client_free_buffer(client, cursor); 80 81 guac_client_log(client, GUAC_LOG_DEBUG, 82 "Client cursor image set to generic built-in dot."); 83 84} 85