~fourdollars/unity-settings-daemon/add-hidpi-support

« back to all changes in this revision

Viewing changes to plugins/xsettings/gsd-xsettings-manager.c

  • Committer: Shih-Yuan Lee (FourDollars)
  • Author(s): Bastien Nocera
  • Date: 2015-01-14 09:24:46 UTC
  • Revision ID: sylee@canonical.com-20150114092446-u0rvrhnkgac3bjl5
xsettings: Check native resolution for scaling factor

Check whether the panel is running at its native resolution before
applying the scaling factor. We don't want hi-dpi screens running
below native resolution to have a high scaling factor.

https://bugzilla.gnome.org/show_bug.cgi?id=709859

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <gdk/gdkx.h>
39
39
#include <gtk/gtk.h>
40
40
 
 
41
#define GNOME_DESKTOP_USE_UNSTABLE_API
 
42
 
 
43
#include <libgnome-desktop/gnome-rr-config.h>
 
44
#include <libgnome-desktop/gnome-rr.h>
 
45
#include <libgnome-desktop/gnome-pnp-ids.h>
 
46
 
41
47
#include "gnome-settings-profile.h"
42
48
#include "gsd-enums.h"
43
49
#include "gsd-xsettings-manager.h"
433
439
        return dpi * factor;
434
440
}
435
441
 
 
442
static gboolean
 
443
primary_monitor_at_native_resolution (void)
 
444
{
 
445
        GnomeRRScreen *screen;
 
446
        GnomeRROutput *primary = NULL;
 
447
        GnomeRROutput **outputs;
 
448
        int current_width, current_height;
 
449
        int pref_width, pref_height;
 
450
        gboolean native = TRUE;
 
451
        GnomeRRMode *mode;
 
452
        guint i;
 
453
 
 
454
        screen = gnome_rr_screen_new (gdk_screen_get_default (), NULL);
 
455
        if (screen == NULL)
 
456
                goto out;
 
457
 
 
458
        outputs = gnome_rr_screen_list_outputs (screen);
 
459
        if (outputs == NULL || outputs[0] == NULL)
 
460
                goto out;
 
461
        for (i = 0; outputs[i] != NULL; i++) {
 
462
                if (gnome_rr_output_get_is_primary (outputs[i])) {
 
463
                        primary = outputs[i];
 
464
                        break;
 
465
                }
 
466
        }
 
467
        if (primary == NULL)
 
468
                primary = outputs[0];
 
469
 
 
470
        mode = gnome_rr_output_get_current_mode (primary);
 
471
        current_width = gnome_rr_mode_get_width (mode);
 
472
        current_height = gnome_rr_mode_get_height (mode);
 
473
        mode = gnome_rr_output_get_preferred_mode (primary);
 
474
        pref_width = gnome_rr_mode_get_width (mode);
 
475
        pref_height = gnome_rr_mode_get_height (mode);
 
476
        if (current_width != pref_width || current_height != pref_height)
 
477
                native = FALSE;
 
478
 
 
479
out:
 
480
        g_clear_object (&screen);
 
481
        return native;
 
482
}
 
483
 
436
484
static int
437
485
get_window_scale (GnomeXSettingsManager *manager)
438
486
{
451
499
        if (window_scale == 0) {
452
500
                int primary;
453
501
 
 
502
                window_scale = 1;
 
503
                if (!primary_monitor_at_native_resolution ())
 
504
                        goto out;
 
505
 
454
506
                display = gdk_display_get_default ();
455
507
                screen = gdk_display_get_default_screen (display);
456
508
                primary = gdk_screen_get_primary_monitor (screen);
471
523
                }
472
524
        }
473
525
 
 
526
out:
474
527
        return window_scale;
475
528
}
476
529