Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Clipboard

This thread is locked; no one can reply to it. rss feed Print
Clipboard
Trezker
Member #1,739
December 2001
avatar

Sony blocked that in my country.

And yes it's a computer job, software development.

Edgar Reynaldo
Member #8,592
May 2007
avatar

ClipboardTest.c compiled OK, but Clipboard.c brought up all these errors:

I think I've fixed all the errors. I forgot a couple includes and fixed the other typos.

Arthur, would you give it another try?
ClipBoardTest4.zip

Arthur Kalliokoski said:

Yes, you can copy and paste images.

Which programs allow you to do this? I want to look at their source code so I can figure out what image format other programs are expecting.

Arthur Kalliokoski
Second in Command
February 2005
avatar

My first try

pepsi@fractalcomet:/home/prog/ClipBoardTest4 12:21 AM $ gcc -c -O2 -Wall Clipboard.c
Clipboard.c:216:23: error: X11/XAtom.h: No such file or directory
Clipboard.c: In function 'SetClipboardString':
Clipboard.c:226: error: 'XA_CLIPBOARD' undeclared (first use in this function)
Clipboard.c:226: error: (Each undeclared identifier is reported only once
Clipboard.c:226: error: for each function it appears in.)
Clipboard.c:226: error: 'XA_STRING' undeclared (first use in this function)
Clipboard.c: In function 'GetNewClipboardString':
Clipboard.c:253: error: 'XA_CLIPBOARD' undeclared (first use in this function)
Clipboard.c:255: error: 'XA_STRING' undeclared (first use in this function)
pepsi@fractalcomet:/home/prog/ClipBoardTest4 12:22 AM $ locate XAtom.h  //"Find" XAtom.h,
(case insensitive) not found since no output
pepsi@fractalcomet:/home/prog/ClipBoardTest4 12:23 AM $ gcc -c -O2 -Wall ClipboardTest.c
pepsi@fractalcomet:/home/prog/ClipBoardTest4 12:23 AM $ 

Anyway I found Xatom.h (not XAtom.h) is in a Slackware repository and installed it, but I still get

Clipboard.c:226: error: 'XA_CLIPBOARD' undeclared (first use in this function)

as well as line 253.

I copy and paste images from Firefox to kolourpaint all the time to zoom in, as well as to/from most any other program that handles images, even within the same program like a rubber stamp. Hell, I just copied a few lines from Clipboard.c and pasted them into kolourpaint in various places as an image.

[EDIT]

I found XA_CLIPBOARD in X11/Xmu/Atoms.h and found it needs a parameter for Display,
so #included it and changed all the XA_CLIPBOARD's to XA_CLIPBOARD(d) and it compiled without errors. Now I just need to find the libraries to link in :D

[EDIT2]

This is the command to get it to work.
gcc -O2 -Wall Clipboard.c ClipboardTest.c -o t -lXxf86vm -lXmu `allegro-config --libs`
but it just flashes a window too fast to see anything, no error messages on the console.

[EDIT4]

Oops! I didn't notice the bitmap wasn't in this zip, copied it from the last, and it showed a window saying to do this and that, but nothing worked. It left a ClipboardLog.txt that simply said "There are no bytes to read in the requested property."

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

Arthur Kalliokoski
Second in Command
February 2005
avatar

You missed a couple things, and the doc says char *atom_name, so I put quotes around "CLIPBOARD" and "STRING" and it compiled without warnings or errors. :-X

Now the S key says it successfully set the clipboard string to CyberMan, but nothing else works, the log file still says "There are no bytes to read in the requested property."

I put the altered file in the paperclip.

[EDIT]

This says my use of quotes was correct.

http://docs.hp.com/en/B1171-90150/ch10s01.html

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

Alright, I got rid of the remaining references to XA_CLIPBOARD and XA_STRING and replaced them with the Atoms retrieved by XInternAtom. I also added in a rest(500) in the GetClipboardString function so hopefully events will be processed in time. Try it one more time, please.

ClipBoardTest7.zip

Arthur Kalliokoski
Second in Command
February 2005
avatar

Results were the exact same as last time, excepting it compiled properly. Perhaps I should add that the log file had two lines saying no bytes to read in this and the previous test.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

Well then, it's back to the drawing board. Maybe I'm using the wrong target for text data, I don't know.

What programs allow you to copy and paste text between them on Linux? I'll look up their source code and see what they do in this scenario.

Arthur Kalliokoski
Second in Command
February 2005
avatar

Honestly, I can't think of anything that doesn't allow me to copy stuff, the pdf viewers are somewhat dodgy to use since you're trying to select text with a rectangle.

I found the file in the paperclip a couple hours ago right after trying your second try, and it works. When executed, it pastes what's in the clipboard onto the console screen before the prompt returns.

[EDIT]

I just thought of trying it after copying an image from kolourpaint, but nothing was shown. I thought it might paste the binary garbage, but no.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

Honestly, I can't think of anything that doesn't allow me to copy stuff, the pdf viewers are somewhat dodgy to use since you're trying to select text with a rectangle.

I need examples though. I can't download the sources because I don't know what programs use copy/paste of text on Linux.

Arthur Kalliokoski said:

I found the file in the paperclip a couple hours ago right after trying your second try, and it works. When executed, it pastes what's in the clipboard onto the console screen before the prompt returns

What file are you referring to? ClipBoardTest1.zip and ClipBoardTest2.zip both use xclip as an intermediary. In the later versions, I was trying to emulate what xclip does by using selections. I suppose I'll look for the xclip source code and see what they do, but that will only get me text selections, not images.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I need examples though. I can't download the sources because I don't know what programs use copy/paste of text on Linux.

Images on clipboard:
http://kolourpaint.sourceforge.net/

Kwrite (text copy and paste)
Somewhere in
http://www.linuxfromscratch.org/blfs/view/svn/kde/kdebase.html

Quote:

What file are you referring to?

http://www.allegro.cc/files/download-attachment/?area=forum%20post&id=899543

It was in the post

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

It was in the post.

Nevermind, I'm a little dense. I'll take a closer look at it tomorrow. I think one of the problems is that XConvertSelection sends a SelectionRequest event to the owner of the selection asking them to store that information on the client's window. I may be looking at the wrong window with XGetWindowProperty. Thanks for testing my code out.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I got curious about the kde dev thing and downloaded it myself. The kolourpaint app isn't in there, but something else called klipper was. I think this might be the thing that does the work for all X apps. I uploaded the 110K file to

http://ompldr.org/vNzJwOA/klipper.zip

[EDIT]

No, it's a thing that installs itself to the task bar as a little icon, when clicked it displays the last five text string copies, when you click on one, it's the current item to be pasted. Copying an image doesn't show up in the list.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

bamccaig
Member #7,536
July 2006
avatar

Wait, is Edgar attempting to write an X implementation without an X server or am I missing something? :-X :D

Arthur Kalliokoski
Second in Command
February 2005
avatar

He's trying to access copy and paste functions for text and images in an Allegro program for X11.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

bamccaig said:

Wait, is Edgar attempting to write an X implementation without an X server or am I missing something?

No, nothing like that. I am trying to write X copy/paste functions without the use of events though, as using events would mean I would have to hack Allegro to have it send selection events to a callback function in the clipboard library. And since Allegro 4 may never produce any new releases, this would make everyone who wanted to use our library have to download SVN allegro and build it themselves, which is at least a small hassle.

Could someone on Linux post the man pages for XConvertSelection and XGetWindowProperty? Maybe the man pages are a little more thorough and up to date than what I am using.

Arthur Kalliokoski
Second in Command
February 2005
avatar

The XConvertSelection simply pointed to another man page so I included that one as well.

clicky

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

Arthur Kalliokoski
Second in Command
February 2005
avatar

Now the Format Police are looking for us!

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

Blame it on bamccaig. He told us to do it. I'm just an innocent CyberMan, trying to take over Earth and turn all humans into fellow CyberMen.

Edit :
Wanna be my guinea pig again?
I wrote up a logging function that will log all available clipboard targets. Run the program, go to a different program and copy something (text / image / whatever). Go back to the program and press L to log the targets. Try this with multiple programs, and remember what you copied from which program and in order so it can be compared with the log file the program produces.

<link removed>

Edit 2 :

In addition to the logging function, I (hopefully) fixed up the GetNewClipboardString function, so use B to view a string copied from another program. I don't think SetNewClipboardString will work yet, because the program doesn't listen to SelectionRequest events and then place the selection on the event specified window. For that to work, I'll probably have to hack Allegro.

ClipBoardTest9.zip

Arthur Kalliokoski
Second in Command
February 2005
avatar

I had to change line 483 in Clipboard.c to this

target_atom_name = XGetAtomName( d,((long*)returned_property)[i]);

to get it to compile, otherwise it's doing the same thing. Only the S key item seems to succeed (except for the new L log function).

The logfile that results from hitting the key on each line is attached.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

I had to change line 483 in Clipboard.c to this

Thanks, I missed that.

Arthur Kalliokoski said:

The logfile that results from hitting the key on each line is attached.

Did you read my last post? The S key will appear to work, but you won't actually be able to paste that string into another program because the program doesn't respond to SelectionRequest events. So don't bother with S for now.

First, try copying a string or image from another program and then coming back to my program and press the L key to log the available clipboard targets. I'm trying to determine what format other programs are using. Remember which programs you copied from when you pressed L so I can match that up with the log.

After that, try copying a string from another program and see if pressing B in my program shows you the string that you copied.

Arthur Kalliokoski
Second in Command
February 2005
avatar

Did you read my last post?

Sorry, I tend to catch up on these things upon awakening, and I wake up real slow (like now).

I didn't think of copying from another program, first I copied your avatar (!), but your program said there was nothing in the clipboard. Then I copied a sentence from the console and your program displayed the start of it until it went off screen. Then I copied about 10 lines out of your source and it displayed those. The entire length of the single sentence and the block of code were both written to the logfile.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

Arthur Kalliokoski
Second in Command
February 2005
avatar

The first sentence I pasted was "getcolor DejaVuSans18.tga 32" and the block of code starts at "int main..." on line 8.

Logging all available TARGETS :
The TARGETS property does not exist on the specified window. Bad window, bad.
Success retrieving property. Return type "STRING" , Format=8 , NumItemsReturned=29
   Bytes Left=0 , String Returned="getcolor DejaVuSans18.tga 32
"Logging all available TARGETS :
The TARGETS property does not exist on the specified window. Bad window, bad.
Success retrieving property. Return type "STRING" , Format=8 , NumItemsReturned=441
   Bytes Left=0 , String Returned="int main(int argc , char** argv) {
   int cd;
   int dw = 800;
   int dh = 600;
   BITMAP* cyberman = 0;
   BITMAP* buffer = 0;
   BITMAP* fromclipbmp = 0;
   char* fromclipstr = 0;
   int redraw = 1;
   int black = 0;
   int white = 0;
   int orange = 0;
   int ret = 0;
   
   if (allegro_init() != 0) {return 0;}
   if (install_keyboard() != 0) {return 0;}
   cd = desktop_color_depth();
   if (cd == 0) {cd = 32;}
   set_color_depth(cd);"

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein



Go to: