jdk/src/java.desktop/unix/native/common/awt/systemscale/systemScale.c
author ssadetsky
Fri, 08 Jul 2016 18:43:12 +0300
changeset 39844 a3cc7e551a48
parent 36869 f8ef78f4157d
child 40996 60d53c39c1b3
permissions -rw-r--r--
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account Reviewed-by: alexsch, azvegint
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"
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    25
#include "jni.h"
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    26
#include "jni_util.h"
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    27
#include "jvm_md.h"
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    28
#include <dlfcn.h>
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    29
#include <stdio.h>
36869
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    30
#include <stdlib.h>
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    31
#include <string.h>
36869
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    32
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    33
typedef void* g_settings_schema_source_get_default();
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    34
typedef void* g_settings_schema_source_ref(void *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    35
typedef void g_settings_schema_source_unref(void *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    36
typedef void* g_settings_schema_source_lookup(void *, char *, int);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    37
typedef int g_settings_schema_has_key(void *, char *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    38
typedef void* g_settings_new_full(void *, void *, char *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    39
typedef void* g_settings_get_value(void *, char *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    40
typedef int g_variant_is_of_type(void *, char *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    41
typedef unsigned long g_variant_n_children(void *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    42
typedef void* g_variant_get_child_value(void *, unsigned long);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    43
typedef void  g_variant_unref(void *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    44
typedef char*  g_variant_get_string(void *, unsigned long *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    45
typedef int  g_variant_get_int32(void *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    46
typedef double  g_variant_get_double(void *);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    47
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    48
static g_settings_schema_has_key* fp_g_settings_schema_has_key;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    49
static g_settings_new_full* fp_g_settings_new_full;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    50
static g_settings_get_value* fp_g_settings_get_value;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    51
static g_variant_is_of_type* fp_g_variant_is_of_type;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    52
static g_variant_n_children* fp_g_variant_n_children;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    53
static g_variant_get_child_value* fp_g_variant_get_child_value;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    54
static g_variant_get_string* fp_g_variant_get_string;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    55
static g_variant_get_int32* fp_g_variant_get_int32;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    56
static g_variant_get_double* fp_g_variant_get_double;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    57
static g_variant_unref* fp_g_variant_unref;
36869
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
    58
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    59
static void* get_schema_value(char *name, char *key) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    60
    static void *lib_handle;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    61
    static int initialized = 0;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    62
    static void * default_schema;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    63
    static g_settings_schema_source_lookup* schema_lookup;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    64
    void *schema = NULL, *fp = NULL;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    65
    if (!initialized) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    66
        initialized = 1;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    67
        lib_handle = dlopen(JNI_LIB_NAME("gio-2.0"), RTLD_GLOBAL | RTLD_LAZY);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    68
        if (!lib_handle) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    69
            CHECK_NULL_RETURN(lib_handle =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    70
                          dlopen(VERSIONED_JNI_LIB_NAME("gio-2.0", "0"),
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    71
                                                RTLD_GLOBAL | RTLD_LAZY), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    72
        }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    73
        CHECK_NULL_RETURN(fp_g_settings_schema_has_key =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    74
                          (g_settings_schema_has_key*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    75
                          dlsym(lib_handle, "g_settings_schema_has_key"), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    76
        CHECK_NULL_RETURN(fp_g_settings_new_full =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    77
                          (g_settings_new_full*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    78
                          dlsym(lib_handle, "g_settings_new_full"), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    79
        CHECK_NULL_RETURN(fp_g_settings_get_value =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    80
                          (g_settings_get_value*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    81
                          dlsym(lib_handle, "g_settings_get_value"), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    82
        CHECK_NULL_RETURN(fp_g_variant_is_of_type =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    83
                          (g_variant_is_of_type*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    84
                          dlsym(lib_handle, "g_variant_is_of_type"), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    85
        CHECK_NULL_RETURN(fp_g_variant_n_children =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    86
                          (g_variant_n_children*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    87
                          dlsym(lib_handle, "g_variant_n_children"), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    88
        CHECK_NULL_RETURN(fp_g_variant_get_child_value =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    89
                          (g_variant_get_child_value*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    90
                          dlsym(lib_handle, "g_variant_get_child_value"), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    91
        CHECK_NULL_RETURN(fp_g_variant_get_string =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    92
                          (g_variant_get_string*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    93
                          dlsym(lib_handle, "g_variant_get_string"), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    94
        CHECK_NULL_RETURN(fp_g_variant_get_int32 =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    95
                          (g_variant_get_int32*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    96
                          dlsym(lib_handle, "g_variant_get_int32"), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    97
        CHECK_NULL_RETURN(fp_g_variant_get_double =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    98
                          (g_variant_get_double*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
    99
                          dlsym(lib_handle, "g_variant_get_double"), NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   100
        CHECK_NULL_RETURN(fp_g_variant_unref =
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   101
                          (g_variant_unref*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   102
                          dlsym(lib_handle, "g_variant_unref"), NULL);
36869
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   103
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   104
        fp = dlsym(lib_handle, "g_settings_schema_source_get_default");
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   105
        if (fp) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   106
            default_schema = ((g_settings_schema_source_get_default*)fp)();
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   107
        }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   108
        if (default_schema) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   109
            fp = dlsym(lib_handle, "g_settings_schema_source_ref");
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   110
            if (fp) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   111
                ((g_settings_schema_source_ref*)fp)(default_schema);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   112
            }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   113
        }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   114
        schema_lookup = (g_settings_schema_source_lookup*)
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   115
                           dlsym(lib_handle, "g_settings_schema_source_lookup");
36869
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   116
    }
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   117
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   118
    if (!default_schema || !schema_lookup) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   119
        return NULL;
36869
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   120
    }
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   121
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   122
    schema = schema_lookup(default_schema, name, 1);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   123
    if (schema) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   124
        if (fp_g_settings_schema_has_key(schema, key)) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   125
            void *settings = fp_g_settings_new_full(schema, NULL, NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   126
            if (settings) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   127
                return fp_g_settings_get_value(settings, key);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   128
            }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   129
        }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   130
    }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   131
    return NULL;
36869
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   132
}
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   133
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   134
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   135
static double getDesktopScale(char *output_name) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   136
    double result = -1;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   137
    if(output_name) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   138
        void *value = get_schema_value("com.ubuntu.user-interface",
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   139
                                                                "scale-factor");
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   140
        if (value) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   141
            if(fp_g_variant_is_of_type(value, "a{si}")) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   142
                int num = fp_g_variant_n_children(value);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   143
                int i = 0;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   144
                while (i < num) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   145
                    void *entry = fp_g_variant_get_child_value(value, i++);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   146
                    if (entry) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   147
                        void *screen = fp_g_variant_get_child_value(entry, 0);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   148
                        void *scale = fp_g_variant_get_child_value(entry, 1);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   149
                        if (screen && scale) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   150
                            char *name = fp_g_variant_get_string(screen, NULL);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   151
                            if (name && strcmp(name, output_name)) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   152
                                result = fp_g_variant_get_int32(scale) / 8.;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   153
                            }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   154
                            fp_g_variant_unref(screen);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   155
                            fp_g_variant_unref(scale);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   156
                        }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   157
                        fp_g_variant_unref(entry);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   158
                    }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   159
                    if (result > 0) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   160
                        break;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   161
                    }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   162
                }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   163
            }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   164
            fp_g_variant_unref(value);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   165
        }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   166
        if (result > 0) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   167
            value = get_schema_value("com.canonical.Unity.Interface",
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   168
                                                           "text-scale-factor");
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   169
            if (value && fp_g_variant_is_of_type(value, "d")) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   170
                result *= fp_g_variant_get_double(value);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   171
                fp_g_variant_unref(value);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   172
            }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   173
        }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   174
    }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   175
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   176
    if (result <= 0) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   177
        void *value = get_schema_value("org.gnome.desktop.interface",
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   178
                                                         "text-scaling-factor");
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   179
        if (value && fp_g_variant_is_of_type(value, "d")) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   180
            result = fp_g_variant_get_double(value);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   181
            fp_g_variant_unref(value);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   182
        }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   183
    }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   184
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   185
    return result;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   186
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   187
}
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   188
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   189
static int getScale(const char *name) {
36869
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   190
    char *uiScale = getenv(name);
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   191
    if (uiScale != NULL) {
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   192
        double scale = strtod(uiScale, NULL);
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   193
        if (scale < 1) {
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   194
            return -1;
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   195
        }
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   196
        return (int) scale;
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   197
    }
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   198
    return -1;
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   199
}
f8ef78f4157d 8145174: HiDPI splash screen support on Linux
rchamyal
parents:
diff changeset
   200
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   201
double getNativeScaleFactor(char *output_name) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   202
    static int scale = -2.0;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   203
    double native_scale = 0;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   204
    int gdk_scale = 0;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   205
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   206
    if (scale == -2) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   207
        scale = getScale("J2D_UISCALE");
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   208
    }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   209
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   210
    if (scale > 0) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   211
        return scale;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   212
    }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   213
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   214
    native_scale = getDesktopScale(output_name);
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   215
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   216
    if (native_scale <= 0) {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   217
        native_scale = 1;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   218
    }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   219
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   220
    gdk_scale = getScale("GDK_SCALE");
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   221
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   222
    return gdk_scale > 0 ? native_scale * gdk_scale : native_scale;
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 36869
diff changeset
   223
}