Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Clipboard

This thread is locked; no one can reply to it. rss feed Print
Clipboard
Thomas Fjellstrom
Member #476
June 2000
avatar

Evert said:

It's not even an integral part of X11.

Eh, X is mostly useless without a WM, at least if used as a desktop. You can make do without it if you have one X app you want to run, and thats it. I'd agree with the rest of what you said though.

Quote:

There's several different ones

Typically there's two. The X selection buffer, and then (possibly shared) toolkit clipboards that behave like you expect a clipboard to behave.

KDE has a nice little tray app that lets you essentially merge the two, or disable one or the other.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Evert
Member #794
November 2000
avatar

X is mostly useless without a WM, at least if used as a desktop. You can make do without it if you have one X app you want to run, and thats it.

That's true. I didn't say a window manager isn't something that's useful or desirable, just that it's not an integral part of X11.
I don't think that's really very different from what you're saying.

Thomas Fjellstrom
Member #476
June 2000
avatar

I would say something is "integral" to something else if removing the former caused the later to be more or less useless.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

bamccaig
Member #7,536
July 2006
avatar

I think Evert just means that Gnome isn't the window manager/desktop environment for Linux. Linux is just a kernel, and it's typically up to the distribution and users which window manager to use.

Edgar Reynaldo
Member #8,592
May 2007
avatar

m c said:

Viewing the bitmap in the program is just a white square, and I can neither paste the bitmap nor the text into other programs (in fact they either show the paste option grayed out, or it is active but selecting it does nothing and then after about 10 seconds I get a dialog box saying that there is no data available in the clipboard).

The white square may be due to \n to \f conversion but I would think then that only random pixels would be off colored, not entirely white. You really can't paste the text using edit->paste or Ctrl-V? I thought that was working at least. Middle mouse click won't work unless xcsi is run with the -p option for the primary selection (which clipboard.c is not configured to do currently). I'll work on adding binary i/o to/from a file and see if that fixes it

I'm still trying to get everything sorted out, I've had to download quite a few packages/libs and CodeBlocks, and doing it over dialup takes a while...

m c said:

I remember that on linux if you try to paste some data from the clipboard after closing the program that it was copied from, then it is no longer available, so I don't really like the way that copy+paste works on linux.

Well, the nice thing about xcsi is that it stays running as long as it is the selection owner, so a program that uses it could close and it would still serve the selection after that.

m c said:

[EDIT] I just tried again, and it is really 30 seconds not 10 seconds before it says "no data found in clipboard"

I don't understand where the delays are coming from. I process Selection Request events as soon as they are received and send the Selection Notify event and XFlush the display right after that. So in theory, a program that requests the selection should know immediately whether or not the data is valid unless they're diddling around doing something else... Maybe I should log all of the events that xcsi is receiving from the display connection...

m c said:

[EDIT 2] Also to get it to work I had to change many "xcsi blah blah" into "./xcsi blah blah" in Clipboard.c for ALLEGRO_UNIX section

I don't remember what the practical difference is between running 'x' and './x'. Could someone explain it to me?

Evert said:

Opposite for me: Fedora (and earlier RedHat) has always given me a headache, never had any real problems with SuSE (later OpenSuSE).
Never tried a Debian-based distribution though.

Well, I just had some sort of lockup in the openSUSE VM. Firefox stopped responding, and then the desktop background turned green, and a little wristwatch mouse icon came up, and then it wouldn't do anything at all. Luckily using VirtualBox's reset command rebooted the VM.

Edit -
Is there someplace to look for system logs / the equivalent of Windows Event viewer?

Arthur Kalliokoski
Second in Command
February 2005
avatar

I don't remember what the practical difference is between running 'x' and './x'. Could someone explain it to me?

You need to type './x' if the current directory isn't in your path, which is a slight security risk.

“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

I used VM's all the time on the old computer, never had to be root. Install VM as root maybe.

If you feel brave, try "cd <directory with problem>", "chown -R username ."

“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

I just checked the vm folders in the old computer, the uid was my username, and the gid was "users", I dunno how Ubuntu does it.

“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 got the folder to work by unmounting and mounting it. I suppose I'll have to do this every time I boot, so I wrote a quick script to do it for me, but I can't figure out how to use chmod to set the permissions to execute for my user account.

#! bin/sh
umount -t vboxsf VBShared
mount -t vboxsf VBShared home/edgar/VBShared

Is there a way to run this at startup?

How do I use chmod to set the correct permissions? When I try to run it using 'sudo ./fixshare.sh' it says 'command not found'.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I use "su" myself, not sudo, and also normally have a root account running on one of the virtual terminals (Cntr-Alt-F(n)). I never did understand the sudo thing, and if that's all I had, I'd use sudo to make a root account. :o

You need to use the -R option to recurse down into directories using chmod, chown and chgrp.

If you feel brave, try "cd <directory with problem>", "chown -R username ."

“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

Evert
Member #794
November 2000
avatar

it's owner is root so I can't access it. Is there a workaround for this?

Set read/write permissions for other users/groups.

Quote:

Shouldn't I be root anyway?

No. You should never be root.
Unless you need to be and know what you're doing. For day-to-day operations, you should never be root.

Can I login as root or something?

Probably, but if you can sudo commands anyway, you don't have to.
To log in as root... well, simply log in as root. You can also become root (in a terminal) using the su command.

Is there a way to run this at startup?

Several.
You should be able to do it from your .login script, but you can also place it in the system startup directory for your current runlevel (/etc/rc.d if I remember correctly).
That said, maybe see if you can set it correctly in /etc/fstab first.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Well, I'm still working on getting Allegro 4.4.1.1 to fully compile and install.

If anyone knows anything about how to write a CMakeLists.txt file, I could use some help in my other thread.

Append -
Problem solved, I got A4.4.1.1 built and installed on my openSUSE VM, so I should be back to working on the Clipboard over the next few days.

Append2 -
I added in file i/o to xcsi.c and now I can copy and paste an image using ClipboardTest. Pasting into Gimp is not working yet, even though the 'paste' option is not grayed out in Gimp's menu. Viewing a (small) image copied from within Gimp is working though. Viewing large images copied into the clipboard doesn't work yet, as they are using the INCR transfer mechanism, which is yet another day or so of work for me to do. I'll bump the thread again when I have another update.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I'm over my mad now, so I'll try it again when you're done.

“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

spellcaster
Member #1,493
September 2001
avatar

This is pretty old, but might be interesting for this thread:

http://steinke.net/coding.php#clipboard

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Trezker
Member #1,739
December 2001
avatar

Nice. How old?
Windows code should be rather backwards compatible. I doubt they've changed the clipboard interface.

But only bitmap copying?
The windows code for this lib doesn't even have text copying yet.

I may not have followed this thread in a very concentrated state since I got my job. But it's been mostly discussion about how to get linux copying working in code instead of using the external program, and adding bitmap copying. So I'm not really interested in merging until that stuff is fully operational.

If someone can put together the code for windows that'd be great. If you do it with git and send a github pull request that'd be awesome.

Edgar Reynaldo
Member #8,592
May 2007
avatar

I posted Windows code for copy/paste of text/images a long time ago in this thread. You never mentioned it, so I figured you didn't care. It's also been included in most every zip file I've posted here.

For Linux copy/paste your program needs to respond to SelectionRequest events, something an Allegro program could not do without hacking Allegro to expose the X11 events that it monitors. For these reasons, an external program is the best solution to manage copy/paste on Linux. Since xsel, xclip and others don't manage images, I wrote my own program that does, xcsi. Copying to the clipboard (through xcsi) also works better, because xcsi stays running as long as it is the selection owner, as opposed to closing your program and losing the selection data.

What we need is someone experienced with MacOSX and obj-C to write clipboard code for OSX.

Trezker
Member #1,739
December 2001
avatar

https://github.com/trezker/clipboard/issues

I've copied the windows code from your latest attachment into my project. I've also added stubs for bitmap copying functions.
I also added a mac file and premake configuration that's just empty.

One issue for me is that you're coding for allegro 4 and I'd like to have an allegro 5 version. It's only a few allegro functions though. In the windows code you need the window handle and convert hbitmap to/from allegro bitmap.

I didn't find any function for converting hbitmap in Allegro 5.

I don't care much about the windows version though, since I moved to Linux that platform means nothing to me.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Update -
I added in support for receiving incremental properties and so you can now paste the requested selection image into ClipboardTest. This means you can view an image copied from Firefox or the screenshot tool or (hopefully) anything else.

Still no luck getting Gimp or Inkscape to paste an image copied with xcsi though. They request the TARGETS property, and so they know that image/bmp is available, but they never request image/bmp when you try to paste inside their applications. It's still a mystery to me. I think I'm going to write the Gimp developer mailing list and see if they know what the problem might be.

Anyway, here is the latest version :
ClipboardTest17.zip

@Trezker
Since it took me well over a month to develop xcsi, I don't want it merged with your library. Since there are only two source files and one test program, I don't see the point of making it a library anyway. Users can just add it to their projects and compile xcsi if they are on Linux.

It shouldn't be that hard if people want an Allegro 5 version of this library, just take a look at the A4 source code for convert_hbitmap_to_bitmap and convert_bitmap_to_hbitmap and adapt it to use ALLEGRO_BITMAP's instead of BITMAP's. Then ask the dev's nicely if they'll write a function for A5 on Windows to return a HWND for the window of a passed ALLEGRO_DISPLAY pointer. Similarly for Linux, all you have to do to support copy/paste of images is change the loading/saving of images in Clipboard.c to use A5's image load/save functions instead.

spellcaster
Member #1,493
September 2001
avatar

Trezker said:

Nice. How old?

I think I posted that code in here in 2002. It was used in my "destroy the desktop" mini app.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Trezker
Member #1,739
December 2001
avatar

Good that you brought up the issue of bundling Edgar.
xcsi is a useful utility on its own. It makes sense for it to be a separate project.

It needs to be available from some stable location so it's easy to fetch and install when people need it for the allegro clipboard library.

If it was me I'd set up a new github repository.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Tiny, ridiculous, stupid mistakes... >:(

I wasn't properly setting some of the fields of a returned SelectionNotify event after getting a SelectionRequest, so the other programs ex-communicated me. :-/

Pasting into Gimp, Inkscape, and Kolourpaint now works for me with the small test bitmap used in the ClipboardTest program. It works with a large (1280 X 677 , 423KB) png as well by using xcsi from the command line. Start your graphics editor, call xcsi with the -s= command and paste away!

To be thorough, I should add support for sending (and not just receiving) INCR transfers, but I haven't done that yet.

Latest version :
ClipboardTest18.zip
(I also included a simple shell script, build.sh, to make compilation easier)

Are there any feature requests for xcsi or the clipboard library? It might be nice to support copy/paste of utf-8 strings, which I think may be doable on Windows and Linux.



Go to: