You are not logged in.
I want to paste a file in the current open file browser, but the problem is how can i get the paste path? when i right-click in the file browser, and click the [paste] button on the popup menu, can i get the path of the current directory at the same time?
When i open a File Browser, i use XGetInputFocus()to get the current focus window when the mouse click event happened on the window.
then i can use XGetWindowProperty() to get the window property, is there any property saves the current path? if there is , how to get it?
Thanks a lot!
Offline
I'm confused. If you're calling functions related to X11 windows, how could Xlib possibly know that the contents of those windows are being used by some program to represent actual files?
It might help to say which file browser you are using and how you are trying to hack it. Surely in the source code, it will have a variable storing the paths of files that get copied and pasted.
6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.
Offline
thanks ConnorBehan,
copy file is another application, we don't need to care about that.
i just want to know, how to get the path of the current File Browser.
can you show me how to hack it, and which variable stores the path?
give me an example will be appreciated。
Offline
copy file is another application, we don't need to care about that.
We do need to care about that. The X server does not store any information about what client programs are doing unless the client program specifically makes this information available.
The X server wouldn't even have any way of knowing the client is a file manager. Presumably the title string might include the words "some-sorta file manager" but the x server does not speak english.
The only way the internal variables of one client program would be available to another using Xlib functions was if the file manager program sets ATOMs for those various properties/variables. There may be toolkit dependent solutions (gtk, qt) as I AFAIK these do store a lot of "properties", but Xlib does not micromanage such data unless/until the client program creates an ATOM.
EDIT: I believe you could use more basic tools (not Xlib functions) to get the current working directory of any given process. But there is no assurance that the processes current working directory represents anything useful about where it would read or write files to/from.
EDIT: if the file manager in question is currently running, and it has a right click menu as you describe, you could (potentially) use XSendEvent calls to simulate the right click and the selection of the paste menu item. If you have also created an ATOM for the file/data you wish to send in your application and have used XSetSelectionOwner to your window and that atom, this could work - but it would be specific to the file manager it was designed for. Actually, if all this could work, it'd probably be easier to simulate a "drag and drop" event "dropping" the file of interest into the file manager's window - but this assumes the file manager accepts such events. In either case it is the file manager that does the copying/moving of the file - you are just triggering the appropriate events to cause it to do so.
Last edited by Trilby (2012-10-22 11:59:30)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
thanks Trilby,
Yes I know that the copying/moving operation is by the application, so I just want to get the paste path.
Just like you said, I should create an ATOM for the file to get the directory path, and the server set the atom property includes the path information, that will be the best to know what atom and events the X server will accept? do you have any idea?
Now I could send an event to the X server, let it know that there is a copy file operation happened, and then I right-click in the file-manager window, I can see the [paste] button is active, that indicate the X server is already know the copy event, Is that right? But I don not know after I click the [paste] button, what should happen behind the operation about the X server? Will it send an event to the application, and what event?
Any other method to solve the problem?
Last edited by cell2009 (2012-10-25 07:20:07)
Offline
Yes I know that the copying/moving operation is by the application, so I just want to get the paste path.
As has been repeatedly stated, there is no way to do this through xlib. The X server knows nothing about the internal variables of the file manager.
Just like you said, I should create an ATOM for the file/data, and the server set the atom property includes the file information, that will be the best to know what atom and events the file-manager will accept? do you have any idea?
The atom would be created by your application. Strictly speaking there is no way to know what events the file-manager would accept without looking at it's code - and you still haven't specified which file manager. But from your description I'd have to assume it accepts ButtonPress events which would display the menu. I suspect you'd have to get the menu window's information through an XQueryTree series then send another ButtonPress to the menu at the appropriate coordinates for the paste.
Now I could send an event to the X server, let it know that there is a copy file operation happened
Will it send an event to the application, and what event?
No, you don't sent events to the server, you send them to the other client (ok perhaps this is a bit pedantic - you do send it through the server). Also X knows nothing about "copy file operations", there is no such event nor message. As above, this would be a (series of) ButtonPress event(s) that you would send to the file manager.
Frankly this all seems quite ridiculous though. This is almost certainly the wrong way to solve whatever the underlying problem is. This would involve a rather elaborate program and based on the types of questions you're asking it's clear that you aren't really equiped for it.
I'm sure it'd be FAR easier to modify the file manager. If you would specify what it is you are actually trying to do, we can get out of this foolish X-Y problem scenario, and if you specify which file manager you are talking about, we might find that it has it's own scripting capability built in.
Edit: if you don't wish to share which file manager you are talking about, you could check `xprop` yourself. Some filemanagers may put their current path in some Atom that is available to other clients. Rox Filer, for example, does this in an Atom called "WM_WINDOW_ROLE"
Last edited by Trilby (2012-10-23 03:31:37)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks for your reply.
I use `xprop` to find that the file manager is `WM_CLASS(STRING) = "nautilus", "Nautilus"`, I do not want to modify the file manager, We know that it will be easy to get the current path use gtk lib, but I just wonder is there any way to get that with xlib?
"Some filemanagers may put their current path in some Atom that is available to other clients." Which Atom represents the current path in the Nautilus file manager?
I use XQueryTree() to get the whole X windows information, like the root window, the "Nautilus" window , the "Gnome-terminal" window and so on.
For the "Nautilus" window, I select the "/root" directory, the files and folders in that directory will be display, Now I want to paste a file in the display window, just like i will paste the file in the "/root/"directory, the problem is how can I get the paste path, like this example, how can I get the path "/root"? If I can get the path, I can create a file in that directory and then send the file contents.
Offline
I don't know why you needed xprop to figure out which file manager you are using. Which atom represents the current parth in Natuilus? How the hell should I know. You used xprop on it, did you see an atom that represented the current path? If so, you have your answer, if not, then it doesn't set one.
If this would be easy to do with gtk - and given that gtk must be installed to run that file manager - why not use gtk?
This is sounding more and more suspicious by every post. You sound less and less willing to share information on what you are trying to accomplish and more and more demanding of unreasonable information. Either you are a troll, or you really need to reevaluate how you request help. Either way I'll wish you luck and leave you be.
Edit: additionally, some of the information you have posted makes it sound like this is not running on a computer you have normal access to which makes me wonder whether you are attempting to do something illegal/unethical. I hope that other community members will insist that you clarify your intent before offering any further help.
Last edited by Trilby (2012-10-24 12:02:21)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I use XQueryTree() to get the whole X windows information, like the root window, the "Nautilus" window , the "Gnome-terminal" window and so on.
For the "Nautilus" window, I select the "/root" directory, the files and folders in that directory will be display, Now I want to paste a file in the display window, just like i will paste the file in the "/root/"directory, the problem is how can I get the paste path, like this example, how can I get the path "/root"? If I can get the path, I can create a file in that directory and then send the file contents.
Are you trying to bypass security? If so, we can not help you, Forum Etiquette: Legality.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
I am learning X window programming, and the "copy-paste file" is an example for learning, I will not do any illegal things. Now I do not know how to get the paste path, and want to get some help here.
Offline
Out of curiosity, I ran xprop on nautilus myself and found no ATOM that stores the current path. So in case you hadn't realized it yet, the information you want is not exposed to X11.
Was this "example for learning" recommended to you by somebody else? It is sounding like a contrived example that you made up because it is a needlessly difficult method for obtaining information about a copy and paste operation.
You might as well write your own program that takes a screenshot and uses a whole slew of algorithms for edge detection and optical character recognition in order to "read" the window drawn by nautilus and "learn" what the file path is.
6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.
Offline
What you are describing is not a copy and paste operation - you are trying to directly copy a file yourself into a path determined by a file manager.
In a copy and paste operation one client program would store file data to a selection and set a couple atoms as the selection owner when something is "copied".
The other client program would handle the paste operation by checking for a current selection owner, and checking for file data in a couple atoms.
Copy and Paste - by definition - requires two coopoerating client programs in addition to the X server. These programs can cooperate without having to be written by the same person because they can follow the same standards for interprocess communication. what you are describing is not a cooperational operation. You are trying to hijack another client program and forcibly implement both the "copy" and "paste" inside your own program.
Either just copy, and leave the paste operation to the receiving program, or simulate a drag and drop event by implementing all the 'drag' aspects and use XSendEvent to simulate a ButtonRelease event on the intended recipient. If the recipient can receive drop events, it will then (just like above) manage the paste event.
You can't learn about interprocess communication by refusing to communicate with other processes.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline