231 lines
6.9 KiB
Diff
231 lines
6.9 KiB
Diff
From 85ff3ca6b09f8fb72cb070ae21105c8a4d058234 Mon Sep 17 00:00:00 2001
|
||
From: wangxiaoqing <wangxiaoqing@kylinos.com.cn>
|
||
Date: Fri, 22 May 2020 19:11:59 +0800
|
||
Subject: [PATCH] add the gdk window scale settings
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
- 添加gdk窗口缩放设置接口,Related #25310
|
||
---
|
||
libmate-desktop/mate-rr-config.c | 61 ++++++++++++++++++++++++---
|
||
libmate-desktop/mate-rr-output-info.c | 14 ++++++
|
||
libmate-desktop/mate-rr-private.h | 2 +
|
||
3 files changed, 71 insertions(+), 6 deletions(-)
|
||
|
||
diff --git a/libmate-desktop/mate-rr-config.c b/libmate-desktop/mate-rr-config.c
|
||
index 3609292..d2831df 100644
|
||
--- a/libmate-desktop/mate-rr-config.c
|
||
+++ b/libmate-desktop/mate-rr-config.c
|
||
@@ -44,6 +44,9 @@
|
||
#define CONFIG_INTENDED_BASENAME "monitors.xml"
|
||
#define CONFIG_BACKUP_BASENAME "monitors.xml.backup"
|
||
|
||
+#define MSD_INTERFACE_SCHEMA "org.mate.interface"
|
||
+#define WINDOW_SCALE_KEY "window-scaling-factor"
|
||
+
|
||
/* In version 0 of the config file format, we had several <configuration>
|
||
* toplevel elements and no explicit version number. So, the filed looked
|
||
* like
|
||
@@ -341,6 +344,21 @@ handle_text (GMarkupParseContext *context,
|
||
parser->output->priv->rotation |= MATE_RR_ROTATION_270;
|
||
}
|
||
}
|
||
+ else if (stack_is (parser, "scale", "output", "configuration", TOPLEVEL_ELEMENT, NULL))
|
||
+ {
|
||
+ if (strcmp (text, "100%") == 0)
|
||
+ {
|
||
+ parser->output->priv->scale = 1;
|
||
+ }
|
||
+ else if (strcmp (text, "200%") == 0)
|
||
+ {
|
||
+ parser->output->priv->scale = 2;
|
||
+ }
|
||
+ else
|
||
+ {
|
||
+ parser->output->priv->scale = 0;
|
||
+ }
|
||
+ }
|
||
else if (stack_is (parser, "reflect_x", "output", "configuration", TOPLEVEL_ELEMENT, NULL))
|
||
{
|
||
if (strcmp (text, "yes") == 0)
|
||
@@ -454,6 +472,7 @@ mate_rr_config_init (MateRRConfig *self)
|
||
self->priv->clone = FALSE;
|
||
self->priv->screen = NULL;
|
||
self->priv->outputs = NULL;
|
||
+ self->priv->ws_settings = g_settings_new (MSD_INTERFACE_SCHEMA);
|
||
}
|
||
|
||
static void
|
||
@@ -487,6 +506,8 @@ mate_rr_config_finalize (GObject *gobject)
|
||
}
|
||
g_free (self->priv->outputs);
|
||
}
|
||
+
|
||
+ g_object_unref (self->priv->ws_settings);
|
||
|
||
G_OBJECT_CLASS (mate_rr_config_parent_class)->finalize (gobject);
|
||
}
|
||
@@ -500,6 +521,7 @@ mate_rr_config_load_current (MateRRConfig *config, GError **error)
|
||
int clone_width = -1;
|
||
int clone_height = -1;
|
||
int last_x;
|
||
+ int scale = 0;
|
||
|
||
g_return_val_if_fail (MATE_IS_RR_CONFIG (config), FALSE);
|
||
|
||
@@ -507,6 +529,9 @@ mate_rr_config_load_current (MateRRConfig *config, GError **error)
|
||
rr_outputs = mate_rr_screen_list_outputs (config->priv->screen);
|
||
|
||
config->priv->clone = FALSE;
|
||
+
|
||
+ /*window scale for gdk */
|
||
+ scale = g_settings_get_int(config->priv->ws_settings, WINDOW_SCALE_KEY);
|
||
|
||
for (i = 0; rr_outputs[i] != NULL; ++i)
|
||
{
|
||
@@ -519,6 +544,7 @@ mate_rr_config_load_current (MateRRConfig *config, GError **error)
|
||
output->priv->name = g_strdup (mate_rr_output_get_name (rr_output));
|
||
output->priv->connected = mate_rr_output_is_connected (rr_output);
|
||
output->priv->hotplug_mode_update = mate_rr_output_has_hotplug_mode_update (rr_output);
|
||
+ output->priv->scale = scale;
|
||
|
||
if (!output->priv->connected)
|
||
{
|
||
@@ -962,6 +988,7 @@ make_outputs (MateRRConfig *config)
|
||
new->priv->width = first_on->priv->width;
|
||
new->priv->height = first_on->priv->height;
|
||
new->priv->rotation = first_on->priv->rotation;
|
||
+ new->priv->scale = first_on->priv->scale;
|
||
new->priv->x = 0;
|
||
new->priv->y = 0;
|
||
}
|
||
@@ -1045,6 +1072,17 @@ get_rotation_name (MateRRRotation r)
|
||
return "normal";
|
||
}
|
||
|
||
+static const char *
|
||
+get_scale_name (int scale)
|
||
+{
|
||
+ if ( scale == 2)
|
||
+ return "200%";
|
||
+ if ( scale == 1)
|
||
+ return "100%";
|
||
+
|
||
+ return "auto";
|
||
+}
|
||
+
|
||
static const char *
|
||
yes_no (int x)
|
||
{
|
||
@@ -1105,6 +1143,8 @@ emit_configuration (MateRRConfig *config,
|
||
string, " <y>%d</y>\n", output->priv->y);
|
||
g_string_append_printf (
|
||
string, " <rotation>%s</rotation>\n", get_rotation_name (output->priv->rotation));
|
||
+ g_string_append_printf (
|
||
+ string, " <scale>%s</scale>\n", get_scale_name (output->priv->scale));
|
||
g_string_append_printf (
|
||
string, " <reflect_x>%s</reflect_x>\n", get_reflect_x (output->priv->rotation));
|
||
g_string_append_printf (
|
||
@@ -1279,6 +1319,14 @@ mate_rr_config_save (MateRRConfig *configuration, GError **error)
|
||
return result;
|
||
}
|
||
|
||
+struct CrtcAssignment
|
||
+{
|
||
+ MateRRScreen *screen;
|
||
+ GHashTable *info;
|
||
+ MateRROutput *primary;
|
||
+ int scale;
|
||
+};
|
||
+
|
||
gboolean
|
||
mate_rr_config_apply_with_time (MateRRConfig *config,
|
||
MateRRScreen *screen,
|
||
@@ -1307,10 +1355,14 @@ mate_rr_config_apply_with_time (MateRRConfig *config,
|
||
if (crtc_assignment_apply (assignment, timestamp, error))
|
||
result = TRUE;
|
||
|
||
+ g_settings_set_int(config->priv->ws_settings, WINDOW_SCALE_KEY, assignment->scale);
|
||
+
|
||
crtc_assignment_free (assignment);
|
||
|
||
display = gdk_display_get_default ();
|
||
gdk_display_flush (display);
|
||
+
|
||
+
|
||
}
|
||
|
||
return result;
|
||
@@ -1439,12 +1491,6 @@ struct CrtcInfo
|
||
GPtrArray *outputs;
|
||
};
|
||
|
||
-struct CrtcAssignment
|
||
-{
|
||
- MateRRScreen *screen;
|
||
- GHashTable *info;
|
||
- MateRROutput *primary;
|
||
-};
|
||
|
||
static gboolean
|
||
can_clone (CrtcInfo *info,
|
||
@@ -1693,6 +1739,9 @@ real_assign_crtcs (MateRRScreen *screen,
|
||
tried_mode = FALSE;
|
||
accumulated_error = g_string_new (NULL);
|
||
|
||
+ /* all outputs use a scale */
|
||
+ assignment->scale = output->priv->scale;
|
||
+
|
||
for (i = 0; crtcs[i] != NULL; ++i)
|
||
{
|
||
MateRRCrtc *crtc = crtcs[i];
|
||
diff --git a/libmate-desktop/mate-rr-output-info.c b/libmate-desktop/mate-rr-output-info.c
|
||
index 85ee50b..3c56930 100644
|
||
--- a/libmate-desktop/mate-rr-output-info.c
|
||
+++ b/libmate-desktop/mate-rr-output-info.c
|
||
@@ -162,6 +162,20 @@ void mate_rr_output_info_set_rotation (MateRROutputInfo *self, MateRRRotation ro
|
||
self->priv->rotation = rotation;
|
||
}
|
||
|
||
+int mate_rr_output_info_get_scale (MateRROutputInfo *self)
|
||
+{
|
||
+ g_return_val_if_fail (MATE_IS_RR_OUTPUT_INFO (self), 0);
|
||
+
|
||
+ return self->priv->scale;
|
||
+}
|
||
+
|
||
+void mate_rr_output_info_set_scale (MateRROutputInfo *self, int scale)
|
||
+{
|
||
+ g_return_if_fail (MATE_IS_RR_OUTPUT_INFO (self));
|
||
+
|
||
+ self->priv->scale = scale;
|
||
+}
|
||
+
|
||
/**
|
||
* mate_rr_output_info_is_connected:
|
||
*
|
||
diff --git a/libmate-desktop/mate-rr-private.h b/libmate-desktop/mate-rr-private.h
|
||
index fa14368..ee3ec42 100644
|
||
--- a/libmate-desktop/mate-rr-private.h
|
||
+++ b/libmate-desktop/mate-rr-private.h
|
||
@@ -60,6 +60,7 @@ struct MateRROutputInfoPrivate
|
||
int x;
|
||
int y;
|
||
MateRRRotation rotation;
|
||
+ int scale;
|
||
|
||
gboolean connected;
|
||
gchar vendor[4];
|
||
@@ -78,6 +79,7 @@ struct MateRRConfigPrivate
|
||
gboolean clone;
|
||
MateRRScreen *screen;
|
||
MateRROutputInfo **outputs;
|
||
+ GSettings *ws_settings;
|
||
};
|
||
|
||
gboolean _mate_rr_output_name_is_laptop (const char *name);
|
||
--
|
||
2.20.1
|
||
|