From 1cca4936a347ad4c7c81e18fcf913e6b393a2994 Mon Sep 17 00:00:00 2001 From: zhuyaliang <15132211195@163.com> Date: Thu, 4 Mar 2021 10:29:23 +0800 Subject: Add adjust window scaling function for display preference and update display-capplet.ui file --- capplets/display/display-capplet.ui | 351 ++++++++++++++++++++---------------- capplets/display/ui-a11y.suppr | 1 + capplets/display/xrandr-capplet.c | 63 +++++++ 3 files changed, 256 insertions(+), 159 deletions(-) diff --git a/capplets/display/display-capplet.ui b/capplets/display/display-capplet.ui index 95f51ba8..be905a8b 100644 --- a/capplets/display/display-capplet.ui +++ b/capplets/display/display-capplet.ui @@ -1,16 +1,16 @@ - + True - False - gtk-apply + False + gtk-apply True - False - help-browser + False + help-browser @@ -34,34 +34,34 @@ True - False - window-close + False + window-close - False - 5 + False + 5 Monitor Preferences - dialog + dialog True - False + False vertical 2 True - False - end + False + end _Help True - True - True - False + True + True + False help_button_img - True + True False @@ -74,10 +74,10 @@ Apply system-wide True - True - True - Applies the current configuration for other MATE users on the computer. Note that this doesn't affect login screens or other desktop environments. - True + True + True + Applies the current configuration for other MATE users on the computer. Note that this doesn't affect login screens or other desktop environments. + True False @@ -89,11 +89,11 @@ _Apply True - True - True - False + True + True + False apply_button_img - True + True False @@ -105,11 +105,11 @@ _Close True - True - True - False + True + True + False window_close_button_img - True + True False @@ -121,26 +121,27 @@ False True - end + end 0 + True - False - 12 - 12 + False + 12 + 12 True - False + False vertical 12 True - False + False @@ -154,16 +155,16 @@ True - False + False 12 Sa_me image in all monitors True - True - False - True - True + True + False + True + True False @@ -175,14 +176,14 @@ _Detect monitors True - True - True - True + True + True + True False False - end + end 1 @@ -195,134 +196,85 @@ - 0 - 0 - - - - - True - False - vertical - - - True - False - Panel icon - 0 - - - - - - False - False - 0 - - - - - True - False - 12 - - - _Show monitors in panel - True - True - False - start - True - True - - - - - False - False - 1 - - - - - 0 - 1 + 0 + 0 True - False + False 0 0 + True - False - 6 - 12 + False + 6 + 12 True - False + False _Resolution: - True - resolution_combo + True + resolution_combo 0 - 0 - 3 + 0 + 3 True - False + False Re_fresh rate: - True - refresh_combo + True + refresh_combo 0 - 0 - 4 + 0 + 4 True - False + False - 1 - 3 + 1 + 3 True - False + False - 1 - 4 + 1 + 4 True - False + False 12 On True - True - False - True + True + False + True True - True + True False @@ -334,10 +286,10 @@ Off True - True - False - True - True + True + False + True + True monitor_on_radio @@ -348,14 +300,14 @@ - 0 - 1 + 0 + 1 True - False + False liststore1 @@ -365,34 +317,34 @@ - 1 - 5 + 1 + 5 Include _panel - True - False - True - True + True + False + True + True - 0 - 6 + 0 + 6 True - False + False - 1 - 5 + 1 + 5 @@ -400,39 +352,39 @@ Set as primary True False - True - True - Sets the selected monitor as primary. + True + True + Sets the selected monitor as primary. - 0 - 2 + 0 + 2 2 True - False + False R_otation: - True - rotation_combo + True + rotation_combo 0 - 0 - 5 + 0 + 5 True - False - False + False + False True - False + False Monitor 0 @@ -442,8 +394,8 @@ - 0 - 0 + 0 + 0 2 @@ -457,10 +409,94 @@ - 1 - 0 + 1 + 0 + + + True + False + vertical + + + True + False + Panel icon + 0 + + + + + + False + False + 0 + + + + + True + False + 12 + + + _Show monitors in panel + True + True + False + start + True + True + + + + + False + False + 1 + + + + + 0 + 2 + + + + + True + False + vertical + 12 + + + True + False + Scaling + 0 + + + + + + False + False + 0 + + + + + + + + 0 + 1 + + + + + @@ -479,8 +515,5 @@ apply_button button2 - - - diff --git a/capplets/display/ui-a11y.suppr b/capplets/display/ui-a11y.suppr index 318cde7c..f75c8d3b 100644 --- a/capplets/display/ui-a11y.suppr +++ b/capplets/display/ui-a11y.suppr @@ -1,2 +1,3 @@ display-capplet.ui://GtkLabel[@id='label8'] orphan-label +display-capplet.ui://GtkLabel[@id='label9'] orphan-label display-capplet.ui://GtkLabel[@id='current_monitor_label'] orphan-label diff --git a/capplets/display/xrandr-capplet.c b/capplets/display/xrandr-capplet.c index dea2614a..012d8936 100644 --- a/capplets/display/xrandr-capplet.c +++ b/capplets/display/xrandr-capplet.c @@ -38,6 +38,9 @@ #include "capplet-util.h" +#define MATE_INTERFACE_SCHEMA "org.mate.interface" +#define WINDOW_SCALE_KEY "window-scaling-factor" + typedef struct App App; typedef struct GrabInfo GrabInfo; @@ -58,6 +61,8 @@ struct App GtkWidget *refresh_combo; GtkWidget *rotation_combo; GtkWidget *panel_checkbox; + GtkWidget *scale_vbox; + GtkWidget *scale_bbox; GtkWidget *clone_checkbox; GtkWidget *show_icon_checkbox; GtkWidget *primary_button; @@ -69,6 +74,7 @@ struct App GtkWidget *area; gboolean ignore_gui_changes; GSettings *settings; + GSettings *scale_settings; /* These are used while we are waiting for the ApplyConfiguration method to be executed over D-bus */ GDBusConnection *connection; @@ -452,6 +458,58 @@ mirror_screens_is_supported (App *app) return mirror_is_supported; } +static void +on_scale_btn_active_changed_cb (GtkWidget *widget, + App *app) +{ + gint scale; + + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) + return; + + scale = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "scale")); + g_settings_set_int (app->scale_settings, WINDOW_SCALE_KEY, scale); +} + +static void +rebuild_scale_window (App *app) +{ + GtkRadioButton *group = NULL; + gint32 scale; + int i; + const char *button_label[] = {_("auto detect"), _("100%"), _("200%"), NULL}; + + if (app->scale_bbox != NULL) + return; + + app->scale_bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); + gtk_container_set_border_width (GTK_CONTAINER (app->scale_bbox), 6); + gtk_container_add (GTK_CONTAINER (app->scale_vbox), app->scale_bbox); + + scale = g_settings_get_int (app->scale_settings, WINDOW_SCALE_KEY); + + for (i = 0; button_label[i] != NULL; i++) + { + GtkWidget *scale_btn; + scale_btn = gtk_radio_button_new_with_label_from_widget (group, button_label[i]); + if (!group) + group = GTK_RADIO_BUTTON (scale_btn); + if (i == scale) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scale_btn), TRUE); + + g_object_set_data (G_OBJECT (scale_btn), + "scale", + GINT_TO_POINTER (i)); + + g_signal_connect (scale_btn, + "toggled", + G_CALLBACK (on_scale_btn_active_changed_cb), + app); + gtk_container_add (GTK_CONTAINER (app->scale_bbox), scale_btn); + } + gtk_widget_show_all (app->scale_bbox); +} + static void rebuild_mirror_screens (App *app) { @@ -646,6 +704,7 @@ rebuild_gui (App *app) #endif rebuild_mirror_screens (app); + rebuild_scale_window (app); rebuild_current_monitor_label (app); rebuild_on_off_radios (app); rebuild_resolution_combo (app); @@ -2397,6 +2456,7 @@ run_application (App *app) } app->settings = g_settings_new (MSD_XRANDR_SCHEMA); + app->scale_settings = g_settings_new (MATE_INTERFACE_SCHEMA); app->dialog = _gtk_builder_get_widget (builder, "dialog"); g_signal_connect_after (app->dialog, "map-event", @@ -2433,6 +2493,8 @@ run_application (App *app) g_signal_connect (app->rotation_combo, "changed", G_CALLBACK (on_rotation_changed), app); + app->scale_vbox = _gtk_builder_get_widget (builder, "scale_vbox"); + app->clone_checkbox = _gtk_builder_get_widget (builder, "clone_checkbox"); g_signal_connect (app->clone_checkbox, "toggled", G_CALLBACK (on_clone_changed), app); @@ -2526,6 +2588,7 @@ restart: gtk_widget_destroy (app->dialog); g_object_unref (app->screen); g_object_unref (app->settings); + g_object_unref (app->scale_settings); } int -- cgit v1.2.1