| 1 |
/* |
| 2 |
* Copyright © 2010 Intel Corporation |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Library General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Library General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Library General Public |
| 15 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#include <glib.h> |
| 24 |
#include <gio/gio.h> |
| 25 |
#include "gdkscreenprivate.h" |
| 26 |
#include "gdkvisualprivate.h" |
| 27 |
#include "gdkdisplay.h" |
| 28 |
#include "gdkdisplay-wayland.h" |
| 29 |
#include "gdkmonitor-wayland.h" |
| 30 |
#include "gdkwayland.h" |
| 31 |
#include "gdkprivate-wayland.h" |
| 32 |
#include "gdk-private.h" |
| 33 |
|
| 34 |
#include "wm-button-layout-translation.h" |
| 35 |
|
| 36 |
typedef struct _GdkWaylandScreen GdkWaylandScreen; |
| 37 |
typedef struct _GdkWaylandScreenClass GdkWaylandScreenClass; |
| 38 |
|
| 39 |
#define GDK_TYPE_WAYLAND_SCREEN (_gdk_wayland_screen_get_type ()) |
| 40 |
#define GDK_WAYLAND_SCREEN(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WAYLAND_SCREEN, GdkWaylandScreen)) |
| 41 |
#define GDK_WAYLAND_SCREEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_WAYLAND_SCREEN, GdkWaylandScreenClass)) |
| 42 |
#define GDK_IS_WAYLAND_SCREEN(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_WAYLAND_SCREEN)) |
| 43 |
#define GDK_IS_WAYLAND_SCREEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_WAYLAND_SCREEN)) |
| 44 |
#define GDK_WAYLAND_SCREEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_WAYLAND_SCREEN, GdkWaylandScreenClass)) |
| 45 |
|
| 46 |
typedef struct { |
| 47 |
gboolean antialias; |
| 48 |
gboolean hinting; |
| 49 |
gint dpi; |
| 50 |
const gchar *rgba; |
| 51 |
const gchar *hintstyle; |
| 52 |
} GsdXftSettings; |
| 53 |
|
| 54 |
typedef struct { |
| 55 |
guint fontconfig_timestamp; |
| 56 |
gchar *modules; |
| 57 |
} GsdExtSettings; |
| 58 |
|
| 59 |
struct _GdkWaylandScreen |
| 60 |
{ |
| 61 |
GdkScreen parent_instance; |
| 62 |
|
| 63 |
GdkDisplay *display; |
| 64 |
GdkWindow *root_window; |
| 65 |
|
| 66 |
int width, height; |
| 67 |
int width_mm, height_mm; |
| 68 |
|
| 69 |
/* Visual Part */ |
| 70 |
GdkVisual *visual; |
| 71 |
|
| 72 |
GHashTable *settings; |
| 73 |
GsdXftSettings xft_settings; |
| 74 |
GsdExtSettings dbus_settings; |
| 75 |
GDBusProxy *settings_portal; |
| 76 |
|
| 77 |
GDBusProxy *dbus_proxy; |
| 78 |
GCancellable *dbus_cancellable; |
| 79 |
gulong dbus_setting_change_id; |
| 80 |
|
| 81 |
guint32 shell_capabilities; |
| 82 |
}; |
| 83 |
|
| 84 |
struct _GdkWaylandScreenClass |
| 85 |
{ |
| 86 |
GdkScreenClass parent_class; |
| 87 |
}; |
| 88 |
|
| 89 |
#define OUTPUT_VERSION_WITH_DONE 2 |
| 90 |
#define NO_XDG_OUTPUT_DONE_SINCE_VERSION 3 |
| 91 |
|
| 92 |
#define GTK_SETTINGS_DBUS_PATH "/org/gtk/Settings" |
| 93 |
#define GTK_SETTINGS_DBUS_NAME "org.gtk.Settings" |
| 94 |
|
| 95 |
GType _gdk_wayland_screen_get_type (void); |
| 96 |
|
| 97 |
G_DEFINE_TYPE (GdkWaylandScreen, _gdk_wayland_screen, GDK_TYPE_SCREEN) |
| 98 |
|
| 99 |
static void |
| 100 |
gdk_wayland_screen_dispose (GObject *object) |
| 101 |
{ |
| 102 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (object); |
| 103 |
|
| 104 |
if (screen_wayland->dbus_proxy && screen_wayland->dbus_setting_change_id > 0) |
| 105 |
{ |
| 106 |
g_signal_handler_disconnect (screen_wayland->dbus_proxy, |
| 107 |
screen_wayland->dbus_setting_change_id); |
| 108 |
screen_wayland->dbus_setting_change_id = 0; |
| 109 |
} |
| 110 |
|
| 111 |
g_cancellable_cancel (screen_wayland->dbus_cancellable); |
| 112 |
|
| 113 |
if (screen_wayland->root_window) |
| 114 |
_gdk_window_destroy (screen_wayland->root_window, FALSE); |
| 115 |
|
| 116 |
G_OBJECT_CLASS (_gdk_wayland_screen_parent_class)->dispose (object); |
| 117 |
} |
| 118 |
|
| 119 |
static void |
| 120 |
gdk_wayland_screen_finalize (GObject *object) |
| 121 |
{ |
| 122 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (object); |
| 123 |
|
| 124 |
g_clear_object (&screen_wayland->dbus_proxy); |
| 125 |
g_clear_object (&screen_wayland->dbus_cancellable); |
| 126 |
|
| 127 |
if (screen_wayland->root_window) |
| 128 |
g_object_unref (screen_wayland->root_window); |
| 129 |
|
| 130 |
g_object_unref (screen_wayland->visual); |
| 131 |
|
| 132 |
if (screen_wayland->settings) |
| 133 |
g_hash_table_destroy (screen_wayland->settings); |
| 134 |
|
| 135 |
g_clear_object (&screen_wayland->settings_portal); |
| 136 |
|
| 137 |
g_free (screen_wayland->dbus_settings.modules); |
| 138 |
|
| 139 |
G_OBJECT_CLASS (_gdk_wayland_screen_parent_class)->finalize (object); |
| 140 |
} |
| 141 |
|
| 142 |
static GdkDisplay * |
| 143 |
gdk_wayland_screen_get_display (GdkScreen *screen) |
| 144 |
{ |
| 145 |
return GDK_WAYLAND_SCREEN (screen)->display; |
| 146 |
} |
| 147 |
|
| 148 |
static gint |
| 149 |
gdk_wayland_screen_get_width (GdkScreen *screen) |
| 150 |
{ |
| 151 |
return GDK_WAYLAND_SCREEN (screen)->width; |
| 152 |
} |
| 153 |
|
| 154 |
static gint |
| 155 |
gdk_wayland_screen_get_height (GdkScreen *screen) |
| 156 |
{ |
| 157 |
return GDK_WAYLAND_SCREEN (screen)->height; |
| 158 |
} |
| 159 |
|
| 160 |
static gint |
| 161 |
gdk_wayland_screen_get_width_mm (GdkScreen *screen) |
| 162 |
{ |
| 163 |
return GDK_WAYLAND_SCREEN (screen)->width_mm; |
| 164 |
} |
| 165 |
|
| 166 |
static gint |
| 167 |
gdk_wayland_screen_get_height_mm (GdkScreen *screen) |
| 168 |
{ |
| 169 |
return GDK_WAYLAND_SCREEN (screen)->height_mm; |
| 170 |
} |
| 171 |
|
| 172 |
static gint |
| 173 |
gdk_wayland_screen_get_number (GdkScreen *screen) |
| 174 |
{ |
| 175 |
return 0; |
| 176 |
} |
| 177 |
|
| 178 |
static GdkWindow * |
| 179 |
gdk_wayland_screen_get_root_window (GdkScreen *screen) |
| 180 |
{ |
| 181 |
return GDK_WAYLAND_SCREEN (screen)->root_window; |
| 182 |
} |
| 183 |
|
| 184 |
static GdkVisual * |
| 185 |
gdk_wayland_screen_get_system_visual (GdkScreen * screen) |
| 186 |
{ |
| 187 |
return (GdkVisual *) GDK_WAYLAND_SCREEN (screen)->visual; |
| 188 |
} |
| 189 |
|
| 190 |
static GdkVisual * |
| 191 |
gdk_wayland_screen_get_rgba_visual (GdkScreen *screen) |
| 192 |
{ |
| 193 |
return (GdkVisual *) GDK_WAYLAND_SCREEN (screen)->visual; |
| 194 |
} |
| 195 |
|
| 196 |
static gboolean |
| 197 |
gdk_wayland_screen_is_composited (GdkScreen *screen) |
| 198 |
{ |
| 199 |
return TRUE; |
| 200 |
} |
| 201 |
|
| 202 |
static gchar * |
| 203 |
gdk_wayland_screen_make_display_name (GdkScreen *screen) |
| 204 |
{ |
| 205 |
return g_strdup (gdk_display_get_name (GDK_WAYLAND_SCREEN (screen)->display)); |
| 206 |
} |
| 207 |
|
| 208 |
static GdkWindow * |
| 209 |
gdk_wayland_screen_get_active_window (GdkScreen *screen) |
| 210 |
{ |
| 211 |
return NULL; |
| 212 |
} |
| 213 |
|
| 214 |
static GList * |
| 215 |
gdk_wayland_screen_get_window_stack (GdkScreen *screen) |
| 216 |
{ |
| 217 |
return NULL; |
| 218 |
} |
| 219 |
|
| 220 |
static void |
| 221 |
gdk_wayland_screen_broadcast_client_message (GdkScreen *screen, |
| 222 |
GdkEvent *event) |
| 223 |
{ |
| 224 |
} |
| 225 |
|
| 226 |
static void |
| 227 |
notify_setting (GdkScreen *screen, |
| 228 |
const gchar *setting) |
| 229 |
{ |
| 230 |
GdkEvent event; |
| 231 |
|
| 232 |
event.type = GDK_SETTING; |
| 233 |
event.setting.window = gdk_screen_get_root_window (screen); |
| 234 |
event.setting.send_event = FALSE; |
| 235 |
event.setting.action = GDK_SETTING_ACTION_CHANGED; |
| 236 |
event.setting.name = (gchar *)setting; |
| 237 |
gdk_event_put (&event); |
| 238 |
} |
| 239 |
|
| 240 |
typedef enum |
| 241 |
{ |
| 242 |
GSD_FONT_ANTIALIASING_MODE_NONE, |
| 243 |
GSD_FONT_ANTIALIASING_MODE_GRAYSCALE, |
| 244 |
GSD_FONT_ANTIALIASING_MODE_RGBA |
| 245 |
} GsdFontAntialiasingMode; |
| 246 |
|
| 247 |
static int |
| 248 |
get_antialiasing (const char *s) |
| 249 |
{ |
| 250 |
const char *names[] = { "none", "grayscale", "rgba" }; |
| 251 |
int i; |
| 252 |
|
| 253 |
for (i = 0; i < G_N_ELEMENTS (names); i++) |
| 254 |
if (strcmp (s, names[i]) == 0) |
| 255 |
return i; |
| 256 |
|
| 257 |
return 0; |
| 258 |
} |
| 259 |
|
| 260 |
typedef enum |
| 261 |
{ |
| 262 |
GSD_FONT_HINTING_NONE, |
| 263 |
GSD_FONT_HINTING_SLIGHT, |
| 264 |
GSD_FONT_HINTING_MEDIUM, |
| 265 |
GSD_FONT_HINTING_FULL |
| 266 |
} GsdFontHinting; |
| 267 |
|
| 268 |
static int |
| 269 |
get_hinting (const char *s) |
| 270 |
{ |
| 271 |
const char *names[] = { "none", "slight", "medium", "full" }; |
| 272 |
int i; |
| 273 |
|
| 274 |
for (i = 0; i < G_N_ELEMENTS (names); i++) |
| 275 |
if (strcmp (s, names[i]) == 0) |
| 276 |
return i; |
| 277 |
|
| 278 |
return 0; |
| 279 |
} |
| 280 |
|
| 281 |
typedef enum |
| 282 |
{ |
| 283 |
GSD_FONT_RGBA_ORDER_RGBA, |
| 284 |
GSD_FONT_RGBA_ORDER_RGB, |
| 285 |
GSD_FONT_RGBA_ORDER_BGR, |
| 286 |
GSD_FONT_RGBA_ORDER_VRGB, |
| 287 |
GSD_FONT_RGBA_ORDER_VBGR |
| 288 |
} GsdFontRgbaOrder; |
| 289 |
|
| 290 |
static int |
| 291 |
get_order (const char *s) |
| 292 |
{ |
| 293 |
const char *names[] = { "rgba", "rgb", "bgr", "vrgb", "vbgr" }; |
| 294 |
int i; |
| 295 |
|
| 296 |
for (i = 0; i < G_N_ELEMENTS (names); i++) |
| 297 |
if (strcmp (s, names[i]) == 0) |
| 298 |
return i; |
| 299 |
|
| 300 |
return 0; |
| 301 |
} |
| 302 |
|
| 303 |
static gdouble |
| 304 |
get_dpi_from_gsettings (GdkWaylandScreen *screen_wayland) |
| 305 |
{ |
| 306 |
GSettings *settings; |
| 307 |
gdouble factor; |
| 308 |
|
| 309 |
settings = g_hash_table_lookup (screen_wayland->settings, |
| 310 |
"org.gnome.desktop.interface"); |
| 311 |
if (settings != NULL) |
| 312 |
factor = g_settings_get_double (settings, "text-scaling-factor"); |
| 313 |
else |
| 314 |
factor = 1.0; |
| 315 |
|
| 316 |
return 96.0 * factor; |
| 317 |
} |
| 318 |
|
| 319 |
/* When using the Settings portal, we cache the value in |
| 320 |
* the fallback member, and we ignore the valid field |
| 321 |
*/ |
| 322 |
typedef struct _TranslationEntry TranslationEntry; |
| 323 |
struct _TranslationEntry { |
| 324 |
gboolean valid; |
| 325 |
const gchar *schema; |
| 326 |
const gchar *key; |
| 327 |
const gchar *setting; |
| 328 |
GType type; |
| 329 |
union { |
| 330 |
const char *s; |
| 331 |
gint i; |
| 332 |
gboolean b; |
| 333 |
} fallback; |
| 334 |
}; |
| 335 |
|
| 336 |
static TranslationEntry * find_translation_entry_by_schema (const char *schema, |
| 337 |
const char *key); |
| 338 |
static void |
| 339 |
update_xft_settings (GdkScreen *screen, gboolean notify) |
| 340 |
{ |
| 341 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 342 |
GSettings *settings; |
| 343 |
GsdFontAntialiasingMode antialiasing; |
| 344 |
GsdFontHinting hinting; |
| 345 |
GsdFontRgbaOrder order; |
| 346 |
gboolean use_rgba = FALSE; |
| 347 |
GsdXftSettings xft_settings; |
| 348 |
double dpi; |
| 349 |
|
| 350 |
if (screen_wayland->settings_portal) |
| 351 |
{ |
| 352 |
TranslationEntry *entry; |
| 353 |
|
| 354 |
entry = find_translation_entry_by_schema ("org.gnome.desktop.interface", "font-antialiasing"); |
| 355 |
|
| 356 |
if (entry->valid) |
| 357 |
{ |
| 358 |
antialiasing = entry->fallback.i; |
| 359 |
|
| 360 |
entry = find_translation_entry_by_schema ("org.gnome.desktop.interface", "font-hinting"); |
| 361 |
hinting = entry->fallback.i; |
| 362 |
|
| 363 |
entry = find_translation_entry_by_schema ("org.gnome.desktop.interface", "font-rgba-order"); |
| 364 |
order = entry->fallback.i; |
| 365 |
} |
| 366 |
else |
| 367 |
{ |
| 368 |
entry = find_translation_entry_by_schema ("org.gnome.settings-daemon.plugins.xsettings", "antialiasing"); |
| 369 |
antialiasing = entry->fallback.i; |
| 370 |
|
| 371 |
entry = find_translation_entry_by_schema ("org.gnome.settings-daemon.plugins.xsettings", "hinting"); |
| 372 |
hinting = entry->fallback.i; |
| 373 |
|
| 374 |
entry = find_translation_entry_by_schema ("org.gnome.settings-daemon.plugins.xsettings", "rgba-order"); |
| 375 |
order = entry->fallback.i; |
| 376 |
} |
| 377 |
|
| 378 |
entry = find_translation_entry_by_schema ("org.gnome.desktop.interface", "text-scaling-factor"); |
| 379 |
dpi = 96.0 * entry->fallback.i / 65536.0 * 1024; /* Xft wants 1/1024th of an inch */ |
| 380 |
} |
| 381 |
else |
| 382 |
{ |
| 383 |
TranslationEntry *entry; |
| 384 |
|
| 385 |
entry = find_translation_entry_by_schema ("org.gnome.desktop.interface", "font-antialiasing"); |
| 386 |
|
| 387 |
if (entry && entry->valid) |
| 388 |
{ |
| 389 |
settings = g_hash_table_lookup (screen_wayland->settings, |
| 390 |
"org.gnome.desktop.interface"); |
| 391 |
antialiasing = g_settings_get_enum (settings, "font-antialiasing"); |
| 392 |
hinting = g_settings_get_enum (settings, "font-hinting"); |
| 393 |
order = g_settings_get_enum (settings, "font-rgba-order"); |
| 394 |
} |
| 395 |
else if (g_hash_table_contains (screen_wayland->settings, |
| 396 |
"org.gnome.settings-daemon.plugins.xsettings")) |
| 397 |
{ |
| 398 |
settings = g_hash_table_lookup (screen_wayland->settings, |
| 399 |
"org.gnome.settings-daemon.plugins.xsettings"); |
| 400 |
antialiasing = g_settings_get_enum (settings, "antialiasing"); |
| 401 |
hinting = g_settings_get_enum (settings, "hinting"); |
| 402 |
order = g_settings_get_enum (settings, "rgba-order"); |
| 403 |
} |
| 404 |
else |
| 405 |
{ |
| 406 |
antialiasing = GSD_FONT_ANTIALIASING_MODE_GRAYSCALE; |
| 407 |
hinting = GSD_FONT_HINTING_MEDIUM; |
| 408 |
order = GSD_FONT_RGBA_ORDER_RGB; |
| 409 |
} |
| 410 |
|
| 411 |
dpi = get_dpi_from_gsettings (screen_wayland) * 1024; |
| 412 |
} |
| 413 |
|
| 414 |
xft_settings.antialias = (antialiasing != GSD_FONT_ANTIALIASING_MODE_NONE); |
| 415 |
xft_settings.hinting = (hinting != GSD_FONT_HINTING_NONE); |
| 416 |
xft_settings.dpi = dpi; |
| 417 |
xft_settings.rgba = "rgb"; |
| 418 |
xft_settings.hintstyle = "hintfull"; |
| 419 |
|
| 420 |
switch (hinting) |
| 421 |
{ |
| 422 |
case GSD_FONT_HINTING_NONE: |
| 423 |
xft_settings.hintstyle = "hintnone"; |
| 424 |
break; |
| 425 |
case GSD_FONT_HINTING_SLIGHT: |
| 426 |
xft_settings.hintstyle = "hintslight"; |
| 427 |
break; |
| 428 |
case GSD_FONT_HINTING_MEDIUM: |
| 429 |
xft_settings.hintstyle = "hintmedium"; |
| 430 |
break; |
| 431 |
case GSD_FONT_HINTING_FULL: |
| 432 |
xft_settings.hintstyle = "hintfull"; |
| 433 |
break; |
| 434 |
} |
| 435 |
|
| 436 |
switch (order) |
| 437 |
{ |
| 438 |
case GSD_FONT_RGBA_ORDER_RGBA: |
| 439 |
xft_settings.rgba = "rgba"; |
| 440 |
break; |
| 441 |
case GSD_FONT_RGBA_ORDER_RGB: |
| 442 |
xft_settings.rgba = "rgb"; |
| 443 |
break; |
| 444 |
case GSD_FONT_RGBA_ORDER_BGR: |
| 445 |
xft_settings.rgba = "bgr"; |
| 446 |
break; |
| 447 |
case GSD_FONT_RGBA_ORDER_VRGB: |
| 448 |
xft_settings.rgba = "vrgb"; |
| 449 |
break; |
| 450 |
case GSD_FONT_RGBA_ORDER_VBGR: |
| 451 |
xft_settings.rgba = "vbgr"; |
| 452 |
break; |
| 453 |
} |
| 454 |
|
| 455 |
switch (antialiasing) |
| 456 |
{ |
| 457 |
case GSD_FONT_ANTIALIASING_MODE_NONE: |
| 458 |
xft_settings.antialias = FALSE; |
| 459 |
break; |
| 460 |
case GSD_FONT_ANTIALIASING_MODE_GRAYSCALE: |
| 461 |
xft_settings.antialias = TRUE; |
| 462 |
break; |
| 463 |
case GSD_FONT_ANTIALIASING_MODE_RGBA: |
| 464 |
xft_settings.antialias = TRUE; |
| 465 |
use_rgba = TRUE; |
| 466 |
} |
| 467 |
|
| 468 |
if (!use_rgba) |
| 469 |
xft_settings.rgba = "none"; |
| 470 |
|
| 471 |
if (screen_wayland->xft_settings.antialias != xft_settings.antialias) |
| 472 |
{ |
| 473 |
screen_wayland->xft_settings.antialias = xft_settings.antialias; |
| 474 |
if (notify) |
| 475 |
notify_setting (screen, "gtk-xft-antialias"); |
| 476 |
} |
| 477 |
|
| 478 |
if (screen_wayland->xft_settings.hinting != xft_settings.hinting) |
| 479 |
{ |
| 480 |
screen_wayland->xft_settings.hinting = xft_settings.hinting; |
| 481 |
if (notify) |
| 482 |
notify_setting (screen, "gtk-xft-hinting"); |
| 483 |
} |
| 484 |
|
| 485 |
if (screen_wayland->xft_settings.hintstyle != xft_settings.hintstyle) |
| 486 |
{ |
| 487 |
screen_wayland->xft_settings.hintstyle = xft_settings.hintstyle; |
| 488 |
if (notify) |
| 489 |
notify_setting (screen, "gtk-xft-hintstyle"); |
| 490 |
} |
| 491 |
|
| 492 |
if (screen_wayland->xft_settings.rgba != xft_settings.rgba) |
| 493 |
{ |
| 494 |
screen_wayland->xft_settings.rgba = xft_settings.rgba; |
| 495 |
if (notify) |
| 496 |
notify_setting (screen, "gtk-xft-rgba"); |
| 497 |
} |
| 498 |
|
| 499 |
if (screen_wayland->xft_settings.dpi != xft_settings.dpi) |
| 500 |
{ |
| 501 |
double dpi = xft_settings.dpi / 1024.; |
| 502 |
const char *scale_env; |
| 503 |
double scale; |
| 504 |
|
| 505 |
screen_wayland->xft_settings.dpi = xft_settings.dpi; |
| 506 |
|
| 507 |
scale_env = g_getenv ("GDK_DPI_SCALE"); |
| 508 |
if (scale_env) |
| 509 |
{ |
| 510 |
scale = g_ascii_strtod (scale_env, NULL); |
| 511 |
if (scale != 0 && dpi > 0) |
| 512 |
dpi *= scale; |
| 513 |
} |
| 514 |
|
| 515 |
_gdk_screen_set_resolution (screen, dpi); |
| 516 |
|
| 517 |
if (notify) |
| 518 |
notify_setting (screen, "gtk-xft-dpi"); |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
#define WM_SETTINGS_SCHEMA "org.gnome.desktop.wm.preferences" |
| 523 |
#define CLASSIC_WM_SETTINGS_SCHEMA "org.gnome.shell.extensions.classic-overrides" |
| 524 |
|
| 525 |
static TranslationEntry translations[] = { |
| 526 |
{ FALSE, "org.gnome.desktop.interface", "gtk-theme", "gtk-theme-name" , G_TYPE_STRING, { .s = "Adwaita" } }, |
| 527 |
{ FALSE, "org.gnome.desktop.interface", "gtk-key-theme", "gtk-key-theme-name" , G_TYPE_STRING, { .s = "Default" } }, |
| 528 |
{ FALSE, "org.gnome.desktop.interface", "icon-theme", "gtk-icon-theme-name", G_TYPE_STRING, { .s = "gnome" } }, |
| 529 |
{ FALSE, "org.gnome.desktop.interface", "cursor-theme", "gtk-cursor-theme-name", G_TYPE_STRING, { .s = "Adwaita" } }, |
| 530 |
{ FALSE, "org.gnome.desktop.interface", "cursor-size", "gtk-cursor-theme-size", G_TYPE_INT, { .i = 32 } }, |
| 531 |
{ FALSE, "org.gnome.desktop.interface", "font-name", "gtk-font-name", G_TYPE_STRING, { .s = "Adwaita Sans 11" } }, |
| 532 |
{ FALSE, "org.gnome.desktop.interface", "cursor-blink", "gtk-cursor-blink", G_TYPE_BOOLEAN, { .b = TRUE } }, |
| 533 |
{ FALSE, "org.gnome.desktop.interface", "cursor-blink-time", "gtk-cursor-blink-time", G_TYPE_INT, { .i = 1200 } }, |
| 534 |
{ FALSE, "org.gnome.desktop.interface", "cursor-blink-timeout", "gtk-cursor-blink-timeout", G_TYPE_INT, { .i = 3600 } }, |
| 535 |
{ FALSE, "org.gnome.desktop.interface", "gtk-im-module", "gtk-im-module", G_TYPE_STRING, { .s = "simple" } }, |
| 536 |
{ FALSE, "org.gnome.desktop.interface", "enable-animations", "gtk-enable-animations", G_TYPE_BOOLEAN, { .b = TRUE } }, |
| 537 |
{ FALSE, "org.gnome.desktop.interface", "gtk-enable-primary-paste", "gtk-enable-primary-paste", G_TYPE_BOOLEAN, { .b = TRUE } }, |
| 538 |
{ FALSE, "org.gnome.desktop.interface", "overlay-scrolling", "gtk-overlay-scrolling", G_TYPE_BOOLEAN, { .b = TRUE } }, |
| 539 |
{ FALSE, "org.gnome.desktop.peripherals.mouse", "double-click", "gtk-double-click-time", G_TYPE_INT, { .i = 400 } }, |
| 540 |
{ FALSE, "org.gnome.desktop.peripherals.mouse", "drag-threshold", "gtk-dnd-drag-threshold", G_TYPE_INT, {.i = 8 } }, |
| 541 |
{ FALSE, "org.gnome.settings-daemon.peripherals.mouse", "double-click", "gtk-double-click-time", G_TYPE_INT, { .i = 400 } }, |
| 542 |
{ FALSE, "org.gnome.settings-daemon.peripherals.mouse", "drag-threshold", "gtk-dnd-drag-threshold", G_TYPE_INT, {.i = 8 } }, |
| 543 |
{ FALSE, "org.gnome.desktop.sound", "theme-name", "gtk-sound-theme-name", G_TYPE_STRING, { .s = "freedesktop" } }, |
| 544 |
{ FALSE, "org.gnome.desktop.sound", "event-sounds", "gtk-enable-event-sounds", G_TYPE_BOOLEAN, { .b = TRUE } }, |
| 545 |
{ FALSE, "org.gnome.desktop.sound", "input-feedback-sounds", "gtk-enable-input-feedback-sounds", G_TYPE_BOOLEAN, { . b = FALSE } }, |
| 546 |
{ FALSE, "org.gnome.desktop.privacy", "recent-files-max-age", "gtk-recent-files-max-age", G_TYPE_INT, { .i = 30 } }, |
| 547 |
{ FALSE, "org.gnome.desktop.privacy", "remember-recent-files", "gtk-recent-files-enabled", G_TYPE_BOOLEAN, { .b = TRUE } }, |
| 548 |
{ FALSE, WM_SETTINGS_SCHEMA, "button-layout", "gtk-decoration-layout", G_TYPE_STRING, { .s = "menu:close" } }, |
| 549 |
{ FALSE, CLASSIC_WM_SETTINGS_SCHEMA, "button-layout", "gtk-decoration-layout", G_TYPE_STRING, { .s = "menu:close" } }, |
| 550 |
{ FALSE, "org.gnome.desktop.interface", "font-antialiasing", "gtk-xft-antialias", G_TYPE_NONE, { .i = 1 } }, |
| 551 |
{ FALSE, "org.gnome.desktop.interface", "font-hinting", "gtk-xft-hinting", G_TYPE_NONE, { .i = 1 } }, |
| 552 |
{ FALSE, "org.gnome.desktop.interface", "font-hinting", "gtk-xft-hintstyle", G_TYPE_NONE, { .i = 1 } }, |
| 553 |
{ FALSE, "org.gnome.desktop.interface", "font-rgba-order", "gtk-xft-rgba", G_TYPE_NONE, { .i = 0 } }, |
| 554 |
{ FALSE, "org.gnome.settings-daemon.plugins.xsettings", "antialiasing", "gtk-xft-antialias", G_TYPE_NONE, { .i = 1 } }, |
| 555 |
{ FALSE, "org.gnome.settings-daemon.plugins.xsettings", "hinting", "gtk-xft-hinting", G_TYPE_NONE, { .i = 1 } }, |
| 556 |
{ FALSE, "org.gnome.settings-daemon.plugins.xsettings", "hinting", "gtk-xft-hintstyle", G_TYPE_NONE, { .i = 1 } }, |
| 557 |
{ FALSE, "org.gnome.settings-daemon.plugins.xsettings", "rgba-order", "gtk-xft-rgba", G_TYPE_NONE, { .i = 0 } }, |
| 558 |
{ FALSE, "org.gnome.desktop.interface", "text-scaling-factor", "gtk-xft-dpi" , G_TYPE_NONE, { .i = 0 } }, |
| 559 |
{ FALSE, "org.gnome.desktop.wm.preferences", "action-double-click-titlebar", "gtk-titlebar-double-click", G_TYPE_STRING, { .s = "toggle-maximize" } }, |
| 560 |
{ FALSE, "org.gnome.desktop.wm.preferences", "action-middle-click-titlebar", "gtk-titlebar-middle-click", G_TYPE_STRING, { .s = "none" } }, |
| 561 |
{ FALSE, "org.gnome.desktop.wm.preferences", "action-right-click-titlebar", "gtk-titlebar-right-click", G_TYPE_STRING, { .s = "menu" } }, |
| 562 |
{ FALSE, "org.gnome.desktop.a11y", "always-show-text-caret", "gtk-keynav-use-caret", G_TYPE_BOOLEAN, { .b = FALSE } }, |
| 563 |
{ FALSE, "org.gnome.desktop.a11y.interface", "high-contrast", "high-contrast", G_TYPE_NONE, { .b = FALSE } }, |
| 564 |
{ FALSE, "org.gnome.fontconfig", "serial", "gtk-fontconfig-timestamp", G_TYPE_INT, { .i = 0 } } |
| 565 |
}; |
| 566 |
|
| 567 |
static TranslationEntry * |
| 568 |
find_translation_entry_by_schema (const char *schema, |
| 569 |
const gchar *key) |
| 570 |
{ |
| 571 |
guint i; |
| 572 |
|
| 573 |
for (i = 0; i < G_N_ELEMENTS (translations); i++) |
| 574 |
{ |
| 575 |
if (g_str_equal (schema, translations[i].schema) && |
| 576 |
g_str_equal (key, translations[i].key)) |
| 577 |
return &translations[i]; |
| 578 |
} |
| 579 |
|
| 580 |
return NULL; |
| 581 |
} |
| 582 |
|
| 583 |
static TranslationEntry * |
| 584 |
find_translation_entry_by_key (GSettings *settings, |
| 585 |
const char *key) |
| 586 |
{ |
| 587 |
char *schema; |
| 588 |
TranslationEntry *entry; |
| 589 |
|
| 590 |
g_object_get (settings, "schema", &schema, NULL); |
| 591 |
entry = find_translation_entry_by_schema (schema, key); |
| 592 |
g_free (schema); |
| 593 |
|
| 594 |
return entry; |
| 595 |
} |
| 596 |
|
| 597 |
static TranslationEntry * |
| 598 |
find_translation_entry_by_setting (const gchar *setting) |
| 599 |
{ |
| 600 |
guint i; |
| 601 |
|
| 602 |
for (i = 0; i < G_N_ELEMENTS (translations); i++) |
| 603 |
{ |
| 604 |
if (g_str_equal (setting, translations[i].setting)) |
| 605 |
return &translations[i]; |
| 606 |
} |
| 607 |
|
| 608 |
return NULL; |
| 609 |
} |
| 610 |
|
| 611 |
static void |
| 612 |
high_contrast_changed (GdkScreen *screen) |
| 613 |
{ |
| 614 |
notify_setting (screen, "gtk-theme-name"); |
| 615 |
notify_setting (screen, "gtk-icon-theme-name"); |
| 616 |
} |
| 617 |
|
| 618 |
static void |
| 619 |
settings_changed (GSettings *settings, |
| 620 |
const gchar *key, |
| 621 |
GdkScreen *screen) |
| 622 |
{ |
| 623 |
TranslationEntry *entry; |
| 624 |
|
| 625 |
entry = find_translation_entry_by_key (settings, key); |
| 626 |
|
| 627 |
if (entry != NULL) |
| 628 |
{ |
| 629 |
if (entry->type != G_TYPE_NONE) |
| 630 |
notify_setting (screen, entry->setting); |
| 631 |
else if (strcmp (key, "high-contrast") == 0) |
| 632 |
high_contrast_changed (screen); |
| 633 |
else |
| 634 |
update_xft_settings (screen, TRUE); |
| 635 |
} |
| 636 |
} |
| 637 |
|
| 638 |
static void |
| 639 |
apply_portal_setting (TranslationEntry *entry, |
| 640 |
GVariant *value, |
| 641 |
GdkScreen *screen) |
| 642 |
{ |
| 643 |
switch (entry->type) |
| 644 |
{ |
| 645 |
case G_TYPE_STRING: |
| 646 |
entry->fallback.s = g_intern_string (g_variant_get_string (value, NULL)); |
| 647 |
break; |
| 648 |
case G_TYPE_INT: |
| 649 |
entry->fallback.i = g_variant_get_int32 (value); |
| 650 |
break; |
| 651 |
case G_TYPE_BOOLEAN: |
| 652 |
entry->fallback.b = g_variant_get_boolean (value); |
| 653 |
break; |
| 654 |
case G_TYPE_NONE: |
| 655 |
if (strcmp (entry->key, "antialiasing") == 0 || |
| 656 |
strcmp (entry->key, "font-antialiasing") == 0) |
| 657 |
entry->fallback.i = get_antialiasing (g_variant_get_string (value, NULL)); |
| 658 |
else if (strcmp (entry->key, "hinting") == 0 || |
| 659 |
strcmp (entry->key, "font-hinting") == 0) |
| 660 |
entry->fallback.i = get_hinting (g_variant_get_string (value, NULL)); |
| 661 |
else if (strcmp (entry->key, "rgba-order") == 0 || |
| 662 |
strcmp (entry->key, "font-rgba-order") == 0) |
| 663 |
entry->fallback.i = get_order (g_variant_get_string (value, NULL)); |
| 664 |
else if (strcmp (entry->key, "text-scaling-factor") == 0) |
| 665 |
entry->fallback.i = (int) (g_variant_get_double (value) * 65536.0); |
| 666 |
update_xft_settings (screen, TRUE); |
| 667 |
break; |
| 668 |
default: |
| 669 |
break; |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
static void |
| 674 |
settings_portal_changed (GDBusProxy *proxy, |
| 675 |
const char *sender_name, |
| 676 |
const char *signal_name, |
| 677 |
GVariant *parameters, |
| 678 |
GdkScreen *screen) |
| 679 |
{ |
| 680 |
if (strcmp (signal_name, "SettingChanged") == 0) |
| 681 |
{ |
| 682 |
const char *namespace; |
| 683 |
const char *name; |
| 684 |
GVariant *value; |
| 685 |
TranslationEntry *entry; |
| 686 |
|
| 687 |
g_variant_get (parameters, "(&s&sv)", &namespace, &name, &value); |
| 688 |
|
| 689 |
entry = find_translation_entry_by_schema (namespace, name); |
| 690 |
if (entry != NULL) |
| 691 |
{ |
| 692 |
char *a = g_variant_print (value, FALSE); |
| 693 |
g_debug ("Using changed portal setting %s %s: %s", namespace, name, a); |
| 694 |
g_free (a); |
| 695 |
apply_portal_setting (entry, value, screen); |
| 696 |
notify_setting (screen, entry->setting); |
| 697 |
} |
| 698 |
else |
| 699 |
g_debug ("Ignoring portal setting %s %s", namespace, name); |
| 700 |
|
| 701 |
g_variant_unref (value); |
| 702 |
} |
| 703 |
} |
| 704 |
|
| 705 |
static void fontconfig_dbus_proxy_open_cb (GObject *object, |
| 706 |
GAsyncResult *result, |
| 707 |
gpointer user_data); |
| 708 |
|
| 709 |
#define PORTAL_BUS_NAME "org.freedesktop.portal.Desktop" |
| 710 |
#define PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop" |
| 711 |
#define PORTAL_SETTINGS_INTERFACE "org.freedesktop.portal.Settings" |
| 712 |
|
| 713 |
static void |
| 714 |
init_settings (GdkScreen *screen) |
| 715 |
{ |
| 716 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 717 |
GSettingsSchemaSource *source; |
| 718 |
GSettingsSchema *schema; |
| 719 |
GSettings *settings; |
| 720 |
gint i; |
| 721 |
|
| 722 |
if (gdk_should_use_portal ()) |
| 723 |
{ |
| 724 |
GVariant *ret; |
| 725 |
GError *error = NULL; |
| 726 |
const char *schema; |
| 727 |
GVariant *val; |
| 728 |
GVariantIter *iter; |
| 729 |
const char *patterns[] = { "org.gnome.*", NULL }; |
| 730 |
|
| 731 |
screen_wayland->settings_portal = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, |
| 732 |
G_DBUS_PROXY_FLAGS_NONE, |
| 733 |
NULL, |
| 734 |
PORTAL_BUS_NAME, |
| 735 |
PORTAL_OBJECT_PATH, |
| 736 |
PORTAL_SETTINGS_INTERFACE, |
| 737 |
NULL, |
| 738 |
&error); |
| 739 |
if (error) |
| 740 |
{ |
| 741 |
g_warning ("Settings portal not found: %s", error->message); |
| 742 |
g_error_free (error); |
| 743 |
|
| 744 |
goto fallback; |
| 745 |
} |
| 746 |
|
| 747 |
ret = g_dbus_proxy_call_sync (screen_wayland->settings_portal, |
| 748 |
"ReadAll", |
| 749 |
g_variant_new ("(^as)", patterns), |
| 750 |
G_DBUS_CALL_FLAGS_NONE, |
| 751 |
G_MAXINT, |
| 752 |
NULL, |
| 753 |
&error); |
| 754 |
if (error) |
| 755 |
{ |
| 756 |
g_warning ("Failed to read portal settings: %s", error->message); |
| 757 |
g_error_free (error); |
| 758 |
g_clear_object (&screen_wayland->settings_portal); |
| 759 |
|
| 760 |
goto fallback; |
| 761 |
} |
| 762 |
|
| 763 |
g_variant_get (ret, "(a{sa{sv}})", &iter); |
| 764 |
|
| 765 |
if (g_variant_iter_n_children (iter) == 0) |
| 766 |
{ |
| 767 |
g_debug ("Received no portal settings"); |
| 768 |
g_clear_pointer (&iter, g_variant_iter_free); |
| 769 |
g_clear_pointer (&ret, g_variant_unref); |
| 770 |
g_clear_object (&screen_wayland->settings_portal); |
| 771 |
|
| 772 |
goto fallback; |
| 773 |
} |
| 774 |
|
| 775 |
while (g_variant_iter_loop (iter, "{s@a{sv}}", &schema, &val)) |
| 776 |
{ |
| 777 |
GVariantIter *iter2 = g_variant_iter_new (val); |
| 778 |
const char *key; |
| 779 |
GVariant *v; |
| 780 |
|
| 781 |
while (g_variant_iter_loop (iter2, "{sv}", &key, &v)) |
| 782 |
{ |
| 783 |
TranslationEntry *entry = find_translation_entry_by_schema (schema, key); |
| 784 |
if (entry) |
| 785 |
{ |
| 786 |
char *a = g_variant_print (v, FALSE); |
| 787 |
g_debug ("Using portal setting for %s %s: %s\n", schema, key, a); |
| 788 |
g_free (a); |
| 789 |
entry->valid = TRUE; |
| 790 |
apply_portal_setting (entry, v, screen); |
| 791 |
} |
| 792 |
else |
| 793 |
{ |
| 794 |
g_debug ("Ignoring portal setting for %s %s", schema, key); |
| 795 |
} |
| 796 |
} |
| 797 |
g_variant_iter_free (iter2); |
| 798 |
} |
| 799 |
g_variant_iter_free (iter); |
| 800 |
|
| 801 |
g_variant_unref (ret); |
| 802 |
|
| 803 |
g_signal_connect (screen_wayland->settings_portal, "g-signal", |
| 804 |
G_CALLBACK (settings_portal_changed), screen_wayland); |
| 805 |
|
| 806 |
return; |
| 807 |
|
| 808 |
fallback: |
| 809 |
g_debug ("Failed to use Settings portal; falling back to gsettings"); |
| 810 |
} |
| 811 |
|
| 812 |
screen_wayland->dbus_cancellable = g_cancellable_new (); |
| 813 |
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, |
| 814 |
G_DBUS_PROXY_FLAGS_NONE, |
| 815 |
NULL, |
| 816 |
GTK_SETTINGS_DBUS_NAME, |
| 817 |
GTK_SETTINGS_DBUS_PATH, |
| 818 |
GTK_SETTINGS_DBUS_NAME, |
| 819 |
screen_wayland->dbus_cancellable, |
| 820 |
fontconfig_dbus_proxy_open_cb, |
| 821 |
screen_wayland); |
| 822 |
|
| 823 |
screen_wayland->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); |
| 824 |
|
| 825 |
source = g_settings_schema_source_get_default (); |
| 826 |
if (source == NULL) |
| 827 |
return; |
| 828 |
|
| 829 |
for (i = 0; i < G_N_ELEMENTS (translations); i++) |
| 830 |
{ |
| 831 |
schema = g_settings_schema_source_lookup (source, translations[i].schema, TRUE); |
| 832 |
if (!schema) |
| 833 |
continue; |
| 834 |
|
| 835 |
if (g_hash_table_lookup (screen_wayland->settings, (gpointer)translations[i].schema) == NULL) |
| 836 |
{ |
| 837 |
settings = g_settings_new_full (schema, NULL, NULL); |
| 838 |
g_signal_connect (settings, "changed", |
| 839 |
G_CALLBACK (settings_changed), screen); |
| 840 |
g_hash_table_insert (screen_wayland->settings, (gpointer)translations[i].schema, settings); |
| 841 |
} |
| 842 |
|
| 843 |
if (g_settings_schema_has_key (schema, translations[i].key)) |
| 844 |
translations[i].valid = TRUE; |
| 845 |
|
| 846 |
g_settings_schema_unref (schema); |
| 847 |
} |
| 848 |
|
| 849 |
update_xft_settings (screen, FALSE); |
| 850 |
} |
| 851 |
|
| 852 |
static void |
| 853 |
gtk_shell_handle_capabilities (void *data, |
| 854 |
struct gtk_shell1 *shell, |
| 855 |
uint32_t capabilities) |
| 856 |
{ |
| 857 |
GdkScreen *screen = data; |
| 858 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (data); |
| 859 |
|
| 860 |
screen_wayland->shell_capabilities = capabilities; |
| 861 |
|
| 862 |
notify_setting (screen, "gtk-shell-shows-app-menu"); |
| 863 |
notify_setting (screen, "gtk-shell-shows-menubar"); |
| 864 |
notify_setting (screen, "gtk-shell-shows-desktop"); |
| 865 |
} |
| 866 |
|
| 867 |
struct gtk_shell1_listener gdk_screen_gtk_shell_listener = { |
| 868 |
gtk_shell_handle_capabilities |
| 869 |
}; |
| 870 |
|
| 871 |
void |
| 872 |
_gdk_wayland_screen_set_has_gtk_shell (GdkScreen *screen) |
| 873 |
{ |
| 874 |
GdkWaylandDisplay *display_wayland = |
| 875 |
GDK_WAYLAND_DISPLAY (GDK_WAYLAND_SCREEN (screen)->display); |
| 876 |
|
| 877 |
gtk_shell1_add_listener (display_wayland->gtk_shell, |
| 878 |
&gdk_screen_gtk_shell_listener, |
| 879 |
screen); |
| 880 |
} |
| 881 |
|
| 882 |
static void |
| 883 |
set_value_from_entry (GdkScreen *screen, |
| 884 |
TranslationEntry *entry, |
| 885 |
GValue *value) |
| 886 |
{ |
| 887 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 888 |
GSettings *settings; |
| 889 |
|
| 890 |
if (screen_wayland->settings_portal) |
| 891 |
{ |
| 892 |
switch (entry->type) |
| 893 |
{ |
| 894 |
case G_TYPE_STRING: |
| 895 |
g_value_set_string (value, entry->fallback.s); |
| 896 |
break; |
| 897 |
case G_TYPE_INT: |
| 898 |
if (g_str_equal (entry->setting, "gtk-fontconfig-timestamp")) |
| 899 |
g_value_set_uint (value, (guint)entry->fallback.i); |
| 900 |
else |
| 901 |
g_value_set_int (value, entry->fallback.i); |
| 902 |
break; |
| 903 |
case G_TYPE_BOOLEAN: |
| 904 |
g_value_set_boolean (value, entry->fallback.b); |
| 905 |
break; |
| 906 |
case G_TYPE_NONE: |
| 907 |
if (g_str_equal (entry->setting, "gtk-xft-antialias")) |
| 908 |
g_value_set_int (value, screen_wayland->xft_settings.antialias); |
| 909 |
else if (g_str_equal (entry->setting, "gtk-xft-hinting")) |
| 910 |
g_value_set_int (value, screen_wayland->xft_settings.hinting); |
| 911 |
else if (g_str_equal (entry->setting, "gtk-xft-hintstyle")) |
| 912 |
g_value_set_static_string (value, screen_wayland->xft_settings.hintstyle); |
| 913 |
else if (g_str_equal (entry->setting, "gtk-xft-rgba")) |
| 914 |
g_value_set_static_string (value, screen_wayland->xft_settings.rgba); |
| 915 |
else if (g_str_equal (entry->setting, "gtk-xft-dpi")) |
| 916 |
g_value_set_int (value, screen_wayland->xft_settings.dpi); |
| 917 |
else |
| 918 |
g_assert_not_reached (); |
| 919 |
break; |
| 920 |
default: |
| 921 |
g_assert_not_reached (); |
| 922 |
break; |
| 923 |
} |
| 924 |
|
| 925 |
return; |
| 926 |
} |
| 927 |
|
| 928 |
settings = (GSettings *)g_hash_table_lookup (screen_wayland->settings, entry->schema); |
| 929 |
switch (entry->type) |
| 930 |
{ |
| 931 |
case G_TYPE_STRING: |
| 932 |
if (settings && entry->valid) |
| 933 |
{ |
| 934 |
gchar *s; |
| 935 |
s = g_settings_get_string (settings, entry->key); |
| 936 |
g_value_set_string (value, s); |
| 937 |
g_free (s); |
| 938 |
} |
| 939 |
else |
| 940 |
{ |
| 941 |
g_value_set_static_string (value, entry->fallback.s); |
| 942 |
} |
| 943 |
break; |
| 944 |
case G_TYPE_INT: |
| 945 |
if (g_str_equal (entry->setting, "gtk-fontconfig-timestamp")) |
| 946 |
g_value_set_uint (value, screen_wayland->dbus_settings.fontconfig_timestamp); |
| 947 |
else |
| 948 |
g_value_set_int (value, settings && entry->valid |
| 949 |
? g_settings_get_int (settings, entry->key) |
| 950 |
: entry->fallback.i); |
| 951 |
break; |
| 952 |
case G_TYPE_BOOLEAN: |
| 953 |
g_value_set_boolean (value, settings && entry->valid |
| 954 |
? g_settings_get_boolean (settings, entry->key) |
| 955 |
: entry->fallback.b); |
| 956 |
break; |
| 957 |
case G_TYPE_NONE: |
| 958 |
if (g_str_equal (entry->setting, "gtk-xft-antialias")) |
| 959 |
g_value_set_int (value, screen_wayland->xft_settings.antialias); |
| 960 |
else if (g_str_equal (entry->setting, "gtk-xft-hinting")) |
| 961 |
g_value_set_int (value, screen_wayland->xft_settings.hinting); |
| 962 |
else if (g_str_equal (entry->setting, "gtk-xft-hintstyle")) |
| 963 |
g_value_set_static_string (value, screen_wayland->xft_settings.hintstyle); |
| 964 |
else if (g_str_equal (entry->setting, "gtk-xft-rgba")) |
| 965 |
g_value_set_static_string (value, screen_wayland->xft_settings.rgba); |
| 966 |
else if (g_str_equal (entry->setting, "gtk-xft-dpi")) |
| 967 |
g_value_set_int (value, screen_wayland->xft_settings.dpi); |
| 968 |
else |
| 969 |
g_assert_not_reached (); |
| 970 |
break; |
| 971 |
default: |
| 972 |
g_assert_not_reached (); |
| 973 |
} |
| 974 |
} |
| 975 |
|
| 976 |
static void |
| 977 |
set_decoration_layout_from_entry (GdkScreen *screen, |
| 978 |
TranslationEntry *entry, |
| 979 |
GValue *value) |
| 980 |
{ |
| 981 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 982 |
GSettings *settings = NULL; |
| 983 |
const char *session; |
| 984 |
|
| 985 |
if (screen_wayland->settings_portal) |
| 986 |
{ |
| 987 |
g_value_set_string (value, entry->fallback.s); |
| 988 |
return; |
| 989 |
} |
| 990 |
|
| 991 |
/* Hack: until we get session-dependent defaults in GSettings, |
| 992 |
* swap out the usual schema for the "classic" one when |
| 993 |
* running in classic mode |
| 994 |
*/ |
| 995 |
session = g_getenv ("XDG_CURRENT_DESKTOP"); |
| 996 |
if (session && strstr (session, "GNOME-Classic")) |
| 997 |
settings = (GSettings *)g_hash_table_lookup (screen_wayland->settings, CLASSIC_WM_SETTINGS_SCHEMA); |
| 998 |
|
| 999 |
if (settings == NULL) |
| 1000 |
settings = (GSettings *)g_hash_table_lookup (screen_wayland->settings, WM_SETTINGS_SCHEMA); |
| 1001 |
|
| 1002 |
if (settings) |
| 1003 |
{ |
| 1004 |
gchar *s = g_settings_get_string (settings, entry->key); |
| 1005 |
|
| 1006 |
translate_wm_button_layout_to_gtk (s); |
| 1007 |
g_value_set_string (value, s); |
| 1008 |
|
| 1009 |
g_free (s); |
| 1010 |
} |
| 1011 |
else |
| 1012 |
{ |
| 1013 |
g_value_set_static_string (value, entry->fallback.s); |
| 1014 |
} |
| 1015 |
} |
| 1016 |
|
| 1017 |
static void |
| 1018 |
set_theme_from_entry (GdkScreen *screen, |
| 1019 |
TranslationEntry *entry, |
| 1020 |
GValue *value) |
| 1021 |
{ |
| 1022 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 1023 |
GSettings *settings = NULL; |
| 1024 |
GSettingsSchema *schema = NULL; |
| 1025 |
gboolean hc = FALSE; |
| 1026 |
|
| 1027 |
if (screen_wayland->settings_portal == NULL) |
| 1028 |
{ |
| 1029 |
settings = (GSettings *)g_hash_table_lookup (screen_wayland->settings, |
| 1030 |
"org.gnome.desktop.a11y.interface"); |
| 1031 |
} |
| 1032 |
|
| 1033 |
if (settings) |
| 1034 |
g_object_get (settings, "settings-schema", &schema, NULL); |
| 1035 |
|
| 1036 |
if (schema && g_settings_schema_has_key (schema, "high-contrast")) |
| 1037 |
hc = g_settings_get_boolean (settings, "high-contrast"); |
| 1038 |
|
| 1039 |
g_clear_pointer (&schema, g_settings_schema_unref); |
| 1040 |
|
| 1041 |
if (hc) |
| 1042 |
g_value_set_static_string (value, "HighContrast"); |
| 1043 |
else |
| 1044 |
set_value_from_entry (screen, entry, value); |
| 1045 |
} |
| 1046 |
|
| 1047 |
static gboolean |
| 1048 |
set_capability_setting (GdkScreen *screen, |
| 1049 |
GValue *value, |
| 1050 |
enum gtk_shell1_capability test) |
| 1051 |
{ |
| 1052 |
GdkWaylandScreen *wayland_screen = GDK_WAYLAND_SCREEN (screen); |
| 1053 |
int testbit = 1 << (test - 1); |
| 1054 |
|
| 1055 |
g_value_set_boolean (value, (wayland_screen->shell_capabilities & testbit) == testbit); |
| 1056 |
|
| 1057 |
return TRUE; |
| 1058 |
} |
| 1059 |
|
| 1060 |
static gboolean |
| 1061 |
gdk_wayland_screen_get_setting (GdkScreen *screen, |
| 1062 |
const gchar *name, |
| 1063 |
GValue *value) |
| 1064 |
{ |
| 1065 |
GdkWaylandScreen *wayland_screen = GDK_WAYLAND_SCREEN (screen); |
| 1066 |
TranslationEntry *entry; |
| 1067 |
|
| 1068 |
g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); |
| 1069 |
|
| 1070 |
if (wayland_screen->settings != NULL && |
| 1071 |
g_hash_table_size (wayland_screen->settings) == 0) |
| 1072 |
return FALSE; |
| 1073 |
|
| 1074 |
entry = find_translation_entry_by_setting (name); |
| 1075 |
if (entry != NULL) |
| 1076 |
{ |
| 1077 |
if (strcmp (name, "gtk-decoration-layout") == 0) |
| 1078 |
set_decoration_layout_from_entry (screen, entry, value); |
| 1079 |
else if (strcmp (name, "gtk-theme-name") == 0) |
| 1080 |
set_theme_from_entry (screen, entry, value); |
| 1081 |
else |
| 1082 |
set_value_from_entry (screen, entry, value); |
| 1083 |
return TRUE; |
| 1084 |
} |
| 1085 |
|
| 1086 |
if (strcmp (name, "gtk-shell-shows-app-menu") == 0) |
| 1087 |
return set_capability_setting (screen, value, |
| 1088 |
GTK_SHELL1_CAPABILITY_GLOBAL_APP_MENU); |
| 1089 |
|
| 1090 |
if (strcmp (name, "gtk-shell-shows-menubar") == 0) |
| 1091 |
return set_capability_setting (screen, value, |
| 1092 |
GTK_SHELL1_CAPABILITY_GLOBAL_MENU_BAR); |
| 1093 |
|
| 1094 |
if (strcmp (name, "gtk-shell-shows-desktop") == 0) |
| 1095 |
return set_capability_setting (screen, value, |
| 1096 |
GTK_SHELL1_CAPABILITY_DESKTOP_ICONS); |
| 1097 |
|
| 1098 |
if (strcmp (name, "gtk-dialogs-use-header") == 0) |
| 1099 |
{ |
| 1100 |
g_value_set_boolean (value, TRUE); |
| 1101 |
return TRUE; |
| 1102 |
} |
| 1103 |
|
| 1104 |
if (strcmp (name, "gtk-fontconfig-timestamp") == 0) |
| 1105 |
{ |
| 1106 |
g_value_set_uint (value, wayland_screen->dbus_settings.fontconfig_timestamp); |
| 1107 |
return TRUE; |
| 1108 |
} |
| 1109 |
|
| 1110 |
if (strcmp (name, "gtk-modules") == 0) |
| 1111 |
{ |
| 1112 |
g_value_set_string (value, wayland_screen->dbus_settings.modules); |
| 1113 |
return TRUE; |
| 1114 |
} |
| 1115 |
|
| 1116 |
return FALSE; |
| 1117 |
} |
| 1118 |
|
| 1119 |
typedef struct _GdkWaylandVisual GdkWaylandVisual; |
| 1120 |
typedef struct _GdkWaylandVisualClass GdkWaylandVisualClass; |
| 1121 |
|
| 1122 |
struct _GdkWaylandVisual |
| 1123 |
{ |
| 1124 |
GdkVisual visual; |
| 1125 |
}; |
| 1126 |
|
| 1127 |
struct _GdkWaylandVisualClass |
| 1128 |
{ |
| 1129 |
GdkVisualClass parent_class; |
| 1130 |
}; |
| 1131 |
|
| 1132 |
GType _gdk_wayland_visual_get_type (void); |
| 1133 |
|
| 1134 |
G_DEFINE_TYPE (GdkWaylandVisual, _gdk_wayland_visual, GDK_TYPE_VISUAL) |
| 1135 |
|
| 1136 |
static void |
| 1137 |
_gdk_wayland_visual_class_init (GdkWaylandVisualClass *klass) |
| 1138 |
{ |
| 1139 |
} |
| 1140 |
|
| 1141 |
static void |
| 1142 |
_gdk_wayland_visual_init (GdkWaylandVisual *visual) |
| 1143 |
{ |
| 1144 |
} |
| 1145 |
|
| 1146 |
static gint |
| 1147 |
gdk_wayland_screen_visual_get_best_depth (GdkScreen *screen) |
| 1148 |
{ |
| 1149 |
return 32; |
| 1150 |
} |
| 1151 |
|
| 1152 |
static GdkVisualType |
| 1153 |
gdk_wayland_screen_visual_get_best_type (GdkScreen *screen) |
| 1154 |
{ |
| 1155 |
return GDK_VISUAL_TRUE_COLOR; |
| 1156 |
} |
| 1157 |
|
| 1158 |
static GdkVisual* |
| 1159 |
gdk_wayland_screen_visual_get_best (GdkScreen *screen) |
| 1160 |
{ |
| 1161 |
return GDK_WAYLAND_SCREEN (screen)->visual; |
| 1162 |
} |
| 1163 |
|
| 1164 |
static GdkVisual* |
| 1165 |
gdk_wayland_screen_visual_get_best_with_depth (GdkScreen *screen, |
| 1166 |
gint depth) |
| 1167 |
{ |
| 1168 |
if (depth == 32) |
| 1169 |
return GDK_WAYLAND_SCREEN (screen)->visual; |
| 1170 |
else |
| 1171 |
return NULL; |
| 1172 |
} |
| 1173 |
|
| 1174 |
static GdkVisual* |
| 1175 |
gdk_wayland_screen_visual_get_best_with_type (GdkScreen *screen, |
| 1176 |
GdkVisualType visual_type) |
| 1177 |
{ |
| 1178 |
if (visual_type == GDK_VISUAL_TRUE_COLOR) |
| 1179 |
return GDK_WAYLAND_SCREEN (screen)->visual; |
| 1180 |
else |
| 1181 |
return NULL; |
| 1182 |
} |
| 1183 |
|
| 1184 |
static GdkVisual* |
| 1185 |
gdk_wayland_screen_visual_get_best_with_both (GdkScreen *screen, |
| 1186 |
gint depth, |
| 1187 |
GdkVisualType visual_type) |
| 1188 |
{ |
| 1189 |
if (depth == 32 && visual_type == GDK_VISUAL_TRUE_COLOR) |
| 1190 |
return GDK_WAYLAND_SCREEN (screen)->visual; |
| 1191 |
else |
| 1192 |
return NULL; |
| 1193 |
} |
| 1194 |
|
| 1195 |
static void |
| 1196 |
gdk_wayland_screen_query_depths (GdkScreen *screen, |
| 1197 |
gint **depths, |
| 1198 |
gint *count) |
| 1199 |
{ |
| 1200 |
static gint static_depths[] = { 32 }; |
| 1201 |
|
| 1202 |
*count = G_N_ELEMENTS(static_depths); |
| 1203 |
*depths = static_depths; |
| 1204 |
} |
| 1205 |
|
| 1206 |
static void |
| 1207 |
gdk_wayland_screen_query_visual_types (GdkScreen *screen, |
| 1208 |
GdkVisualType **visual_types, |
| 1209 |
gint *count) |
| 1210 |
{ |
| 1211 |
static GdkVisualType static_visual_types[] = { GDK_VISUAL_TRUE_COLOR }; |
| 1212 |
|
| 1213 |
*count = G_N_ELEMENTS(static_visual_types); |
| 1214 |
*visual_types = static_visual_types; |
| 1215 |
} |
| 1216 |
|
| 1217 |
static GList * |
| 1218 |
gdk_wayland_screen_list_visuals (GdkScreen *screen) |
| 1219 |
{ |
| 1220 |
GList *list; |
| 1221 |
GdkWaylandScreen *screen_wayland; |
| 1222 |
|
| 1223 |
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); |
| 1224 |
screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 1225 |
|
| 1226 |
list = g_list_append (NULL, screen_wayland->visual); |
| 1227 |
|
| 1228 |
return list; |
| 1229 |
} |
| 1230 |
|
| 1231 |
#define GDK_TYPE_WAYLAND_VISUAL (_gdk_wayland_visual_get_type ()) |
| 1232 |
#define GDK_WAYLAND_VISUAL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WAYLAND_VISUAL, GdkWaylandVisual)) |
| 1233 |
|
| 1234 |
/* Currently, the Wayland backend only ever uses ARGB8888. |
| 1235 |
*/ |
| 1236 |
static GdkVisual * |
| 1237 |
gdk_wayland_visual_new (GdkScreen *screen) |
| 1238 |
{ |
| 1239 |
GdkVisual *visual; |
| 1240 |
|
| 1241 |
visual = g_object_new (GDK_TYPE_WAYLAND_VISUAL, NULL); |
| 1242 |
visual->screen = GDK_SCREEN (screen); |
| 1243 |
visual->type = GDK_VISUAL_TRUE_COLOR; |
| 1244 |
visual->depth = 32; |
| 1245 |
visual->red_mask = 0xff0000; |
| 1246 |
visual->green_mask = 0x00ff00; |
| 1247 |
visual->blue_mask = 0x0000ff; |
| 1248 |
visual->bits_per_rgb = 8; |
| 1249 |
|
| 1250 |
return visual; |
| 1251 |
} |
| 1252 |
|
| 1253 |
static void |
| 1254 |
dbus_properties_change_cb (GDBusProxy *proxy, |
| 1255 |
GVariant *changed_properties, |
| 1256 |
const gchar* const *invalidated_properties, |
| 1257 |
gpointer user_data) |
| 1258 |
{ |
| 1259 |
GdkWaylandScreen *screen_wayland = user_data; |
| 1260 |
GVariant *value; |
| 1261 |
gint64 timestamp; |
| 1262 |
|
| 1263 |
if (g_variant_n_children (changed_properties) <= 0) |
| 1264 |
return; |
| 1265 |
|
| 1266 |
value = g_variant_lookup_value (changed_properties, |
| 1267 |
"FontconfigTimestamp", |
| 1268 |
G_VARIANT_TYPE_INT64); |
| 1269 |
|
| 1270 |
if (value != NULL) |
| 1271 |
{ |
| 1272 |
timestamp = g_variant_get_int64 (value); |
| 1273 |
timestamp = timestamp / G_TIME_SPAN_SECOND; |
| 1274 |
|
| 1275 |
if (timestamp > 0 && timestamp <= G_MAXUINT) |
| 1276 |
screen_wayland->dbus_settings.fontconfig_timestamp = (guint)timestamp; |
| 1277 |
else if (timestamp > G_MAXUINT) |
| 1278 |
g_warning ("Could not handle fontconfig update: timestamp out of bound"); |
| 1279 |
|
| 1280 |
notify_setting (GDK_SCREEN (screen_wayland), "gtk-fontconfig-timestamp"); |
| 1281 |
|
| 1282 |
g_variant_unref (value); |
| 1283 |
} |
| 1284 |
|
| 1285 |
value = g_variant_lookup_value (changed_properties, |
| 1286 |
"Modules", |
| 1287 |
G_VARIANT_TYPE_STRING); |
| 1288 |
|
| 1289 |
if (value != NULL) |
| 1290 |
{ |
| 1291 |
g_free (screen_wayland->dbus_settings.modules); |
| 1292 |
|
| 1293 |
screen_wayland->dbus_settings.modules = g_variant_dup_string (value, NULL); |
| 1294 |
|
| 1295 |
notify_setting (GDK_SCREEN (screen_wayland), "gtk-modules"); |
| 1296 |
|
| 1297 |
g_variant_unref (value); |
| 1298 |
} |
| 1299 |
} |
| 1300 |
|
| 1301 |
static void |
| 1302 |
fontconfig_dbus_proxy_open_cb (GObject *object, |
| 1303 |
GAsyncResult *result, |
| 1304 |
gpointer user_data) |
| 1305 |
{ |
| 1306 |
GdkWaylandScreen *screen_wayland = user_data; |
| 1307 |
GDBusProxy *proxy; |
| 1308 |
GVariant *value; |
| 1309 |
gint64 timestamp; |
| 1310 |
|
| 1311 |
proxy = g_dbus_proxy_new_for_bus_finish (result, NULL); |
| 1312 |
|
| 1313 |
if (proxy == NULL) |
| 1314 |
return; |
| 1315 |
|
| 1316 |
screen_wayland->dbus_proxy = proxy; |
| 1317 |
screen_wayland->dbus_setting_change_id = |
| 1318 |
g_signal_connect (screen_wayland->dbus_proxy, |
| 1319 |
"g-properties-changed", |
| 1320 |
G_CALLBACK (dbus_properties_change_cb), |
| 1321 |
screen_wayland); |
| 1322 |
|
| 1323 |
value = g_dbus_proxy_get_cached_property (screen_wayland->dbus_proxy, |
| 1324 |
"FontconfigTimestamp"); |
| 1325 |
|
| 1326 |
if (value && g_variant_is_of_type (value, G_VARIANT_TYPE_INT64)) |
| 1327 |
{ |
| 1328 |
timestamp = g_variant_get_int64 (value); |
| 1329 |
timestamp = timestamp / G_TIME_SPAN_SECOND; |
| 1330 |
|
| 1331 |
if (timestamp > 0 && timestamp <= G_MAXUINT) |
| 1332 |
screen_wayland->dbus_settings.fontconfig_timestamp = (guint)timestamp; |
| 1333 |
else if (timestamp > G_MAXUINT) |
| 1334 |
g_warning ("Could not handle fontconfig init: timestamp out of bound"); |
| 1335 |
} |
| 1336 |
|
| 1337 |
if (value != NULL) |
| 1338 |
g_variant_unref (value); |
| 1339 |
|
| 1340 |
value = g_dbus_proxy_get_cached_property (screen_wayland->dbus_proxy, |
| 1341 |
"Modules"); |
| 1342 |
|
| 1343 |
if (value && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) |
| 1344 |
{ |
| 1345 |
g_free (screen_wayland->dbus_settings.modules); |
| 1346 |
|
| 1347 |
screen_wayland->dbus_settings.modules = g_variant_dup_string (value, NULL); |
| 1348 |
notify_setting (GDK_SCREEN (screen_wayland), "gtk-modules"); |
| 1349 |
} |
| 1350 |
|
| 1351 |
if (value != NULL) |
| 1352 |
g_variant_unref (value); |
| 1353 |
} |
| 1354 |
|
| 1355 |
GdkScreen * |
| 1356 |
_gdk_wayland_screen_new (GdkDisplay *display) |
| 1357 |
{ |
| 1358 |
GdkScreen *screen; |
| 1359 |
GdkWaylandScreen *screen_wayland; |
| 1360 |
|
| 1361 |
screen = g_object_new (GDK_TYPE_WAYLAND_SCREEN, NULL); |
| 1362 |
|
| 1363 |
screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 1364 |
screen_wayland->display = display; |
| 1365 |
screen_wayland->width = 0; |
| 1366 |
screen_wayland->height = 0; |
| 1367 |
|
| 1368 |
screen_wayland->visual = gdk_wayland_visual_new (screen); |
| 1369 |
|
| 1370 |
screen_wayland->root_window = |
| 1371 |
_gdk_wayland_screen_create_root_window (screen, |
| 1372 |
screen_wayland->width, |
| 1373 |
screen_wayland->height); |
| 1374 |
|
| 1375 |
init_settings (screen); |
| 1376 |
|
| 1377 |
return screen; |
| 1378 |
} |
| 1379 |
|
| 1380 |
static void |
| 1381 |
_gdk_wayland_screen_class_init (GdkWaylandScreenClass *klass) |
| 1382 |
{ |
| 1383 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 1384 |
GdkScreenClass *screen_class = GDK_SCREEN_CLASS (klass); |
| 1385 |
|
| 1386 |
object_class->dispose = gdk_wayland_screen_dispose; |
| 1387 |
object_class->finalize = gdk_wayland_screen_finalize; |
| 1388 |
|
| 1389 |
screen_class->get_display = gdk_wayland_screen_get_display; |
| 1390 |
screen_class->get_width = gdk_wayland_screen_get_width; |
| 1391 |
screen_class->get_height = gdk_wayland_screen_get_height; |
| 1392 |
screen_class->get_width_mm = gdk_wayland_screen_get_width_mm; |
| 1393 |
screen_class->get_height_mm = gdk_wayland_screen_get_height_mm; |
| 1394 |
screen_class->get_number = gdk_wayland_screen_get_number; |
| 1395 |
screen_class->get_root_window = gdk_wayland_screen_get_root_window; |
| 1396 |
screen_class->get_system_visual = gdk_wayland_screen_get_system_visual; |
| 1397 |
screen_class->get_rgba_visual = gdk_wayland_screen_get_rgba_visual; |
| 1398 |
screen_class->is_composited = gdk_wayland_screen_is_composited; |
| 1399 |
screen_class->make_display_name = gdk_wayland_screen_make_display_name; |
| 1400 |
screen_class->get_active_window = gdk_wayland_screen_get_active_window; |
| 1401 |
screen_class->get_window_stack = gdk_wayland_screen_get_window_stack; |
| 1402 |
screen_class->broadcast_client_message = gdk_wayland_screen_broadcast_client_message; |
| 1403 |
screen_class->get_setting = gdk_wayland_screen_get_setting; |
| 1404 |
screen_class->visual_get_best_depth = gdk_wayland_screen_visual_get_best_depth; |
| 1405 |
screen_class->visual_get_best_type = gdk_wayland_screen_visual_get_best_type; |
| 1406 |
screen_class->visual_get_best = gdk_wayland_screen_visual_get_best; |
| 1407 |
screen_class->visual_get_best_with_depth = gdk_wayland_screen_visual_get_best_with_depth; |
| 1408 |
screen_class->visual_get_best_with_type = gdk_wayland_screen_visual_get_best_with_type; |
| 1409 |
screen_class->visual_get_best_with_both = gdk_wayland_screen_visual_get_best_with_both; |
| 1410 |
screen_class->query_depths = gdk_wayland_screen_query_depths; |
| 1411 |
screen_class->query_visual_types = gdk_wayland_screen_query_visual_types; |
| 1412 |
screen_class->list_visuals = gdk_wayland_screen_list_visuals; |
| 1413 |
} |
| 1414 |
|
| 1415 |
static void |
| 1416 |
_gdk_wayland_screen_init (GdkWaylandScreen *screen_wayland) |
| 1417 |
{ |
| 1418 |
} |
| 1419 |
|
| 1420 |
static void |
| 1421 |
update_screen_size (GdkWaylandScreen *screen_wayland) |
| 1422 |
{ |
| 1423 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (screen_wayland->display); |
| 1424 |
gboolean emit_changed = FALSE; |
| 1425 |
gint width, height; |
| 1426 |
gint width_mm, height_mm; |
| 1427 |
int i; |
| 1428 |
|
| 1429 |
width = height = 0; |
| 1430 |
width_mm = height_mm = 0; |
| 1431 |
for (i = 0; i < display_wayland->monitors->len; i++) |
| 1432 |
{ |
| 1433 |
GdkMonitor *monitor = display_wayland->monitors->pdata[i]; |
| 1434 |
|
| 1435 |
/* XXX: Largely assuming here that monitor areas |
| 1436 |
* are contiguous and never overlap. |
| 1437 |
*/ |
| 1438 |
if (monitor->geometry.x > 0) |
| 1439 |
width_mm += monitor->width_mm; |
| 1440 |
else |
| 1441 |
width_mm = MAX (width_mm, monitor->width_mm); |
| 1442 |
|
| 1443 |
if (monitor->geometry.y > 0) |
| 1444 |
height_mm += monitor->height_mm; |
| 1445 |
else |
| 1446 |
height_mm = MAX (height_mm, monitor->height_mm); |
| 1447 |
|
| 1448 |
width = MAX (width, monitor->geometry.x + monitor->geometry.width); |
| 1449 |
height = MAX (height, monitor->geometry.y + monitor->geometry.height); |
| 1450 |
} |
| 1451 |
|
| 1452 |
if (screen_wayland->width_mm != width_mm || |
| 1453 |
screen_wayland->height_mm != height_mm) |
| 1454 |
{ |
| 1455 |
emit_changed = TRUE; |
| 1456 |
screen_wayland->width_mm = width_mm; |
| 1457 |
screen_wayland->height_mm = height_mm; |
| 1458 |
} |
| 1459 |
|
| 1460 |
if (screen_wayland->width != width || |
| 1461 |
screen_wayland->height != height) |
| 1462 |
{ |
| 1463 |
emit_changed = TRUE; |
| 1464 |
screen_wayland->width = width; |
| 1465 |
screen_wayland->height = height; |
| 1466 |
} |
| 1467 |
|
| 1468 |
if (emit_changed) |
| 1469 |
g_signal_emit_by_name (screen_wayland, "size-changed"); |
| 1470 |
} |
| 1471 |
|
| 1472 |
#ifdef G_ENABLE_DEBUG |
| 1473 |
|
| 1474 |
static const char * |
| 1475 |
subpixel_to_string (int layout) |
| 1476 |
{ |
| 1477 |
int i; |
| 1478 |
struct { int layout; const char *name; } layouts[] = { |
| 1479 |
{ WL_OUTPUT_SUBPIXEL_UNKNOWN, "unknown" }, |
| 1480 |
{ WL_OUTPUT_SUBPIXEL_NONE, "none" }, |
| 1481 |
{ WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, "rgb" }, |
| 1482 |
{ WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR, "bgr" }, |
| 1483 |
{ WL_OUTPUT_SUBPIXEL_VERTICAL_RGB, "vrgb" }, |
| 1484 |
{ WL_OUTPUT_SUBPIXEL_VERTICAL_BGR, "vbgr" }, |
| 1485 |
{ 0xffffffff, NULL } |
| 1486 |
}; |
| 1487 |
|
| 1488 |
for (i = 0; layouts[i].name; i++) |
| 1489 |
{ |
| 1490 |
if (layouts[i].layout == layout) |
| 1491 |
return layouts[i].name; |
| 1492 |
} |
| 1493 |
return NULL; |
| 1494 |
} |
| 1495 |
|
| 1496 |
static const char * |
| 1497 |
transform_to_string (int transform) |
| 1498 |
{ |
| 1499 |
int i; |
| 1500 |
struct { int transform; const char *name; } transforms[] = { |
| 1501 |
{ WL_OUTPUT_TRANSFORM_NORMAL, "normal" }, |
| 1502 |
{ WL_OUTPUT_TRANSFORM_90, "90" }, |
| 1503 |
{ WL_OUTPUT_TRANSFORM_180, "180" }, |
| 1504 |
{ WL_OUTPUT_TRANSFORM_270, "270" }, |
| 1505 |
{ WL_OUTPUT_TRANSFORM_FLIPPED, "flipped" }, |
| 1506 |
{ WL_OUTPUT_TRANSFORM_FLIPPED_90, "flipped 90" }, |
| 1507 |
{ WL_OUTPUT_TRANSFORM_FLIPPED_180, "flipped 180" }, |
| 1508 |
{ WL_OUTPUT_TRANSFORM_FLIPPED_270, "flipped 270" }, |
| 1509 |
{ 0xffffffff, NULL } |
| 1510 |
}; |
| 1511 |
|
| 1512 |
for (i = 0; transforms[i].name; i++) |
| 1513 |
{ |
| 1514 |
if (transforms[i].transform == transform) |
| 1515 |
return transforms[i].name; |
| 1516 |
} |
| 1517 |
return NULL; |
| 1518 |
} |
| 1519 |
|
| 1520 |
#endif |
| 1521 |
|
| 1522 |
static gboolean |
| 1523 |
screen_has_xdg_output_support (GdkScreen *screen) |
| 1524 |
{ |
| 1525 |
GdkDisplay *display = gdk_screen_get_display (screen); |
| 1526 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 1527 |
|
| 1528 |
return (display_wayland->xdg_output_manager != NULL); |
| 1529 |
} |
| 1530 |
|
| 1531 |
static gboolean |
| 1532 |
monitor_has_xdg_output (GdkWaylandMonitor *monitor) |
| 1533 |
{ |
| 1534 |
return (monitor->xdg_output != NULL); |
| 1535 |
} |
| 1536 |
|
| 1537 |
static gboolean |
| 1538 |
should_update_monitor (GdkWaylandMonitor *monitor) |
| 1539 |
{ |
| 1540 |
return (GDK_MONITOR (monitor)->geometry.width != 0 && |
| 1541 |
monitor->version < OUTPUT_VERSION_WITH_DONE); |
| 1542 |
} |
| 1543 |
|
| 1544 |
static gboolean |
| 1545 |
should_expect_xdg_output_done (GdkWaylandMonitor *monitor) |
| 1546 |
{ |
| 1547 |
GdkDisplay *display = GDK_MONITOR (monitor)->display; |
| 1548 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 1549 |
|
| 1550 |
return (monitor_has_xdg_output (monitor) && |
| 1551 |
display_wayland->xdg_output_version < NO_XDG_OUTPUT_DONE_SINCE_VERSION); |
| 1552 |
} |
| 1553 |
|
| 1554 |
static void |
| 1555 |
apply_monitor_change (GdkWaylandMonitor *monitor) |
| 1556 |
{ |
| 1557 |
GDK_NOTE (MISC, |
| 1558 |
g_message ("monitor %d changed position %d %d, size %d %d", |
| 1559 |
monitor->id, monitor->output_geometry.x, |
| 1560 |
monitor->output_geometry.y, |
| 1561 |
monitor->output_geometry.width, |
| 1562 |
monitor->output_geometry.height)); |
| 1563 |
|
| 1564 |
GdkDisplay *display = GDK_MONITOR (monitor)->display; |
| 1565 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (gdk_display_get_default_screen (display)); |
| 1566 |
|
| 1567 |
GdkRectangle logical_geometry; |
| 1568 |
gboolean needs_scaling = FALSE; |
| 1569 |
|
| 1570 |
if (monitor_has_xdg_output (monitor) && |
| 1571 |
monitor->xdg_output_geometry.width != 0 && |
| 1572 |
monitor->xdg_output_geometry.height != 0) |
| 1573 |
{ |
| 1574 |
logical_geometry = monitor->xdg_output_geometry; |
| 1575 |
needs_scaling = |
| 1576 |
logical_geometry.width == monitor->output_geometry.width || |
| 1577 |
logical_geometry.height == monitor->output_geometry.height; |
| 1578 |
} |
| 1579 |
else |
| 1580 |
{ |
| 1581 |
logical_geometry = monitor->output_geometry; |
| 1582 |
needs_scaling = TRUE; |
| 1583 |
} |
| 1584 |
|
| 1585 |
if (needs_scaling) |
| 1586 |
{ |
| 1587 |
int scale = gdk_monitor_get_scale_factor (GDK_MONITOR (monitor)); |
| 1588 |
logical_geometry.y /= scale; |
| 1589 |
logical_geometry.x /= scale; |
| 1590 |
logical_geometry.width /= scale; |
| 1591 |
logical_geometry.height /= scale; |
| 1592 |
} |
| 1593 |
|
| 1594 |
gdk_monitor_set_position (GDK_MONITOR (monitor), logical_geometry.x, logical_geometry.y); |
| 1595 |
gdk_monitor_set_size (GDK_MONITOR (monitor), logical_geometry.width, logical_geometry.height); |
| 1596 |
gdk_monitor_set_connector (GDK_MONITOR (monitor), monitor->name); |
| 1597 |
monitor->wl_output_done = FALSE; |
| 1598 |
monitor->xdg_output_done = FALSE; |
| 1599 |
|
| 1600 |
g_signal_emit_by_name (screen_wayland, "monitors-changed"); |
| 1601 |
update_screen_size (screen_wayland); |
| 1602 |
} |
| 1603 |
|
| 1604 |
static void |
| 1605 |
xdg_output_handle_logical_position (void *data, |
| 1606 |
struct zxdg_output_v1 *xdg_output, |
| 1607 |
int32_t x, |
| 1608 |
int32_t y) |
| 1609 |
{ |
| 1610 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data; |
| 1611 |
|
| 1612 |
GDK_NOTE (MISC, |
| 1613 |
g_message ("handle logical position xdg-output %d, position %d %d", |
| 1614 |
monitor->id, x, y)); |
| 1615 |
|
| 1616 |
monitor->xdg_output_geometry.x = x; |
| 1617 |
monitor->xdg_output_geometry.y = y; |
| 1618 |
} |
| 1619 |
|
| 1620 |
static void |
| 1621 |
xdg_output_handle_logical_size (void *data, |
| 1622 |
struct zxdg_output_v1 *xdg_output, |
| 1623 |
int32_t width, |
| 1624 |
int32_t height) |
| 1625 |
{ |
| 1626 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data; |
| 1627 |
|
| 1628 |
GDK_NOTE (MISC, |
| 1629 |
g_message ("handle logical size xdg-output %d, size %d %d", |
| 1630 |
monitor->id, width, height)); |
| 1631 |
|
| 1632 |
monitor->xdg_output_geometry.width = width; |
| 1633 |
monitor->xdg_output_geometry.height = height; |
| 1634 |
} |
| 1635 |
|
| 1636 |
static void |
| 1637 |
xdg_output_handle_done (void *data, |
| 1638 |
struct zxdg_output_v1 *xdg_output) |
| 1639 |
{ |
| 1640 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data; |
| 1641 |
|
| 1642 |
GDK_NOTE (MISC, |
| 1643 |
g_message ("handle done xdg-output %d", monitor->id)); |
| 1644 |
|
| 1645 |
monitor->xdg_output_done = TRUE; |
| 1646 |
if (monitor->wl_output_done && should_expect_xdg_output_done (monitor)) |
| 1647 |
apply_monitor_change (monitor); |
| 1648 |
} |
| 1649 |
|
| 1650 |
static void |
| 1651 |
xdg_output_handle_name (void *data, |
| 1652 |
struct zxdg_output_v1 *xdg_output, |
| 1653 |
const char *name) |
| 1654 |
{ |
| 1655 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data; |
| 1656 |
|
| 1657 |
GDK_NOTE (MISC, |
| 1658 |
g_message ("handle name xdg-output %d", monitor->id)); |
| 1659 |
|
| 1660 |
g_free (monitor->name); |
| 1661 |
monitor->name = g_strdup (name); |
| 1662 |
} |
| 1663 |
|
| 1664 |
static void |
| 1665 |
xdg_output_handle_description (void *data, |
| 1666 |
struct zxdg_output_v1 *xdg_output, |
| 1667 |
const char *description) |
| 1668 |
{ |
| 1669 |
#ifdef G_ENABLE_DEBUG |
| 1670 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data; |
| 1671 |
|
| 1672 |
GDK_NOTE (MISC, |
| 1673 |
g_message ("handle description xdg-output %d", monitor->id)); |
| 1674 |
#endif |
| 1675 |
} |
| 1676 |
|
| 1677 |
static const struct zxdg_output_v1_listener xdg_output_listener = { |
| 1678 |
xdg_output_handle_logical_position, |
| 1679 |
xdg_output_handle_logical_size, |
| 1680 |
xdg_output_handle_done, |
| 1681 |
xdg_output_handle_name, |
| 1682 |
xdg_output_handle_description, |
| 1683 |
}; |
| 1684 |
|
| 1685 |
static void |
| 1686 |
gdk_wayland_screen_get_xdg_output (GdkWaylandMonitor *monitor) |
| 1687 |
{ |
| 1688 |
GdkDisplay *display = GDK_MONITOR (monitor)->display; |
| 1689 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 1690 |
|
| 1691 |
GDK_NOTE (MISC, |
| 1692 |
g_message ("get xdg-output for monitor %d", monitor->id)); |
| 1693 |
|
| 1694 |
monitor->xdg_output = |
| 1695 |
zxdg_output_manager_v1_get_xdg_output (display_wayland->xdg_output_manager, |
| 1696 |
monitor->output); |
| 1697 |
|
| 1698 |
zxdg_output_v1_add_listener (monitor->xdg_output, |
| 1699 |
&xdg_output_listener, |
| 1700 |
monitor); |
| 1701 |
} |
| 1702 |
|
| 1703 |
static void |
| 1704 |
output_handle_geometry (void *data, |
| 1705 |
struct wl_output *wl_output, |
| 1706 |
int x, |
| 1707 |
int y, |
| 1708 |
int physical_width, |
| 1709 |
int physical_height, |
| 1710 |
int subpixel, |
| 1711 |
const char *make, |
| 1712 |
const char *model, |
| 1713 |
int32_t transform) |
| 1714 |
{ |
| 1715 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *)data; |
| 1716 |
|
| 1717 |
GDK_NOTE (MISC, |
| 1718 |
g_message ("handle geometry output %d, position %d %d, phys. size %d %d, subpixel layout %s, manufacturer %s, model %s, transform %s", |
| 1719 |
monitor->id, x, y, physical_width, physical_height, subpixel_to_string (subpixel), make, model, transform_to_string (transform))); |
| 1720 |
|
| 1721 |
monitor->output_geometry.x = x; |
| 1722 |
monitor->output_geometry.y = y; |
| 1723 |
|
| 1724 |
switch (transform) |
| 1725 |
{ |
| 1726 |
case WL_OUTPUT_TRANSFORM_90: |
| 1727 |
case WL_OUTPUT_TRANSFORM_270: |
| 1728 |
case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1729 |
case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 1730 |
gdk_monitor_set_physical_size (GDK_MONITOR (monitor), |
| 1731 |
physical_height, physical_width); |
| 1732 |
break; |
| 1733 |
default: |
| 1734 |
gdk_monitor_set_physical_size (GDK_MONITOR (monitor), |
| 1735 |
physical_width, physical_height); |
| 1736 |
} |
| 1737 |
|
| 1738 |
gdk_monitor_set_subpixel_layout (GDK_MONITOR (monitor), subpixel); |
| 1739 |
gdk_monitor_set_manufacturer (GDK_MONITOR (monitor), make); |
| 1740 |
gdk_monitor_set_model (GDK_MONITOR (monitor), model); |
| 1741 |
|
| 1742 |
if (should_update_monitor (monitor) || !monitor_has_xdg_output (monitor)) |
| 1743 |
apply_monitor_change (monitor); |
| 1744 |
} |
| 1745 |
|
| 1746 |
static void |
| 1747 |
output_handle_done (void *data, |
| 1748 |
struct wl_output *wl_output) |
| 1749 |
{ |
| 1750 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *)data; |
| 1751 |
|
| 1752 |
GDK_NOTE (MISC, |
| 1753 |
g_message ("handle done output %d", monitor->id)); |
| 1754 |
|
| 1755 |
monitor->wl_output_done = TRUE; |
| 1756 |
|
| 1757 |
if (!should_expect_xdg_output_done (monitor) || monitor->xdg_output_done) |
| 1758 |
apply_monitor_change (monitor); |
| 1759 |
} |
| 1760 |
|
| 1761 |
static void |
| 1762 |
output_handle_scale (void *data, |
| 1763 |
struct wl_output *wl_output, |
| 1764 |
int32_t scale) |
| 1765 |
{ |
| 1766 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *)data; |
| 1767 |
|
| 1768 |
GDK_NOTE (MISC, |
| 1769 |
g_message ("handle scale output %d, scale %d", monitor->id, scale)); |
| 1770 |
|
| 1771 |
/* Set the scale from wl_output protocol, regardless of xdg-output support */ |
| 1772 |
gdk_monitor_set_scale_factor (GDK_MONITOR (monitor), scale); |
| 1773 |
|
| 1774 |
if (should_update_monitor (monitor)) |
| 1775 |
apply_monitor_change (monitor); |
| 1776 |
} |
| 1777 |
|
| 1778 |
static void |
| 1779 |
output_handle_mode (void *data, |
| 1780 |
struct wl_output *wl_output, |
| 1781 |
uint32_t flags, |
| 1782 |
int width, |
| 1783 |
int height, |
| 1784 |
int refresh) |
| 1785 |
{ |
| 1786 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *)data; |
| 1787 |
|
| 1788 |
GDK_NOTE (MISC, |
| 1789 |
g_message ("handle mode output %d, size %d %d, rate %d", |
| 1790 |
monitor->id, width, height, refresh)); |
| 1791 |
|
| 1792 |
if ((flags & WL_OUTPUT_MODE_CURRENT) == 0) |
| 1793 |
return; |
| 1794 |
|
| 1795 |
monitor->output_geometry.width = width; |
| 1796 |
monitor->output_geometry.height = height; |
| 1797 |
gdk_monitor_set_refresh_rate (GDK_MONITOR (monitor), refresh); |
| 1798 |
|
| 1799 |
if (should_update_monitor (monitor) || !monitor_has_xdg_output (monitor)) |
| 1800 |
apply_monitor_change (monitor); |
| 1801 |
} |
| 1802 |
|
| 1803 |
static void |
| 1804 |
output_handle_name (void *data, |
| 1805 |
struct wl_output *wl_output, |
| 1806 |
const char *name) |
| 1807 |
{ |
| 1808 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data; |
| 1809 |
|
| 1810 |
GDK_NOTE (MISC, |
| 1811 |
g_message ("handle name output %d", monitor->id)); |
| 1812 |
|
| 1813 |
g_free (monitor->name); |
| 1814 |
monitor->name = g_strdup (name); |
| 1815 |
} |
| 1816 |
|
| 1817 |
static void |
| 1818 |
output_handle_description (void *data, |
| 1819 |
struct wl_output *xdg_output, |
| 1820 |
const char *description) |
| 1821 |
{ |
| 1822 |
#ifdef G_ENABLE_DEBUG |
| 1823 |
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data; |
| 1824 |
|
| 1825 |
GDK_NOTE (MISC, |
| 1826 |
g_message ("handle description output %d", monitor->id)); |
| 1827 |
#endif |
| 1828 |
} |
| 1829 |
|
| 1830 |
static const struct wl_output_listener output_listener = |
| 1831 |
{ |
| 1832 |
output_handle_geometry, |
| 1833 |
output_handle_mode, |
| 1834 |
output_handle_done, |
| 1835 |
output_handle_scale, |
| 1836 |
output_handle_name, |
| 1837 |
output_handle_description, |
| 1838 |
}; |
| 1839 |
|
| 1840 |
void |
| 1841 |
_gdk_wayland_screen_add_output (GdkScreen *screen, |
| 1842 |
guint32 id, |
| 1843 |
struct wl_output *output, |
| 1844 |
guint32 version) |
| 1845 |
{ |
| 1846 |
GdkDisplay *display = gdk_screen_get_display (screen); |
| 1847 |
GdkWaylandMonitor *monitor; |
| 1848 |
|
| 1849 |
monitor = g_object_new (GDK_TYPE_WAYLAND_MONITOR, |
| 1850 |
"display", display, |
| 1851 |
NULL); |
| 1852 |
|
| 1853 |
monitor->id = id; |
| 1854 |
monitor->output = output; |
| 1855 |
monitor->version = version; |
| 1856 |
|
| 1857 |
g_ptr_array_add (GDK_WAYLAND_DISPLAY (display)->monitors, monitor); |
| 1858 |
gdk_display_monitor_added (display, GDK_MONITOR (monitor)); |
| 1859 |
wl_output_add_listener (output, &output_listener, monitor); |
| 1860 |
|
| 1861 |
GDK_NOTE (MISC, |
| 1862 |
g_message ("xdg_output_manager %p", |
| 1863 |
GDK_WAYLAND_DISPLAY (display)->xdg_output_manager)); |
| 1864 |
|
| 1865 |
if (screen_has_xdg_output_support (screen)) |
| 1866 |
gdk_wayland_screen_get_xdg_output (monitor); |
| 1867 |
} |
| 1868 |
|
| 1869 |
struct wl_output * |
| 1870 |
_gdk_wayland_screen_get_wl_output (GdkScreen *screen, |
| 1871 |
gint monitor_num) |
| 1872 |
{ |
| 1873 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (GDK_WAYLAND_SCREEN (screen)->display); |
| 1874 |
GdkWaylandMonitor *monitor; |
| 1875 |
|
| 1876 |
monitor = display_wayland->monitors->pdata[monitor_num]; |
| 1877 |
|
| 1878 |
return monitor->output; |
| 1879 |
} |
| 1880 |
|
| 1881 |
static GdkWaylandMonitor * |
| 1882 |
get_monitor_for_id (GdkWaylandScreen *screen_wayland, |
| 1883 |
guint32 id) |
| 1884 |
{ |
| 1885 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (screen_wayland->display); |
| 1886 |
int i; |
| 1887 |
|
| 1888 |
for (i = 0; i < display_wayland->monitors->len; i++) |
| 1889 |
{ |
| 1890 |
GdkWaylandMonitor *monitor = display_wayland->monitors->pdata[i]; |
| 1891 |
|
| 1892 |
if (monitor->id == id) |
| 1893 |
return monitor; |
| 1894 |
} |
| 1895 |
|
| 1896 |
return NULL; |
| 1897 |
} |
| 1898 |
|
| 1899 |
static GdkWaylandMonitor * |
| 1900 |
get_monitor_for_output (GdkWaylandScreen *screen_wayland, |
| 1901 |
struct wl_output *output) |
| 1902 |
{ |
| 1903 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (screen_wayland->display); |
| 1904 |
int i; |
| 1905 |
|
| 1906 |
for (i = 0; i < display_wayland->monitors->len; i++) |
| 1907 |
{ |
| 1908 |
GdkWaylandMonitor *monitor = display_wayland->monitors->pdata[i]; |
| 1909 |
|
| 1910 |
if (monitor->output == output) |
| 1911 |
return monitor; |
| 1912 |
} |
| 1913 |
|
| 1914 |
return NULL; |
| 1915 |
} |
| 1916 |
|
| 1917 |
void |
| 1918 |
_gdk_wayland_screen_remove_output (GdkScreen *screen, |
| 1919 |
guint32 id) |
| 1920 |
{ |
| 1921 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 1922 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (screen_wayland->display); |
| 1923 |
GdkWaylandMonitor *monitor; |
| 1924 |
|
| 1925 |
monitor = get_monitor_for_id (screen_wayland, id); |
| 1926 |
if (monitor != NULL) |
| 1927 |
{ |
| 1928 |
g_object_ref (monitor); |
| 1929 |
g_ptr_array_remove (display_wayland->monitors, monitor); |
| 1930 |
gdk_display_monitor_removed (GDK_DISPLAY (display_wayland), GDK_MONITOR (monitor)); |
| 1931 |
g_object_unref (monitor); |
| 1932 |
g_signal_emit_by_name (screen_wayland, "monitors-changed"); |
| 1933 |
update_screen_size (screen_wayland); |
| 1934 |
} |
| 1935 |
} |
| 1936 |
|
| 1937 |
int |
| 1938 |
_gdk_wayland_screen_get_output_refresh_rate (GdkScreen *screen, |
| 1939 |
struct wl_output *output) |
| 1940 |
{ |
| 1941 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 1942 |
GdkWaylandMonitor *monitor; |
| 1943 |
|
| 1944 |
monitor = get_monitor_for_output (screen_wayland, output); |
| 1945 |
if (monitor != NULL) |
| 1946 |
return gdk_monitor_get_refresh_rate (GDK_MONITOR (monitor)); |
| 1947 |
|
| 1948 |
return 0; |
| 1949 |
} |
| 1950 |
|
| 1951 |
guint32 |
| 1952 |
_gdk_wayland_screen_get_output_scale (GdkScreen *screen, |
| 1953 |
struct wl_output *output) |
| 1954 |
{ |
| 1955 |
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen); |
| 1956 |
GdkWaylandMonitor *monitor; |
| 1957 |
|
| 1958 |
monitor = get_monitor_for_output (screen_wayland, output); |
| 1959 |
if (monitor != NULL) |
| 1960 |
return gdk_monitor_get_scale_factor (GDK_MONITOR (monitor)); |
| 1961 |
|
| 1962 |
return 0; |
| 1963 |
} |
| 1964 |
|
| 1965 |
void |
| 1966 |
_gdk_wayland_screen_init_xdg_output (GdkScreen *screen) |
| 1967 |
{ |
| 1968 |
GdkDisplay *display = gdk_screen_get_display (screen); |
| 1969 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 1970 |
int i; |
| 1971 |
|
| 1972 |
GDK_NOTE (MISC, |
| 1973 |
g_message ("init xdg-output support, %d monitor(s) already present", |
| 1974 |
display_wayland->monitors->len)); |
| 1975 |
|
| 1976 |
for (i = 0; i < display_wayland->monitors->len; i++) |
| 1977 |
gdk_wayland_screen_get_xdg_output (display_wayland->monitors->pdata[i]); |
| 1978 |
} |