forked from dorkbox/SystemTray
Moved JnaHelper + windows JNA to util project
This commit is contained in:
parent
6b1d0c4a12
commit
1bcf51c755
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2016 dorkbox, llc
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package dorkbox.systemTray.jna;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.sun.jna.Library;
|
|
||||||
import com.sun.jna.Native;
|
|
||||||
import com.sun.jna.NativeLibrary;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to get the library info from JNA when registering via direct map
|
|
||||||
*/
|
|
||||||
public
|
|
||||||
class JnaHelper {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static
|
|
||||||
NativeLibrary register(final String libraryName, final Class<?> clazz) throws IllegalArgumentException {
|
|
||||||
final Map<String, Object> options = new HashMap<String, Object>();
|
|
||||||
options.put(Library.OPTION_CLASSLOADER, clazz.getClassLoader());
|
|
||||||
|
|
||||||
final NativeLibrary library = NativeLibrary.getInstance(libraryName, options);
|
|
||||||
if (library == null) {
|
|
||||||
throw new IllegalArgumentException(libraryName + " doesn't exist or cannot be loaded.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Native.register(clazz, library);
|
|
||||||
return library;
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,7 +22,7 @@ import com.sun.jna.NativeLibrary;
|
|||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
|
|
||||||
import dorkbox.systemTray.SystemTray;
|
import dorkbox.systemTray.SystemTray;
|
||||||
import dorkbox.systemTray.jna.JnaHelper;
|
import dorkbox.util.jna.JnaHelper;
|
||||||
import dorkbox.util.OS;
|
import dorkbox.util.OS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +17,7 @@ package dorkbox.systemTray.jna.linux;
|
|||||||
|
|
||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
|
|
||||||
import dorkbox.systemTray.jna.JnaHelper;
|
import dorkbox.util.jna.JnaHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bindings for libgthread
|
* bindings for libgthread
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 dorkbox, llc
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package dorkbox.systemTray.jna.windows;
|
|
||||||
|
|
||||||
import com.sun.jna.Pointer;
|
|
||||||
|
|
||||||
import dorkbox.systemTray.jna.JnaHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bindings for GDI32
|
|
||||||
*
|
|
||||||
* Direct-mapping, See: https://github.com/java-native-access/jna/blob/master/www/DirectMapping.md
|
|
||||||
*/
|
|
||||||
public
|
|
||||||
class Gdi32 {
|
|
||||||
|
|
||||||
static {
|
|
||||||
JnaHelper.register("gdi32", Gdi32.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of pixels per logical inch along the screen width. In a system with multiple display monitors, this value is the same for
|
|
||||||
* all monitors.
|
|
||||||
*/
|
|
||||||
public static final int LOGPIXELSX = 88;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The GetDeviceCaps function retrieves device-specific information for the specified device.
|
|
||||||
*
|
|
||||||
* https://msdn.microsoft.com/en-us/library/dd144877(v=vs.85).aspx
|
|
||||||
*
|
|
||||||
* @param handle A handle to the DC.
|
|
||||||
* @param nIndex The item to be returned.
|
|
||||||
*/
|
|
||||||
public static native int GetDeviceCaps(Pointer handle, int nIndex);
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 dorkbox, llc
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package dorkbox.systemTray.jna.windows;
|
|
||||||
|
|
||||||
import com.sun.jna.Pointer;
|
|
||||||
|
|
||||||
import dorkbox.systemTray.jna.JnaHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bindings for User32
|
|
||||||
* <p>
|
|
||||||
* Direct-mapping, See: https://github.com/java-native-access/jna/blob/master/www/DirectMapping.md
|
|
||||||
*/
|
|
||||||
public
|
|
||||||
class User32 {
|
|
||||||
|
|
||||||
static {
|
|
||||||
JnaHelper.register("user32", User32.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://msdn.microsoft.com/en-us/library/windows/desktop/dd144871(v=vs.85).aspx
|
|
||||||
*
|
|
||||||
* @param shouldBeNull A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire
|
|
||||||
* screen.
|
|
||||||
*
|
|
||||||
* @return if the function succeeds, the return value is a handle to the DC for the specified window's client area. If the function
|
|
||||||
* fails, the return value is NULL.
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
Pointer GetDC(Pointer shouldBeNull);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://msdn.microsoft.com/en-us/library/windows/desktop/dd162920(v=vs.85).aspx
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
void ReleaseDC(Pointer shouldBeNull, Pointer dcHandle);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user