Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Clipboard

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

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
Member #7,536
July 2006
avatar

^ 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
Member #1,739
December 2001
avatar

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
Member #3,110
January 2003
avatar

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

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

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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
Member #7,536
July 2006
avatar

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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
Member #1,739
December 2001
avatar

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
Member #7,536
July 2006
avatar

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
Major Reynaldo
May 2007
avatar

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
Member #1,739
December 2001
avatar

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
Major Reynaldo
May 2007
avatar

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
Member #1,739
December 2001
avatar

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
Member #7,536
July 2006
avatar

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
Major Reynaldo
May 2007
avatar

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
Second in Command
February 2005
avatar

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.

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

GullRaDriel
Member #3,861
September 2003
avatar

Arthur said:

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

Which ClipboardTest.c are you talking about ?

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Arthur Kalliokoski
Second in Command
February 2005
avatar

Which ClipboardTest.c are you talking about ?

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

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

GullRaDriel
Member #3,861
September 2003
avatar

OMG he doesn't see his mistake :o

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Arthur Kalliokoski
Second in Command
February 2005
avatar

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

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

GullRaDriel
Member #3,861
September 2003
avatar

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

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Trezker
Member #1,739
December 2001
avatar

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
Member #7,536
July 2006
avatar

Arthur Kalliokoski
Second in Command
February 2005
avatar

Trezker said:

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

Something to do with computers, hopefully?

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

Thomas Fjellstrom
Member #476
June 2000
avatar

Trezker said:

My life just got turned upside down

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

video

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



Go to: