WIP: Getting windows DPI checks in order.

This commit is contained in:
nathan 2016-10-12 19:14:44 +02:00
parent 01f3e0e90a
commit 109def7db2
25 changed files with 191 additions and 58 deletions

View File

@ -31,9 +31,9 @@ import javax.swing.SwingUtilities;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import dorkbox.systemTray.jna.linux.AppIndicator;
import dorkbox.systemTray.jna.linux.Gtk;
import dorkbox.systemTray.linux.GnomeShellExtension; import dorkbox.systemTray.linux.GnomeShellExtension;
import dorkbox.systemTray.linux.jna.AppIndicator;
import dorkbox.systemTray.linux.jna.Gtk;
import dorkbox.systemTray.nativeUI.NativeUI; import dorkbox.systemTray.nativeUI.NativeUI;
import dorkbox.systemTray.nativeUI._AppIndicatorNativeTray; import dorkbox.systemTray.nativeUI._AppIndicatorNativeTray;
import dorkbox.systemTray.nativeUI._AwtTray; import dorkbox.systemTray.nativeUI._AwtTray;

View File

@ -13,21 +13,22 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna;
import java.util.HashMap;
import java.util.Map;
import com.sun.jna.Library; import com.sun.jna.Library;
import com.sun.jna.Native; import com.sun.jna.Native;
import com.sun.jna.NativeLibrary; import com.sun.jna.NativeLibrary;
import java.util.HashMap;
import java.util.Map;
/** /**
* Helper method to get the library info from JNA when registering via direct map * Helper method to get the library info from JNA when registering via direct map
*/ */
public
class JnaHelper { class JnaHelper {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
static public static
NativeLibrary register(final String libraryName, final Class<?> clazz) throws IllegalArgumentException { NativeLibrary register(final String libraryName, final Class<?> clazz) throws IllegalArgumentException {
final Map<String, Object> options = new HashMap<String, Object>(); final Map<String, Object> options = new HashMap<String, Object>();
options.put(Library.OPTION_CLASSLOADER, clazz.getClassLoader()); options.put(Library.OPTION_CLASSLOADER, clazz.getClassLoader());

View File

@ -0,0 +1,47 @@
/*
* 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);
}
public static final int LOGPIXELSX = 88;
public static final int LOGPIXELSY = 90;
/**
* 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);
}

View File

@ -0,0 +1,52 @@
/*
* 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);
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import static dorkbox.systemTray.SystemTray.logger; import static dorkbox.systemTray.SystemTray.logger;
@ -22,6 +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;
/** /**
* bindings for libappindicator * bindings for libappindicator

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import dorkbox.util.Keep; import dorkbox.util.Keep;
@Keep @Keep

View File

@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import dorkbox.util.Keep; import dorkbox.util.Keep;
@Keep @Keep

View File

@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import dorkbox.util.Keep; import dorkbox.util.Keep;
@Keep @Keep

View File

@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import dorkbox.util.Keep;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import dorkbox.util.Keep;
@Keep @Keep
public public
class GObjectStruct extends Structure { class GObjectStruct extends Structure {

View File

@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import dorkbox.systemTray.jna.JnaHelper;
/** /**
* bindings for libgthread * bindings for libgthread
* *

View File

@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import dorkbox.util.Keep;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import dorkbox.util.Keep;
@Keep @Keep
public public
class GTypeInstanceStruct extends Structure { class GTypeInstanceStruct extends Structure {

View File

@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import dorkbox.util.Keep;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import dorkbox.util.Keep;
@Keep @Keep
public public
class GdkEventButton extends Structure { class GdkEventButton extends Structure {

View File

@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.NativeLong; import com.sun.jna.NativeLong;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.ptr.PointerByReference; import com.sun.jna.ptr.PointerByReference;
import dorkbox.systemTray.jna.JnaHelper;
/** /**
* bindings for libgobject-2.0 * bindings for libgobject-2.0
* *

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.systemTray.linux.jna; package dorkbox.systemTray.jna.linux;
import static dorkbox.systemTray.SystemTray.logger; import static dorkbox.systemTray.SystemTray.logger;
@ -28,6 +28,7 @@ import dorkbox.systemTray.Action;
import dorkbox.systemTray.Entry; import dorkbox.systemTray.Entry;
import dorkbox.systemTray.Menu; import dorkbox.systemTray.Menu;
import dorkbox.systemTray.SystemTray; import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.jna.JnaHelper;
import dorkbox.systemTray.util.JavaFX; import dorkbox.systemTray.util.JavaFX;
import dorkbox.systemTray.util.Swt; import dorkbox.systemTray.util.Swt;

View File

@ -23,7 +23,7 @@ import com.sun.jna.Pointer;
import dorkbox.systemTray.Entry; import dorkbox.systemTray.Entry;
import dorkbox.systemTray.Menu; import dorkbox.systemTray.Menu;
import dorkbox.systemTray.linux.jna.Gtk; import dorkbox.systemTray.jna.linux.Gtk;
import dorkbox.systemTray.util.ImageUtils; import dorkbox.systemTray.util.ImageUtils;
abstract abstract

View File

@ -21,9 +21,9 @@ import com.sun.jna.NativeLong;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import dorkbox.systemTray.Action; import dorkbox.systemTray.Action;
import dorkbox.systemTray.linux.jna.GCallback; import dorkbox.systemTray.jna.linux.GCallback;
import dorkbox.systemTray.linux.jna.Gobject; import dorkbox.systemTray.jna.linux.Gobject;
import dorkbox.systemTray.linux.jna.Gtk; import dorkbox.systemTray.jna.linux.Gtk;
import dorkbox.systemTray.util.ImageUtils; import dorkbox.systemTray.util.ImageUtils;
class GtkEntryItem extends GtkEntry implements GCallback { class GtkEntryItem extends GtkEntry implements GCallback {

View File

@ -19,7 +19,7 @@ import java.io.File;
import dorkbox.systemTray.Action; import dorkbox.systemTray.Action;
import dorkbox.systemTray.Separator; import dorkbox.systemTray.Separator;
import dorkbox.systemTray.linux.jna.Gtk; import dorkbox.systemTray.jna.linux.Gtk;
class GtkEntrySeparator extends GtkEntry implements Separator { class GtkEntrySeparator extends GtkEntry implements Separator {

View File

@ -16,7 +16,7 @@
package dorkbox.systemTray.nativeUI; package dorkbox.systemTray.nativeUI;
import dorkbox.systemTray.Action; import dorkbox.systemTray.Action;
import dorkbox.systemTray.linux.jna.Gtk; import dorkbox.systemTray.jna.linux.Gtk;
// you might wonder WHY this extends MenuEntryItem -- the reason is that an AppIndicator "status" will be offset from everyone else, // you might wonder WHY this extends MenuEntryItem -- the reason is that an AppIndicator "status" will be offset from everyone else,
// where a GtkStatusIconTray + SwingUI will have everything lined up. (with or without icons). This is to normalize how it looks // where a GtkStatusIconTray + SwingUI will have everything lined up. (with or without icons). This is to normalize how it looks

View File

@ -29,8 +29,8 @@ import dorkbox.systemTray.Action;
import dorkbox.systemTray.Entry; import dorkbox.systemTray.Entry;
import dorkbox.systemTray.Menu; import dorkbox.systemTray.Menu;
import dorkbox.systemTray.SystemTray; import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.linux.jna.Gobject; import dorkbox.systemTray.jna.linux.Gobject;
import dorkbox.systemTray.linux.jna.Gtk; import dorkbox.systemTray.jna.linux.Gtk;
import dorkbox.systemTray.util.MenuBase; import dorkbox.systemTray.util.MenuBase;
class GtkMenu extends MenuBase implements NativeUI { class GtkMenu extends MenuBase implements NativeUI {

View File

@ -21,10 +21,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import dorkbox.systemTray.SystemTray; import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.linux.jna.AppIndicator; import dorkbox.systemTray.jna.linux.AppIndicator;
import dorkbox.systemTray.linux.jna.AppIndicatorInstanceStruct; import dorkbox.systemTray.jna.linux.AppIndicatorInstanceStruct;
import dorkbox.systemTray.linux.jna.Gobject; import dorkbox.systemTray.jna.linux.Gobject;
import dorkbox.systemTray.linux.jna.Gtk; import dorkbox.systemTray.jna.linux.Gtk;
import dorkbox.systemTray.util.ImageUtils; import dorkbox.systemTray.util.ImageUtils;
/** /**

View File

@ -24,10 +24,10 @@ import com.sun.jna.NativeLong;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import dorkbox.systemTray.SystemTray; import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.linux.jna.GEventCallback; import dorkbox.systemTray.jna.linux.GEventCallback;
import dorkbox.systemTray.linux.jna.GdkEventButton; import dorkbox.systemTray.jna.linux.GdkEventButton;
import dorkbox.systemTray.linux.jna.Gobject; import dorkbox.systemTray.jna.linux.Gobject;
import dorkbox.systemTray.linux.jna.Gtk; import dorkbox.systemTray.jna.linux.Gtk;
/** /**
* Class for handling all system tray interactions via GTK. * Class for handling all system tray interactions via GTK.

View File

@ -25,12 +25,12 @@ import com.sun.jna.Pointer;
import com.sun.jna.ptr.PointerByReference; import com.sun.jna.ptr.PointerByReference;
import dorkbox.systemTray.SystemTray; import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.linux.jna.AppIndicator; import dorkbox.systemTray.jna.linux.AppIndicator;
import dorkbox.systemTray.linux.jna.AppIndicatorInstanceStruct; import dorkbox.systemTray.jna.linux.AppIndicatorInstanceStruct;
import dorkbox.systemTray.linux.jna.GEventCallback; import dorkbox.systemTray.jna.linux.GEventCallback;
import dorkbox.systemTray.linux.jna.GdkEventButton; import dorkbox.systemTray.jna.linux.GdkEventButton;
import dorkbox.systemTray.linux.jna.Gobject; import dorkbox.systemTray.jna.linux.Gobject;
import dorkbox.systemTray.linux.jna.Gtk; import dorkbox.systemTray.jna.linux.Gtk;
import dorkbox.systemTray.util.ImageUtils; import dorkbox.systemTray.util.ImageUtils;
import dorkbox.util.SwingUtil; import dorkbox.util.SwingUtil;

View File

@ -28,10 +28,10 @@ import com.sun.jna.NativeLong;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import dorkbox.systemTray.SystemTray; import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.linux.jna.GEventCallback; import dorkbox.systemTray.jna.linux.GEventCallback;
import dorkbox.systemTray.linux.jna.GdkEventButton; import dorkbox.systemTray.jna.linux.GdkEventButton;
import dorkbox.systemTray.linux.jna.Gobject; import dorkbox.systemTray.jna.linux.Gobject;
import dorkbox.systemTray.linux.jna.Gtk; import dorkbox.systemTray.jna.linux.Gtk;
/** /**
* Class for handling all system tray interactions via GTK. * Class for handling all system tray interactions via GTK.

View File

@ -15,6 +15,10 @@
*/ */
package dorkbox.systemTray.util; package dorkbox.systemTray.util;
import static dorkbox.systemTray.jna.Windows.Gdi32.GetDeviceCaps;
import static dorkbox.systemTray.jna.Windows.Gdi32.LOGPIXELSX;
import static dorkbox.systemTray.jna.Windows.Gdi32.LOGPIXELSY;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
@ -35,7 +39,10 @@ import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.ImageInputStream;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import com.sun.jna.Pointer;
import dorkbox.systemTray.SystemTray; import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.jna.Windows.User32;
import dorkbox.util.CacheUtil; import dorkbox.util.CacheUtil;
import dorkbox.util.FileUtil; import dorkbox.util.FileUtil;
import dorkbox.util.LocationResolver; import dorkbox.util.LocationResolver;
@ -91,6 +98,9 @@ class ImageUtils {
} }
} }
// vista - 8.0 - only global DPI settings
// 8.1 - 10 - global + per-monitor DPI settings
// 1 = 16 // 1 = 16
// 2 = 32 // 2 = 32
// 4 = 64 // 4 = 64
@ -124,6 +134,8 @@ class ImageUtils {
} else if (windowsVersion.startsWith("6.3")) { } else if (windowsVersion.startsWith("6.3")) {
// Windows 8.1 // Windows 8.1
// Windows Server 2012 6.3.9200 // Windows Server 2012 6.3.9200
scalingFactor = 4; scalingFactor = 4;
} else if (windowsVersion.startsWith("6.4")) { } else if (windowsVersion.startsWith("6.4")) {
@ -133,15 +145,24 @@ class ImageUtils {
} else if (windowsVersion.startsWith("10.0")) { } else if (windowsVersion.startsWith("10.0")) {
// Windows 10 Technical Preview 4 10.0.9926 // Windows 10 Technical Preview 4 10.0.9926
// Windows 10 Insider Preview 10.0.14915 // Windows 10 Insider Preview 10.0.14915
scalingFactor = 8; scalingFactor = 4;
} else { } else {
// dunnno, but i'm going to assume HiDPI for this... // dunnno, but i'm going to assume HiDPI for this...
scalingFactor = 8; scalingFactor = 8;
} }
Pointer screen = User32.GetDC(null);
int dpiX = GetDeviceCaps (screen, LOGPIXELSX);
int dpiY = GetDeviceCaps (screen, LOGPIXELSY);
User32.ReleaseDC(null, screen);
System.err.println("DPI : " + dpiX + "," + dpiY);
if (SystemTray.DEBUG) { if (SystemTray.DEBUG) {
SystemTray.logger.error("Windows version (partial): '{}'", windowsVersion); SystemTray.logger.debug("Windows version (partial): '{}'", windowsVersion);
} }
} else if (OS.isLinux()) { } else if (OS.isLinux()) {
// GtkStatusIcon will USUALLY automatically scale the icon // GtkStatusIcon will USUALLY automatically scale the icon