Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Clipboard

This thread is locked; no one can reply to it. rss feed Print
Clipboard
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Well, at least one thing is working. ::)

The stupid ICCCM says clients are supposed to support the TARGETS property, but apparently they didn't feel like doing that. So that means I still have to guess what format images will be in.

I think the only way forward is to write a modified version of xclip that supports images and then call that from the program that wants to use the clipboard. Ideas anyone?

Thanks for your help testing stuff Arthur. :)

Edit :
Made it to 100 posts! Woo! :D

Arthur Kalliokoski
Second in Command
February 2005
avatar

I had the bright idea of watching the system calls during a paste with the strace utility, but all I got was 1444 lines of junk like this:

poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, revents=POLLOUT}])
writev(7, [{"7\5\4\0\312\341\0\2+Z\0\2\0\0\0\0007\4\4\0\313\341\0\2+Z\0\2\0\0\0\0008"..., 3920}, {"\1\1\1\1ZZZ_abbf\30\30\30\31\2\2\2\2\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 18864}, {""..., 0}], 3) = 22784
poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, revents=POLLIN|POLLOUT}])
read(7, "\34\0z\335\255\1\0\0L\1\0\0?\"?\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\34"..., 4096) = 64
writev(7, [{"<\5\2\0\332\341\0\2\226\10\t\0\3\0\0\0\331\341\0\2\0\0\0\0\325\341\0\2\0\0\0\0\0"..., 14864}, {"\0\0\0\0\n\n\v\17XYZ\202\213\214\215\316\232\233\235\344\230\230\232\340\224\225\227\333\221\222\223\326\215"..., 16704}, {""..., 0}], 3) = 31568
poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, revents=POLLIN}])
read(7, "\34\0\22\336\255\1\0\0\"\1\0\0B\"?\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 32
poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, revents=POLLOUT}])
writev(7, [{"<\5\2\0\340\341\0\2\226\10\t\0\3\0\0\0\337\341\0\2\0\0\0\0\325\341\0\2\0\0\0\0\0"..., 16368}, {NULL, 0}, {""..., 0}], 3) = 16368
read(7, 0x81557d0, 4096)                = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, revents=POLLOUT}])
writev(7, [{"\226\10\t\0\3\341\0\2\364\341\0\2\0\0\0\0\370\341\0\2\0\0\0\0\0\0\0\0\0\0\4\0\4"..., 13656}, {"\1\1\1\1PQQTJKKN\20\20\20\20\1\1\1\1\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 2736}, {""..., 0}], 3) = 16392
clock_gettime(CLOCK_MONOTONIC, {71246, 415387992}) = 0
poll([{fd=3, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9, events=POLLIN}, {fd=7, events=POLLIN}], 4, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {71246, 415497496}) = 0
poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, revents=POLLOUT}])
writev(7, [{"<\10\2\0#\342\0\2\226\10\t\0\3\0\0\0\"\342\0\2\0\0\0\0\36\342\0\2\0\0\0\0\0"..., 14764}, {NULL, 0}, {""..., 0}], 3) = 14764
read(7, 0x81557d0, 4096)                = -1 EAGAIN (Resource temporarily unavailable)
clock_gettime(CLOCK_MONOTONIC, {71246, 416440091}) = 0
read(7, 0x81557d0, 4096)                = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=3, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9, events=POLLIN}, {fd=7, events=POLLIN}], 4, 0) = 0 (Timeout)
read(7, 0x81557d0, 4096)                = -1 EAGAIN (Resource temporarily unavailable)
clock_gettime(CLOCK_MONOTONIC, {71246, 418935003}) = 0
clock_gettime(CLOCK_MONOTONIC, {71246, 419022695}) = 0
read(7, 0x81557d0, 4096)                = -1 EAGAIN (Resource temporarily unavailable)
clock_gettime(CLOCK_MONOTONIC, {71246, 419115259}) = 0
poll([{fd=3, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9, events=POLLIN}, {fd=7, events=POLLIN}], 4, 4372) = 0 (Timeout)
read(7, 0x81557d0, 4096)                = -1 EAGAIN (Resource temporarily unavailable)
clock_gettime(CLOCK_MONOTONIC, {71250, 795721149}) = 0
clock_gettime(CLOCK_MONOTONIC, {71250, 795764055}) = 0
clock_gettime(CLOCK_MONOTONIC, {71250, 795845848}) = 0

