/*
* CINELERRA
* Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ *
*/
#include "bcclipboard.h"
BC_Clipboard::BC_Clipboard(const char *display_name)
: Thread(1, 0, 0)
{
- if(display_name)
+ if(display_name)
strcpy(this->display_name, display_name);
else
this->display_name[0] = 0;
strtype_atom = XInternAtom(out_display, "UTF8_STRING", False);
else
strtype_atom = XA_STRING;
- in_win = XCreateSimpleWindow(in_display,
- DefaultRootWindow(in_display),
+ in_win = XCreateSimpleWindow(in_display,
+ DefaultRootWindow(in_display),
0, 0, 1, 1, 0, 0, 0);
- out_win = XCreateSimpleWindow(out_display,
- DefaultRootWindow(out_display),
+ out_win = XCreateSimpleWindow(out_display,
+ DefaultRootWindow(out_display),
0, 0, 1, 1, 0, 0, 0);
data[0] = 0;
data[1] = 0;
#endif
// Must use a different display handle to send events.
Display *display = BC_WindowBase::init_display(display_name);
- XEvent event;
+ XEvent event; memset(&event, 0, sizeof(event));
XClientMessageEvent *ptr = (XClientMessageEvent*)&event;
event.type = ClientMessage;
while(XPending(out_display))
{
#endif
-//printf("BC_Clipboard::run 1\n");
+//printf("BC_Clipboard::run 1\n");
XNextEvent(out_display, &event);
-//printf("BC_Clipboard::run 2 %d\n", event.type);
+//printf("BC_Clipboard::run 2 %d\n", event.type);
#ifdef SINGLE_THREAD
BC_Display::lock_display("BC_Clipboard::run");
case SelectionRequest:
handle_selectionrequest((XSelectionRequestEvent*)&event);
break;
-
+
case SelectionClear:
if(data[0]) data[0][0] = 0;
if(data[1]) data[1][0] = 0;
else if (request->target == targets_atom)
success = handle_request_targets(request);
- XEvent reply;
+ XEvent reply; memset(&reply, 0, sizeof(reply));
// 'None' tells the client that the request was denied
reply.xselection.property = success ? request->property : None;
reply.xselection.type = SelectionNotify;
reply.xselection.selection = request->selection;
reply.xselection.target = request->target;
reply.xselection.time = request->time;
-
+
XSendEvent(out_display, request->requestor, 0, 0, &reply);
XFlush(out_display);
#endif
// Store in local buffer
- if(this->data[clipboard_num] && length[clipboard_num] != len + 1)
+ if(this->data[clipboard_num] && length[clipboard_num] != len)
{
delete [] this->data[clipboard_num];
this->data[clipboard_num] = 0;
{
length[clipboard_num] = len;
this->data[clipboard_num] = new char[len + 1];
- memcpy(this->data[clipboard_num], data, len);
- this->data[clipboard_num][len] = 0;
}
+ memcpy(this->data[clipboard_num], data, len);
+ this->data[clipboard_num][len] = 0;
+
if(clipboard_num == PRIMARY_SELECTION)
{
- XSetSelectionOwner(out_display,
- primary,
- out_win,
+ XSetSelectionOwner(out_display,
+ primary,
+ out_win,
CurrentTime);
}
else
if(clipboard_num == SECONDARY_SELECTION)
{
- XSetSelectionOwner(out_display,
- secondary,
- out_win,
+ XSetSelectionOwner(out_display,
+ secondary,
+ out_win,
CurrentTime);
}
data[i] = 0;
XFree(data2);
-
-
+
+
return 0;
}
unsigned long nitems, size, new_size;
char *temp_data = 0;
- pty = (clipboard_num == PRIMARY_SELECTION) ? primary : secondary;
+ pty = (clipboard_num == PRIMARY_SELECTION) ? primary : secondary;
/* a property of our window
for apps to put their
selection into */
- XConvertSelection(in_display,
- clipboard_num == PRIMARY_SELECTION ? primary : secondary,
+ XConvertSelection(in_display,
+ clipboard_num == PRIMARY_SELECTION ? primary : secondary,
strtype_atom,
pty,
- in_win,
+ in_win,
CurrentTime);
data[0] = 0;
#else
XUnlockDisplay(in_display);
#endif
-
+//int len = strlen(data);
+//printf("BC_Clipboard::from_clipboard %d: %d '%*.*s'\n",clipboard_num,len,len,len,data);
return 0;
}
char *temp_data = 0;
int result = 0;
- pty = (clipboard_num == PRIMARY_SELECTION) ? primary : secondary;
+ pty = (clipboard_num == PRIMARY_SELECTION) ? primary : secondary;
/* a property of our window
for apps to put their
selection into */
- XConvertSelection(in_display,
- (clipboard_num == PRIMARY_SELECTION) ? primary : secondary,
+ XConvertSelection(in_display,
+ (clipboard_num == PRIMARY_SELECTION) ? primary : secondary,
strtype_atom, pty, in_win, CurrentTime);
do