JNA - getting all visible window handles on OSX - java

I am looking for a way to get(in z order), move and resize visible windows on OSX using Java and JNA. Goal of the project is to manage 3rd party windows, so I do not own the windows and cannot access them via simple java code. I already do this on windows7/8, which is an easy task with the user32.dll. I already wasted hours googling but I cannot find any documentation or anything about how to accomplish this on the latest OSX. So my question is - what is the OSX equivalence to the User32.dll with stuff like FindWindow, EnumWindows, SetWindowPos etc?
Or any other advice on how to accomplish something like this.

You can try using old Carbon functions. PDF Reference. Looks like GetWindowList and GetNextWindow is what you need.
You can find a sample mapping for Carbon functions here

Related

Method to implement Windows Explorer icon overlays with Java

I am writing a cloud-sync application in Java with .jni integration to virtualize a cloud file-system in windows explorer.
Now i want to implement icon overlays like owncloud to see the state of a node like this:
I found some solutions for C#. Is this also possible with Java if using a jni interface to get access to the Icon Handlers.
Anyone knows a existing solution?
P.S. Tha last question for this is 4 years old so there is eventually a new solution for modern systems with java8 in combination with a native .dll available.
Thank you for any hint.
I just found a solution for Java 1.7+ in combination with native and jni dlls. Works with Windows Vista+, Mac and Linux.
"Liferay Nativity is a cross-platform library for adding icon overlays and context menus to file browsers."
You can find the GIT project here:
https://github.com/liferay/liferay-nativity
Anyone sucessfully integrated this? Trying to do a test implementation now.

Swing Works different on different Platform

I have made a Screen Recorder using Java Swing and Xuggler 5.4. I have developed it in Windows 8 64 bit. It's working excellent for Windows. But at client side on Linux's environment , nothing is working. I have searched thoroughly but not getting any solutions. I have checked this thread , but it didn't work for me.
Then I tried to create simple Transparent window in Linux but it's also not working. I was not able to click through the Resizeable Panel. I have used the same JRE version (1.7) for both. Have I miss understood Java's Cross Platform Support as far as Swing is concerned?
Please Give Me Some Advice...
I have always found logging to be the best debugging tool at your disposal! Many a times, java debuggers take you into APIs where you need not go every time. Logging values of your variables, and generic 'I have reached till this point' statements make life a lot easier.
So, I suppose you have ample logging done in your code. That could give you clues on what's happening on your client's system.
Are the right environment variables set? Are they pointing to the correct Java versions you need.
If there are some specific Screen capturing requirements(plugins / modules / API) your code has, are they available on the Linux m/c?
Like #MadProgrammer said, in the end, Java has to talk with the native graphics APIs to render your screen.
I would try to debug it in this way -
Check whether my main screen loads or no(by disabling the screen capture functions for a while).
if not, dig deeper.
Check whether all necessary components for capturing screen(audio and video) are available.
Check whether the code is being run with appropriate permissions to control the h/w devices you may need.

Controlling applications through Java

I am looking for a way to mimic operating-system (Windows in specific) actions through Java. Preferably, the program should run in the background, but it is not a big deal if it does not. I got the background part covered thanks to this question. I was looking for the following specific features :
Maximizing/Minimizing the currently active window. (Can be any window, not just the Java application window.)
Closing the currently active window.
Open installed programs, and system utilities like the calculator, paint, etc. (I figured out this one from this question.)
Shutdown/Restart (This one's done too, thanks to the question here.)
So, my actual question is:
Is it possible to minimize/maximize or close an application window from a java program? (in Windows)
Example Scenario:
Firstly the java program is started, and it runs either as a background process or as a window. Bottom-line is that it should be able to accept triggers like maybe a keyboard shortcut or microphone input to trigger the action. After that suppose a Chrome window is opened and is currently active. Now on pressing the pre-defined shortcut, the Chrome window will minimize/maximize or close.
If the answer to the question is yes, I could use some pointers to start with my application. Thanks!
What you need is like an OS shell programming interface.
In Java side you will define a few interfaces.
Another Java layer will detect which OS is used and will return an implementation of interface: Windows, Linux, Macosx.
Some functionality you can have with simple bash command: in windows cmd, in linux .. to many. Eg shut down, launch MSPaint, Calculator.
Other functionality you can have it with windows API: you will need to write some JNI functions and call it. eg minimize, maximize. It is possible.
Edit:
I see there is no accepted answer, although it is answered properly.
Here is a C# code which does what you need in Java.
Now you need to migrate this code to Java:
In your java class declare a function:
private native maximizeOrMinimizeWindowWithName(String windowName, boolean maximize);
Compile -it
use Javah.exe - it will generate the necesary .h files
Use a C editor, configure environment, use the generated .h file.
-include windows api headers
-load user32.dll
- do more stuf..
compile your C code to .dll
put the your.dll into your app PATH environment variable. ( windows has the . in path, linux not)
-text, bugfix,
for more info you should see a basic JNI tutorials.
-upvote accept :)
This can be initiated from Java, but not actually implemented in Java. In other words, it will take a lot of platform-specfiic JNI library code to get it working.
Java will give you almost no benefit for your use case; you should avoid it altogether for this project.
You should look into Autohotkey. It's an system dedicated to simulate user programmaticly.
Using AH scripts you can easily access all open windows, installed programs and even control mouse and keyboard.

Coordinates of active window on the desktop with java

Is there any way to get the title and coordinates of the active window on the desktop? Window can belong to any process, not necessarily to the one that I'm developing. I'd like to do it on java, probably with the calls of some native API.
Someone correct me if i am wrong but you wont be able to use a native API with java if it isnt part of java already, meaning you wont be able to find a pure Java solution.
You can use JNI(Java Native Interface) to create a 'link' using C/C++ and that would allow you to use native API from Java.
EDIT: JNA(Java Native Access) is another possible solution i believe.
You could also use C# or VB.net which i believe that already have support for windows API.
The functions you are looking for might be
GetForegroundWindow to get the window itself.
GetWindowRect to get coordinates.
( note that these links are for C++, C#/VB might have access to those in some way )
For you to use Java you will have to ,as i said, somehow 'link' the native API with java because Java alone can't.
This question about getting window title might have answers that explain Java's limits for this type of things better.
Get current active window's title in Java

How to implement file icon overlay in java, the way, e.g., turtoisesvn or dropbox do

I am looking for the best (fast and easy to implement, not necessary most robust) way to overlay file icons in Windows 7 Explorer from a prototype written in java. I have seen on SO questions on the icon overlaying in Net and Python, none for java.
I'm affraid this cannot be entirely done in java. You must create and register a COM object that implements the IExtractIcon interface among other things, and associate it with the files you want to manage. more info here
Look into JNA (https://github.com/twall/jna) - it will allow you to call native code - eg. from user32.dll, etc. - without the burden than JNI would put on you. We're using JNA to get other windows' titles for instance. If you find the information about making icon overlays from native code, you should be able to translate it into JNA quite easly.

Categories

Resources