They all watch too much MSNBC... they get ideas.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

To any helpful Linux users :

Do any of you have the x11proto-core-dev package installed, or could you install it, and then post usr/include/X11/Xatom.h for me please? I'm trying to find an updated list of the target atoms currently in use so I can determine which formats to support. Since I'm not on Linux, package managers won't work for me, and the header I need wasn't included in the X11 library source code. Thanks to anyone who takes the time for me. ;)

Arthur Kalliokoski
Second in Command
February 2005
avatar

This is the one I have.

They all watch too much MSNBC... they get ideas.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Arthur Kalliokoski
Second in Command
February 2005
avatar

I find XA_CLIPBOARD in /usr/include/X11/Xmu/Atoms.h

They all watch too much MSNBC... they get ideas.

bamccaig
Member #7,536
July 2006
avatar

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Well, I guess that XA_CLIPBOARD is an extension of some kind then. I just thought it would be part of the core X11 library. I don't need it anyway, as XInternAtom(display , "CLIPBOARD" , true) finds it anyway.

I'm getting close to having a working clone of xclip that will have support for images, but it won't support images until I find out what format image editors are using to copy/paste images. Luckily my version of xclip will log what selection targets are available and are requested by other programs, so the more it gets run, the more information I will have.

Once my program is complete, I will bump the thread and post it.

Append :
Okay, here's my version of xclip, along with a version of ClipboardTest designed to use it. Linux users compile and test please. ;D

ClipboardTest10.zip
You'll need to compile both programs separately this time and the command line should be something like :

gcc -O2 -Wall xcsi.c -LX11 -o xcsi.exe
gcc -O2 -Wall ClipboardTest.c Clipboard.c -o ClipboardTest.exe `allegro-config --libs`

To test, run ClipboardTest.exe. Copy text or an image in another program and then press the L key in ClipboardTest.exe. Do this for as many programs as you have that support copying text or images.

After that, try setting the clipboard string using S and getting the clipboard string using B.

When you're done, please post the contents of ClipboardLog.txt and xcsi_log.txt.

Thanks again for helping me test this. ;)

m c
Member #5,337
December 2004
avatar

xcsi.c cannot compile because you forgot xcsi.h in the archive.

the second one gave lots of compilation errors because you forgot to incclude stdio.h in the top of Clipboard.h, then it compiles cleanly. Of course it won't let me do anything until xcsi is built.

(\ /)
(O.o)
(> <)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Sorry, just erase the line in xcsi.c that #includes xcsi.h, I got rid of that file.

Append
Fixed the two things you mentioned and added in logging of the window name and target in selection requests.

ClipboardTest11.zip

Append2
m c, where did you go? Did you try the latest code?

It looks like Arthur's gone AWOL or on a walkabout or something...

@bamccaig || Trezker || Any other Linux users
Would one of you like to test things for me? Pretty please with sugar on top. :)

Arthur Kalliokoski
Second in Command
February 2005
avatar

I fiddled with xcsi.c for about an hour to get it to compile.
Some errors were just typos such as backslashes in the #includes or no trailing semicolon to a statement, but most of my "fixes" were just wild guesses.

Now my brain's too fried to figure out what to do with it. It seems to work, but I haven't fiddled with it much. The Clipboard program just exits immediately again.
Maybe tomorrow.

Altered xcsi.c is in the paperclip.

They all watch too much MSNBC... they get ideas.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Okay, I made a diff using your altered xcsi.c and I updated mine to fix everything you pointed out. I had to change some of your changes though, so here's the new source code (ClipboardTest.c changed some as well) :

ClipboardTest12.zip

Now, if it quits, it should output why it quit if you run it from a console. I don't know if you need to specify a special flag with gcc to link it as a console application or not though. On MinGW, the flag is -Wl,--subsystem,console. So if it quits and you don't get any output, try that.

Also, thanks for compiling it. If I had Linux and gcc I wouldn't post code with so many errors in it.

bamccaig
Member #7,536
July 2006
avatar

Also, thanks for compiling it. If I had Linux and gcc I wouldn't post code with so many errors in it.

