jdk/src/java.desktop/unix/native/common/awt/systemscale/systemScale.c
author rchamyal
Fri, 11 Mar 2016 11:00:38 +0530
changeset 36869 f8ef78f4157d
child 39844 a3cc7e551a48
permissions -rw-r--r--
8145174: HiDPI splash screen support on Linux Reviewed-by: serb, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36869
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
     1
/*
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
     2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
     4
*
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
     7
* published by the Free Software Foundation.
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
     8
*
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    13
* accompanied this code).
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    14
*
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    18
*
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    21
* questions.
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    22
*/
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    23
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    24
#include "systemScale.h"
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    25
#include <stdlib.h>
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    26
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    27
int getNativeScaleFactor() {
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    28
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    29
    static int scale = -2.0;
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    30
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    31
    if (scale == -2) {
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    32
        scale = getScale("J2D_UISCALE");
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    33
    }
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    34
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    35
    if (scale >= 1) {
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    36
        return (int) scale;
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    37
    }
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    38
    return getScale("GDK_SCALE");
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    39
}
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    40
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    41
int getScale(const char *name) {
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    42
    char *uiScale = getenv(name);
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    43
    if (uiScale != NULL) {
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    44
        double scale = strtod(uiScale, NULL);
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    45
        if (scale < 1) {
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    46
            return -1;
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    47
        }
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    48
        return (int) scale;
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    49
    }
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    50
    return -1;
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    51
}
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    52