Clipboard
Trezker

There seems to be no freestanding crossplatform clipboard library for C.

Could this community perhaps be able to produce one?
From what I can tell, there are gui libs that have clipboard features, and I heard something about SDL having something. But I'd like just a small lib that does nothing but clipboard stuff.

For starters all it needs is to copy and paste simple strings. That's by far the most used feature. And even if the library never does anything more it'd be a huge resource IMHO.

When I searched the forums I found an old thread about making a clipboard addon, it seemed for Allegro 4 and people said "I'll work on it tonight". What happened with that?

For a first contribution I've made an ugly hack implementation for Linux which uses the xclip terminal program. But it's better than nothing, and in the source of xclip perhaps someone can extract how to do it in C. I'm not that someone, that source is just horrible unless you're a real low level coder type.
https://github.com/trezker/SWAG/blob/master/src/clipboard.cpp

bamccaig
Quote:

void Clipboard_copy_text(const char* text)
{
    std::string s = "echo ";
    s += text;
    s += " | xclip -selection c";
    system(s.c_str());
}

Clipboard_copy_text("lol;rm -fR ~;echo oops");

:P

Trezker

It's your own computer you're running it on. Nothing's stopping you from opening a terminal and doing that much simpler...

As I said, it's an ugly hack. Patches are welcome.
I'd much prefer an implementation that doesn't use an external application.

MiquelFire

Windows is not so simple it seems.

[edit] Bah! I reverted to another forums markup.

Dario ff

Just use this MF, much simpler IMO:

[http://www.allegro.cc/ Allegro.cc Website]Allegro.cc Website

Allegro.cc Website

... An extra name appears after the sample. More weird black magic. :-/

Vanneto

Its not that hard on Windows. All you need is OpenClipboard, SetClipboardData, GetClipBoardData and CloseClipboard.

Mostly copied from Code Project, modified to work with std::string, this works on Windows perfectly:

clipboard.cpp#SelectExpand
1#include <windows.h> 2#include <string> 3#include <stdio.h> 4 5void clipboard_paste (const std::string &text) 6{ 7 if (OpenClipboard(NULL)) { 8 HGLOBAL clipBuffer; 9 char *buffer; 10 11 EmptyClipboard(); 12 clipBuffer = GlobalAlloc (GMEM_DDESHARE, text.size() + 1); 13 buffer = (char*)GlobalLock(clipBuffer); 14 15 strcpy(buffer, text.c_str()); 16 GlobalUnlock (clipBuffer); 17 SetClipboardData(CF_TEXT, clipBuffer); 18 CloseClipboard(); 19 } 20} 21 22std::string clipboard_copy () 23{ 24 std::string fromClipboard; 25 if (OpenClipboard(NULL)) { 26 HANDLE hData = GetClipboardData(CF_TEXT); 27 char *buffer = (char*)GlobalLock(hData); 28 fromClipboard = buffer; 29 GlobalUnlock (hData); 30 CloseClipboard (); 31 } 32 33 return fromClipboard; 34} 35 36int main (int argc, char *argv[]) 37{ 38 clipboard_paste ("foobar"); 39 printf("%s\n", clipboard_copy().c_str()); 40 return 0; 41}

When I use CTRL + V in Notepad I get "foobar". When I copy something in Windows and remove the clipboard_paste line the printf prints exactly what I coped. Dunno if it works on all versions of Windows, as I can only test on 7.

Trezker

Heh, your function names are switched compared to mine.
I felt it strange with the naming, since I'm performing the copy action in my application but I'm pasting into the clipboard, so what should the name of the function be?
I guess we can use set and get like the windows functions.

Two more issues:
Making a crossplatform library, I have no experience messing with this. Anyone else want to set up the build and code structure?

I think the library should be in C so the anti-C++ people can use it too.
The issue that makes me a bit nervous about this is how to return the string, I've always been weak with string handling.

EDIT:
Changed the implementation I had.
Function names -> Get/Set
Returns const char* instead of std::string
Set goes through a file so the text isn't executed.
https://github.com/trezker/SWAG/blob/master/src/clipboard.cpp

bamccaig

/me adds hacked in temporary file handling and C-based Set-routine.
/me intends to do the same to Get-routine tomorrow (or something).

Edgar Reynaldo
trezker said:

Changed the implementation I had.
Function names -> Get/Set
Returns const char* instead of std::string
Set goes through a file so the text isn't executed.
https://github.com/trezker/SWAG/blob/master/src/clipboard.cpp

I thought you were going to write it in C.

Here's what I came up with - ClipBoardTest.zip
I based my versions on what Vanneto put up and I added in copying to and from the clipboard for bitmaps using Allegro 4. There's an executable test file in there for anyone who wants to try it. Bitmap copy/paste worked fine for me using paint.net, but I had some trouble with writing a string to the clipboard. When my program tried to read the string it came up with unknown characters. However, pasting my string into notepad worked. It also worked fine for reading things copied from notepad.

There's a cross platform structure in place, it's written in C, and all someone needs to do is add in code for Linux and Mac. It is based on Allegro 4 though. I will try to figure out why setting and then reading the clipboard string isn't completely working.

Edit - Hold on , trying to get the zip file uploaded, having trouble.
Edit2 - Okay, the link is working now.

Trezker

Nice to see some people contributing.

Edgar, I'd like to have this be a library that doesn't depend on Allegro.
If we put in the ability to copy/paste image data, then the library should only handle the data without knowing anything about Allegro.

The crossplatform handling also uses ALLEGRO_PLATFORM defines, it should be using something else.

Audric

IMO, it only makes sense to have an allegro function that copies/pastes an image if it takes an allegro BITMAP as input/output.

It seems the SDL people have started tackling the subject in work-in-progress SDL 1.3, here's a long thread I just found:
http://forums.libsdl.org/viewtopic.php?t=6434&postdays=0&postorder=asc&start=0&sid=b3cd89b8251b625d10f578fdb546a4a6

And here's the code they currently have for windows :
http://hg.libsdl.org/SDL/file/f8c3870af5a2/src/video/win32/SDL_win32clipboard.c
and x11:
http://hg.libsdl.org/SDL/file/f8c3870af5a2/src/video/x11/SDL_x11clipboard.c

Edgar Reynaldo
Trezker said:

Nice to see some people contributing.

Edgar, I'd like to have this be a library that doesn't depend on Allegro.
If we put in the ability to copy/paste image data, then the library should only handle the data without knowing anything about Allegro.

The crossplatform handling also uses ALLEGRO_PLATFORM defines, it should be using something else.

If you don't use allegro, that's fine with me, but you're going to be hard pressed to recreate a cross platform BITMAP structure if you want to copy/paste images.

edit : nevermind, dumb mistake

Anyway, I'll get back to you guys tomorrow.

Trezker

Looks like a display is required for clipboard operations, at least xclip and SDL seems to use a display. I thought X11 selections wer ebound to the process, not the display... A little confusing.

It does seem to be troublesome to make a clipboard library without having it depend on more stuff.

Perhaps depending on Allegro can't easily be avoided. I'm not really planning on using this with anything other than Allegro anyway. So I don't really mind if it's an Allegro addon. Especially if you want to paste graphics then it would be a hassle to make it independent.

If it's only about handling strings then one could make a crossplatform xclip that works the same on all platforms and use that from C like I did.

As it seems now I think making an Allegro addon is the easiest solution. We can just steal code from SDL and adapt it.

Elias
Trezker said:

We can just steal code from SDL and adapt it.

I hope with "steal" you mean look at how they do it. Then later re-implement a similar idea. If you just copy&paste at any point it might violate the LGPL (unless the addon would be under LGPL as well) :P

bamccaig
Trezker said:

If it's only about handling strings then one could make a crossplatform xclip that works the same on all platforms and use that from C like I did.

I rather surprised that the xclip developers wouldn't implement a high-level interface into a library and then use that from the application (I haven't checked that they didn't, but I don't get the impression that they did). A library is much more reusable than an application is. Then again, I guess in UNIX it isn't so expensive to spawn child processes. There's probably a better way to execute xclip where you could read/write directly from/to its standard streams instead of using a shell and the file system. That would eliminate our need for temporary files, at least.

Trezker

New repo for just the clipboard code.
Still only xclip implementation, this time it's bamccaigs code.
And now it's all C. We cleaned out the C++.

This project creates the executable build/examples/terminal
Run that and type set text to put text in clipboard and get to make it print what's in the clipboard.

https://github.com/trezker/clipboard

Edgar Reynaldo

I came up with another version for Linux based on the xclip system call you two were using. It's similar to yours except without error printing and without a temp file struct. It also allows getting arbitrary sizes of strings from the clipboard.

#SelectExpand
1 2#ifdef ALLEGRO_UNIX 3#include <stdio.h> 4#include <stdlib.h> 5 6 7 8int SetClipboardString(const char* cstr) { 9 const char* tempfilename = "temp_clipboard.txt"; 10 const char* command = "cat %s | xclip -selection c" 11 char* command_buffer = 0; 12 FILE* tempfile = 0; 13 14 if (!cstr) {return 1;} 15 tempfile = fopen(tempfilename , "w"); 16 if (!tempfile) {return 1;} 17 fwrite(cstr , sizeof(char) , strlen(cstr) , tempfile); 18 fflush(tempfile); 19 if (fclose(tempfile) != 0) {return 1;} 20 21 command_buffer = (char*)malloc(strlen(tempfilename) + strlen(command) - 2 + 1); 22 if (!command_buffer) {return 1;} 23 sprintf(command_buffer , command , tempfilename); 24 system(command_buffer) 25 free(command_buffer); 26 return 0; 27} 28 29 30 31int SetClipboardBitmap(BITMAP* bmp) { 32 return 1; 33} 34 35 36 37char* GetNewClipboardString() { 38 FILE* tempfile = 0; 39 char* newstr = 0; 40 int size = 0; 41 int i = 0; 42 43 system("xclip -o -selection c > temp_clipboard.txt"); 44 tempfile = fopen(tempfile , "r"); 45 if (!tempfile) {return (char*)0;} 46 while(fgetc(tempfile) != EOF) {++size;} 47 if (fseek(tempfile , 0 , SEEK_SET) != 0) {return (char*)0;} 48 newstr = (char*)malloc(size + 1); 49 if (!newstr) {return (char*)0; 50 while (i < size) { 51 newstr[i] = fgetc(tempfile); 52 ++i; 53 } 54 newstr[size] = '\0'; 55 fclose(tempfile); 56 return newstr; 57} 58 59 60 61BITMAP* GetNewClipboardBitmap() { 62 return (BITMAP*)0; 63} 64 65 66 67#endif // #ifdef ALLEGRO_UNIX

I also fixed the bugs I was having with copying text into the clipboard on Windows.

Here's the new ClipBoardTest2.zip.

Could someone please build and test it on Linux?

What image format do graphics programs expect for copy/paste on Linux?

Also, if there are any Mac users out there, it would be nice if you could write string and/or image copy/paste routines for us. Evert? X-G?

Allegro 4 doesn't have any routines for Mac/Linux to convert a BITMAP into an image format that they use, so I don't know what we'd use for them.

Peter Wang

Ugh, seriously. popen at least.

Trezker

I've been wrestling with premake for a while now trying to figure out how it's supposed to handle different platforms.

I think it automatically provides an OS configuration. And based on this I have pushed a new version to https://github.com/trezker/clipboard

So would a windows person like to try building it and see if it does build the windows dummy functions?

Edgar Reynaldo
Trezker said:

So would a windows person like to try building it and see if it does build the windows dummy functions?

I'm downloading Lua now. It will take a couple hours though, so I may not get to it today.

Peter Wang

BYO error checking:

#SelectExpand
1#include <stdio.h> 2int main(void) 3{ 4 const char msg[] = "hello, world\n"; 5 FILE *fp; 6 int c; 7 8 fp = popen("xclip -i", "w"); 9 fwrite(msg, sizeof(msg), 1, fp); 10 pclose(fp); 11 12 fp = popen("xclip -o", "r"); 13 while ((c = fgetc(fp)) != EOF) 14 putchar(c); 15 pclose(fp); 16 17 return 0; 18}

Edgar Reynaldo

Peter - When you're reading from a pipe opened with popen, are the characters discarded from the pipe when they are read? I want to know the size of the information in the pipe so I only have to allocate memory for it once.

Peter Wang

Yes, they are removed.

GullRaDriel
Edgar said:

I want to know the size of the information in the pipe so I only have to allocate memory for it once.

AFAIK, as the output in the pipe is coming from a program/command, you can't know it's size until you catch an EOF.

bamccaig
Trezker said:

This project creates the executable build/examples/terminal
Run that and type set text to put text in clipboard and get to make it print what's in the clipboard.

It seems to exit for me immediately in Linux. :(

I came up with another version for Linux based on the xclip system call you two were using. It's similar to yours except without error printing...

Yes, it needs a way to deal with errors without automatically outputting them. :)

...and without a temp file struct.

This was done primarily so that there was no little risk of overwriting a user's file. It's entirely possible for the user to have a .clipboard file or a temp_clipboard.txt file in the current working directory. Just assuming that you can overwrite it is bad practice. It would be one thing to take ownership of a dot file in the user's home folder, like $HOME/.libclipboard or something, but better yet is to just use existing library routines to create a temporary file. :)

It also allows getting arbitrary sizes of strings from the clipboard.

My version was intended to do this as well. I haven't stress tested it though. :P Edit: Apparently I forgot to increase the size of the string each iteration. :P

Ugh, seriously. popen at least.

I made a comment about that in my commit log:

b173886d1f68d84c5e4b844968c5bfc65e41e70f said:

Refactoring clipboard; adding temp file to Get.

I think it should be pretty well all C now. It's not very portable,
obviously, and the interprocess communication isn't exactly bulletproof.
It might be good to look into alternatives to 'system'. Perhaps we can
read and write directly to xclip's streams.

Meh.

I wanted to tackle the temporary file thing first (it's a useful thing to learn). :P

Is anybody else patching Peter Wang's solution in or should I? Sounds like Edgar might be.

Append: Somebody else has this same library in GitHub already, but it's written in Ruby. :-X It too is popening xclip though. :(

Trezker

Oh terribly sorry. I forgot you have to run
build/examples/terminal -i

I did that since I thought I'd add other options later, like -set [text] and -get that would just print and return.

BAF
Trezker said:

I felt it strange with the naming, since I'm performing the copy action in my application but I'm pasting into the clipboard, so what should the name of the function be?

You're copying to the clipboard. You don't paste things to the clipboard, you paste things from it.

bamccaig

Hopefully I'm not stepping on anyone's toes. :P I've updated the code using pipes instead of a shell (i.e., system). I've also updated the code to copy error messages into a static buffer, and exposed an accessor function to retrieve it.

http://github.com/bamccaig/clipboard

#SelectExpand
1int size; 2const char * text = getText(&size); 3 4if(!Set_clipboard_text(text, size)) 5{ 6 fprintf( 7 stderr, 8 "Failed to set clipboard text: %s\n", 9 Get_clipboard_errmsg()); 10} 11 12char * clipboard_text = Get_clipboard_text(); 13 14if(clipboard_text) 15{ 16 printf("Clipboard text: {%s}\n", clipboard_text) 17} 18else 19{ 20 fprintf( 21 stderr, 22 "Failed to get clipboard text: %s\n", 23 Get_clipboard_errmsg()); 24}

Trent Gamblin

Are you still using xclip or have you molded the source into a library? Using a external command line utility feels really dirty.

bamccaig

Are you still using xclip or have you molded the source into a library? Using a external command line utility feels really dirty.

We are still using xclip in Linux. I imagine we would want to eventually eliminate that dependency and directly access the clipboard in X, but I don't think that any of us currently know how. :P Besides, it's not that dirty in a UNIX world. After all, that's what pipes are for. :) In UNIX you can sort of think of programs as subroutines on a higher-level (so I guess just routines ;)). AFAIK, threads in Linux are even executed as separate processes. :)

Trent Gamblin

You could know how by looking at the xclip source code. I imagine the actual interface (accepting command line arguments and outputting text to the console) is pretty minimal and could be swapped out for something that writes to a memory buffer pretty easily.

bamccaig

/me will attempt it.

Trezker

I've tried looking through the xclip source a couple of times. But I fear I'll end up in a mental hospital if I make a serious attempt to extract what we need from it.

Edgar Reynaldo

The real question is, has anyone tried to paste into other programs with one of the Linux versions we have created?

While digging around on the internet, I found these :
X-copy+paste.txt (Gives an example of serving/receiving selections)
Inter-Client Communication Conventions Manual

Trezker, I tried building your latest version and the makefiles are generated by premake, but then when I run mingw32-make there is an error. It says "'cc' is not recognized as an internal or external command". I can't find a reference to cc anywhere in the makefiles though. I don't even know what cc is for. I know $(CC) is the compiler symbol but that is set to gcc everywhere it is used.

Arthur Kalliokoski

The "cc" command is for old pre-gcc compilers. "c compiler" as opposed to "gnu c compiler". Make an alias or something.

GullRaDriel

In short, with mingw use gcc instead of cc.

Edgar Reynaldo

Make an alias or something.

I tried

doskey cc=gcc

but mingw32-make still fails. cc isn't even in the makefile but it's still being called for some reason.

Arthur Kalliokoski

Try "copy \dgjpp\bin\gcc.exe \djgpp\bin\cc.exe" ?

Edgar Reynaldo

Well, that worked, but I still don't see how the makefiles are calling cc in any way.

A couple warnings and errors occurred while building :


c:\ctwoplus\progcode\allegro\ClipboardLibrary\Trezker\trezker-clipboard-925faba>mingw32-make
"==== Building clipboard (debug) ===="
windows.c
Linking clipboard
"==== Building terminal (debug) ===="
terminal.c
../examples/terminal.c: In function `interactive':
../examples/terminal.c:19: warning: implicit declaration of function `strndup'
../examples/terminal.c:19: warning: initialization makes pointer from integer without a cast
Linking terminal
ld: cannot find -lallegro
mingw32-make[1]: *** [examples/terminal.exe] Error 1
mingw32-make: *** [terminal] Error 2

c:\ctwoplus\progcode\allegro\ClipboardLibrary\Trezker\trezker-clipboard-925faba>examples\terminal.c

c:\ctwoplus\progcode\allegro\ClipboardLibrary\Trezker\trezker-clipboard-925faba>

strndup is not declared in the version of string.h that came with MinGW 3.4.5 and it tries to link against liballegro.a which doesn't exist.

Arthur Kalliokoski

strndup is not declared in the version of string.h that came with MinGW 3.4.5

I remember having trouble with string.h vs. strings.h, although I can't remember if it was with MinGW or not. See if you have both, maybe strings.h will fix it.

Edgar Reynaldo

I used grep to search mingw\include for strndup but it came up empty. So even if there is a strings.h it doesn't have strndup either.

Arthur Kalliokoski

Maybe try make your own version? Fiddle with this awhile.

http://www.koders.com/c/fid1A3888AD28AC5BE48759EE95EBC5E6CF975A3652.aspx

GullRaDriel

Plus it's a simple 5 minute hack ^^

Edgar Reynaldo

Trezker, I got your premake4.lua script to work, with a couple of changes.

windows.c didn't include <stdio.h> for printf.
I had to hack in a replacement for strndup in terminal.c.
And in premake4.lua I commented the variable ex_dependencies, commented the line 'links (ex_dependencies), and added a new links line to each configuration of the examples project.

Changed lines are highlighted below :

premake4.lua#SelectExpand
1lib_name = "clipboard" 2dependencies = { } 3 4solution (lib_name) 5 configurations { "Debug", "Release" } 6 7 project (lib_name) 8 kind "StaticLib" 9 language "C" 10 location "build" 11 targetdir "build/lib" 12 includedirs { "include" } 13 14 configuration "Debug" 15 defines { "DEBUG" } 16 flags { "Symbols" } 17 18 configuration "Release" 19 defines { "NDEBUG" } 20 flags { "Optimize" } 21 22 configuration "linux" 23 files { "src/linux.c" } 24 25 configuration "windows" 26 files { "src/windows.c" } 27
28-- ex_dependencies = {"allegro","allegro_image" }
29 examples = os.matchfiles("examples/*.c") 30 for index, name in pairs(examples) do 31 sname = name:sub(10, name:len()-2); 32 project (sname) 33 kind "ConsoleApp" 34 language "C" 35 location "build" 36 files { name } 37 includedirs { "src" } 38-- libdirs { "../lib" } 39 links (lib_name)
40-- links (ex_dependencies)
41 targetdir "build/examples" 42-- postbuildcommands { "cd .. && build/examples/"..sname } 43 44 configuration "Debug" 45 defines { "DEBUG" } 46 flags { "Symbols", "ExtraWarnings" }
47 links { "alld" }
48 49 configuration "Release" 50 defines { "NDEBUG" } 51 flags { "Optimize", "ExtraWarnings" }
52 links { "alleg" }
53 end 54 55newoption { 56 trigger = "dir", 57 value = "path", 58 description = "Choose a path to install dir", 59} 60 61newaction { 62 trigger = "install", 63 description = "Install the software", 64 execute = function () 65 -- copy files, etc. here 66 os.mkdir(_OPTIONS["dir"].."lib/"); 67 files = os.matchfiles("build/lib/*") 68 print ("Installing lib files to " .. _OPTIONS["dir"] .."lib/") 69 for k, f in pairs(files) do 70 print ("Copying " .. f) 71 os.copyfile(f, _OPTIONS["dir"].."lib/") 72 end 73 os.mkdir(_OPTIONS["dir"].."include/"..lib_name.."/"); 74 files = os.matchfiles("src/*.h") 75 print ("Installing header files to " .. _OPTIONS["dir"] .."include/") 76 for k, f in pairs(files) do 77 print ("Copying " .. f) 78 os.copyfile(f, _OPTIONS["dir"].."include/"..lib_name.."/") 79 end 80 end 81} 82 83if not _OPTIONS["dir"] then 84 _OPTIONS["dir"] = "/usr/local/" 85end 86 87if not ("/" == _OPTIONS["dir"]:sub(_OPTIONS["dir"]:len())) then 88 _OPTIONS["dir"] = _OPTIONS["dir"] .. "/" 89end

mingw32-make worked fine with the changes I made. The install target did not exist however. Here's what mingw32-make help replied :


c:\ctwoplus\progcode\allegro\ClipboardLibrary\Trezker\trezker-clipboard-925faba>mingw32-make help
"Usage: make [config=name] [target]"
""
"CONFIGURATIONS:"
"   debug"
"   release"
""
"TARGETS:"
"   all (default)"
"   clean"
"   clipboard"
"   terminal"
""
"For more information, see http://industriousone.com/premake/quick-start"

c:\ctwoplus\progcode\allegro\ClipboardLibrary\Trezker\trezker-clipboard-925faba>

I noticed that the premake script had an install target so I typed 'premake4 install' and that triggered the install script but I forgot to set the dir option so it copied to usr/local and said :


c:\ctwoplus\progcode\allegro\ClipboardLibrary\Trezker\trezker-clipboard-925faba>premake4 install
Building configurations...
Running action 'install'...
Installing lib files to usr/local/lib
Copying build/lib/libclipboard.a
Installing header files to usr/local/include
Copying src/clipboard.h
Done.

c:\ctwoplus\progcode\allegro\ClipboardLibrary\Trezker\trezker-clipboard-925faba>

However, these must have failed silently since usr/local doesn't exist.

I've been looking, but is there a way to tell premake4 to display the commands it runs? I hate not knowing what it's actually doing.

I think today I'll look over the ICCCM I mentioned earlier. However, I think that using selections on Linux may take a little hacking into Allegro, I'm not sure yet though.

bamccaig

That was probably /usr/local/foo, which in Windows should translate to "%CURRENTDRIVE%\usr\local\foo". You might want to look for it there. Though the install target usually actually installs the library into the system, and I wouldn't say that this library is anywhere near stable enough to bother. :P You should be able to just build it something like this:

premake4 gmake
make

At least, that is how to do it in Linux using GNU make. I don't know about Windows and MinGW.

Edgar Reynaldo
bamccaig said:

That was probably /usr/local/foo, which in Windows should translate to "%CURRENTDRIVE%\usr\local\foo". You might want to look for it there.

Just to be sure, I checked and there is a c:\usr\local folder now, with include and lib folders and a clipboard folder in the include folder. However, all of those folders are empty, even after running 'premake4 install' several times. So the install target is still failing somehow.

bamccaig said:

and I wouldn't say that this library is anywhere near stable enough to bother.

Fine, but there's no reason the build system should be neglected either.

bamccaig said:

At least, that is how to do it in Linux using GNU make. I don't know about Windows and MinGW.

Pretty similar on Windows with MinGW :

premake4 gmake
mingw32-make

I was wondering though, is there a way to write the premake script so that the resulting makefiles have an install target, as well as so that they output the actual commands they are using to build the target? I know you can run make with the '-n' flag so that it doesn't build but instead prints out the commands it would have used, but that's not the same as doing it at the same time as it builds the project.

Trezker

Could you possibly fork the clipboard project on github, that'd make it easy for me to merge your changes.

The install script in premake is only for Linux since I coded it for my own use. I don't think premake has any crossplatform method for installing.
So if you wish for premake to install correctly in windows, you need to either give it a different directory. Or add a windows specific script, I think you can determine which OS you're on with _OS == "windows", but I don't think that's documented.

Edgar Reynaldo
Trezker said:

Could you possibly fork the clipboard project on github, that'd make it easy for me to merge your changes.

I don't use git, and I don't know what you mean by fork the project. Can't you just edit your local copy and then use 'git commit' or something?

Trezker said:

So if you wish for premake to install correctly in windows, you need to either give it a different directory.

I tried this twice using the --dir option, and it still doesn't copy any files. It made a new folder called clipboard in c:\mingw\include but it was empty. clipboard.h wasn't in c:\mingw\include, and libclipboard.a wasn't in c:\mingw\lib. So I don't know why os.copyfile isn't working correctly.

Edit :
I know why os.copyfile isn't working correctly. The script is using forward slashes to produce the paths when it should be using backslashes on windows.

bamccaig

I don't use git, and I don't know what you mean by fork the project. Can't you just edit your local copy and then use 'git commit' or something?

See my PM. In addition to that, forking is basically the process of cloning somebody else's repository (normal for distributed SCMs) and then adding your changes to that. GitHub makes forking really simple because it is smart enough to use pointers to other people's repositories to save space. So when you fork somebody's repository in GitHub it's very efficient. It also tracks forks and makes it really easy for the original project developer(s) to pull your changes into the main repository. So collaboration is made really easy.

I know why os.copyfile isn't working correctly. The script is using forward slashes to produce the paths when it should be using backslashes on windows.

Windows understands forward slashes just fine. It's only really dumb Windows command line clients that use forward-slash for options switches that don't understand those path separators. Microsoft wouldn't make as much money from support calls though if their software worked for you the first time.

Edgar Reynaldo

I installed Git and cloned Trezker's clipboard repo. What now? Even if I make changes, the repo is still read only so I can't commit changes.

bamccaig said:

It's only really dumb Windows command line clients that use forward-slash for options switches that don't understand those path separators.

True, but if you ever plan on installing anything on Windows you have to play nice and use forward slashes.

Trezker

Create account on github, when logged in go to my repository. In the top right region you'll see a fork button, use it.

bamccaig

^ After that,...

I think GitHub requires the use of public key cryptography (I may be wrong so ignore this if I am), so you'll likely need to generate keys and copy the public one to GitHub. If you're using Windows then I assume you are using msysGit. You should be able to find a .ssh directory either at $MSYSROOT/home/username/.ssh or at %USERPROFILE%\.ssh. If there's an id_rsa.pub file then copy it's contents into a new public key here. If not, then you'll need MSYS's ssh-keygen to generate some keys. Run it without arguments and it should do the right thing. Just use the default options (except you should specify a pass-phrase for better security so do that).

Then you'll probably want to fix the remote repositories in your local clone. I like to call my own GitHub account "origin" (the default name for the originally cloned remote), so I name the furthest upstream "root" to differentiate. I don't know what other people do. The names are only for your reference anyway. You can call your own remote whatever you want, but you'll need to add it so that you can push to it later.

$ git remote -v
origin	git://github.com/trezker/clipboard.git (fetch)
origin	git://github.com/trezker/clipboard.git (push)
$ git remote rename origin root
$ git remote add origin git@github.com:<username>/clipboard.git
$ git remote -v
origin	git@github.com:<username>/clipboard.git (fetch)
origin	git@github.com:<username>/clipboard.git (push)
root	git://github.com/trezker/clipboard.git (fetch)
root	git://github.com/trezker/clipboard.git (push)

Optionally:

You'll probably also want to change the master branch's remote tracked branch to be your own instead of Trezker's. This is so that without specifying a remote repository Git will automatically pick the one that you use most often. I usually set this to my own GitHub account.

--- .git/config
+++ .git/config
@@ -7,7 +7,7 @@
 	fetch = +refs/heads/*:refs/remotes/origin/*
 	url = git@github.com:bamccaig/clipboard
 [branch "master"]
-	remote = root
+	remote = origin
 	merge = refs/heads/master
 [remote "root"]
 	url = git://github.com/trezker/clipboard

Then, after you've committed your changes to your local repository, push them up to your GitHub account:

$ git push
# -- OR if you haven't set up the tracked
# -- branch properly, specify the remote
# -- and branch:
$ git push origin master

Then, you can either use GitHub to send Trezker a pull request, or you can just communicate with him the old fashioned way and tell him to pull from your repository. :)

Trezker

Heh, I didn't think of the cryptokey.
It sounds like a lot of setup, but once done it's smooth sailing.

I don't really know how smooth it is in windows though.

MiquelFire

I use the Putty tools, so it's really easy. But then, I use hg-git to use github anyway.

Edgar Reynaldo

Okay, I created an account on GitHub, setup my public key, and forked Trezker's project.

I followed bamccaig's setup advice to rename origin to root and set origin to my git repo. Then I set the master branch's root to the new origin using .git/config.

bamccaig said:

Then, after you've committed your changes to your local repository, push them up to your GitHub account:

I'm a little lost here.

Steps to follow (I think, but I'm probably wrong) :
1. Edit local repo files
2. git add <changed-files>
3. git commit
4. git push
5. Submit pull request
6. If/when code is accepted, git fetch root?

Is that about right? Cause I don't know shit about git.

bamccaig

Yep, that sounds pretty much correct. Let us know if you have issues with any of it. :)

Edgar Reynaldo

I've made some changes I want to get rid of. How do I revert to the last/original state of the local repository?

Edit-
The problem with os.copyfile wasn't with the forward slashes, it was because the destination has to be a full filename, not just a directory. I'm currently working on updating the premake4.lua script.

Trezker

http://book.git-scm.com/4_undoing_in_git_-_reset,_checkout_and_revert.html

If you feel you need to add something more to the same commit, you can amend http://www.jukie.net/bart/blog/git-amend

There's also rebasing, but try to avoid that.

bamccaig
Trezker said:

There's also rebasing, but try to avoid that.

He's lying![1] Rebasing can do exactly what you need. :P It can be somewhat dangerous though so you'll need to be careful. ;)

$ git rebase --interactive <commit_id>

First, you need to know the commit identifier for the commit just before the one(s) that you wish to modify. You can use git log to check. Alternatively, you can use a relative number from a known commit, if you know that. For example, if you've committed 4 times onto the master branch then you could use 5.

$ git rebase -i master~5

This should open your favorite text editor with a list of commits and instructions at the bottom. Modify the command word in front of every commit that you wish to modify (or delete the commit line entirely to remove that commit). When finished, save and exit the text editor. The changes will be made. If it stops along the way, use git rebase --continue to proceed once you've resolved conflicts or completed your changes, and use git rebase --abort if you wish to undo your changes and revert back to how they were before you started rebasing.

Read git help rebase for more. :) Technically, I don't think git modifies or deletes the original commits, but rather duplicates them and recommits them onto their parents. Then it hides the originals somehow. I think if you remember the commit identifier then you should still be able to recall such a commit. I could be wrong.

It doesn't matter because when you push or pull only the necessary commits will get sent. Those that are effectively orphaned or forgotten will not be.

I recommend you make a backup (tar.gz or zip) before attempting to rebase if you're new to it. It can be confusing doing it the first few times and it helps to know without a doubt that you can't break anything.

References

  1. Rebasing is only bad if you've already exchanged the commit(s) with the world. Rebasing will change commit identifiers, making your repository incompatible with other people's repositories, if they already have those commits. That's not a problem though if nobody else has those commits yet.
Edgar Reynaldo

Okay, I'll take a look at those links.

Installing and uninstalling now work properly on my machine. I pushed the changes up to my repo - https://github.com/Edgar-Reynaldo/clipboard. There were some minor changes to the source files and strndup was replaced with regular code doing the same thing because strndup is not implemented in MinGW 3.4.5. I cleaned up and fixed premake4.lua so copying files worked and added an uninstall target to it. Take a look and see what you think.

Trezker

I've merged your stuff but I also cleaned up a bit. So update on your side.

I noticed you added linking to allegro 4, but the code in repo doesn't use it yet so I commented those lines for now.

I think once code that requires allegro is in there we should support both allegro 4 and 5. I think premake will let us add configuration options for this easily.

Edgar Reynaldo
Trezker said:

I've merged your stuff but I also cleaned up a bit. So update on your side.

I did 'git fetch root' and it appeared to update my repo, but I don't see anything different. I tried 'git diff HEAD~1' but that only gave my the changes I committed, not yours. Also, how do you quit the git diff viewer? I've tried ESC, CTRL+C, quit<enter>, so on... but nothing works.

I have a question about the way xcip works. Using your terminal.exe program on Linux, can you copy text from another program and then use the 'get' command and see whether xclip reads a global selection or whether it just uses it's own internal buffer.

I'm going to take a more serious look at using selections tomorrow.

Trezker

You exit with Q.
Fetch only retrieves the branch, I don't really know the details. But you also have to merge, it's a separate action. If you use git pull it will do both fetch and merge. Then you have git checkout, where you switch to a branch.
http://stackoverflow.com/questions/292357/whats-the-difference-between-git-pull-and-git-fetch

xclip works against the system clipboard. So yes, you get the global selection.

bamccaig

I did 'git fetch root' and it appeared to update my repo, but I don't see anything different.

As Trezker pointed out, fetch only downloads commits. It doesn't merge them into your own branch. You'll have to merge it into your own branch if you want that to happen.

I've been experimenting with this just recently so that I could understand it better. For starters, a really useful command is:

$ git log --graph

It basically shows you a text-based "graphical" representation of the history. Lets you visualize branching and such. You can also specify paths.

$ git log --graph master root/master

That should show you history for both 'master' and 'root/master' branches. For me, after fetching, I can see two new commits that I haven't merged into my master branch yet:

Quote:

* commit ec7dd317751516472e40d2efbdef8d2521784e02
| Author: Anders Andersson <trezker@gmail.com>
| Date:   Mon Jan 17 17:25:15 2011 +0100
| 
|     Small cleanup of Edgars version
|  
* commit 9073608c1b6f77b459d7adf17e9d29be07456a85
| Author: Edgar Reynaldo <nospam@toobadsosad.com>
| Date:   Mon Jan 17 07:16:21 2011 -0600
| 
|     Minor changes plus revision of premake4.lua to fix file copy and add uninstall target
|      
| *   commit 27b4c95e0eb9f68af1c7bd808a51a3c2f06d1090
| |\  Merge: cd9cf94 67dbdf2
| |/  Author: Brandon McCaig <bamccaig@gmail.com>
|/|   Date:   Mon Jan 17 09:23:39 2011 -0500
| |   
| |       Merge remote branch 'root/master'
| |     
*snip*

IIRC, the last one you see there is from the last time I did a fetch and merge (experimenting). Notice how the history stops there. After that * there's no paths further upward. To the left of that is another path (branch) that has two commits: "Minor changes plus..." and "Small cleanup..." That is the root/master branch that I've fetched and not yet merged.

I can merge them into my master branch like this:

# This is probably already done, but just for completeness.
$ git checkout master
# Merge with the remote branch.
$ git merge root/master
Merge made by recursive.
 examples/terminal.c |   36 ++++++++++++-------
 premake4.lua        |   97 +++++++++++++++++++++++++++++++++++++++++++++------
 src/clipboard.h     |    2 +-
 src/linux.c         |    2 +-
 src/windows.c       |    5 +++
 5 files changed, 116 insertions(+), 26 deletions(-)

Now if we visualize the history again:

$ git log --graph master root/master

We get this:

Quote:

*   commit c472f08de68d296b24eb1020908945925710abb4
|\  Merge: 27b4c95 ec7dd31
| | Author: Brandon McCaig <bamccaig@gmail.com>
| | Date:   Tue Jan 18 09:42:10 2011 -0500
| | 
| |     Merge remote branch 'root/master'
| |   
| * commit ec7dd317751516472e40d2efbdef8d2521784e02
| | Author: Anders Andersson <trezker@gmail.com>
| | Date:   Mon Jan 17 17:25:15 2011 +0100
| | 
| |     Small cleanup of Edgars version
| |   
| * commit 9073608c1b6f77b459d7adf17e9d29be07456a85
| | Author: Edgar Reynaldo <nospam@toobadsosad.com>
| | Date:   Mon Jan 17 07:16:21 2011 -0600
| | 
| |     Minor changes plus revision of premake4.lua to fix file copy and add uninstall target
| |     
* |   commit 27b4c95e0eb9f68af1c7bd808a51a3c2f06d1090
|\ \  Merge: cd9cf94 67dbdf2
| |/  Author: Brandon McCaig <bamccaig@gmail.com>
| |   Date:   Mon Jan 17 09:23:39 2011 -0500
| |   
| |       Merge remote branch 'root/master'
| |     
*snip*

We can see that my master branch (now on the left instead of right) joins up with the remote branch. I think that fetch is used to look around at remote branches to see what has been done and determine if you want to merge. For example, it seems you can:

$ git checkout root/master

This should let you view history, build and run the modified code, and determine just what was done and whether or not you actually want it. Contrarily:

$ git pull root master

Basically skips the review step and just merges right in. So pull would be useful if you were pulling in permanent changes from upstream, but fetch would be useful if you were just reviewing experimental changes from elsewhere and didn't necessarily want to merge with them. I think.

It's something that I've been wondering about for a while. In Mercurial, there are two pretty simple commands: hg incoming and hg outgoing that tell you which commits, if any, would be pulled or pushed. I'm sure there's a reason Git is designed the way it is though. I think I'm starting to figure out the Git way and I rather do like it (I use Mercurial at j0rb so I'm forced to learn about it faster). :)

Edgar Reynaldo

I've got a basic handle on using selections. I think I can get by without sending/receiving any events in Linux, but I'm not totally sure.

Here's my first attempt :

#SelectExpand
1 2#include <xalleg.h> 3 4int SetClipboardString(const char* cstr) { 5 Display* d = _xwin.display; 6 Window w = _xwin.window; 7 char* str = 0; 8 9 if (!cstr) {return 1;} 10 str = strdup(cstr); 11 XChangeProperty(d , w , XA_CLIPBOARD , XA_STRING , 8 , PropModeReplace , (unsigned char*)str , strlen(str) + 1); 12 XFlush(d); 13 free(str); 14 XSetSelectionOwner(d , XA_CLIPBOARD , w , CurrentTime); 15 return 0; 16}// returns 0 if successful, non-zero otherwise 17 18 19 20int SetClipboardBitmap(BITMAP* bmp) { 21 return 1;// not implemented yet 22}// returns 0 if successful, non-zero otherwise 23 24 25 26char* GetNewClipboardString() { 27 Display* d = _xwin.display; 28 Window w = _xwin.window; 29 Atom returned_type; 30 int returned_format; 31 unsigned long num_items_returned; 32 unsigned long bytes_left; 33 unsigned char* returned_property; 34 char* return_string = 0; 35 int ret = 0; 36 char* AtomName = 0; 37 38 Window selowner = XGetSelectionOwner(d , XA_CLIPBOARD); 39 if (selowner == None) {return (char*)0;} 40 XConvertSelection(d , XA_CLIPBOARD , XA_STRING , None , selowner , CurrentTime); 41 XFlush(d); 42 43 // check for data 44 ret = XGetWindowProperty(d , selowner , XA_STRING , 0 , 0 , 0 , AnyPropertyType , &returned_type , 45 &returned_format , &num_items_returned , &bytes_left , &returned_property); 46 if (ret != Success) { 47 fprintf(Log() , "Failed to Get Window Property XA_STRING attempt 1\n") 48 return (char*)0; 49 } 50 if (bytes_left < 1) { 51 fprintf(Log() , "There are no bytes to read in the requested property.\n"); 52 return (char*)0; 53 } 54 ret = XgetWindowProperty(d , selowner , XA_STRING , 0 , bytes_left*4 , 0 , AnyPropertyType , &returned_type , 55 &returned_format , &num_items_returned , &bytes_left , &returned_property); 56 if (ret != Success) { 57 fprintf(Log() , "Failed to Get Window Property XA_STRING attempt 2\n"); 58 return (char*)0; 59 } 60 // Success, temporary logging of returned data 61//* 62 AtomName = XGetAtomName(d , returned_type); 63 if (!AtomName) {AtomName = "Unidentified Atom";} 64 fprintf(Log() , "Success retrieving property. Return type \"%s\" , Format=%d , NumItemsReturned=%d\n" 65 " Bytes Left=%d , String Returned=\"%s\"" , 66 AtomName , returned_format , num_items_returned , bytes_left , returned_property); 67 if (strcmp(AtomName , "Unidentified Atom") != 0) {XFree(AtomName);} 68//*/ 69 if (returned_format == 8) { 70 return_string = strdup(returned_property); 71 } else { 72 fprintf(Log() , "The string returned was not in char format. Data size was %d." , returned_format); 73 } 74 XFree(returned_property); 75 76 return return_string; 77}// returns a new string if successful, else returns 0 78 79 80 81BITMAP* GetNewClipboardBitmap() { 82 return 0;// not implemented yet 83}// returns a new bitmap if successful, else returns 0

Can someone compile and test this on Linux please?
ClipBoardTest3.zip

Use the S key to set the clipboard text to "CyberMan" and use the B key to retrieve the clipboard text.

It doesn't work with images yet because I can't find out what the standard expected format for an image in the Linux clipboard is supposed to be. I've googled and googled with no results. I'm downloading the source to Gimp now, so maybe that can give me a clue. Does Gimp let you copy and paste images between programs on Linux? If it doesn't, what programs do?

Arthur Kalliokoski

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

pepsi@fractalcomet:/home/prog/ClipBoardTest3 05:14 AM $ gcc -c -O2 -Wall Clipboard.c
Clipboard.c:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
Clipboard.c:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
Clipboard.c: In function 'SetClipboardString':
Clipboard.c:225: error: 'XA_CLIPBOARD' undeclared (first use in this function)
Clipboard.c:225: error: (Each undeclared identifier is reported only once
Clipboard.c:225: error: for each function it appears in.)
Clipboard.c:225: error: 'XA_STRING' undeclared (first use in this function)
Clipboard.c: In function 'GetNewClipboardString':
Clipboard.c:252: error: 'XA_CLIPBOARD' undeclared (first use in this function)
Clipboard.c:254: error: 'XA_STRING' undeclared (first use in this function)
Clipboard.c:261: warning: implicit declaration of function 'Log'
Clipboard.c:261: warning: passing argument 1 of 'fprintf' makes pointer from integer without a cast
/usr/include/stdio.h:333: note: expected 'struct FILE * _restrict_' but argument is of type 'int'
Clipboard.c:262: error: expected ';' before 'return'
Clipboard.c:265: warning: passing argument 1 of 'fprintf' makes pointer from integer without a cast
/usr/include/stdio.h:333: note: expected 'struct FILE * _restrict_' but argument is of type 'int'
Clipboard.c:268: warning: implicit declaration of function 'XgetWindowProperty'
Clipboard.c:271: warning: passing argument 1 of 'fprintf' makes pointer from integer without a cast
/usr/include/stdio.h:333: note: expected 'struct FILE * _restrict_' but argument is of type 'int'
Clipboard.c:280: warning: passing argument 1 of 'fprintf' makes pointer from integer without a cast
/usr/include/stdio.h:333: note: expected 'struct FILE * _restrict_' but argument is of type 'int'
Clipboard.c:280: warning: format '%d' expects type 'int', but argument 5 has type 'long unsigned int'
Clipboard.c:280: warning: format '%d' expects type 'int', but argument 6 has type 'long unsigned int'
Clipboard.c:284: warning: pointer targets in passing argument 1 of 'strlen' differ in signedness
/usr/include/string.h:397: note: expected 'const char *' but argument is of type 'unsigned char *'
Clipboard.c:284: warning: pointer targets in passing argument 1 of '__strdup' differ in signedness
/usr/include/bits/string2.h:1303: note: expected 'const char *' but argument is of type 'unsigned char *'
Clipboard.c:286: warning: passing argument 1 of 'fprintf' makes pointer from integer without a cast
/usr/include/stdio.h:333: note: expected 'struct FILE * _restrict_' but argument is of type 'int'
Clipboard.c:242: warning: unused variable 'w'
Clipboard.c: At top level:
Clipboard.c:333: error: conflicting types for 'Log'
Clipboard.c:261: note: previous implicit declaration of 'Log' was here
Clipboard.c: In function 'Log':
Clipboard.c:334: error: 'logfile' undeclared (first use in this function)
Clipboard.c: In function 'CloseLog':
Clipboard.c:343: error: 'logfile' undeclared (first use in this function)

pepsi@fractalcomet:/home/prog/ClipBoardTest3 05:14 AM $ gcc -v
Reading specs from /usr/lib/gcc/i486-slackware-linux/4.4.4/specs
Target: i486-slackware-linux
Configured with: ../gcc-4.4.4/configure --prefix=/usr --libdir=/usr/lib --enable-shared --enable-bootstrap --enable-languages=ada,c,c++,fortran,java,objc --enable-threads=posix --enable-checking=release --with-system-zlib --with-python-dir=/lib/python2.6/site-packages --disable-libunwind-exceptions --enable-__cxa_atexit --enable-libssp --with-gnu-ld --verbose --with-arch=i486 --target=i486-slackware-linux --build=i486-slackware-linux --host=i486-slackware-linux
Thread model: posix
gcc version 4.4.4 (GCC) 

Yes, you can copy and paste images.

GullRaDriel
Arthur said:

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

Which ClipboardTest.c are you talking about ?

Arthur Kalliokoski

Which ClipboardTest.c are you talking about ?

The one in the zipfile? That causes Clipboard.c to complain about missing functions without it?

GullRaDriel

OMG he doesn't see his mistake :o

Arthur Kalliokoski

OK, I've been drinking again, but what mistake other than confusing the names?

[EDIT]

Or you mean this on line 150 in Clipboard.c?

// #include <LINUX_HEADER> // TODO : Find out what linux header to include

GullRaDriel

I just find it strange that the same file is able to compile fine and stop compiling by giving compilation errors at the same time.

Other than the names, nothing else. But screwing the names screw the whole sentence, isn't it ?

And we are, BTW, way out of topic ^^

Trezker

Hi everybody.
My life just got turned upside down by getting a fulltime job. So I thought you guys might want to know that my alertness in keeping up with this project may suffer. :-/

bamccaig

/congrats!

Arthur Kalliokoski
Trezker said:

My life just got turned upside down by getting a fulltime job.

Something to do with computers, hopefully?

Thomas Fjellstrom
Trezker said:

My life just got turned upside down

When I read that, I thought this was to follow:

video

Trezker

Sony blocked that in my country.

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

Edgar Reynaldo

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

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."

Edgar Reynaldo

I'm working from 12 year old xlib documentation here, so thank you for your patience.

This time I tried a roundabout way to get the Atom's using XInternAtom, so maybe this time it will work.

ClipBoardTest5.zip

Arthur Kalliokoski

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

Edgar Reynaldo

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

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.

Edgar Reynaldo

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

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.

Edgar Reynaldo

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

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

Edgar Reynaldo

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

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.

bamccaig

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

Arthur Kalliokoski

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

Edgar Reynaldo
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

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

clicky

Edgar Reynaldo

I don't have a man page viewer, so those are pretty cryptic looking in my text editor. Could you copy the screen contents into a text file please?

Arthur Kalliokoski

Now the Format Police are looking for us!

Edgar Reynaldo

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

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.

Edgar Reynaldo

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

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.

Edgar Reynaldo

Copy/paste of images won't work on Linux until I figure out what format they're using. That's why I wrote the logging function.

What did the logfile say?

Arthur Kalliokoski

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);"

Edgar Reynaldo

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

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

Edgar Reynaldo

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

This is the one I have.

Edgar Reynaldo

The fact that it doesn't #define XA_CLIPBOARD suggests it is an old version. It would be nice to see a more modern release of Xatom.h if possible. However, I guess I can just use XInternAtom instead.

Arthur Kalliokoski

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

bamccaig

Same here.

Edgar Reynaldo

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

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.

Edgar Reynaldo

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

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.

Edgar Reynaldo

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

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

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.

Edgar Reynaldo
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

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.

Edgar Reynaldo

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

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.

Edgar Reynaldo

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

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
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

Arthur Kalliokoski
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

MiquelFire

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.

bamccaig

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
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.

Arthur Kalliokoski

Neither my header files nor Google know what an ImageTypeAtom is, there are several references to ImageType, but those all seem to be gtk or C++ specific etc.

[EDIT]

I got a new computer, and had to reinstall a4.4 to compile the Clipboard*.c files, and while playing with the example programs and the demo, I just want to say that going to a fullscreen mode at the very start is a Bad Thing(TM). Bombing out with errors leaves you at 320x200 for a desktop mode.

Edgar Reynaldo

Neither my header files nor Google know what an ImageTypeAtom is, there are several references to ImageType, but those all seem to be gtk or C++ specific etc.

I'm a dimwit. Change line 351 of xcsi.c to :

   Atom ImageTypeAtom = StringTypeAtom;/// TODO : STRING , really? What Type should an image have?

Arthur Kalliokoski said:

I just want to say that going to a fullscreen mode at the very start is a Bad Thing(TM). Bombing out with errors leaves you at 320x200 for a desktop mode.

You'll probably hate me for saying this, but I can't remember a time that Windows didn't reset the video mode back to the original desktop setting when a program aborted.

I'm going to go work on adding support for INCR transfers. You might need it when trying to retrieve an image from the clipboard when you copy your desktop image or maybe other times as well. If only I could figure out what the supposed maximum transfer size was...

Arthur Kalliokoski

wait...

bamccaig

I'm a dimwit. Change line 351 of xcsi.c to :

Atom ImageTypeAtom = StringTypeAtom;/// TODO : STRING , really? What Type should an image have?

There's a file type for that. ;) It's called a patch file (or less formally a diff file).[1] You wouldn't know that in the Windows world though. Every one of you would just ... ugh ... edit the file manually. ;) For the record, the MSYS (or maybe MinGW) version of patch does work and should be sufficient to inline a basic patch for something like ^ that. :-X Cygwin's port definitely works. In fact, that simple of a patch is easy enough to write manually if you know what the original file looked like. :P

You'll probably hate me for saying this, but I can't remember a time that Windows didn't reset the video mode back to the original desktop setting when a program aborted.

Windows does things rather fucked up. Its programs actually seem to need to know what type of program they are and such and that controls what they can and can't do. As a result, most Windows programmers are probably oblivious to the concept of standard streams, command line arguments, or exit codes, making their software pretty useless unless you hire a babysitter... In Linux, I think a program is just a program, and if it happens to create and draw X windows, or enable full screen mode and set the screen resolution then so be it. Of course, if it crashes after it has changed the screen resolution then X remains in the state that it is in. You might think that Windows is doing a better job here, and perhaps given the context it is, but I think the Linux (perhaps it's more correct to say UNIX) way is far better. It would be nice though to create a temporary context that dies with the application regardless of a clean exit. Given the design I'm not sure that it would make sense to though (I'm not very familiar with how it works [yet]).

Arthur Kalliokoski

I got it to say it successfully copied the CyberMan image, and blitting it just showed a white square.

The log file said

QueryAvailableTargets info : selection owner window's name : 
QueryAvailableTargets : 4 targets available :
   TARGETS
   TIMESTAMP
   MULTIPLE
   image/bmp

It also caused the Konquerer file browser to not refresh properly :-X.

Edgar Reynaldo
bamccaig said:

There's a file type for that. ;) It's called a patch file (or less formally a diff file). You wouldn't know that in the Windows world though. You people just ... ugh ... edit the file manually. ;)

It's a one line change, of exactly 4 whole characters. 6 if you count Ctrl-S. :P
Compared to

patch xcsi.c xcsi.diff

I saved you exactly 16 characters of typing. :P

I know exactly what a diff and a patch is, not to mention that I have gnuwin32 diff and patch installed on my computer and I've used them to send patches to the allegro mailing list before. Not to mention earlier in this thread I used diff to see what changes Arthur had made to my source file to get it to compile. :P

Bill the Cat said:

THBBFT!

{"name":"603460","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/0\/90b3fb297211d5b8314a51d47479e84a.jpg","w":370,"h":406,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/0\/90b3fb297211d5b8314a51d47479e84a"}603460

I got it to say it successfully copied the CyberMan image, and blitting it just showed a white square.

Well, that's progress, sort of... It means the bitmap saved and loaded, so at least it was recognized as a bitmap. I'll try testing some things here.

Maybe the transfer process corrupted the file somehow?
Can you see anything wrong with using cat to pipe the file into xcsi's stdin?

cat xcsi_image_temp.bmp | xcsi -c -s=bmp
 

Is there a better way to feed a file to xcsi through stdin?

Try copying images from other programs and see what paste (key V) does with those.

Arthur Kalliokoski said:

It also caused the Konquerer file browser to not refresh properly :-X.

Are you sure it was ClipboardTest or xcsi that caused it? I can't see why it would do that. I respond to all SelectionRequest and SelectionNotify events where appropriate.

bamccaig

It's a one line change, of exactly 4 whole characters. 6 if you count Ctrl-S. :P
Compared to

patch xcsi.c xcsi.diff

I saved you exactly 16 characters of typing. :P

That's not true. You aren't considering the keystrokes and mouse movements to navigate to that line of the file and manually edit it (which in itself can be error prone). The computer can do it much faster and more reliably (not to mention bash completion on the command and patch file). Also, you usually don't specify the file to patch (that's stored in the patch itself), and the patch file is either provided on stdin or with the -i option (at least in Linux, but I think it's the same in Cygwin and MSYS). ;)

I know exactly what a diff and a patch is, not to mention that I have gnuwin32 diff and patch installed on my computer and I've used them to send patches to the allegro mailing list before. Not to mention earlier in this thread I used diff to see what changes Arthur had made to my source file to get it to compile. :P

:-X

Is there a better way to feed a file to xcsi through stdin?

You could just use the stream redirection operator:

xcsi -c -s=bmp < xcsi_image_temp.bmp

Arthur Kalliokoski

cat xcsi_image_temp.bmp | xcsi -c -s=bmp

I copied CyberMan.bmp to xcsi_image_temp.bmp, then ran the command. Nothing happened as far as I could see, so I blasted the the xcsi log to screen again, and saw a whole slew of SelectionRequest to Konqueror. I deleted the log and ran that cat command again, but no new log was created. But then both Konqueror and Firefox were pretty much catatonic when trying to post this. Get your own Linux to futz with! I'm not playing anymore! >:(

bamccaig
I said:

You could just use the stream redirection operator...

I would imagine that STDIN would be considered text by default though so you may or may not need to do something special to treat it as binary data to get reliable results. :-/

Arthur Kalliokoski
bamccaig said:

I would imagine that STDIN would be considered text by default though so you may or may not need to do something special to treat it as binary data to get reliable results.

I thought it was only Windows that differentiated between text and binary data? The "rb" and "wb" parameters to fread() & fwrite().

bamccaig

I thought it was only Windows that differentiated between text and binary data? The "rb" and "wb" parameters to fread() & fwrite().

You're probably right. Windows and other weird OSes are the only ones that consider newlines as multi-character... I imagine that it depends how the file is read also (some routines will assume text), but those wouldn't be used when reading images anyway so maybe I'm just being paranoid...

Edgar Reynaldo
bamccaig said:

You could just use the stream redirection operator:

xcsi -c -s=bmp < xcsi_image_temp.bmp

Okay, thanks, I'll try that instead.

I copied CyberMan.bmp to xcsi_image_temp.bmp, then ran the command. Nothing happened as far as I could see

No problem there, when you set the clipboard or primary selection with xcsi, it forks and then waits for SelectionRequest events.

Arthur Kalliokoski said:

so I blasted the the xcsi log to screen again, and saw a whole slew of SelectionRequest to Konqueror.

Define 'whole slew'. Do you mean 50, 100, 500 requests? Also, do you remember the target that it was requesting? TARGETS would be normal, but image/bmp would be rather expensive to do on each update.

Arthur Kalliokoski said:

I deleted the log and ran that cat command again, but no new log was created.

That's okay, no requests, no log entries.

Arthur Kalliokoski said:

But then both Konqueror and Firefox were pretty much catatonic when trying to post this.

It's hard for me to determine why without xcsi_log.txt to tell me what was going on while the programs were unresponsive. If you use pskill to stop xcsi from running, does that return konqueror and firefox to a normal responsive state?

Arthur Kalliokoski said:

Get your own Linux to futz with! I'm not playing anymore! >:(

It's up to you. I wouldn't have gotten this far without your help though, so many thanks for what you've done so far.

bamccaig said:

I would imagine that STDIN would be considered text by default though so you may or may not need to do something special to treat it as binary data to get reliable results. :-/

Hmm, you may be right. STDIN is probably being read as text. Although I don't believe that any character translations like \n to <CR><LF> are being performed on Linux, so technically, using getchar should act as if it were binary data.

Maybe I need to specify an input file as an argument to xcsi and then open the file in binary read mode and specify an output file as an argument and open the file in binary write mode.

bamccaig

Hmm, you may be right. STDIN is probably being read as text. Although I don't believe that any character translations like \n to <CR><LF> are being performed on Linux, so technically, using getchar should act as if it were binary data.

Maybe I need to specify an input file as an argument to xcsi and then open the file in binary read mode and specify an output file as an argument and open the file in binary write mode.

In reality I can't think of a case where binary and text files should be interpreted differently in Linux. :-/ So I don't think it would matter. Either way, I would hope that it is possible to change STDIN to binary mode because it is a very good practice to use it when it makes sense. Even if you do support a command line argument (probably a good idea if you intend for the program to be used directly), that depends on the data being in a file, and sometimes you want to write the data directly to the process without using the underlying file system.

Edgar Reynaldo

That's easy enough to support though, the 4th (file) argument would be optional. If present, i/o would be performed through the specified file, otherwise through stdin.

Append
I'm currently posting this from FireFox using openSUSE 11.3 in a virtual machine under Vista. Whee! I have to say though, so far I'm not that impressed with Linux. It's okay, but it's nothing to brag about. I could also install either Fedora 14 or Ubuntu 10.10 if anyone recommends that. I'm currently using Gnome as my desktop.

Anyway, now that I have a Linux install up and running, maybe I can see about fixing the problems Arthur was having with my clipboard. It may be a few days though, until I get A4.4 up and running again.

Arthur Kalliokoski

It's okay, but it's nothing to brag about.

Give it time, son, give it time. OTOH, you have to use it regularly to achieve nirvana, once every couple months it'll always seem strange.

AMCerasoli

Trezker, if you manage to do the clipboard lib could you post it in the Depot?, I was reading the topic but I get lost in page 3-4, so if you can do it using Allegro 5 I would like to try it, since I need something like that in my program. thanks

bamccaig

I'm currently posting this from FireFox using openSUSE 11.3 in a virtual machine under Vista. Whee! I have to say though, so far I'm not that impressed with Linux. It's okay, but it's nothing to brag about. I could also install either Fedora 14 or Ubuntu 10.10 if anyone recommends that. I'm currently using Gnome as my desktop.

What specifically do you find unimpressive? The Linux desktop is nothing to gawk at. It's functional, but generally not that much different from Windows (and I presume OS X). You can install some eye candy if you want (i.e., compiz). KDE4 is also a bit more fancy, but last time I checked I also found it a bit less polished. Just remember that if it's not doing something that you want it to do there might already be a way to make it with configuration options. And if not, a way can always be added. :P The real power of a Linux (or UNIX) system though is on the command line shell. You now have one that works and works well. Learn to use it to your advantage.

I personally recommend Fedora, but that's mostly because it's the distribution that I have the most experience with (and might become an official contributor to soon...).

It may be a few days though, until I get A4.4 up and running again.

Now that you're in Linux getting A4.4 up and running is a breeze. :P

m c

Edgar sorry I went away I was busy with IRL stuff, you know how it goes.

I don't think that loading packfiles from memory is supposed to be very difficult though? But then I read the docs and it says

Quote:

Note that prior to version 4.1.18, some internal fields were accidentally documented - but PACKFILE should be treated as an opaque structure, just like the libc FILE type.

So maybe my memory is obsolete now.

Edgar Reynaldo
bamccaig said:

What specifically do you find unimpressive?

So far :

  • 1) The file manager - there's no folder tree to navigate folders, only hard links to special folders.

  • 2) Software management

    • a) zypper search only gives you package names, it doesn't tell you how to download specific versions of a certain package. This gave me a bunch of trouble because I'm trying to install the VirtualBox Guest Additions and I have to have the same kernel development version as the kernel I'm using.

    • b) YaST Software Management
      - I run it, and it tells me

      Quote:

      System management is locked by the application with pid 22596 (usr/sbin/packagekitd). Close this application before trying again.

      So I can't even use YaST to update software without killing another process (and that process doesn't even show up on the taskbar, nor do I know what the equivalent of Windows Task Manager is in openSUSE, if there even is one...).

  • 3) Application viewer / start menu
    The start menu shows favorite applications, and recent applications, with an option to show all applications, but when you show all the applications, you get a whole bunch of icons instead of a simple menu. I never liked OSX for all the stupid icon views it has, and it's equally annoying in Linux.

Trezker, if you manage to do the clipboard lib could you post it in the Depot?, I was reading the topic but I get lost in page 3-4, so if you can do it using Allegro 5 I would like to try it, since I need something like that in my program. thanks

I don't think Trezker is working on his version of the clipboard library anymore. As far as I know, I'm the only one who's still actively developing this. So far my version has support for copy/paste of text/images on Windows and support for copy/paste of text and almost images on Linux. No MacOSX support yet though.

It's also only Allegro 4 at this point, but if someone writes al_bitmap_to_hbitmap and hbitmap_to_al_bitmap functions then it could easily be converted to work with Allegro 5.

m c said:

Edgar sorry I went away I was busy with IRL stuff, you know how it goes.

No big deal. Thanks for trying it though. The latest version is here if you want to give it a go. Arthur was having some problems with it though and I'm currently trying to get my Linux development environment set up to test it.

BAF

KDE4 is far too plastic-y looking. It looks like a cheap toy, and functions about equally as well. Linux user interfaces are a joke, they're about on par with Windows 95.

Evert

The file manager

You can almost certainly configure it for whatever your preferred view is (not sure I understand what you mean though) or use a different one that suits you better.

Quote:

a) zypper search only gives you package names, it doesn't tell you how to download specific versions of a certain package. This gave me a bunch of trouble because I'm trying to install the VirtualBox Guest Additions and I have to have the same kernel development version as the kernel I'm using.

Does it have a manpage? Or a --help option? My guess is that you simply add the version number (as "-versionnumber") to the package name.
Ultimately though, you should use whatever the latest version in the repository is. As long as you update the kernel and the sources at the same time, you should be ok.

Quote:

b) YaST Software Management
- I run it, and it tells me
Quote:

System management is locked by the application with pid 22596 (usr/sbin/packagekitd). Close this application before trying again.

So I can't even use YaST to update software without killing another process (and that process doesn't even show up on the taskbar, nor do I know what the equivalent of Windows Task Manager is in openSUSE, if there even is one...).

$ kill -9 22596
I'm sure there's a way to do it through the GUI, but I've never used it.

Quote:

The start menu shows favorite applications, and recent applications, with an option to show all applications, but when you show all the applications, you get a whole bunch of icons instead of a simple menu. I never liked OSX for all the stupid icon views it has, and it's equally annoying in Linux.

Not sure what you're referring to here either, but it depends very much on what window manager you use. Some of them don't have a "start menu" at all, for others its entirely optional.

None of those things have specifically to do with "Linux", but more with the window manager you're using, and how that window manager is configured (which can depend a lot on the distribution). Just experiment with different options and see if there's one you like better.

bamccaig

So far :

  • 1) The file manager - there's no folder tree to navigate folders, only hard links to special folders.

  • 2) Software management

    • a) zypper search only gives you package names, it doesn't tell you how to download specific versions of a certain package. This gave me a bunch of trouble because I'm trying to install the VirtualBox Guest Additions and I have to have the same kernel development version as the kernel I'm using.

    • b) YaST Software Management
      - I run it, and it tells me

      Quote:

      System management is locked by the application with pid 22596 (usr/sbin/packagekitd). Close this application before trying again.

      So I can't even use YaST to update software without killing another process (and that process doesn't even show up on the taskbar, nor do I know what the equivalent of Windows Task Manager is in openSUSE, if there even is one...).

  • 3) Application viewer / start menu
    The start menu shows favorite applications, and recent applications, with an option to show all applications, but when you show all the applications, you get a whole bunch of icons instead of a simple menu. I never liked OSX for all the stupid icon views it has, and it's equally annoying in Linux.

So basically your complaint is that it's not Windows? :P There is a learning curve involved. If you installed Linux looking for a free Windows then I'm afraid that you'll be sorely disappointed. On the other hand, GNU/Linux distributions do most things better than Windows, once you get used to them. And the things that they don't do better usually still work pretty well and are always open to improvement. There are still a handful of things that need improvement, but then you paid fuck all so who are you complaining to?

Then again, I'm not too sure about your choice of distribution. I've never used OpenSUSE so I can't really critique it fairly, but I have heard of problems and know Fedora to be relatively smooth sailing and Debian-based distros (Ubuntu being the most n00b friendly, I guess) are pretty well kept up as well. It's possible that you've chosen a lemon, though I suspect that your biggest problems are just change. Those are going to be there no matter what distribution you choose. Either stick it out or try a different distribution. Honestly, the best way to learn is to make the OS your primary OS. Then you have to learn. Of course, it still takes time. I wonder why you were even trying to make an X implementation if you're completely new to unices... :-X

The file explorer can be configured somewhat. It should be able to satisfy your desires. I'm too drunk to figure out what those are though. The one option that I always enable isn't even present anymore when I check Nautilus' dialog, though it does behave correctly still. Aside from that, Nautilus (Gnome's default file manager AFAIK) works pretty predictable. Can you better describe what is wrong?

As for versions of software, I honestly couldn't tell you. In my experience, I either deal with whatever version my distribution offers through its package manager, or attempt to build from source (which can go easily and can go difficult, depending mostly on dependencies). I would suggest that you ask yourself when you need a particular version. Often, the version available with the default options is sufficient. If not then you'll just have to accept the need for manual processing. Often the GUI interfaces in Linux are hacked together by people trying to fill a niche. The most complete and powerful interfaces are usually accessible from the command line first. Don't expect to point and click your way through Linux.

As for the existing PID lock, that is a GUI manager designed to show you when updates are available. There should be an icon in the analogue to the notification area (usually next to the time). Generally, you won't hurt anything by killing that process either if you feel so bold. It's a reasonable thing to occur though, and once you've gained more experience you'll learn to appreciate it. That said, as I mentioned earlier, I have zero experience with OpenSUSE (or any SUSE derivatives) so I can't honestly say how the system is built or even what package format is used. If you really can't survive with it then try a different distribution.

I have no idea what you're talking about regarding the icons on the menu. Maybe that's a theme used by OpenSUSE. With Fedora, Gnome's default menu(s), at least as far Fedora 13, are even easier to use than on Windows. Applications are grouped by type, and each option typically has an icon and a name, and displays a summary when moused-over.

Edgar Reynaldo
Evert said:

Does it have a manpage? Or a --help option?

Yes, the --help option didn't describe versioning syntax, but after taking a look at the manpage today, it was there. But I figured out how to do it with the YaST Software Manager first.

Evert said:

None of those things have specifically to do with "Linux", but more with the window manager you're using, and how that window manager is configured (which can depend a lot on the distribution). Just experiment with different options and see if there's one you like better.

Well, to be fair, the window manager is an integral part of Linux. Maybe other window managers perform better, but I don't know that yet. I'll keep working with it and see how it goes.

bamccaig said:

So basically your complaint is that it's not Windows?

In a sense, yes, because Windows works. To be fair, I've sorted out most of the things that I didn't like so far. And to be honest, it's fairly common that you complain that Windows isn't Linux. Pot meet kettle?

There was a drop down list above the special folder links in the file manager and it had a folder tree view in the list. Yay! So I'm happy with that now.

YaST Software Manager is working now. Some process was downloading some kind of update list which interfered with the Software Manager. The upside is that the Software Manager lets me view and choose which version of a package to install, so I'm currently downloading the (hopefully) correct kernel-default-devel package.

bamccaig said:

Either stick it out or try a different distribution.

Well, it's not so bad I would give up on it after just a day using it. I did find the equivalent of Windows Task Manager, the Gnome System Monitor, so that's good.

bamccaig said:

I wonder why you were even trying to make an X implementation if you're completely new to unices... :-X

The main point of this library was that it would be cross platform, wasn't it? And to reveal the truth of it, this will be an addition to my GUI library, so I'm committed to it, because I want to be able to build applications as well as games with my library. Even if I'm new to Linux, I'm not new to C/C++. All it took was learning to use a new lib (Xlib). If you're not willing to branch out sometimes, then you'll never grow, am I correct? :D

m c

log file attached.

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).

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.

One example is the screenshot utility, I would normally press print screen, choose "copy to clipboard" and then close the dialog that comes up, and then paste into GIMP, but I have to remember to leave the dialog open until I have pasted into gimp otherwise the screenshot data is lost....

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

[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

Evert
bamccaig said:

I've never used OpenSUSE so I can't really critique it fairly, but I have heard of problems and know Fedora to be relatively smooth sailing and Debian-based distros (Ubuntu being the most n00b friendly, I guess) are pretty well kept up as well.

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.

But I figured out how to do it with the YaST Software Manager first.

I remember it being fairly straightforward with YaST, but haven't used it recently enough that I could explain off the top of my head how to do it.

Quote:

Well, to be fair, the window manager is an integral part of Linux. Maybe other window managers perform better, but I don't know that yet.

No, you see, it is not an integral part of Linux. It's not even an integral part of X11. That's why you can swap it for another window manager that works completely differently so easily.

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.

That depends. There's no such thing as "/the/ clipboard". There's several different ones, some of which may behave the way you describe and others that don't.
Those that don't may deal exclusively with text though.

Thomas Fjellstrom
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.

Evert

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

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

bamccaig

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
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

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.

Edgar Reynaldo

The VirtualBox Shared Folder is not working. It's visible from the File Manager in the openSUSE VM, but it's owner is root so I can't access it. Is there a workaround for this? Shouldn't I be root anyway?

Arthur Kalliokoski

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 ."

Edgar Reynaldo

Well, I did

sudo chown edgar ./sf_VBShared/

and it said nothing, but root still owns it. Can I login as root or something?

Arthur Kalliokoski

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.

Edgar Reynaldo

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

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 ."

Evert

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

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

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

spellcaster

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

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

Trezker

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

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

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

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
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.

Trezker

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

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.

Thread #606034. Printed from Allegro.cc