Out of curiosity, why don't you get a GNU/Linux distribution? It's free you know. :P It just seems strange and incredibly inefficient to develop this way... :-X

** APPEND **

Ugh, I hate archives that don't have a root directory... :-X

** APPEND **

You appear to be trying to execute your xcsi program with a .exe file extension in Linux... :-X Linux executables generally don't have file extensions unless they're libraries (e.g., .so), scripts (e.g., .pl), .NET/Mono executables (e.g., .exe), or proprietary installers (e.g., .bin). :-X Since xcsi is a C program I would recommend updating the code. :P

Arthur Kalliokoski
Second in Command
February 2005
avatar

You undid some of the things I did to get it to compile. I don't want to guess again.

pepsi@fractalcomet:/home/prog/ClipboardTest12 11:26 AM $ gcc -s -O2 -Wall xcsi.c -o xcsi.exe
xcsi.c: In function 'main':
xcsi.c:103: error: 'true' undeclared (first use in this function)
xcsi.c:103: error: (Each undeclared identifier is reported only once
xcsi.c:103: error: for each function it appears in.)
xcsi.c: In function 'QueryAvailableTargets':
xcsi.c:379: error: 'Event' undeclared (first use in this function)
xcsi.c:379: error: expected ';' before 'e'
xcsi.c:423: error: 'true' undeclared (first use in this function)
xcsi.c:446: error: 'e' undeclared (first use in this function)
xcsi.c: In function 'WaitForPaste':
xcsi.c:519: warning: unused variable 'return_property'
xcsi.c: In function 'RetrieveTarget':
xcsi.c:714: error: 'true' undeclared (first use in this function)
xcsi.c:730: error: expected ';' before 'if'
xcsi.c:689: warning: unused variable 'str'
xcsi.c:687: warning: unused variable 'xse'
pepsi@fractalcomet:/home/prog/ClipboardTest12 11:26 AM $ 

[EDIT]
I used yesterday's executable with this Clipboard.c and tried all the selections, got "0 Available Targets" in the console and this was in the logfile

RetrieveTarget warning : QueryAvailableTargets says this target is unavailable. Proceeding anyway.
RetrieveTarget failure : No selection owner.

They all watch too much MSNBC... they get ideas.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

bamccaig said:

Out of curiosity, why don't you get a GNU/Linux distribution? It's free you know.

I might. I have a free hard drive I could install it on, but then I would have to use the BIOS to pick the hard drive to start from each time. I could also try to install it using VirtualBox, but I really have no idea how that works. I'm not sure if I need a preinstalled image, or whether I could run VirtualBox and then install Linux normally.

bamccaig said:

Ugh, I hate archives that don't have a root directory...

You know, 7-zip lets you view archives before you unzip them... Besides, if I zipped the directory the stuff was in, there would be a whole bunch of other stuff with it.

bamccaig said:

You appear to be trying to execute your xcsi program with a .exe file extension in Linux...

Fine. Fixed.

You undid some of the things I did to get it to compile. I don't want to guess again.

Sorry about that. I skipped fixing the 'true' values at first, but then forgot to come back and update it to 'True'. Still getting used to using XLib.

Log file said:

RetrieveTarget warning : QueryAvailableTargets says this target is unavailable. Proceeding anyway.
RetrieveTarget failure : No selection owner.

Did you copy something before you tried that? XGetSelectionOwner should work right, at least.

Anyway, I fixed all the errors you posted, and modified ClipboardTest.c and Clipboard.c to rename xcsi.exe to xcsi, so don't use the exe extension when you compile xcsi.c this time.

Here's the latest version. 3rd (13th) time's a charm?

ClipboardTest13.zip

Arthur Kalliokoski
Second in Command
February 2005
avatar

OK, they all compiled this time.

Step by step test:
Run the clipboard executable.
Copy this line in a.cc reply box by dragging mouse.
Pressed B key and see the text appear correctly.
Pressed the S key and see the message about copying "CyberMan".
Pressed B key again to see "CyberMan" appear.
Pressed C key to see message "Could not set the clipboard bitmap to the CyberMan image"
Pressed V key to see message "There is no image in the clipboard to view".
Opened Cyberman_80x80.bmp with kolorpaint, select all and copy.
Pressed V key to see message "There is no image in the clipboard to view".
Pressed L key.

The resulting log file is in the paperclip.

[EDIT]

Virtual machines are pretty easy. You use the GUI to "create" a new machine,
you get a plethora of options as to the size of the virtual hard disk, how much
memory, to use the actual hardware DVD drive or to mount an ISO file, etc.
Then you either put the actual install disk for the OS into the drive or point
the virtual CD at the ISO, start the machine and install (in the window) just like
it was a real machine.
You may or may not have some trouble running hardware accelerated programs, but A4
and gcc should work fine. It will be slower than the real thing, obviously, but
not too bad.

They all watch too much MSNBC... they get ideas.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Yes! Now we're getting somewhere. :D

Try copying an image in Firefox and then press the L key to log the available targets. I'm curious to see what targets it supports and whether they are different from the ones kolourpaint supports.

bamccaig, it would help if you tested copying images and text from other programs (assuming you have different image editors than Arthur, for example Gimp or Paint.net or whatever else you might have) and then pressed the L key in ClipboardTest.exe. All I need then is for you to post xcsi_log.txt.

Edit -
Regarding VM's, I don't know if my laptop's hardware will be supported properly because I have to download custom drivers from Gateway that are only for Vista. Do you think that Linux ATI drivers will support my integrated graphics card?

Arthur Kalliokoski
Second in Command
February 2005
avatar

I clicked on your avatar, right clicked to "View Image", then clicked on it again and selected "Copy Image" and ran the executable, only to have it say "There is no image in the clipboard to view" again. Log is in paperclip.

[EDIT]

Do you think that Linux ATI drivers will support my integrated graphics card?

You can't install hardware drivers to a virtual machine, it tries to emulate them with its own "drivers" but sometimes fails. It'll work with software rendering though, otherwise it couldn't even show a desktop.

They all watch too much MSNBC... they get ideas.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

only to have it say "There is no image in the clipboard to view" again.

That's okay. I couldn't add image support until I figured out what targets they were using to transfer images. Now maybe I can hack something together over the next few days. I'll have to make some custom functions to read/write a bitmap/jpg/png to memory though. Thanks for everything you've done so far, you've been a great help to me. ;)

bamccaig
Member #7,536
July 2006
avatar

I might. I have a free hard drive I could install it on, but then I would have to use the BIOS to pick the hard drive to start from each time.

That's what I used to do. It's not too bad to put up with depending in the BIOS and how often you switch. I did get tired of it though. With experience, I learned to just boot Windows from Grub, and make Grub my boot loader for all. :)

Depending on your distribution of choice (I generally use Fedora), the installer might even prompt you to add other partitions that it detects an operating system on (i.e., other Linux installs and even Windows). If not, it's relatively easy to manually add Windows to your grub.conf. After that, you modify the CMOS settings to always boot from your other hard drive (with Grub on it) which will provide you with a menu to choose from. You may need to alter the timeout though because IIRC Fedora 13's default timeout is 0, which basically means there's no time to actually choose an option. I changed it to like 3 (seconds) so there's enough time to interrupt it if you need to (the countdown stops if you interact with it), but it doesn't slow down booting too much. You can also pick the default boot entry, so if you want Windows to boot normally you can set that up.

You know, 7-zip lets you view archives before you unzip them... Besides, if I zipped the directory the stuff was in, there would be a whole bunch of other stuff with it.

I'm in Linux and don't use GUI tools for regular tasks. That's far too slow. I do it from the command line. I can (and do, from experience) view the contents of archives before extracting them, but it's always a pain when I find an archive that doesn't have a root directory; it means I need to create one, which slows me down. When I don't need to create one then I can generally just recall my last command, change a t or l to x and I'm done. :)

bamccaig, it would help if you tested copying images and text from other programs (assuming you have different image editors than Arthur, for example Gimp or Paint.net or whatever else you might have) and then pressed the L key in ClipboardTest.exe. All I need then is for you to post xcsi_log.txt.

You promise it won't do anything malicious? >:( (I don't feel like trying to make sense of all of the code :P)

** EDIT **

What am I missing?

[bamccaig@krypton ClipboardTest]$ gcc -Wall *.c `allegro-config --libs` -lX11
xcsi.c: In function ‘main’:
xcsi.c:95: warning: unused variable ‘j’
/tmp/ccetAgdd.o:(.bss+0x8): multiple definition of `logfile'
/tmp/ccoJCrKt.o:(.bss+0x0): first defined here
/tmp/ccetAgdd.o: In function `main':
xcsi.c:(.text+0x0): multiple definition of `main'
/tmp/cc1EN0iQ.o:ClipboardTest.c:(.text+0x13): first defined here
/tmp/ccetAgdd.o: In function `Log':
xcsi.c:(.text+0xb5b): multiple definition of `Log'
/tmp/ccoJCrKt.o:Clipboard.c:(.text+0x231): first defined here
/tmp/ccetAgdd.o: In function `CloseLog':
xcsi.c:(.text+0xba8): multiple definition of `CloseLog'
/tmp/ccoJCrKt.o:Clipboard.c:(.text+0x27e): first defined here
collect2: ld returned 1 exit status
[bamccaig@krypton ClipboardTest]$ 

This is from ClipboardTest13.zip.

Vanneto
Member #8,643
May 2007

bamccaig said:

I'm in Linux and don't use GUI tools for regular tasks. That's far too slow.

Slightly slower would me more appropriate really. :P

In capitalist America bank robs you.

Arthur Kalliokoski
Second in Command
February 2005
avatar

bamccaig said:

What am I missing?

I did

gcc -s -O2 -Wall xcsi.c -o xcsi
gcc -s -O2 ClipboardTest.c Clipboard.c -o clpbrd `allegro-config --libs`

clpbrd then exec()'s xcsi

They all watch too much MSNBC... they get ideas.

MiquelFire
Member #3,110
January 2003
avatar

With VMs, the only piece of hardware from your machine the OS in the VM can ever hope to see the processor. EVERYTHING else is a set of hardware that the VM maker chose to emulate.

I think Sound Blaster 16 might be an option if you want to put DOS in a VM.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

bamccaig
Member #7,536
July 2006
avatar

I did...

My mistake was trying to compile everything into one... :-X I wasn't really paying much attention (though this is what they invented README for). :P

xcsi_log.txt#SelectExpand
1QueryAvailableTargets info : selection owner window's name : 2QueryAvailableTargets : 4 targets available : 3 TARGETS 4 TIMESTAMP 5 MULTIPLE 6 STRING 7QueryAvailableTargets info : selection owner window's name : 8QueryAvailableTargets : 4 targets available : 9 TARGETS 10 TIMESTAMP 11 MULTIPLE 12 STRING 13QueryAvailableTargets info : selection owner window's name : Terminal 14QueryAvailableTargets : 9 targets available : 15 TIMESTAMP 16 TARGETS 17 MULTIPLE 18 UTF8_STRING 19 COMPOUND_TEXT 20 TEXT 21 STRING 22 text/plain;charset=utf-8 23 text/plain 24Selection Request received from main - requested target : TARGETS 25Selection Request received from nautilus - requested target : TARGETS 26Selection Request received from nautilus - requested target : TARGETS 27Selection Request received from - requested target : TARGETS 28Selection Request received from - requested target : STRING 29Selection Request received from - requested target : TARGETS

As expected, it works to copy the string into the clipboard and retrieve it again. It fails to copy an image into or out of the clipboard.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

bamccaig said:

It fails to copy an image into or out of the clipboard.

Don't expect that to work yet, because I haven't added that functionality in yet.

What would help though, is if you copied an image using (Gimp , Paint.net , etc...) and then pressed the L key in ClipboardTest.exe and posted xcsi_log.txt.

That will tell me the selection targets that they have available for images, and therefore, how to support copy/paste of images. So far, I've seen image/png, image/bmp, and image/jpeg so those are the ones that I'll try to support for now.

Append -
Well, I've looked into loading/saving bitmap images into memory, and it wouldn't be pretty. I would have to re-implement packfiles as memory files to be able to hack a version of allegro's load_bmp and save_bmp functions to work for our purpose.

The easiest thing to do is to use allegro's built in load_bitmap and save_bitmap functions to load/save a BITMAP* as a temporary file which is piped to xcsi as binary data or piped from xcsi's output to a temporary file. So that is what I did. At least this way, every file format supported by allegro's load/save functions can be used.

ClipboardTest14.zip

This version does not yet have support for INCR transfers, so it may not work for retrieving large images.



Go to: