Compare commits
1 Commits
master
...
fix-damage
Author | SHA1 | Date |
---|---|---|
Andri Yngvason | fc249a35a4 |
|
@ -1,4 +1,3 @@
|
||||||
build*
|
build*
|
||||||
subprojects
|
subprojects
|
||||||
.clang_complete
|
.clang_complete
|
||||||
.vscode
|
|
|
@ -34,7 +34,6 @@ struct buffer {
|
||||||
enum buffer_type type;
|
enum buffer_type type;
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
int32_t scale;
|
|
||||||
size_t size;
|
size_t size;
|
||||||
uint32_t format;
|
uint32_t format;
|
||||||
struct wl_buffer* wl_buffer;
|
struct wl_buffer* wl_buffer;
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
#include "wlr-data-control-unstable-v1.h"
|
|
||||||
#include "seat.h"
|
|
||||||
|
|
||||||
typedef void (*vnc_write_clipboard_t)(char* text, size_t size);
|
|
||||||
|
|
||||||
struct data_control {
|
|
||||||
struct wl_display* wl_display;
|
|
||||||
struct nvnc* server;
|
|
||||||
struct zwlr_data_control_manager_v1* manager;
|
|
||||||
struct zwlr_data_control_device_v1* device;
|
|
||||||
struct zwlr_data_control_source_v1* selection;
|
|
||||||
struct zwlr_data_control_source_v1* primary_selection;
|
|
||||||
struct zwlr_data_control_offer_v1* offer;
|
|
||||||
const char* mime_type;
|
|
||||||
char* cb_data;
|
|
||||||
size_t cb_len;
|
|
||||||
vnc_write_clipboard_t vnc_write_clipboard;
|
|
||||||
};
|
|
||||||
|
|
||||||
void data_control_init(struct data_control* self, struct seat* seat, struct zwlr_data_control_manager_v1 *manager);
|
|
||||||
void data_control_to_clipboard(struct data_control* self, const char* text, size_t len);
|
|
||||||
void data_control_destroy(struct data_control* self);
|
|
||||||
|
|
||||||
#pragma once
|
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 - 2022 Andri Yngvason
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
||||||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
||||||
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
* PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <wayland-client.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
struct output {
|
|
||||||
struct wl_output* wl_output;
|
|
||||||
struct wl_list link;
|
|
||||||
|
|
||||||
uint32_t id;
|
|
||||||
int32_t scale;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct output* output_new(struct wl_output* wl_output, uint32_t id);
|
|
||||||
void output_destroy(struct output* output);
|
|
||||||
|
|
||||||
void output_list_destroy(struct wl_list* list);
|
|
||||||
struct output* output_find_by_id(struct wl_list* list, uint32_t id);
|
|
||||||
int32_t output_list_get_max_scale(const struct wl_list* list);
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ typedef struct _rfbClient {
|
||||||
|
|
||||||
const char* programName;
|
const char* programName;
|
||||||
char* serverHost;
|
char* serverHost;
|
||||||
int serverPort;
|
int serverPort; /**< if -1, then use file recorded by vncrec */
|
||||||
rfbBool listenSpecified;
|
rfbBool listenSpecified;
|
||||||
int listenPort, flashPort;
|
int listenPort, flashPort;
|
||||||
|
|
||||||
|
@ -610,7 +610,7 @@ extern rfbBool SendClientCutText(rfbClient* client,char *str, int len);
|
||||||
*/
|
*/
|
||||||
extern rfbBool HandleRFBServerMessage(rfbClient* client);
|
extern rfbBool HandleRFBServerMessage(rfbClient* client);
|
||||||
|
|
||||||
extern rfbBool ReadToBuffer(rfbClient* client);
|
extern void ReadToBuffer(rfbClient* client);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a text chat message to the server.
|
* Sends a text chat message to the server.
|
||||||
|
@ -737,6 +737,7 @@ extern rfbBool SetNonBlocking(rfbSocket sock);
|
||||||
extern rfbBool SetBlocking(rfbSocket sock);
|
extern rfbBool SetBlocking(rfbSocket sock);
|
||||||
extern rfbBool SetDSCP(rfbSocket sock, int dscp);
|
extern rfbBool SetDSCP(rfbSocket sock, int dscp);
|
||||||
|
|
||||||
|
extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
|
||||||
extern rfbBool SameMachine(rfbSocket sock);
|
extern rfbBool SameMachine(rfbSocket sock);
|
||||||
|
|
||||||
/* vncviewer.c */
|
/* vncviewer.c */
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "rfbclient.h"
|
#include "rfbclient.h"
|
||||||
#include "data-control.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -37,7 +36,6 @@ struct vnc_av_frame {
|
||||||
struct vnc_client {
|
struct vnc_client {
|
||||||
rfbClient* client;
|
rfbClient* client;
|
||||||
|
|
||||||
struct data_control* data_control;
|
|
||||||
struct open_h264* open_h264;
|
struct open_h264* open_h264;
|
||||||
bool current_rect_is_av_frame;
|
bool current_rect_is_av_frame;
|
||||||
struct vnc_av_frame* av_frames[VNC_CLIENT_MAX_AV_FRAMES];
|
struct vnc_av_frame* av_frames[VNC_CLIENT_MAX_AV_FRAMES];
|
||||||
|
@ -55,7 +53,7 @@ struct vnc_client {
|
||||||
bool is_updating;
|
bool is_updating;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vnc_client* vnc_client_create(struct data_control* data_control);
|
struct vnc_client* vnc_client_create(void);
|
||||||
void vnc_client_destroy(struct vnc_client* self);
|
void vnc_client_destroy(struct vnc_client* self);
|
||||||
|
|
||||||
int vnc_client_connect(struct vnc_client* self, const char* address, int port);
|
int vnc_client_connect(struct vnc_client* self, const char* address, int port);
|
||||||
|
@ -81,5 +79,3 @@ void vnc_client_set_compression_level(struct vnc_client* self, int value);
|
||||||
void vnc_client_send_cut_text(struct vnc_client* self, const char* text,
|
void vnc_client_send_cut_text(struct vnc_client* self, const char* text,
|
||||||
size_t len);
|
size_t len);
|
||||||
void vnc_client_clear_av_frames(struct vnc_client* self);
|
void vnc_client_clear_av_frames(struct vnc_client* self);
|
||||||
rfbCredential* handle_vnc_authentication(struct _rfbClient *client, int credentialType);
|
|
||||||
void cut_text (struct vnc_client* self, const char* text, size_t size);
|
|
|
@ -16,7 +16,6 @@ prefix = get_option('prefix')
|
||||||
|
|
||||||
c_args = [
|
c_args = [
|
||||||
'-D_GNU_SOURCE',
|
'-D_GNU_SOURCE',
|
||||||
'-DAML_UNSTABLE_API=1',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if buildtype != 'debug' and buildtype != 'debugoptimized'
|
if buildtype != 'debug' and buildtype != 'debugoptimized'
|
||||||
|
@ -66,11 +65,9 @@ sources = [
|
||||||
'src/main.c',
|
'src/main.c',
|
||||||
'src/shm.c',
|
'src/shm.c',
|
||||||
'src/seat.c',
|
'src/seat.c',
|
||||||
'src/output.c',
|
|
||||||
'src/pointer.c',
|
'src/pointer.c',
|
||||||
'src/keyboard.c',
|
'src/keyboard.c',
|
||||||
'src/vnc.c',
|
'src/vnc.c',
|
||||||
'src/data-control.c',
|
|
||||||
'src/strlcpy.c',
|
'src/strlcpy.c',
|
||||||
'src/evdev-to-qnum.c',
|
'src/evdev-to-qnum.c',
|
||||||
'src/pixels.c',
|
'src/pixels.c',
|
||||||
|
|
|
@ -16,7 +16,6 @@ wayland_scanner_client = generator(
|
||||||
client_protocols = [
|
client_protocols = [
|
||||||
'xdg-shell.xml',
|
'xdg-shell.xml',
|
||||||
'linux-dmabuf-unstable-v1.xml',
|
'linux-dmabuf-unstable-v1.xml',
|
||||||
'wlr-data-control-unstable-v1.xml'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
client_protos_src = []
|
client_protos_src = []
|
||||||
|
|
|
@ -1,278 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<protocol name="wlr_data_control_unstable_v1">
|
|
||||||
<copyright>
|
|
||||||
Copyright © 2018 Simon Ser
|
|
||||||
Copyright © 2019 Ivan Molodetskikh
|
|
||||||
|
|
||||||
Permission to use, copy, modify, distribute, and sell this
|
|
||||||
software and its documentation for any purpose is hereby granted
|
|
||||||
without fee, provided that the above copyright notice appear in
|
|
||||||
all copies and that both that copyright notice and this permission
|
|
||||||
notice appear in supporting documentation, and that the name of
|
|
||||||
the copyright holders not be used in advertising or publicity
|
|
||||||
pertaining to distribution of the software without specific,
|
|
||||||
written prior permission. The copyright holders make no
|
|
||||||
representations about the suitability of this software for any
|
|
||||||
purpose. It is provided "as is" without express or implied
|
|
||||||
warranty.
|
|
||||||
|
|
||||||
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
||||||
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
|
||||||
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
||||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
||||||
THIS SOFTWARE.
|
|
||||||
</copyright>
|
|
||||||
|
|
||||||
<description summary="control data devices">
|
|
||||||
This protocol allows a privileged client to control data devices. In
|
|
||||||
particular, the client will be able to manage the current selection and take
|
|
||||||
the role of a clipboard manager.
|
|
||||||
|
|
||||||
Warning! The protocol described in this file is experimental and
|
|
||||||
backward incompatible changes may be made. Backward compatible changes
|
|
||||||
may be added together with the corresponding interface version bump.
|
|
||||||
Backward incompatible changes are done by bumping the version number in
|
|
||||||
the protocol and interface names and resetting the interface version.
|
|
||||||
Once the protocol is to be declared stable, the 'z' prefix and the
|
|
||||||
version number in the protocol and interface names are removed and the
|
|
||||||
interface version number is reset.
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<interface name="zwlr_data_control_manager_v1" version="2">
|
|
||||||
<description summary="manager to control data devices">
|
|
||||||
This interface is a manager that allows creating per-seat data device
|
|
||||||
controls.
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<request name="create_data_source">
|
|
||||||
<description summary="create a new data source">
|
|
||||||
Create a new data source.
|
|
||||||
</description>
|
|
||||||
<arg name="id" type="new_id" interface="zwlr_data_control_source_v1"
|
|
||||||
summary="data source to create"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<request name="get_data_device">
|
|
||||||
<description summary="get a data device for a seat">
|
|
||||||
Create a data device that can be used to manage a seat's selection.
|
|
||||||
</description>
|
|
||||||
<arg name="id" type="new_id" interface="zwlr_data_control_device_v1"/>
|
|
||||||
<arg name="seat" type="object" interface="wl_seat"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<request name="destroy" type="destructor">
|
|
||||||
<description summary="destroy the manager">
|
|
||||||
All objects created by the manager will still remain valid, until their
|
|
||||||
appropriate destroy request has been called.
|
|
||||||
</description>
|
|
||||||
</request>
|
|
||||||
</interface>
|
|
||||||
|
|
||||||
<interface name="zwlr_data_control_device_v1" version="2">
|
|
||||||
<description summary="manage a data device for a seat">
|
|
||||||
This interface allows a client to manage a seat's selection.
|
|
||||||
|
|
||||||
When the seat is destroyed, this object becomes inert.
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<request name="set_selection">
|
|
||||||
<description summary="copy data to the selection">
|
|
||||||
This request asks the compositor to set the selection to the data from
|
|
||||||
the source on behalf of the client.
|
|
||||||
|
|
||||||
The given source may not be used in any further set_selection or
|
|
||||||
set_primary_selection requests. Attempting to use a previously used
|
|
||||||
source is a protocol error.
|
|
||||||
|
|
||||||
To unset the selection, set the source to NULL.
|
|
||||||
</description>
|
|
||||||
<arg name="source" type="object" interface="zwlr_data_control_source_v1"
|
|
||||||
allow-null="true"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<request name="destroy" type="destructor">
|
|
||||||
<description summary="destroy this data device">
|
|
||||||
Destroys the data device object.
|
|
||||||
</description>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<event name="data_offer">
|
|
||||||
<description summary="introduce a new wlr_data_control_offer">
|
|
||||||
The data_offer event introduces a new wlr_data_control_offer object,
|
|
||||||
which will subsequently be used in either the
|
|
||||||
wlr_data_control_device.selection event (for the regular clipboard
|
|
||||||
selections) or the wlr_data_control_device.primary_selection event (for
|
|
||||||
the primary clipboard selections). Immediately following the
|
|
||||||
wlr_data_control_device.data_offer event, the new data_offer object
|
|
||||||
will send out wlr_data_control_offer.offer events to describe the MIME
|
|
||||||
types it offers.
|
|
||||||
</description>
|
|
||||||
<arg name="id" type="new_id" interface="zwlr_data_control_offer_v1"/>
|
|
||||||
</event>
|
|
||||||
|
|
||||||
<event name="selection">
|
|
||||||
<description summary="advertise new selection">
|
|
||||||
The selection event is sent out to notify the client of a new
|
|
||||||
wlr_data_control_offer for the selection for this device. The
|
|
||||||
wlr_data_control_device.data_offer and the wlr_data_control_offer.offer
|
|
||||||
events are sent out immediately before this event to introduce the data
|
|
||||||
offer object. The selection event is sent to a client when a new
|
|
||||||
selection is set. The wlr_data_control_offer is valid until a new
|
|
||||||
wlr_data_control_offer or NULL is received. The client must destroy the
|
|
||||||
previous selection wlr_data_control_offer, if any, upon receiving this
|
|
||||||
event.
|
|
||||||
|
|
||||||
The first selection event is sent upon binding the
|
|
||||||
wlr_data_control_device object.
|
|
||||||
</description>
|
|
||||||
<arg name="id" type="object" interface="zwlr_data_control_offer_v1"
|
|
||||||
allow-null="true"/>
|
|
||||||
</event>
|
|
||||||
|
|
||||||
<event name="finished">
|
|
||||||
<description summary="this data control is no longer valid">
|
|
||||||
This data control object is no longer valid and should be destroyed by
|
|
||||||
the client.
|
|
||||||
</description>
|
|
||||||
</event>
|
|
||||||
|
|
||||||
<!-- Version 2 additions -->
|
|
||||||
|
|
||||||
<event name="primary_selection" since="2">
|
|
||||||
<description summary="advertise new primary selection">
|
|
||||||
The primary_selection event is sent out to notify the client of a new
|
|
||||||
wlr_data_control_offer for the primary selection for this device. The
|
|
||||||
wlr_data_control_device.data_offer and the wlr_data_control_offer.offer
|
|
||||||
events are sent out immediately before this event to introduce the data
|
|
||||||
offer object. The primary_selection event is sent to a client when a
|
|
||||||
new primary selection is set. The wlr_data_control_offer is valid until
|
|
||||||
a new wlr_data_control_offer or NULL is received. The client must
|
|
||||||
destroy the previous primary selection wlr_data_control_offer, if any,
|
|
||||||
upon receiving this event.
|
|
||||||
|
|
||||||
If the compositor supports primary selection, the first
|
|
||||||
primary_selection event is sent upon binding the
|
|
||||||
wlr_data_control_device object.
|
|
||||||
</description>
|
|
||||||
<arg name="id" type="object" interface="zwlr_data_control_offer_v1"
|
|
||||||
allow-null="true"/>
|
|
||||||
</event>
|
|
||||||
|
|
||||||
<request name="set_primary_selection" since="2">
|
|
||||||
<description summary="copy data to the primary selection">
|
|
||||||
This request asks the compositor to set the primary selection to the
|
|
||||||
data from the source on behalf of the client.
|
|
||||||
|
|
||||||
The given source may not be used in any further set_selection or
|
|
||||||
set_primary_selection requests. Attempting to use a previously used
|
|
||||||
source is a protocol error.
|
|
||||||
|
|
||||||
To unset the primary selection, set the source to NULL.
|
|
||||||
|
|
||||||
The compositor will ignore this request if it does not support primary
|
|
||||||
selection.
|
|
||||||
</description>
|
|
||||||
<arg name="source" type="object" interface="zwlr_data_control_source_v1"
|
|
||||||
allow-null="true"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<enum name="error" since="2">
|
|
||||||
<entry name="used_source" value="1"
|
|
||||||
summary="source given to set_selection or set_primary_selection was already used before"/>
|
|
||||||
</enum>
|
|
||||||
</interface>
|
|
||||||
|
|
||||||
<interface name="zwlr_data_control_source_v1" version="1">
|
|
||||||
<description summary="offer to transfer data">
|
|
||||||
The wlr_data_control_source object is the source side of a
|
|
||||||
wlr_data_control_offer. It is created by the source client in a data
|
|
||||||
transfer and provides a way to describe the offered data and a way to
|
|
||||||
respond to requests to transfer the data.
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<enum name="error">
|
|
||||||
<entry name="invalid_offer" value="1"
|
|
||||||
summary="offer sent after wlr_data_control_device.set_selection"/>
|
|
||||||
</enum>
|
|
||||||
|
|
||||||
<request name="offer">
|
|
||||||
<description summary="add an offered MIME type">
|
|
||||||
This request adds a MIME type to the set of MIME types advertised to
|
|
||||||
targets. Can be called several times to offer multiple types.
|
|
||||||
|
|
||||||
Calling this after wlr_data_control_device.set_selection is a protocol
|
|
||||||
error.
|
|
||||||
</description>
|
|
||||||
<arg name="mime_type" type="string"
|
|
||||||
summary="MIME type offered by the data source"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<request name="destroy" type="destructor">
|
|
||||||
<description summary="destroy this source">
|
|
||||||
Destroys the data source object.
|
|
||||||
</description>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<event name="send">
|
|
||||||
<description summary="send the data">
|
|
||||||
Request for data from the client. Send the data as the specified MIME
|
|
||||||
type over the passed file descriptor, then close it.
|
|
||||||
</description>
|
|
||||||
<arg name="mime_type" type="string" summary="MIME type for the data"/>
|
|
||||||
<arg name="fd" type="fd" summary="file descriptor for the data"/>
|
|
||||||
</event>
|
|
||||||
|
|
||||||
<event name="cancelled">
|
|
||||||
<description summary="selection was cancelled">
|
|
||||||
This data source is no longer valid. The data source has been replaced
|
|
||||||
by another data source.
|
|
||||||
|
|
||||||
The client should clean up and destroy this data source.
|
|
||||||
</description>
|
|
||||||
</event>
|
|
||||||
</interface>
|
|
||||||
|
|
||||||
<interface name="zwlr_data_control_offer_v1" version="1">
|
|
||||||
<description summary="offer to transfer data">
|
|
||||||
A wlr_data_control_offer represents a piece of data offered for transfer
|
|
||||||
by another client (the source client). The offer describes the different
|
|
||||||
MIME types that the data can be converted to and provides the mechanism
|
|
||||||
for transferring the data directly from the source client.
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<request name="receive">
|
|
||||||
<description summary="request that the data is transferred">
|
|
||||||
To transfer the offered data, the client issues this request and
|
|
||||||
indicates the MIME type it wants to receive. The transfer happens
|
|
||||||
through the passed file descriptor (typically created with the pipe
|
|
||||||
system call). The source client writes the data in the MIME type
|
|
||||||
representation requested and then closes the file descriptor.
|
|
||||||
|
|
||||||
The receiving client reads from the read end of the pipe until EOF and
|
|
||||||
then closes its end, at which point the transfer is complete.
|
|
||||||
|
|
||||||
This request may happen multiple times for different MIME types.
|
|
||||||
</description>
|
|
||||||
<arg name="mime_type" type="string"
|
|
||||||
summary="MIME type desired by receiver"/>
|
|
||||||
<arg name="fd" type="fd" summary="file descriptor for data transfer"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<request name="destroy" type="destructor">
|
|
||||||
<description summary="destroy this offer">
|
|
||||||
Destroys the data offer object.
|
|
||||||
</description>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<event name="offer">
|
|
||||||
<description summary="advertise offered MIME type">
|
|
||||||
Sent immediately after creating the wlr_data_control_offer object.
|
|
||||||
One event per offered MIME type.
|
|
||||||
</description>
|
|
||||||
<arg name="mime_type" type="string" summary="offered MIME type"/>
|
|
||||||
</event>
|
|
||||||
</interface>
|
|
||||||
</protocol>
|
|
|
@ -1,308 +0,0 @@
|
||||||
#include "data-control.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <aml.h>
|
|
||||||
#include <seat.h>
|
|
||||||
#include <vnc.h>
|
|
||||||
|
|
||||||
struct receive_context {
|
|
||||||
//struct data_control* data_control;
|
|
||||||
struct zwlr_data_control_offer_v1* offer;
|
|
||||||
int fd;
|
|
||||||
FILE* mem_fp;
|
|
||||||
size_t mem_size;
|
|
||||||
char* mem_data;
|
|
||||||
struct data_control* self;
|
|
||||||
};
|
|
||||||
|
|
||||||
static char* mime_type = "text/plain;charset=utf-8";
|
|
||||||
|
|
||||||
static bool isStringEqual(int lena, char* a, int lenb, char* b) {
|
|
||||||
if (lena != lenb) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compare every character
|
|
||||||
for (size_t i = 0; i < lena; ++i) {
|
|
||||||
if (a[i] != b[i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void on_receive(void* handler)
|
|
||||||
{
|
|
||||||
struct receive_context* ctx = aml_get_userdata(handler);
|
|
||||||
int fd = aml_get_fd(handler);
|
|
||||||
assert(ctx->fd == fd);
|
|
||||||
|
|
||||||
char buf[4096];
|
|
||||||
|
|
||||||
ssize_t ret = read(fd, &buf, sizeof(buf));
|
|
||||||
if (ret > 0) {
|
|
||||||
fwrite(&buf, 1, ret, ctx->mem_fp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(ctx->mem_fp);
|
|
||||||
ctx->mem_fp = NULL;
|
|
||||||
|
|
||||||
if (ctx->mem_size && ctx->self->vnc_write_clipboard) {
|
|
||||||
// If we receive clipboard data from the VNC server, we set the clipboard of the client.
|
|
||||||
// This "change" of clipboard data results into this "on_receive" event. That would leed
|
|
||||||
// to an endless loop...
|
|
||||||
// So we check if we send exactle that clipboard string to avoid an loop
|
|
||||||
if (!ctx->self->cb_data || !isStringEqual(ctx->self->cb_len, ctx->self->cb_data, strlen(ctx->mem_data), ctx->mem_data)) {
|
|
||||||
//printf("Received data FROM clipboard: %s\n", ctx->mem_data);
|
|
||||||
ctx->self->vnc_write_clipboard(ctx->mem_data, ctx->mem_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
aml_stop(aml_get_default(), handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void destroy_receive_context(void* raw_ctx)
|
|
||||||
{
|
|
||||||
struct receive_context* ctx = raw_ctx;
|
|
||||||
int fd = ctx->fd;
|
|
||||||
|
|
||||||
if (ctx->mem_fp)
|
|
||||||
fclose(ctx->mem_fp);
|
|
||||||
free(ctx->mem_data);
|
|
||||||
zwlr_data_control_offer_v1_destroy(ctx->offer);
|
|
||||||
close(fd);
|
|
||||||
free(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void receive_data(void* data,
|
|
||||||
struct zwlr_data_control_offer_v1* offer)
|
|
||||||
{
|
|
||||||
struct data_control* self = data;
|
|
||||||
int pipe_fd[2];
|
|
||||||
|
|
||||||
if (pipe(pipe_fd) == -1) {
|
|
||||||
printf("pipe() failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct receive_context* ctx = calloc(1, sizeof(*ctx));
|
|
||||||
if (!ctx) {
|
|
||||||
printf("OOM");
|
|
||||||
close(pipe_fd[0]);
|
|
||||||
close(pipe_fd[1]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
zwlr_data_control_offer_v1_receive(self->offer, mime_type, pipe_fd[1]);
|
|
||||||
//wl_display_flush(self->wl_display);
|
|
||||||
close(pipe_fd[1]);
|
|
||||||
|
|
||||||
ctx->self = self;
|
|
||||||
ctx->fd = pipe_fd[0];
|
|
||||||
//ctx->data_control = self;
|
|
||||||
ctx->offer = self->offer;
|
|
||||||
ctx->mem_fp = open_memstream(&ctx->mem_data, &ctx->mem_size);
|
|
||||||
if (!ctx->mem_fp) {
|
|
||||||
close(ctx->fd);
|
|
||||||
free(ctx);
|
|
||||||
printf("open_memstream() failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct aml_handler* handler = aml_handler_new(ctx->fd, on_receive,
|
|
||||||
ctx, destroy_receive_context);
|
|
||||||
if (!handler) {
|
|
||||||
close(ctx->fd);
|
|
||||||
free(ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
aml_start(aml_get_default(), handler);
|
|
||||||
aml_unref(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void data_control_offer(void* data,
|
|
||||||
struct zwlr_data_control_offer_v1* zwlr_data_control_offer_v1,
|
|
||||||
const char* mime_type)
|
|
||||||
{
|
|
||||||
struct data_control* self = data;
|
|
||||||
|
|
||||||
if (self->offer)
|
|
||||||
return;
|
|
||||||
if (strcmp(mime_type, mime_type) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self->offer = zwlr_data_control_offer_v1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct zwlr_data_control_offer_v1_listener data_control_offer_listener = {
|
|
||||||
data_control_offer
|
|
||||||
};
|
|
||||||
|
|
||||||
static void data_control_device_offer(void* data,
|
|
||||||
struct zwlr_data_control_device_v1* zwlr_data_control_device_v1,
|
|
||||||
struct zwlr_data_control_offer_v1* id)
|
|
||||||
{
|
|
||||||
if (!id)
|
|
||||||
return;
|
|
||||||
|
|
||||||
zwlr_data_control_offer_v1_add_listener(id, &data_control_offer_listener, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void data_control_device_selection(void* data,
|
|
||||||
struct zwlr_data_control_device_v1* zwlr_data_control_device_v1,
|
|
||||||
struct zwlr_data_control_offer_v1* id)
|
|
||||||
{
|
|
||||||
struct data_control* self = data;
|
|
||||||
if (id && self->offer == id) {
|
|
||||||
receive_data(data, id);
|
|
||||||
self->offer = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void data_control_device_primary_selection(void* data,
|
|
||||||
struct zwlr_data_control_device_v1* zwlr_data_control_device_v1,
|
|
||||||
struct zwlr_data_control_offer_v1* id)
|
|
||||||
{
|
|
||||||
struct data_control* self = data;
|
|
||||||
if (id && self->offer == id) {
|
|
||||||
receive_data(data, id);
|
|
||||||
self->offer = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void data_control_device_finished(void* data,
|
|
||||||
struct zwlr_data_control_device_v1* zwlr_data_control_device_v1)
|
|
||||||
{
|
|
||||||
zwlr_data_control_device_v1_destroy(zwlr_data_control_device_v1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct zwlr_data_control_device_v1_listener data_control_device_listener = {
|
|
||||||
.data_offer = data_control_device_offer,
|
|
||||||
.selection = data_control_device_selection,
|
|
||||||
.finished = data_control_device_finished,
|
|
||||||
.primary_selection = data_control_device_primary_selection
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
data_control_source_send(void* data,
|
|
||||||
struct zwlr_data_control_source_v1* zwlr_data_control_source_v1,
|
|
||||||
const char* mime_type,
|
|
||||||
int32_t fd)
|
|
||||||
{
|
|
||||||
struct data_control* self = data;
|
|
||||||
char* d = self->cb_data;
|
|
||||||
size_t len = self->cb_len;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
assert(d);
|
|
||||||
|
|
||||||
ret = write(fd, d, len);
|
|
||||||
|
|
||||||
if (ret < (int)len)
|
|
||||||
printf("write from clipboard incomplete");
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void data_control_source_cancelled(void* data,
|
|
||||||
struct zwlr_data_control_source_v1* zwlr_data_control_source_v1)
|
|
||||||
{
|
|
||||||
struct data_control* self = data;
|
|
||||||
|
|
||||||
if (self->selection == zwlr_data_control_source_v1) {
|
|
||||||
self->selection = NULL;
|
|
||||||
}
|
|
||||||
if (self->primary_selection == zwlr_data_control_source_v1) {
|
|
||||||
self->primary_selection = NULL;
|
|
||||||
}
|
|
||||||
zwlr_data_control_source_v1_destroy(zwlr_data_control_source_v1);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct zwlr_data_control_source_v1_listener data_control_source_listener = {
|
|
||||||
.send = data_control_source_send,
|
|
||||||
.cancelled = data_control_source_cancelled
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct zwlr_data_control_source_v1* set_selection(struct data_control* self, bool primary) {
|
|
||||||
struct zwlr_data_control_source_v1* selection;
|
|
||||||
selection = zwlr_data_control_manager_v1_create_data_source(self->manager);
|
|
||||||
if (selection == NULL) {
|
|
||||||
printf("zwlr_data_control_manager_v1_create_data_source() failed");
|
|
||||||
free(self->cb_data);
|
|
||||||
self->cb_data = NULL;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
zwlr_data_control_source_v1_add_listener(selection, &data_control_source_listener, self);
|
|
||||||
zwlr_data_control_source_v1_offer(selection, mime_type);
|
|
||||||
|
|
||||||
if (primary)
|
|
||||||
zwlr_data_control_device_v1_set_primary_selection(self->device, selection);
|
|
||||||
else
|
|
||||||
zwlr_data_control_device_v1_set_selection(self->device, selection);
|
|
||||||
|
|
||||||
return selection;
|
|
||||||
}
|
|
||||||
|
|
||||||
void data_control_init(struct data_control* self, struct seat* seat, struct zwlr_data_control_manager_v1 *manager) {
|
|
||||||
self->manager = manager;
|
|
||||||
self->device = zwlr_data_control_manager_v1_get_data_device(self->manager, seat->wl_seat);
|
|
||||||
self->cb_data = NULL;
|
|
||||||
self->cb_len = 0;
|
|
||||||
|
|
||||||
zwlr_data_control_device_v1_add_listener(self->device, &data_control_device_listener, self);
|
|
||||||
}
|
|
||||||
|
|
||||||
void data_control_to_clipboard(struct data_control* self, const char* text, size_t len)
|
|
||||||
{
|
|
||||||
//printf("Writing text TO CLIPBOARD: %s\n", text);
|
|
||||||
if (!len) {
|
|
||||||
printf("%s called with 0 length", __func__);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (self->cb_data) {
|
|
||||||
free(self->cb_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
self->cb_data = malloc(len);
|
|
||||||
if (!self->cb_data) {
|
|
||||||
printf("OOM");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(self->cb_data, text, len);
|
|
||||||
self->cb_len = len;
|
|
||||||
// Set copy/paste buffer
|
|
||||||
self->selection = set_selection(self, false);
|
|
||||||
// Set highlight/middle_click buffer
|
|
||||||
self->primary_selection = set_selection(self, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void data_control_destroy(struct data_control* self)
|
|
||||||
{
|
|
||||||
if (self->selection) {
|
|
||||||
zwlr_data_control_source_v1_destroy(self->selection);
|
|
||||||
self->selection = NULL;
|
|
||||||
}
|
|
||||||
if (self->primary_selection) {
|
|
||||||
zwlr_data_control_source_v1_destroy(self->primary_selection);
|
|
||||||
self->primary_selection = NULL;
|
|
||||||
}
|
|
||||||
zwlr_data_control_device_v1_destroy(self->device);
|
|
||||||
free(self->cb_data);
|
|
||||||
}
|
|
146
src/main.c
146
src/main.c
|
@ -46,16 +46,10 @@
|
||||||
#include "renderer-egl.h"
|
#include "renderer-egl.h"
|
||||||
#include "linux-dmabuf-unstable-v1.h"
|
#include "linux-dmabuf-unstable-v1.h"
|
||||||
#include "time-util.h"
|
#include "time-util.h"
|
||||||
#include "output.h"
|
|
||||||
#include "data-control.h"
|
|
||||||
|
|
||||||
#define CANARY_TICK_PERIOD INT64_C(100000) // us
|
#define CANARY_TICK_PERIOD INT64_C(100000) // us
|
||||||
#define CANARY_LETHALITY_LEVEL INT64_C(8000) // us
|
#define CANARY_LETHALITY_LEVEL INT64_C(8000) // us
|
||||||
|
|
||||||
struct point {
|
|
||||||
double x, y;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct window {
|
struct window {
|
||||||
struct wl_surface* wl_surface;
|
struct wl_surface* wl_surface;
|
||||||
struct xdg_surface* xdg_surface;
|
struct xdg_surface* xdg_surface;
|
||||||
|
@ -83,14 +77,10 @@ struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf_v1 = NULL;
|
||||||
struct gbm_device* gbm_device = NULL;
|
struct gbm_device* gbm_device = NULL;
|
||||||
static struct xdg_wm_base* xdg_wm_base;
|
static struct xdg_wm_base* xdg_wm_base;
|
||||||
static struct wl_list seats;
|
static struct wl_list seats;
|
||||||
static struct wl_list outputs;
|
|
||||||
struct pointer_collection* pointers;
|
struct pointer_collection* pointers;
|
||||||
struct keyboard_collection* keyboards;
|
struct keyboard_collection* keyboards;
|
||||||
static int drm_fd = -1;
|
static int drm_fd = -1;
|
||||||
static uint64_t last_canary_tick;
|
static uint64_t last_canary_tick;
|
||||||
static struct data_control* data_control;
|
|
||||||
static struct zwlr_data_control_manager_v1 *manager;
|
|
||||||
static struct vnc_client* vnc;
|
|
||||||
|
|
||||||
static bool have_egl = false;
|
static bool have_egl = false;
|
||||||
|
|
||||||
|
@ -118,9 +108,6 @@ static void on_seat_capability_change(struct seat* seat)
|
||||||
struct wl_keyboard* wl_keyboard =
|
struct wl_keyboard* wl_keyboard =
|
||||||
wl_seat_get_keyboard(seat->wl_seat);
|
wl_seat_get_keyboard(seat->wl_seat);
|
||||||
keyboard_collection_add_wl_keyboard(keyboards, wl_keyboard);
|
keyboard_collection_add_wl_keyboard(keyboards, wl_keyboard);
|
||||||
|
|
||||||
data_control = malloc(sizeof(data_control));
|
|
||||||
data_control_init(data_control, seat, manager);
|
|
||||||
} else {
|
} else {
|
||||||
// TODO Remove
|
// TODO Remove
|
||||||
}
|
}
|
||||||
|
@ -151,19 +138,6 @@ static void registry_add(void* data, struct wl_registry* registry, uint32_t id,
|
||||||
|
|
||||||
wl_list_insert(&seats, &seat->link);
|
wl_list_insert(&seats, &seat->link);
|
||||||
seat->on_capability_change = on_seat_capability_change;
|
seat->on_capability_change = on_seat_capability_change;
|
||||||
} else if (strcmp(interface, "wl_output") == 0) {
|
|
||||||
struct wl_output* wl_output;
|
|
||||||
wl_output = wl_registry_bind(registry, id, &wl_output_interface, 2);
|
|
||||||
|
|
||||||
struct output* output = output_new(wl_output, id);
|
|
||||||
if (!output) {
|
|
||||||
wl_output_destroy(wl_output);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wl_list_insert(&outputs, &output->link);
|
|
||||||
} else if (strcmp(interface, zwlr_data_control_manager_v1_interface.name) == 0) {
|
|
||||||
manager = wl_registry_bind(registry, id, &zwlr_data_control_manager_v1_interface, 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,32 +259,6 @@ static void window_attach(struct window* w, int x, int y)
|
||||||
{
|
{
|
||||||
w->back_buffer->is_attached = true;
|
w->back_buffer->is_attached = true;
|
||||||
wl_surface_attach(w->wl_surface, w->back_buffer->wl_buffer, x, y);
|
wl_surface_attach(w->wl_surface, w->back_buffer->wl_buffer, x, y);
|
||||||
wl_surface_set_buffer_scale(window->wl_surface,
|
|
||||||
window->back_buffer->scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct point surface_coord_to_buffer_coord(double x, double y)
|
|
||||||
{
|
|
||||||
double scale = output_list_get_max_scale(&outputs);
|
|
||||||
|
|
||||||
struct point result = {
|
|
||||||
.x = round(x * scale),
|
|
||||||
.y = round(y * scale),
|
|
||||||
};
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct point buffer_coord_to_surface_coord(double x, double y)
|
|
||||||
{
|
|
||||||
double scale = output_list_get_max_scale(&outputs);
|
|
||||||
|
|
||||||
struct point result = {
|
|
||||||
.x = x / scale,
|
|
||||||
.y = y / scale,
|
|
||||||
};
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_calculate_transform(struct window* w, double* scale,
|
static void window_calculate_transform(struct window* w, double* scale,
|
||||||
|
@ -400,27 +348,22 @@ static const struct xdg_surface_listener xdg_surface_listener = {
|
||||||
.configure = xdg_surface_configure,
|
.configure = xdg_surface_configure,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void window_resize(struct window* w, int width, int height, int scale)
|
static void window_resize(struct window* w, int width, int height)
|
||||||
{
|
{
|
||||||
if (width == 0 || height == 0 || scale == 0)
|
if (width == 0 || height == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (w->back_buffer && w->back_buffer->width == width &&
|
if (w->back_buffer && w->back_buffer->width == width &&
|
||||||
w->back_buffer->height == height &&
|
w->back_buffer->height == height)
|
||||||
w->back_buffer->scale == scale)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i)
|
for (int i = 0; i < 3; ++i)
|
||||||
buffer_destroy(w->buffers[i]);
|
buffer_destroy(w->buffers[i]);
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i)
|
||||||
w->buffers[i] = have_egl
|
w->buffers[i] = have_egl ?
|
||||||
? buffer_create_dmabuf(scale * width, scale * height,
|
buffer_create_dmabuf(width, height, dmabuf_format) :
|
||||||
dmabuf_format)
|
buffer_create_shm(width, height, 4 * width, shm_format);
|
||||||
: buffer_create_shm(scale * width, scale * height,
|
|
||||||
scale * 4 * width, shm_format);
|
|
||||||
w->buffers[i]->scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
w->back_buffer = w->buffers[0];
|
w->back_buffer = w->buffers[0];
|
||||||
}
|
}
|
||||||
|
@ -428,8 +371,7 @@ static void window_resize(struct window* w, int width, int height, int scale)
|
||||||
static void xdg_toplevel_configure(void* data, struct xdg_toplevel* toplevel,
|
static void xdg_toplevel_configure(void* data, struct xdg_toplevel* toplevel,
|
||||||
int32_t width, int32_t height, struct wl_array* state)
|
int32_t width, int32_t height, struct wl_array* state)
|
||||||
{
|
{
|
||||||
int32_t scale = output_list_get_max_scale(&outputs);
|
window_resize(data, width, height);
|
||||||
window_resize(data, width, height, scale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xdg_toplevel_close(void* data, struct xdg_toplevel* toplevel)
|
static void xdg_toplevel_close(void* data, struct xdg_toplevel* toplevel)
|
||||||
|
@ -503,12 +445,8 @@ void on_pointer_event(struct pointer_collection* collection,
|
||||||
int x_pos, y_pos;
|
int x_pos, y_pos;
|
||||||
window_calculate_transform(window, &scale, &x_pos, &y_pos);
|
window_calculate_transform(window, &scale, &x_pos, &y_pos);
|
||||||
|
|
||||||
struct point coord = surface_coord_to_buffer_coord(
|
int x = round((wl_fixed_to_double(pointer->x) - (double)x_pos) / scale);
|
||||||
wl_fixed_to_double(pointer->x),
|
int y = round((wl_fixed_to_double(pointer->y) - (double)y_pos) / scale);
|
||||||
wl_fixed_to_double(pointer->y));
|
|
||||||
|
|
||||||
int x = round((coord.x - (double)x_pos) / scale);
|
|
||||||
int y = round((coord.y - (double)y_pos) / scale);
|
|
||||||
|
|
||||||
enum pointer_button_mask pressed = pointer->pressed;
|
enum pointer_button_mask pressed = pointer->pressed;
|
||||||
int vertical_steps = pointer->vertical_scroll_steps;
|
int vertical_steps = pointer->vertical_scroll_steps;
|
||||||
|
@ -568,9 +506,7 @@ int on_vnc_client_alloc_fb(struct vnc_client* client)
|
||||||
if (!window) {
|
if (!window) {
|
||||||
window = window_create(app_id, vnc_client_get_desktop_name(client));
|
window = window_create(app_id, vnc_client_get_desktop_name(client));
|
||||||
window->vnc = client;
|
window->vnc = client;
|
||||||
|
window_resize(window, width, height);
|
||||||
int32_t scale = output_list_get_max_scale(&outputs);
|
|
||||||
window_resize(window, width, height, scale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(window->vnc_fb);
|
free(window->vnc_fb);
|
||||||
|
@ -623,36 +559,27 @@ static void render_from_vnc(void)
|
||||||
window->vnc->n_av_frames == 0)
|
window->vnc->n_av_frames == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
double scale;
|
||||||
|
int x_pos, y_pos;
|
||||||
|
window_calculate_transform(window, &scale, &x_pos, &y_pos);
|
||||||
|
|
||||||
|
struct pixman_region16 damage_scaled = { 0 }, damage = { 0 };
|
||||||
|
region_scale(&damage_scaled, &window->current_damage, scale);
|
||||||
|
|
||||||
|
region_translate(&damage, &damage_scaled, x_pos, y_pos);
|
||||||
|
pixman_region_fini(&damage_scaled);
|
||||||
|
|
||||||
|
apply_buffer_damage(&damage);
|
||||||
|
|
||||||
if (window->is_frame_committed)
|
if (window->is_frame_committed)
|
||||||
return;
|
goto done;
|
||||||
|
|
||||||
if (window->back_buffer->is_attached)
|
if (window->back_buffer->is_attached)
|
||||||
fprintf(stderr, "Oops, back-buffer is still attached.\n");
|
fprintf(stderr, "Oops, back-buffer is still attached.\n");
|
||||||
|
|
||||||
window_attach(window, 0, 0);
|
window_attach(window, 0, 0);
|
||||||
|
|
||||||
double scale;
|
window_damage_region(window, &damage);
|
||||||
int x_pos, y_pos;
|
|
||||||
window_calculate_transform(window, &scale, &x_pos, &y_pos);
|
|
||||||
|
|
||||||
struct pixman_region16 damage_scaled = { 0 }, buffer_damage = { 0 },
|
|
||||||
surface_damage = { 0 };
|
|
||||||
region_scale(&damage_scaled, &window->current_damage, scale);
|
|
||||||
region_translate(&buffer_damage, &damage_scaled, x_pos, y_pos);
|
|
||||||
pixman_region_clear(&damage_scaled);
|
|
||||||
|
|
||||||
double output_scale = output_list_get_max_scale(&outputs);
|
|
||||||
struct point scoord = buffer_coord_to_surface_coord(x_pos, y_pos);
|
|
||||||
region_scale(&damage_scaled, &window->current_damage,
|
|
||||||
scale / output_scale);
|
|
||||||
region_translate(&surface_damage, &damage_scaled, scoord.x, scoord.y);
|
|
||||||
pixman_region_fini(&damage_scaled);
|
|
||||||
|
|
||||||
apply_buffer_damage(&buffer_damage);
|
|
||||||
window_damage_region(window, &surface_damage);
|
|
||||||
|
|
||||||
pixman_region_fini(&surface_damage);
|
|
||||||
pixman_region_fini(&buffer_damage);
|
|
||||||
|
|
||||||
window_transfer_pixels(window);
|
window_transfer_pixels(window);
|
||||||
|
|
||||||
|
@ -664,6 +591,9 @@ static void render_from_vnc(void)
|
||||||
|
|
||||||
pixman_region_clear(&window->current_damage);
|
pixman_region_clear(&window->current_damage);
|
||||||
vnc_client_clear_av_frames(window->vnc);
|
vnc_client_clear_av_frames(window->vnc);
|
||||||
|
|
||||||
|
done:
|
||||||
|
pixman_region_fini(&damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_vnc_client_update_fb(struct vnc_client* client)
|
void on_vnc_client_update_fb(struct vnc_client* client)
|
||||||
|
@ -818,16 +748,12 @@ static void create_canary_ticker(void)
|
||||||
last_canary_tick = gettime_us();
|
last_canary_tick = gettime_us();
|
||||||
|
|
||||||
struct aml* aml = aml_get_default();
|
struct aml* aml = aml_get_default();
|
||||||
struct aml_ticker* ticker = aml_ticker_new(CANARY_TICK_PERIOD,
|
struct aml_ticker* ticker = aml_ticker_new(CANARY_TICK_PERIOD / 1000ULL,
|
||||||
on_canary_tick, NULL, NULL);
|
on_canary_tick, NULL, NULL);
|
||||||
aml_start(aml, ticker);
|
aml_start(aml, ticker);
|
||||||
aml_unref(ticker);
|
aml_unref(ticker);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnc_send_clipboard(char* text, size_t size) {
|
|
||||||
vnc_client_send_cut_text(vnc, text, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void run_main_loop_once(void)
|
void run_main_loop_once(void)
|
||||||
{
|
{
|
||||||
struct aml* aml = aml_get_default();
|
struct aml* aml = aml_get_default();
|
||||||
|
@ -918,11 +844,6 @@ int main(int argc, char* argv[])
|
||||||
if (n_args >= 2)
|
if (n_args >= 2)
|
||||||
port = atoi(argv[optind + 1]);
|
port = atoi(argv[optind + 1]);
|
||||||
|
|
||||||
if (aml_unstable_abi_version != AML_UNSTABLE_API) {
|
|
||||||
fprintf(stderr, "libaml is incompatible with current build of wlvncc!\n");
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct aml* aml = aml_new();
|
struct aml* aml = aml_new();
|
||||||
if (!aml)
|
if (!aml)
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -958,7 +879,6 @@ int main(int argc, char* argv[])
|
||||||
goto registry_failure;
|
goto registry_failure;
|
||||||
|
|
||||||
wl_list_init(&seats);
|
wl_list_init(&seats);
|
||||||
wl_list_init(&outputs);
|
|
||||||
|
|
||||||
wl_registry_add_listener(wl_registry, ®istry_listener, wl_display);
|
wl_registry_add_listener(wl_registry, ®istry_listener, wl_display);
|
||||||
wl_display_roundtrip(wl_display);
|
wl_display_roundtrip(wl_display);
|
||||||
|
@ -977,13 +897,12 @@ int main(int argc, char* argv[])
|
||||||
wl_display_roundtrip(wl_display);
|
wl_display_roundtrip(wl_display);
|
||||||
wl_display_roundtrip(wl_display);
|
wl_display_roundtrip(wl_display);
|
||||||
|
|
||||||
vnc = vnc_client_create(data_control);
|
struct vnc_client* vnc = vnc_client_create();
|
||||||
if (!vnc)
|
if (!vnc)
|
||||||
goto vnc_failure;
|
goto vnc_failure;
|
||||||
|
|
||||||
vnc->alloc_fb = on_vnc_client_alloc_fb;
|
vnc->alloc_fb = on_vnc_client_alloc_fb;
|
||||||
vnc->update_fb = on_vnc_client_update_fb;
|
vnc->update_fb = on_vnc_client_update_fb;
|
||||||
data_control->vnc_write_clipboard = vnc_send_clipboard;
|
|
||||||
|
|
||||||
if (vnc_client_set_pixel_format(vnc, shm_format) < 0) {
|
if (vnc_client_set_pixel_format(vnc, shm_format) < 0) {
|
||||||
fprintf(stderr, "Unsupported pixel format\n");
|
fprintf(stderr, "Unsupported pixel format\n");
|
||||||
|
@ -1038,7 +957,6 @@ int main(int argc, char* argv[])
|
||||||
vnc_setup_failure:
|
vnc_setup_failure:
|
||||||
vnc_client_destroy(vnc);
|
vnc_client_destroy(vnc);
|
||||||
vnc_failure:
|
vnc_failure:
|
||||||
output_list_destroy(&outputs);
|
|
||||||
seat_list_destroy(&seats);
|
seat_list_destroy(&seats);
|
||||||
wl_compositor_destroy(wl_compositor);
|
wl_compositor_destroy(wl_compositor);
|
||||||
wl_shm_destroy(wl_shm);
|
wl_shm_destroy(wl_shm);
|
||||||
|
@ -1063,9 +981,5 @@ display_failure:
|
||||||
signal_handler_failure:
|
signal_handler_failure:
|
||||||
aml_unref(aml);
|
aml_unref(aml);
|
||||||
printf("Exiting...\n");
|
printf("Exiting...\n");
|
||||||
|
|
||||||
// @TODO this will throw an segfault (can't determine proxy version, but why?)
|
|
||||||
if (data_control)
|
|
||||||
data_control_destroy(data_control);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,9 +153,6 @@ static void reset_all_contexts(struct open_h264* self)
|
||||||
|
|
||||||
struct open_h264* open_h264_create(rfbClient* client)
|
struct open_h264* open_h264_create(rfbClient* client)
|
||||||
{
|
{
|
||||||
// Use this to enable debug logs
|
|
||||||
// av_log_set_level(AV_LOG_DEBUG);
|
|
||||||
|
|
||||||
struct open_h264* self = calloc(1, sizeof(*self));
|
struct open_h264* self = calloc(1, sizeof(*self));
|
||||||
if (!self)
|
if (!self)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
108
src/output.c
108
src/output.c
|
@ -1,108 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 - 2022 Andri Yngvason
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
||||||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
||||||
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
* PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <wayland-client.h>
|
|
||||||
|
|
||||||
#include "output.h"
|
|
||||||
|
|
||||||
static void output_handle_geometry(void* data, struct wl_output* wl_output,
|
|
||||||
int32_t x, int32_t y, int32_t phys_width, int32_t phys_height,
|
|
||||||
int32_t subpixel, const char* make, const char* model,
|
|
||||||
int32_t transform)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void output_handle_mode(void* data, struct wl_output* wl_output,
|
|
||||||
uint32_t flags, int32_t width, int32_t height, int32_t refresh)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void output_handle_done(void* data, struct wl_output* wl_output)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void output_handle_scale(void* data, struct wl_output* wl_output,
|
|
||||||
int32_t factor)
|
|
||||||
{
|
|
||||||
struct output* output = data;
|
|
||||||
output->scale = factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct wl_output_listener output_listener = {
|
|
||||||
.geometry = output_handle_geometry,
|
|
||||||
.mode = output_handle_mode,
|
|
||||||
.done = output_handle_done,
|
|
||||||
.scale = output_handle_scale,
|
|
||||||
};
|
|
||||||
|
|
||||||
void output_destroy(struct output* output)
|
|
||||||
{
|
|
||||||
wl_output_destroy(output->wl_output);
|
|
||||||
free(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
void output_list_destroy(struct wl_list* list)
|
|
||||||
{
|
|
||||||
struct output* output;
|
|
||||||
struct output* tmp;
|
|
||||||
|
|
||||||
wl_list_for_each_safe(output, tmp, list, link) {
|
|
||||||
wl_list_remove(&output->link);
|
|
||||||
output_destroy(output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t output_list_get_max_scale(const struct wl_list* list)
|
|
||||||
{
|
|
||||||
struct output* output;
|
|
||||||
|
|
||||||
int32_t scale = 1;
|
|
||||||
|
|
||||||
wl_list_for_each(output, list, link)
|
|
||||||
if (output->scale > scale)
|
|
||||||
scale = output->scale;
|
|
||||||
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct output* output_new(struct wl_output* wl_output, uint32_t id)
|
|
||||||
{
|
|
||||||
struct output* output = calloc(1, sizeof(*output));
|
|
||||||
if (!output)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
output->wl_output = wl_output;
|
|
||||||
output->id = id;
|
|
||||||
|
|
||||||
wl_output_add_listener(output->wl_output, &output_listener,
|
|
||||||
output);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct output* output_find_by_id(struct wl_list* list, uint32_t id)
|
|
||||||
{
|
|
||||||
struct output* output;
|
|
||||||
|
|
||||||
wl_list_for_each(output, list, link)
|
|
||||||
if (output->id == id)
|
|
||||||
return output;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
|
@ -491,7 +491,7 @@ void render_image_egl(struct buffer* dst, const struct image* src,
|
||||||
|
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
glFlush();
|
glFinish();
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
@ -534,7 +534,7 @@ void render_av_frames_egl(struct buffer* dst, struct vnc_av_frame** src,
|
||||||
|
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
glFlush();
|
glFinish();
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
glDeleteFramebuffers(1, &fbo.fbo);
|
glDeleteFramebuffers(1, &fbo.fbo);
|
||||||
|
|
104
src/rfbproto.c
104
src/rfbproto.c
|
@ -286,13 +286,59 @@ static rfbBool IsUnixSocket(const char* name)
|
||||||
|
|
||||||
rfbBool ConnectToRFBServer(rfbClient* client, const char* hostname, int port)
|
rfbBool ConnectToRFBServer(rfbClient* client, const char* hostname, int port)
|
||||||
{
|
{
|
||||||
if (IsUnixSocket(hostname)) {
|
if (client->serverPort == -1) {
|
||||||
|
/* serverHost is a file recorded by vncrec. */
|
||||||
|
const char* magic = "vncLog0.0";
|
||||||
|
char buffer[10];
|
||||||
|
rfbVNCRec* rec = (rfbVNCRec*)malloc(sizeof(rfbVNCRec));
|
||||||
|
if (!rec) {
|
||||||
|
rfbClientLog("Could not allocate rfbVNCRec memory\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
client->vncRec = rec;
|
||||||
|
|
||||||
|
rec->file = fopen(client->serverHost, "rb");
|
||||||
|
rec->tv.tv_sec = 0;
|
||||||
|
rec->readTimestamp = FALSE;
|
||||||
|
rec->doNotSleep = FALSE;
|
||||||
|
|
||||||
|
if (!rec->file) {
|
||||||
|
rfbClientLog("Could not open %s.\n", client->serverHost);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
setbuf(rec->file, NULL);
|
||||||
|
|
||||||
|
if (fread(buffer, 1, strlen(magic), rec->file) != strlen(magic) ||
|
||||||
|
strncmp(buffer, magic, strlen(magic))) {
|
||||||
|
rfbClientLog("File %s was not recorded by vncrec.\n",
|
||||||
|
client->serverHost);
|
||||||
|
fclose(rec->file);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
client->sock = RFB_INVALID_SOCKET;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsUnixSocket(hostname))
|
||||||
/* serverHost is a UNIX socket. */
|
/* serverHost is a UNIX socket. */
|
||||||
client->sock = ConnectClientToUnixSockWithTimeout(
|
client->sock = ConnectClientToUnixSockWithTimeout(
|
||||||
hostname, client->connectTimeout);
|
hostname, client->connectTimeout);
|
||||||
} else {
|
else {
|
||||||
|
#ifdef LIBVNCSERVER_IPv6
|
||||||
client->sock = ConnectClientToTcpAddr6WithTimeout(
|
client->sock = ConnectClientToTcpAddr6WithTimeout(
|
||||||
hostname, port, client->connectTimeout);
|
hostname, port, client->connectTimeout);
|
||||||
|
#else
|
||||||
|
unsigned int host;
|
||||||
|
|
||||||
|
/* serverHost is a hostname */
|
||||||
|
if (!StringToIPAddr(hostname, &host)) {
|
||||||
|
rfbClientLog("Couldn't convert '%s' to host address\n",
|
||||||
|
hostname);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
client->sock = ConnectClientToTcpAddrWithTimeout(
|
||||||
|
host, port, client->connectTimeout);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->sock == RFB_INVALID_SOCKET) {
|
if (client->sock == RFB_INVALID_SOCKET) {
|
||||||
|
@ -317,8 +363,20 @@ rfbBool ConnectToRFBRepeater(rfbClient* client, const char* repeaterHost,
|
||||||
int major, minor;
|
int major, minor;
|
||||||
char tmphost[250];
|
char tmphost[250];
|
||||||
|
|
||||||
|
#ifdef LIBVNCSERVER_IPv6
|
||||||
client->sock = ConnectClientToTcpAddr6WithTimeout(
|
client->sock = ConnectClientToTcpAddr6WithTimeout(
|
||||||
repeaterHost, repeaterPort, client->connectTimeout);
|
repeaterHost, repeaterPort, client->connectTimeout);
|
||||||
|
#else
|
||||||
|
unsigned int host;
|
||||||
|
if (!StringToIPAddr(repeaterHost, &host)) {
|
||||||
|
rfbClientLog("Couldn't convert '%s' to host address\n",
|
||||||
|
repeaterHost);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
client->sock = ConnectClientToTcpAddrWithTimeout(host, repeaterPort,
|
||||||
|
client->connectTimeout);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (client->sock == RFB_INVALID_SOCKET) {
|
if (client->sock == RFB_INVALID_SOCKET) {
|
||||||
rfbClientLog("Unable to connect to VNC repeater\n");
|
rfbClientLog("Unable to connect to VNC repeater\n");
|
||||||
|
@ -530,27 +588,29 @@ static rfbBool HandleVncAuth(rfbClient* client)
|
||||||
if (!ReadFromRFBServer(client, (char*)challenge, CHALLENGESIZE))
|
if (!ReadFromRFBServer(client, (char*)challenge, CHALLENGESIZE))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (client->GetPassword)
|
if (client->serverPort != -1) { /* if not playing a vncrec file */
|
||||||
passwd = client->GetPassword(client);
|
if (client->GetPassword)
|
||||||
|
passwd = client->GetPassword(client);
|
||||||
|
|
||||||
if ((!passwd) || (strlen(passwd) == 0)) {
|
if ((!passwd) || (strlen(passwd) == 0)) {
|
||||||
rfbClientLog("Reading password failed\n");
|
rfbClientLog("Reading password failed\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (strlen(passwd) > 8) {
|
||||||
|
passwd[8] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
rfbClientEncryptBytes(challenge, passwd);
|
||||||
|
|
||||||
|
/* Lose the password from memory */
|
||||||
|
for (i = strlen(passwd); i >= 0; i--) {
|
||||||
|
passwd[i] = '\0';
|
||||||
|
}
|
||||||
|
free(passwd);
|
||||||
|
|
||||||
|
if (!WriteToRFBServer(client, (char*)challenge, CHALLENGESIZE))
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (strlen(passwd) > 8) {
|
|
||||||
passwd[8] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
rfbClientEncryptBytes(challenge, passwd);
|
|
||||||
|
|
||||||
/* Lose the password from memory */
|
|
||||||
for (i = strlen(passwd); i >= 0; i--) {
|
|
||||||
passwd[i] = '\0';
|
|
||||||
}
|
|
||||||
free(passwd);
|
|
||||||
|
|
||||||
if (!WriteToRFBServer(client, (char*)challenge, CHALLENGESIZE))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* Handle the SecurityResult message */
|
/* Handle the SecurityResult message */
|
||||||
if (!rfbHandleAuthResult(client))
|
if (!rfbHandleAuthResult(client))
|
||||||
|
@ -2371,6 +2431,8 @@ rfbBool HandleRFBServerMessage(rfbClient* client)
|
||||||
{
|
{
|
||||||
rfbServerToClientMsg msg;
|
rfbServerToClientMsg msg;
|
||||||
|
|
||||||
|
if (client->serverPort == -1)
|
||||||
|
client->vncRec->readTimestamp = TRUE;
|
||||||
if (!ReadFromRFBServer(client, (char*)&msg, 1))
|
if (!ReadFromRFBServer(client, (char*)&msg, 1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
|
104
src/sockets.c
104
src/sockets.c
|
@ -38,9 +38,9 @@ void run_main_loop_once(void);
|
||||||
|
|
||||||
rfbBool errorMessageOnReadFailure = TRUE;
|
rfbBool errorMessageOnReadFailure = TRUE;
|
||||||
|
|
||||||
rfbBool ReadToBuffer(rfbClient* client) {
|
void ReadToBuffer(rfbClient* client) {
|
||||||
if (client->buffered == RFB_BUF_SIZE)
|
if (client->buffered == RFB_BUF_SIZE)
|
||||||
return FALSE;
|
return;
|
||||||
|
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
|
|
||||||
|
@ -61,13 +61,8 @@ rfbBool ReadToBuffer(rfbClient* client) {
|
||||||
RFB_BUF_SIZE - client->buffered, MSG_DONTWAIT);
|
RFB_BUF_SIZE - client->buffered, MSG_DONTWAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
client->buffered += size;
|
client->buffered += size;
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
|
rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
|
||||||
|
@ -78,8 +73,7 @@ rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
|
||||||
while (n != 0) {
|
while (n != 0) {
|
||||||
while (n != 0 && client->buffered == 0) {
|
while (n != 0 && client->buffered == 0) {
|
||||||
run_main_loop_once();
|
run_main_loop_once();
|
||||||
if (!ReadToBuffer(client))
|
ReadToBuffer(client);
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int size = MIN(client->buffered, n);
|
unsigned int size = MIN(client->buffered, n);
|
||||||
|
@ -111,6 +105,9 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n)
|
||||||
int err;
|
int err;
|
||||||
#endif /* LIBVNCSERVER_HAVE_SASL */
|
#endif /* LIBVNCSERVER_HAVE_SASL */
|
||||||
|
|
||||||
|
if (client->serverPort==-1)
|
||||||
|
return TRUE; /* vncrec playing */
|
||||||
|
|
||||||
if (client->tlsSession) {
|
if (client->tlsSession) {
|
||||||
/* WriteToTLS() will guarantee either everything is written, or error/eof returns */
|
/* WriteToTLS() will guarantee either everything is written, or error/eof returns */
|
||||||
i = WriteToTLS(client, buf, n);
|
i = WriteToTLS(client, buf, n);
|
||||||
|
@ -179,6 +176,55 @@ static rfbBool WaitForConnected(int socket, unsigned int secs)
|
||||||
return so_error == 0 ? TRUE : FALSE;
|
return so_error == 0 ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rfbSocket
|
||||||
|
ConnectClientToTcpAddr(unsigned int host, int port)
|
||||||
|
{
|
||||||
|
rfbSocket sock = ConnectClientToTcpAddrWithTimeout(host, port, DEFAULT_CONNECT_TIMEOUT);
|
||||||
|
/* put socket back into blocking mode for compatibility reasons */
|
||||||
|
if (sock != RFB_INVALID_SOCKET) {
|
||||||
|
SetBlocking(sock);
|
||||||
|
}
|
||||||
|
return sock;
|
||||||
|
}
|
||||||
|
|
||||||
|
rfbSocket
|
||||||
|
ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, unsigned int timeout)
|
||||||
|
{
|
||||||
|
rfbSocket sock;
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
int one = 1;
|
||||||
|
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_port = htons(port);
|
||||||
|
addr.sin_addr.s_addr = host;
|
||||||
|
|
||||||
|
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (sock == RFB_INVALID_SOCKET) {
|
||||||
|
rfbClientErr("ConnectToTcpAddr: socket (%s)\n",strerror(errno));
|
||||||
|
return RFB_INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SetNonBlocking(sock))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
|
if (!((errno == EWOULDBLOCK || errno == EINPROGRESS) && WaitForConnected(sock, timeout))) {
|
||||||
|
rfbClientErr("ConnectToTcpAddr: connect\n");
|
||||||
|
rfbCloseSocket(sock);
|
||||||
|
return RFB_INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
|
||||||
|
(char *)&one, sizeof(one)) < 0) {
|
||||||
|
rfbClientErr("ConnectToTcpAddr: setsockopt\n");
|
||||||
|
rfbCloseSocket(sock);
|
||||||
|
return RFB_INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sock;
|
||||||
|
}
|
||||||
|
|
||||||
rfbSocket
|
rfbSocket
|
||||||
ConnectClientToTcpAddr6(const char *hostname, int port)
|
ConnectClientToTcpAddr6(const char *hostname, int port)
|
||||||
{
|
{
|
||||||
|
@ -193,6 +239,7 @@ ConnectClientToTcpAddr6(const char *hostname, int port)
|
||||||
rfbSocket
|
rfbSocket
|
||||||
ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int timeout)
|
ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int timeout)
|
||||||
{
|
{
|
||||||
|
#ifdef LIBVNCSERVER_IPv6
|
||||||
rfbSocket sock;
|
rfbSocket sock;
|
||||||
int n;
|
int n;
|
||||||
struct addrinfo hints, *res, *ressave;
|
struct addrinfo hints, *res, *ressave;
|
||||||
|
@ -248,6 +295,13 @@ ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int
|
||||||
}
|
}
|
||||||
|
|
||||||
return sock;
|
return sock;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
rfbClientErr("ConnectClientToTcpAddr6: IPv6 disabled\n");
|
||||||
|
return RFB_INVALID_SOCKET;
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
rfbSocket
|
rfbSocket
|
||||||
|
@ -338,10 +392,12 @@ SetDSCP(rfbSocket sock, int dscp)
|
||||||
|
|
||||||
switch(addr.sa_family)
|
switch(addr.sa_family)
|
||||||
{
|
{
|
||||||
|
#if defined LIBVNCSERVER_IPv6 && defined IPV6_TCLASS
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
level = IPPROTO_IPV6;
|
level = IPPROTO_IPV6;
|
||||||
cmd = IPV6_TCLASS;
|
cmd = IPV6_TCLASS;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
level = IPPROTO_IP;
|
level = IPPROTO_IP;
|
||||||
cmd = IP_TOS;
|
cmd = IP_TOS;
|
||||||
|
@ -361,6 +417,36 @@ SetDSCP(rfbSocket sock, int dscp)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* StringToIPAddr - convert a host string to an IP address.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rfbBool
|
||||||
|
StringToIPAddr(const char *str, unsigned int *addr)
|
||||||
|
{
|
||||||
|
struct hostent *hp;
|
||||||
|
|
||||||
|
if (strcmp(str,"") == 0) {
|
||||||
|
*addr = htonl(INADDR_LOOPBACK); /* local */
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*addr = inet_addr(str);
|
||||||
|
|
||||||
|
if (*addr != -1)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
hp = gethostbyname(str);
|
||||||
|
|
||||||
|
if (hp) {
|
||||||
|
*addr = *(unsigned int *)hp->h_addr;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test if the other end of a socket is on the same machine.
|
* Test if the other end of a socket is on the same machine.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include <gnutls/x509.h>
|
#include <gnutls/x509.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static const char *rfbTLSPriority = "NORMAL:+DHE-DSS:+RSA:+DHE-RSA";
|
static const char *rfbTLSPriority = "NORMAL:+DHE-DSS:+RSA:+DHE-RSA:+SRP";
|
||||||
static const char *rfbAnonTLSPriority= "NORMAL:+ANON-DH";
|
static const char *rfbAnonTLSPriority= "NORMAL:+ANON-DH";
|
||||||
|
|
||||||
#define DH_BITS 1024
|
#define DH_BITS 1024
|
||||||
|
@ -112,13 +112,12 @@ verify_certificate_callback (gnutls_session_t session)
|
||||||
return GNUTLS_E_CERTIFICATE_ERROR;
|
return GNUTLS_E_CERTIFICATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hostname verification does NOT work
|
if (!gnutls_x509_crt_check_hostname (cert, hostname))
|
||||||
//if (!gnutls_x509_crt_check_hostname (cert, hostname))
|
{
|
||||||
// {
|
rfbClientLog("The certificate's owner does not match hostname '%s'\n",
|
||||||
// rfbClientLog("The certificate's owner does not match hostname '%s'\n",
|
hostname);
|
||||||
// hostname);
|
return GNUTLS_E_CERTIFICATE_ERROR;
|
||||||
// return GNUTLS_E_CERTIFICATE_ERROR;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
gnutls_x509_crt_deinit (cert);
|
gnutls_x509_crt_deinit (cert);
|
||||||
|
|
||||||
|
@ -338,9 +337,6 @@ FreeX509Credential(rfbCredential *cred)
|
||||||
static gnutls_certificate_credentials_t
|
static gnutls_certificate_credentials_t
|
||||||
CreateX509CertCredential(rfbCredential *cred)
|
CreateX509CertCredential(rfbCredential *cred)
|
||||||
{
|
{
|
||||||
// Use this to enable debug logs
|
|
||||||
//gnutls_global_set_log_level(GNUTLS_DEBUG_LEVEL);
|
|
||||||
|
|
||||||
gnutls_certificate_credentials_t x509_cred;
|
gnutls_certificate_credentials_t x509_cred;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
45
src/vnc.c
45
src/vnc.c
|
@ -23,8 +23,6 @@
|
||||||
#include <pixman.h>
|
#include <pixman.h>
|
||||||
#include <libdrm/drm_fourcc.h>
|
#include <libdrm/drm_fourcc.h>
|
||||||
#include <libavutil/frame.h>
|
#include <libavutil/frame.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <data-control.h>
|
|
||||||
|
|
||||||
#include "rfbclient.h"
|
#include "rfbclient.h"
|
||||||
#include "vnc.h"
|
#include "vnc.h"
|
||||||
|
@ -136,9 +134,6 @@ static void vnc_client_got_cut_text(rfbClient* client, const char* text,
|
||||||
|
|
||||||
if (self->cut_text)
|
if (self->cut_text)
|
||||||
self->cut_text(self, text, len);
|
self->cut_text(self, text, len);
|
||||||
else {
|
|
||||||
printf("Cut text is not defined!\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static rfbBool vnc_client_handle_open_h264_rect(rfbClient* client,
|
static rfbBool vnc_client_handle_open_h264_rect(rfbClient* client,
|
||||||
|
@ -221,7 +216,7 @@ static void vnc_client_init_pts_ext(void)
|
||||||
rfbClientRegisterExtension(&ext);
|
rfbClientRegisterExtension(&ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vnc_client* vnc_client_create(struct data_control* data_control)
|
struct vnc_client* vnc_client_create(void)
|
||||||
{
|
{
|
||||||
vnc_client_init_open_h264();
|
vnc_client_init_open_h264();
|
||||||
vnc_client_init_pts_ext();
|
vnc_client_init_pts_ext();
|
||||||
|
@ -243,7 +238,6 @@ struct vnc_client* vnc_client_create(struct data_control* data_control)
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
self->client = client;
|
self->client = client;
|
||||||
self->data_control = data_control;
|
|
||||||
rfbClientSetClientData(client, NULL, self);
|
rfbClientSetClientData(client, NULL, self);
|
||||||
|
|
||||||
client->MallocFrameBuffer = vnc_client_alloc_fb;
|
client->MallocFrameBuffer = vnc_client_alloc_fb;
|
||||||
|
@ -252,13 +246,9 @@ struct vnc_client* vnc_client_create(struct data_control* data_control)
|
||||||
client->StartingFrameBufferUpdate = vnc_client_start_update;
|
client->StartingFrameBufferUpdate = vnc_client_start_update;
|
||||||
client->CancelledFrameBufferUpdate = vnc_client_cancel_update;
|
client->CancelledFrameBufferUpdate = vnc_client_cancel_update;
|
||||||
client->GotXCutText = vnc_client_got_cut_text;
|
client->GotXCutText = vnc_client_got_cut_text;
|
||||||
self->cut_text = cut_text;
|
|
||||||
|
|
||||||
self->pts = NO_PTS;
|
self->pts = NO_PTS;
|
||||||
|
|
||||||
// Handle authentication
|
|
||||||
client->GetCredential = handle_vnc_authentication;
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
failure:
|
failure:
|
||||||
|
@ -266,36 +256,6 @@ failure:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rfbCredential* handle_vnc_authentication(struct _rfbClient *client, int credentialType) {
|
|
||||||
rfbCredential* creds = (rfbCredential*) malloc(sizeof(rfbCredential));
|
|
||||||
|
|
||||||
if (client->authScheme == rfbVeNCrypt && credentialType == rfbCredentialTypeX509) {
|
|
||||||
char* path = getenv("TLS_CA");
|
|
||||||
rfbClientLog("Using TLS CA certificate from env 'TLS_CA': %s\n", path);
|
|
||||||
|
|
||||||
creds->x509Credential.x509CACertFile = malloc(strlen(path) + 1);
|
|
||||||
strcpy(creds->x509Credential.x509CACertFile, path);
|
|
||||||
creds->x509Credential.x509CrlVerifyMode = rfbX509CrlVerifyAll;
|
|
||||||
} else if (client->authScheme == rfbVeNCrypt && credentialType == rfbCredentialTypeUser) {
|
|
||||||
const* username = getenv("VNC_USERNAME");
|
|
||||||
const* password = getenv("VNC_PASSWORD");
|
|
||||||
rfbClientLog("Using username and password for VNC authentication 'VNC_USERNAME', 'VNC_PASSWORD'\n");
|
|
||||||
|
|
||||||
creds->userCredential.password = malloc(strlen(password) + 1);
|
|
||||||
creds->userCredential.username = malloc(strlen(username) + 1);
|
|
||||||
strcpy(creds->userCredential.password, password);
|
|
||||||
strcpy(creds->userCredential.username, username);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
return creds;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cut_text (struct vnc_client* self, const char* text, size_t size) {
|
|
||||||
data_control_to_clipboard(self->data_control, text, size);
|
|
||||||
//printf("Received string FROM vnc_server: %s\n", text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vnc_client_destroy(struct vnc_client* self)
|
void vnc_client_destroy(struct vnc_client* self)
|
||||||
{
|
{
|
||||||
vnc_client_clear_av_frames(self);
|
vnc_client_clear_av_frames(self);
|
||||||
|
@ -425,8 +385,7 @@ const char* vnc_client_get_desktop_name(const struct vnc_client* self)
|
||||||
|
|
||||||
int vnc_client_process(struct vnc_client* self)
|
int vnc_client_process(struct vnc_client* self)
|
||||||
{
|
{
|
||||||
if (!ReadToBuffer(self->client))
|
ReadToBuffer(self->client);
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!vnc_client_lock_handler(self))
|
if (!vnc_client_lock_handler(self))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue