|
|
|
@ -29,7 +29,6 @@
|
|
|
|
|
#include "parse.h"
|
|
|
|
|
#include "os_calls.h"
|
|
|
|
|
#include "chansrv.h"
|
|
|
|
|
#include "log.h"
|
|
|
|
|
#include "clipboard.h"
|
|
|
|
|
|
|
|
|
|
static Atom g_clipboard_atom = 0;
|
|
|
|
@ -80,7 +79,7 @@ clipboard_error_handler(Display* dis, XErrorEvent* xer)
|
|
|
|
|
char text[256];
|
|
|
|
|
|
|
|
|
|
XGetErrorText(dis, xer->error_code, text, 255);
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"error [%s]", text);
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR,"error [%s]", text));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -91,7 +90,7 @@ clipboard_error_handler(Display* dis, XErrorEvent* xer)
|
|
|
|
|
int DEFAULT_CC
|
|
|
|
|
clipboard_fatal_handler(Display* dis)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ALWAYS,"fatal error, exiting");
|
|
|
|
|
LOGM((LOG_LEVEL_ALWAYS, "fatal error, exiting"));
|
|
|
|
|
main_cleanup();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -141,7 +140,7 @@ clipboard_init(void)
|
|
|
|
|
int ver_min;
|
|
|
|
|
Status st;
|
|
|
|
|
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"xrdp-chansrv: in clipboard_init");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "xrdp-chansrv: in clipboard_init"));
|
|
|
|
|
if (g_clip_up)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
@ -155,7 +154,7 @@ clipboard_init(void)
|
|
|
|
|
g_display = XOpenDisplay(0);
|
|
|
|
|
if (g_display == 0)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: XOpenDisplay failed");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: XOpenDisplay failed"));
|
|
|
|
|
rv = 1;
|
|
|
|
|
}
|
|
|
|
|
if (rv == 0)
|
|
|
|
@ -163,7 +162,7 @@ clipboard_init(void)
|
|
|
|
|
g_x_socket = XConnectionNumber(g_display);
|
|
|
|
|
if (g_x_socket == 0)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: XConnectionNumber failed");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: XConnectionNumber failed"));
|
|
|
|
|
rv = 2;
|
|
|
|
|
}
|
|
|
|
|
g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0);
|
|
|
|
@ -173,7 +172,7 @@ clipboard_init(void)
|
|
|
|
|
g_clipboard_atom = XInternAtom(g_display, "CLIPBOARD", False);
|
|
|
|
|
if (g_clipboard_atom == None)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: XInternAtom failed");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: XInternAtom failed"));
|
|
|
|
|
rv = 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -181,15 +180,17 @@ clipboard_init(void)
|
|
|
|
|
{
|
|
|
|
|
if (!XFixesQueryExtension(g_display, &g_xfixes_event_base, &dummy))
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: no xfixes");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: no xfixes"));
|
|
|
|
|
rv = 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rv == 0)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: g_xfixes_event_base %d", g_xfixes_event_base);
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: g_xfixes_event_base %d",
|
|
|
|
|
g_xfixes_event_base));
|
|
|
|
|
st = XFixesQueryVersion(g_display, &ver_maj, &ver_min);
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init st %d, maj %d min %d", st, ver_maj, ver_min);
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init st %d, maj %d min %d", st,
|
|
|
|
|
ver_maj, ver_min));
|
|
|
|
|
g_screen_num = DefaultScreen(g_display);
|
|
|
|
|
g_screen = ScreenOfDisplay(g_display, g_screen_num);
|
|
|
|
|
g_clip_property_atom = XInternAtom(g_display, "XRDP_CLIP_PROPERTY_ATOM",
|
|
|
|
@ -223,13 +224,13 @@ clipboard_init(void)
|
|
|
|
|
out_uint32_le(s, 0); /* extra 4 bytes ? */
|
|
|
|
|
s_mark_end(s);
|
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_init: data out, sending "
|
|
|
|
|
"CLIPRDR_CONNECT (clip_msg_id = 1)");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_init: data out, sending "
|
|
|
|
|
"CLIPRDR_CONNECT (clip_msg_id = 1)"));
|
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
|
if (rv != 0)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: send_channel_data failed "
|
|
|
|
|
"rv = %d", rv);
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: send_channel_data failed "
|
|
|
|
|
"rv = %d", rv));
|
|
|
|
|
rv = 4;
|
|
|
|
|
}
|
|
|
|
|
free_stream(s);
|
|
|
|
@ -242,7 +243,7 @@ clipboard_init(void)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"xrdp-chansrv: clipboard_init: error on exit");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "xrdp-chansrv: clipboard_init: error on exit"));
|
|
|
|
|
}
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
@ -284,10 +285,11 @@ clipboard_send_data_request(void)
|
|
|
|
|
int size;
|
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_data_request:");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_send_data_request:"));
|
|
|
|
|
if (!g_got_format_announce)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_send_data_request: error, no format announce");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_send_data_request: error, "
|
|
|
|
|
"no format announce"));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
g_got_format_announce = 0;
|
|
|
|
@ -299,8 +301,8 @@ clipboard_send_data_request(void)
|
|
|
|
|
out_uint32_le(s, 0x0d);
|
|
|
|
|
s_mark_end(s);
|
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_data_request: data out, sending "
|
|
|
|
|
"CLIPRDR_DATA_REQUEST (clip_msg_id = 4)");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_send_data_request: data out, sending "
|
|
|
|
|
"CLIPRDR_DATA_REQUEST (clip_msg_id = 4)"));
|
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
|
free_stream(s);
|
|
|
|
|
return rv;
|
|
|
|
@ -322,8 +324,8 @@ clipboard_send_format_ack(void)
|
|
|
|
|
out_uint32_le(s, 0); /* extra 4 bytes ? */
|
|
|
|
|
s_mark_end(s);
|
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_format_ack: data out, sending "
|
|
|
|
|
"CLIPRDR_FORMAT_ACK (clip_msg_id = 3)");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_send_format_ack: data out, sending "
|
|
|
|
|
"CLIPRDR_FORMAT_ACK (clip_msg_id = 3)"));
|
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
|
free_stream(s);
|
|
|
|
|
return rv;
|
|
|
|
@ -346,8 +348,8 @@ clipboard_send_format_announce(void)
|
|
|
|
|
out_uint8s(s, 0x90);
|
|
|
|
|
s_mark_end(s);
|
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_format_announce: data out, sending "
|
|
|
|
|
"CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_send_format_announce: data out, sending "
|
|
|
|
|
"CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)"));
|
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
|
free_stream(s);
|
|
|
|
|
return rv;
|
|
|
|
@ -401,7 +403,7 @@ clipboard_send_data_response(void)
|
|
|
|
|
num_chars = g_mbstowcs(0, g_last_clip_data, 0);
|
|
|
|
|
if (num_chars < 0)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_send_data_response: bad string");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_send_data_response: bad string"));
|
|
|
|
|
num_chars = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -415,16 +417,16 @@ clipboard_send_data_response(void)
|
|
|
|
|
out_uint32_le(s, num_chars * 2 + 2); /* length */
|
|
|
|
|
if (clipboard_out_unicode(s, g_last_clip_data, num_chars) != num_chars * 2)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_send_data_response: error "
|
|
|
|
|
"clipboard_out_unicode didn't write right number of bytes");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR,"clipboard_send_data_response: error "
|
|
|
|
|
"clipboard_out_unicode didn't write right number of bytes"));
|
|
|
|
|
}
|
|
|
|
|
out_uint16_le(s, 0); /* nil for string */
|
|
|
|
|
out_uint32_le(s, 0);
|
|
|
|
|
s_mark_end(s);
|
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_data_response: data out, sending "
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_send_data_response: data out, sending "
|
|
|
|
|
"CLIPRDR_DATA_RESPONSE (clip_msg_id = 5) size %d num_chars %d",
|
|
|
|
|
size, num_chars);
|
|
|
|
|
size, num_chars));
|
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
|
free_stream(s);
|
|
|
|
|
return rv;
|
|
|
|
@ -494,14 +496,16 @@ static int APP_CC
|
|
|
|
|
clipboard_process_format_announce(struct stream* s, int clip_msg_status,
|
|
|
|
|
int clip_msg_len)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_process_format_announce: CLIPRDR_FORMAT_ANNOUNCE");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_process_format_announce: "
|
|
|
|
|
"CLIPRDR_FORMAT_ANNOUNCE"));
|
|
|
|
|
//g_hexdump(s->p, s->end - s->p);
|
|
|
|
|
clipboard_send_format_ack();
|
|
|
|
|
g_got_format_announce = 1;
|
|
|
|
|
g_data_in_up_to_date = 0;
|
|
|
|
|
if (clipboard_set_selection_owner() != 0)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_process_format_announce: XSetSelectionOwner failed");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_process_format_announce: "
|
|
|
|
|
"XSetSelectionOwner failed"));
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -511,7 +515,7 @@ static int APP_CC
|
|
|
|
|
clipboard_prcoess_format_ack(struct stream* s, int clip_msg_status,
|
|
|
|
|
int clip_msg_len)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_prcoess_format_ack: CLIPRDR_FORMAT_ACK");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_prcoess_format_ack: CLIPRDR_FORMAT_ACK"));
|
|
|
|
|
//g_hexdump(s->p, s->end - s->p);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -521,7 +525,8 @@ static int APP_CC
|
|
|
|
|
clipboard_process_data_request(struct stream* s, int clip_msg_status,
|
|
|
|
|
int clip_msg_len)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_process_data_request: CLIPRDR_DATA_REQUEST");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_process_data_request: "
|
|
|
|
|
"CLIPRDR_DATA_REQUEST"));
|
|
|
|
|
//g_hexdump(s->p, s->end - s->p);
|
|
|
|
|
clipboard_send_data_response();
|
|
|
|
|
return 0;
|
|
|
|
@ -539,7 +544,8 @@ clipboard_process_data_response(struct stream* s, int clip_msg_status,
|
|
|
|
|
int index;
|
|
|
|
|
int data_in_len;
|
|
|
|
|
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_process_data_response: CLIPRDR_DATA_RESPONSE");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_process_data_response: "
|
|
|
|
|
"CLIPRDR_DATA_RESPONSE"));
|
|
|
|
|
g_waiting_for_data_response = 0;
|
|
|
|
|
len = (int)(s->end - s->p);
|
|
|
|
|
if (len < 1)
|
|
|
|
@ -590,8 +596,8 @@ clipboard_process_data_response(struct stream* s, int clip_msg_status,
|
|
|
|
|
lxev = &(g_selection_request_event[index]);
|
|
|
|
|
clipboard_provide_selection(lxev, lxev->target, 8, g_data_in,
|
|
|
|
|
data_in_len);
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_process_data_response: requestor %d data_in_len %d",
|
|
|
|
|
lxev->requestor, data_in_len);
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_process_data_response: requestor %d "
|
|
|
|
|
"data_in_len %d", lxev->requestor, data_in_len));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_selection_request_event_count = 0;
|
|
|
|
@ -657,7 +663,8 @@ clipboard_data_in(struct stream* s, int chan_id, int chan_flags, int length,
|
|
|
|
|
clip_msg_len);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_data_in: unknown clip_msg_id %d", clip_msg_id);
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_data_in: unknown clip_msg_id %d",
|
|
|
|
|
clip_msg_id));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
XFlush(g_display);
|
|
|
|
@ -685,13 +692,13 @@ clipboard_event_selection_owner_notify(XEvent* xevent)
|
|
|
|
|
XFixesSelectionNotifyEvent* lxevent;
|
|
|
|
|
|
|
|
|
|
lxevent = (XFixesSelectionNotifyEvent*)xevent;
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_owner_notify: "
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_owner_notify: "
|
|
|
|
|
"window %d subtype %d owner %d g_wnd %d",
|
|
|
|
|
lxevent->window, lxevent->subtype, lxevent->owner, g_wnd);
|
|
|
|
|
lxevent->window, lxevent->subtype, lxevent->owner, g_wnd));
|
|
|
|
|
if (lxevent->owner == g_wnd)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_owner_notify: skipping, "
|
|
|
|
|
"onwer == g_wnd");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_event_selection_owner_notify: skipping, "
|
|
|
|
|
"onwer == g_wnd"));
|
|
|
|
|
g_got_selection = 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -811,7 +818,10 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
|
int* atoms;
|
|
|
|
|
Atom type;
|
|
|
|
|
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify:");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_notify:"));
|
|
|
|
|
data_size = 0;
|
|
|
|
|
n_items = 0;
|
|
|
|
|
fmt = 0;
|
|
|
|
|
convert_to_string = 0;
|
|
|
|
|
convert_to_utf8 = 0;
|
|
|
|
|
send_format_announce = 0;
|
|
|
|
@ -821,8 +831,8 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
|
lxevent = (XSelectionEvent*)xevent;
|
|
|
|
|
if (lxevent->property == None)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: clip could "
|
|
|
|
|
"not be converted");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: clip could "
|
|
|
|
|
"not be converted"));
|
|
|
|
|
rv = 1;
|
|
|
|
|
}
|
|
|
|
|
if (rv == 0)
|
|
|
|
@ -832,8 +842,8 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
|
&n_items, &data, &data_size);
|
|
|
|
|
if (rv != 0)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: "
|
|
|
|
|
"clipboard_get_window_property failed error %d", rv);
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: "
|
|
|
|
|
"clipboard_get_window_property failed error %d", rv));
|
|
|
|
|
}
|
|
|
|
|
XDeleteProperty(g_display, lxevent->requestor, lxevent->property);
|
|
|
|
|
}
|
|
|
|
@ -849,8 +859,8 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
|
for (index = 0; index < n_items; index++)
|
|
|
|
|
{
|
|
|
|
|
atom = atoms[index];
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: %d %s %d", atom,
|
|
|
|
|
XGetAtomName(g_display, atom), XA_STRING);
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: %d %s %d",
|
|
|
|
|
atom, XGetAtomName(g_display, atom), XA_STRING));
|
|
|
|
|
if (atom == g_utf8_atom)
|
|
|
|
|
{
|
|
|
|
|
convert_to_utf8 = 1;
|
|
|
|
@ -863,15 +873,15 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: error, target is "
|
|
|
|
|
"'TARGETS' and type[%d] or fmt[%d] not right, should be "
|
|
|
|
|
"type[%d], fmt[%d]", type, fmt, XA_ATOM, 32);
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: error, "
|
|
|
|
|
"target is 'TARGETS' and type[%d] or fmt[%d] not right, "
|
|
|
|
|
"should be type[%d], fmt[%d]", type, fmt, XA_ATOM, 32));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (lxevent->target == g_utf8_atom)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: UTF8_STRING data_size %d",
|
|
|
|
|
data_size);
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: UTF8_STRING "
|
|
|
|
|
"data_size %d", data_size));
|
|
|
|
|
g_free(g_last_clip_data);
|
|
|
|
|
g_last_clip_size = data_size;
|
|
|
|
|
g_last_clip_data = g_malloc(g_last_clip_size + 1, 0);
|
|
|
|
@ -882,8 +892,8 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
|
}
|
|
|
|
|
else if (lxevent->target == XA_STRING)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: XA_STRING data_size %d",
|
|
|
|
|
data_size);
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: XA_STRING "
|
|
|
|
|
"data_size %d", data_size));
|
|
|
|
|
g_free(g_last_clip_data);
|
|
|
|
|
g_last_clip_size = data_size;
|
|
|
|
|
g_last_clip_data = g_malloc(g_last_clip_size + 1, 0);
|
|
|
|
@ -894,12 +904,14 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: unknown target");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: "
|
|
|
|
|
"unknown target"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: unknown selection");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR,"clipboard_event_selection_notify: "
|
|
|
|
|
"unknown selection"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (convert_to_utf8)
|
|
|
|
@ -941,7 +953,7 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
|
static int APP_CC
|
|
|
|
|
clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
|
{
|
|
|
|
|
XEvent xev;
|
|
|
|
|
//XEvent xev;
|
|
|
|
|
XSelectionRequestEvent* lxev;
|
|
|
|
|
tui32 ui32[8];
|
|
|
|
|
Atom type;
|
|
|
|
@ -951,19 +963,21 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
|
char* xdata;
|
|
|
|
|
|
|
|
|
|
lxev = (XSelectionRequestEvent*)xevent;
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_wnd %d, "
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_wnd %d, "
|
|
|
|
|
".requestor %d .owner %d .selection %d '%s' .target %d .property %d",
|
|
|
|
|
g_wnd, lxev->requestor, lxev->owner, lxev->selection,
|
|
|
|
|
XGetAtomName(g_display, lxev->selection),
|
|
|
|
|
lxev->target, lxev->property);
|
|
|
|
|
lxev->target, lxev->property));
|
|
|
|
|
if (lxev->property == None)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: lxev->property is None");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
|
|
|
|
"lxev->property is None"));
|
|
|
|
|
}
|
|
|
|
|
else if (lxev->target == g_targets_atom)
|
|
|
|
|
{
|
|
|
|
|
/* requestor is asking what the selection can be converted to */
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_targets_atom");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
|
|
|
|
"g_targets_atom"));
|
|
|
|
|
ui32[0] = g_targets_atom;
|
|
|
|
|
ui32[1] = g_timestamp_atom;
|
|
|
|
|
ui32[2] = g_multiple_atom;
|
|
|
|
@ -974,29 +988,33 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
|
else if (lxev->target == g_timestamp_atom)
|
|
|
|
|
{
|
|
|
|
|
/* requestor is asking the time I got the selection */
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_timestamp_atom");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
|
|
|
|
"g_timestamp_atom"));
|
|
|
|
|
ui32[0] = g_selection_time;
|
|
|
|
|
return clipboard_provide_selection(lxev, XA_INTEGER, 32, (char*)ui32, 1);
|
|
|
|
|
}
|
|
|
|
|
else if (lxev->target == g_multiple_atom)
|
|
|
|
|
{
|
|
|
|
|
/* target, property pairs */
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_multiple_atom");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
|
|
|
|
"g_multiple_atom"));
|
|
|
|
|
#if 0
|
|
|
|
|
if (clipboard_get_window_property(xev.xselection.requestor,
|
|
|
|
|
xev.xselection.property,
|
|
|
|
|
&type, &fmt, &n_items, &xdata,
|
|
|
|
|
&xdata_size) == 0)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_multiple_atom "
|
|
|
|
|
"n_items %d", n_items);
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_multiple_atom "
|
|
|
|
|
"n_items %d", n_items));
|
|
|
|
|
/* todo */
|
|
|
|
|
g_free(xdata);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else if ((lxev->target == XA_STRING) || (lxev->target == g_utf8_atom))
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: %s",
|
|
|
|
|
XGetAtomName(g_display, lxev->target));
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: %s",
|
|
|
|
|
XGetAtomName(g_display, lxev->target)));
|
|
|
|
|
if (g_data_in_up_to_date)
|
|
|
|
|
{
|
|
|
|
|
return clipboard_provide_selection(lxev, lxev->target, 8,
|
|
|
|
@ -1004,7 +1022,8 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
|
}
|
|
|
|
|
if (g_selection_request_event_count > 10)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_request: error, too many requests");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_request: error, "
|
|
|
|
|
"too many requests"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -1022,8 +1041,8 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_request: unknown "
|
|
|
|
|
"target %s", XGetAtomName(g_display, lxev->target));
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR,"clipboard_event_selection_request: unknown "
|
|
|
|
|
"target %s", XGetAtomName(g_display, lxev->target)));
|
|
|
|
|
}
|
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
|
return 0;
|
|
|
|
@ -1044,7 +1063,7 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
|
static int APP_CC
|
|
|
|
|
clipboard_event_selection_clear(XEvent* xevent)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_clear:");
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_clear:"));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1105,7 +1124,7 @@ clipboard_check_wait_objs(void)
|
|
|
|
|
if (XPending(g_display) < 1)
|
|
|
|
|
{
|
|
|
|
|
/* something is wrong, should not get here */
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_check_wait_objs: sck closed");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_check_wait_objs: sck closed"));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (g_waiting_for_data_response)
|
|
|
|
@ -1114,8 +1133,8 @@ clipboard_check_wait_objs(void)
|
|
|
|
|
g_waiting_for_data_response_time;
|
|
|
|
|
if (time_diff > 1000)
|
|
|
|
|
{
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_check_wait_objs: warning, waiting for "
|
|
|
|
|
"data response too long");
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_check_wait_objs: warning, "
|
|
|
|
|
"waiting for data response too long"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (XPending(g_display) > 0)
|
|
|
|
@ -1144,8 +1163,8 @@ clipboard_check_wait_objs(void)
|
|
|
|
|
clipboard_event_selection_owner_notify(&xevent);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_check_wait_objs unknown type %d",
|
|
|
|
|
xevent.type);
|
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_check_wait_objs unknown type %d",
|
|
|
|
|
xevent.type));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|